Calling an EJB 3.1 from an Application-Client

Hello,
I'm currently learning to use the GlassFish3-Features with help of the book "Beginning Java EE 6 Platform with GlassFish 3: From Novice to Professional (Expert's Voice in Java Technology)" from Antonio Goncalves. He says that i should use the following code to get the connection to an EJB:
            EJBContainer ec = EJBContainer.createEJBContainer();
            Context ctx = ec.getContext();
            MyBean ejbInstance = (MyBean) ctx.lookup("java:global/ejb");This does not work because I get a couple of Exceptions telling me that some classes are not serializable. This happens in the "EJBContainer.createEJBContainer() call. The classes wich are mentioned are:
org.glassfish.javaee.services.ConnectorDescriptorProxy
org.glassfish.javaee.services.ResourceProxy
com.sun.enterprise.container.common.impl.util.InjectionManagerImpl
and the application ends after this call.
If I use instead the following code:
{code} Context ctx = new InitialContext();
MyBeanInterface ejbInstance = (MyBeanInterface) ctx.lookup("java:global/ejb");
{code}
it works.
I use GlassFish 3.1 because there is a general bug in V3 for App-client calling an EJB, NetBeans 6.8 and SDK 6_20.
Can anybody shed any light why the first version is not running?
Appending the stack-trace didn't worked out. It was to big.
Thanks and best regards,
Willi

it doesn't work because the lookup call does NOT return an instance of MyBean - it returns a proxy object that implements all the methods of its common interface. Hence you program against the business interface, not the implementation bean. Using this way also, you do not need to have the implementation of MyBean in your client's classpath, only the interface.

Similar Messages

  • How to call OWSM secured web-service from ADF application

    I have a OWSM secured web-service, which takes username/password.
    I want to invoke this webservice from ADF application. ADF application has its own security and it takes its own username/password. End user can't provide the username/password for web-service call. My ADF application should call the webservice and provide it appropriate username/password.
    What is the best practice to handle such scenario. I don't want to hardcode username/password in Java (ADF) code.
    Thanks
    Sanjeev.

    it is not clear to me if you are having problems with calling java code from OIM or if the problem is the web service API.
    Lets do some divide and conquer:
    Can you create a simple java class that just writes a couple of lines to the log? Please attach this code to the OIM task and make sure it runs.
    Once this works we can start looking at the web service call.
    Best regards
    /Martin

  • Calling an EJB 3 SessionBean from a servlet in a Standalone oc4j instance.

    I think that this should be simple, but for some reason can't get it to work.
    Latest version of jDev and oc4j, running on Linux Fedora 5.
    In a jdev application I have ejb and web projects. **EJB 3.0**
    The ejb project is deployed first, then the web project -with the ejb project as its parent-.
    In the ejb project I have a FacadeBean (SLSB) that implements both remote and local as well as Serializable interfaces. (Do I need to implement Serializable?)
    Question:
    How do I get the handle on the FacadeBean from the servlet?
    I tried:
    ic = new InitialContext();
    facade = (Facade)ic.lookup("java:comp/env/ejb/Facade");
    as well as numerous other variations including remote/local stubs, long and short ejb names, facade.getClass().getName, but they all fail!
    This should be simple (if not genned automatically by jDev!) !
    Please advise.
    Thank you.
    nat

    One way of getting the code to do this is to right click on your session bean in JDeveloper and choose "New sample Java Client", then "Connect to a remote OC4J" etc...
    This will create a piece of code that you can then use in your servlet to locate the EJB and invoke it.
    Here is a sample Servlet code:
    public class Servlet1 extends HttpServlet {
        private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
        public void init(ServletConfig config) throws ServletException {
            super.init(config);
        public void doGet(HttpServletRequest request,
                          HttpServletResponse response) throws ServletException, IOException {response.setContentType(CONTENT_TYPE);
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println("<head><title>Servlet1</title></head>");
            out.println("<body>");
            out.println("<p>The servlet has received a GET. This is the reply.</p>");
            try {
                final Context context = getInitialContext();
                SessionEJB sessionEJB = (SessionEJB)context.lookup("java:comp/env/ejb/SessionEJB");
                // No Remote methods found
            String a = sessionEJB.sayHi("joe");
            out.println(a);
            } catch (Exception ex) {
                ex.printStackTrace();
            out.println("</body></html>");
            out.close();
        private static Context getInitialContext() throws NamingException {
            Hashtable env = new Hashtable();
            //  Standalone OC4J connection details
            env.put( Context.INITIAL_CONTEXT_FACTORY, "oracle.j2ee.naming.ApplicationClientInitialContextFactory" );
            env.put( Context.SECURITY_PRINCIPAL, "oc4jadmin" );
            env.put( Context.SECURITY_CREDENTIALS, "welcome" );
            env.put(Context.PROVIDER_URL, "ormi://localhost:23791/ejb1");
            return new InitialContext( env );
    }

  • Create a batch file that will loop a copy command that will call it as a task from another application

    I've created a script to copy large files from one system to another system. Unfortunately the transaction language of that system isn't feature rich, so I can't code a loop to copy multiple files to move concurrently. My goal is to create a batch file that
    will do the loop of copying multiple files, after being called by the application that is copying the large files one at a time. Can I get some pointer on how to do this? Basically, the code is like this:
    Copy from  \\Server_1\directory\sent_file.xyz
    To   \\Server_2\Directory\received_file.abc
    So the purpose is to perform the successful copy, then if the copy is good, execute the loop until completed.

    Might look around here.
    http://gallery.technet.microsoft.com/scriptcenter/site/search?f%5B0%5D.Type=RootCategory&f%5B0%5D.Value=storage&f%5B0%5D.Text=Storage
    Or ask over here.
    MSDN Scripting forum
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • Ejb 3 injection from another application on glassfish v2

    hi, i need help probably with some links
    there is an ejb3 module (1) that is deployed in glassfish. it contains beans:
    package org.bambrikii.administrator.logic;
    @javax.ejb.Stateless
    public class AdministratorServiceBean implements AdministratorServiceRemote{
        @javax.persistence.PersistenceContext(unitName = "accountService")
        protected javax.persistence.EntityManager em;
        // Users
        public List getUsers() {
         if (this.em != null) {
             try {
              return this.em.createNamedQuery("User.getList").getResultList();
             } catch (NoResultException e) {
         return null;
    package org.bambrikii.administrator.logic;
    @javax.ejb.Remote
    public interface AdministratorServiceRemote {
    public List getUsers();  
    }on the same app server i deploy a war module (2). could you help me how can i inject (1) beans in this war? probably something like this?:
    package org.bambrikii.administrator.logic;
    public class UserBean {
        @javax.ejb.EJB
        public AdministratorServiceRemote administratorServiceBean;
    }thanks in advance
    Edited by: Bambrikii on Dec 10, 2007 6:22 PM

    This is covered in our EJB FAQ :
    https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#mappingRemoteejbdependency

  • Calling IBM content Manager  images from Oracle APplications

    Gurus,
    The requirement is like this
    the Images are stored in IBM content Mgr.Client want to show the image for a particular employee from the content mgmt.
    If anybody have pointers please share with me
    [email protected]
    Regards,
    -Chandra Sekhar Byna

    Hi!
    So if you use forms 10 you can use the read_image_file build-in like:
    read_image_file ( 'image_url', 'url', 'block.image_item' );Regards

  • Calling 8i EJB's/BC4J from OAS

    Can someone tell me, or show me some sample code for OAS java classes on how to contect to deployed 8iEJB's and use of deployed BC4J?

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by profictjeroen:
    Can someone tell me, or show me some sample code for OAS java classes on how to contect to deployed 8iEJB's and use of deployed BC4J?<HR></BLOCKQUOTE>
    OTN has sample code for OAS here: http://technet.oracle.com/sample_code/products/oas/listing.htm
    For EJB samples, visit: http://technet.oracle.com/sample_code/tech/java/ejb_corba/listing.htm
    Here's a new BC4J sample app: http://technet.oracle.com/products/bc4j/index2.htm?Code&listing.htm
    Thanks,
    -rh
    null

  • Calling a webservice(JAX-RPC) from non java client ?

    Hi,
    I read JAX-RPC is used for accessing webservices by calling the webservice methods from a java-based client.
    Is it possible to call the Webservice methods(writeen using jax-rpc) from a non-java client,who sends his request in the form of SOAP based calls?
    If JAX-RPC is not the correct one to call a RPC from a non-java client,In what way i can do this?
    Can anyone please clarify my doubt..,
    Thanks in Advance
    Rao.,

    Hi Arun,
    Can i write a my client program using cgi scripts?
    In the JAX-RPC docs it was said that i can invoke my Webservices through my Service endpoints or using WSDL location?
    If iam using a Non-java Client,it will be easier(I think) to use the WSDL file to call the Web-Service(deployed using JAX-RPC).But,the Client should be aware of that WSDL file.
    I have to develop a small Application using webServices(must use XML,SOAP technologies).The user will pass some Parameters as request and the Response should be an XML(SOAP message) message.User should be able to request via browser.(http://localhost:8080/)
    Can you please suggest me which technology is correct to use,so that i can use the XML,SOAP in it.
    Please let me know...,
    thank you once again..,
    Regards
    Rao.,

  • Calling JCO RFC Server program from JCO RFC client

    Hi,
    I have an RFC registered server program which implements JCO.Server.  It seems to be working fine, when called from SAP.
    For testing purposes, I was trying to write a JCO client program which would take the place of the SAP client.
    This program opens a connection to the RFC server and executes a function e.g.
    JCO.Client client = JCO.createClient("xx.yy.com", "sapgw35", "MYPROGID");
    client.connect();
    client.execute(function);
    The RFC server program receives the call fine, when I test with a simple function which has no table parameters.  However when I tried a more complex function with table parameters, I get an serverExceptionOccurred from the RFC server program:
    com.sap.mw.jco.JCO$Exception: (104) RFC_ERROR_SYSTEM_FAILURE: connection closed without message (CM_NO_DATA_RECEIVED)
        at com.sap.mw.jco.rfc.MiddlewareRFC$Server.nativeListen(Native Method)
        at com.sap.mw.jco.rfc.MiddlewareRFC$Server.listen(MiddlewareRFC.java:1368)
        at com.sap.mw.jco.JCO$Server.listen(JCO.java:6805)
    I have tried to initialize the repositories in both server and client programs correctly, so that the function is in the cached function list and the table structures in the cached structures list before the function is invoked.  But I am not sure if there is still something I am missing, so any ideas would be welcome.
    Thanks,
    Richard

    JCO example 5 is a very good one for server side programming.
    try the example,somethings you 'd better make clear.
    1) JCO.server
    2) repositories--data mapping
    3) parameters: export import,table...
    further topic:
    1) JCO pool
    2) tRFC,qRFC
    After you have success in Client side programming,try example 5.
    Regards

  • Calling an EJB throws an UNKNOWN exception

    Hi EJB experts!
    I`m trying to call an EJB on OAS from Java application running within a JDeveloper. After several calls of remote method the application invokes the remote method again but exception
    java.rmi.UnexpectedException: CORBA: org.omg.CORBA.UNKNOWN: get a timeout exception; nested exception is:
    org.omg.CORBA.UNKNOWN: get a timeout
    is thown.
    class Context {
    public java.sql.Connection conn;
    public EJBRemote logger;
    Reference to a remote EJB is stored in class Context. Instance of Context is shared among three other objects. Strange thing is that whether the exception is thrown or not depends on the number of method calls on objects accessing the Context. In any case remote method completes successfuly. Do you have an idea what to do with this exception?
    Thanks for any advice. David Mrva

    http://www.jboss.org/online-manual/HTML/ch11s21.html

  • Calling workbook from oracle application 11.03

    hi,
    i want to call one report of discoverer from oracle application 11.03 request set.if any one has done this ever or have any idea how should i do this,please reply back.
    thanks in anticipation
    null

    hi,
    this will help u in solving the problem.
    This can be simply achieved via the following steps:
    Add a 'Push Button' to an existing form, where you wish Discoverer to be run from.
    Add a standard 'WHEN_BUTTON_PRESSED' trigger to this button.
    Edit the trigger to insert the HOST command referencing the Discoverer executable(including the full path), plus the command line options you require. An example of this is shown below:
    HOST('C:\ORAWIN95\DISCVR31\DIS31USR.EXE /CONNECT SCOTT/TIGER /OPENDB TESTQUERY1 /SHEET ALL');
    In this example, command line options have been appended to the Discoverer executable to first connect as a specific user, then open a Workbook that has been saved to the database, and then run all the sheets in the workbook. These command line functions are optional and there are others that can be used to perform various functions. For more information on the complete Command Line options available, see Chapter 13, section 13.3, of the Discoverer 3.1 Administration Guide or see the following WebIV Note copy of the same:
    Note.68739.1 - Complete Command Line Options for Discoverer 3.1(Admin & User Edition)
    Other references
    For command line options available with the 3.0.8 release of Discoverer(which were only available for the 'User Edition' in this release), see the following note:
    Note.44841.1 - Command Line Parameters With Discoverer 3.0 User Edition
    bye
    raj

  • How to call  Java method from SAPUI5 applications?

    Hi Experts,
        Please give me information that how can I call Java method or jars from SAPUI5 applications?
    Thanks,
    Nag

    Hello Nag,
    why do open this thread in BRM Space? I would suggest reopen this in "UI Development Toolkit for HTML5 Developer Center" Space.
    Regards,
    Tobias

  • How to execute any cmd command from java application?

    Hi all,
    How to execute or call any command of cmd from java application??
    Is there any method to do so??
    Or, is it possible to do it using Runtime.exec() ??? And if so, how to use it, please explain with ab example...
    I'll highly appreciate....
    Thank you.

    If google would be the best option, then I would not be on Sun's forums and I would not have asked experts like you, sir !! :-)
    Neway, I got the solution from PhHein !!
    Good link indeed..
    Cheers..

  • Application client / jndi

    hello
    how can i get access to a bean running on a application server from a application client that doesn't run i a container ( is not statred e.g. with suns runclient -client... ). what do i have to write in my lookup(..) call? lookup(java:comp/env/ejb...) doesn't work. ( errormessage: " can use java:comp/env only from a j2ee component".)
    thanks

    You can use the following code to get the reference to Context
    * url - url of the app server
    * username - username for accessing the appserver
    * password - password for accessing the appserver
    public static Context getInitialContext(String url, String username, String password)
    Context context = null;
    try
    Properties prop = new Properties();
    prop.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    prop.put(Context.PROVIDER_URL, url);
    prop.put(Context.SECURITY_PRINCIPAL, username);
    prop.put(Context.SECURITY_CREDENTIALS, password);
    context = new InitialContext(prop);
    catch (NamingException ne)          
    ne.printStackTrace();     
    return context;          
    "weblogic.jndi.WLInitialContextFactory" is a class specific to WebLogic. You should refer to the documentation for the app server you are using for this fully qualified class name

  • Using JAAS on an Application Client Container

    I am trying to authenticate users who are going to be accessing
    EJBs from an Application Client Container developed using AWT/Swing.
    I am able to authenticate users accessing these EJBs via the Web Client.
    But some how I get the following error when I run the ACC client:
    Nov 11, 2004 3:47:30 PM com.sun.enterprise.security.auth.login.PasswordLoginModule login
    SEVERE: SEC1105: A PasswordCredential was required but not provided.
    I have tried lc.login with/without the subject and/or principal with the same result.
    Here is the login code
    // Obtain a LoginContext, needed for authentication. Tell
    // it to use the LoginModule implementation specified by
    // the entry named "jdbcRealm" in the JAAS login
    // configuration file and to also use the specified
    // CallbackHandler.
    LoginContext lc = null;
    NameCallback namecb = new NameCallback( "Enter User name: " );
    PasswordCallback passwdcb = new PasswordCallback( "Enter password: ", true );
    Callback[] callbackparm = new Callback[2];
    callbackparm[0] = namecb;
    callbackparm[1] = passwdcb;
    try {
    System.out.println( "entering atUser: login()" );
    //TextCallbackHandler callback = new TextCallbackHandler();
    DialogCallbackHandler callback = new DialogCallbackHandler();
    callback.handle( callbackparm );
    //lc = new LoginContext( "jdbcRealm", callback );
    System.out.println( "entering atUser: login() namecb.getName() = " + namecb.getName() );
    System.out.println( "entering atUser: login() passwdcb.getPassword() = " +
    passwdcb.getPassword() );
    PasswordCredential pwd = new PasswordCredential (namecb.getName(), passwdcb.getPassword() );
    System.out.println( "entering atUser: login() PasswordCredential pwd = " + pwd );
    Subject subject = new Subject();
    //subject.getPrincipals().addAll(tempPrincipals);
    if (!subject.getPrincipals().contains(pwd)) {
    Principal principal = new X500Principal( "CN=JdbcRealm,OU=AkanTech,O=Akan Technology, C=US" );
    subject.getPrincipals().add( principal );
    System.out.println( "entering atUser: login() subject.getPrincipals().add(pwd) = " +
    subject.getPrincipals() );
    if (!subject.getPrivateCredentials().contains(pwd)) {
    subject.getPrivateCredentials().add( pwd );
    subject.getPublicCredentials().add( pwd );
    System.out.println( "entering atUser: login() subject.getPrivateCredentials().add(pwd) = " +
    subject.getPrivateCredentials() );
    System.out.println( "entering atUser: login() subject.getPrivateCredentials().add(pwd) = " +
    subject.getPrivateCredentials() );
    lc = new LoginContext( "jdbcRealm", subject, callback );
    System.out.println( "entering atUser: login() loginContext = " + lc );
    System.out.println( "entering atUser: login() lc.getSubject() = " + lc.getSubject() );
    } catch (LoginException le) {
    System.err.println("atUser login() LoginException: Cannot create LoginContext: " +
    le.getMessage());
    System.exit( -1 );
    } catch (SecurityException se) {
    System.err.println("atUser login() SecurityException: Cannot create LoginContext: " +
    se.getMessage());
    System.exit( -1 );
    //} catch (UnsupportedCallbackException se) {
    //System.err.println("atUser login() UnsupportedCallbackException: Cannot create LoginContext: " +
    se.getMessage());
    //System.exit( -1 );
    } catch (Exception se) {
    System.err.println("atUser login() Exception: Cannot create LoginContext: " + se.getMessage());
    System.exit( -1 );
    try {
    // attempt authentication
    lc.login();
    } catch (LoginException le) {
    System.err.println( "atUser login() LoginException Authentication failed: " + le.getMessage() );
    System.exit( -1 );
    System.out.println( "atUser login() Authentication succeeded!" );
    Here is the content of: appclientlogin.conf
    /* Copyright 2004 Sun Microsystems, Inc. All rights reserved. */
    /* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */
    default {
         com.sun.enterprise.security.auth.login.ClientPasswordLoginModule required debug=false;
    certificate {
         com.sun.enterprise.security.auth.login.ClientCertificateLoginModule required debug=false;
    jdbcRealm {
         com.akantech.security.jdbcrealm.JDBCLoginModule required debug=false;
    Here is the content of sun-acc.xml.
    I have tried with/without the client-credential entry with the same result.
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    Copyright 2004 Sun Microsystems, Inc. All rights reserved.
    SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
    -->
    <!DOCTYPE client-container PUBLIC "-//Sun Microsystems Inc.//DTD Application Server 8.0 Application Client Container//EN" "http://www.sun.com/software/appserver/dtds/sun-application-client-container_1_0.dtd">
    <client-container>
    <target-server name="winxppro" address="winxppro" port="3700"/>
    <log-service file="C:/Sun/AppServer/lib/appclient/logs/client.log" level="WARNING"/>
    <auth-realm classname="com.akantech.security.jdbcrealm.JDBCRealm" name="jdbc">
    <property name="dbdrivername" value="com.ibm.db2.jcc.DB2Driver"/>
    <property name="auth-type" value="jdbccustomrealm"/>
    <property name="dburl" value="jdbc:db2://localhost:50000/authuser"/>
    <property name="jaas-context" value="jdbcRealm"/>
    </auth-realm>
    <client-credential user-name="admin" password="akantech" realm="jdbc"/>
    </client-container>
    What am I missing?
    I have read the following documentation but cant seem to figure out what I am missing.
    http://docs.sun.com/source/819-0079/dgdesc.html#wp130029
    http://docs.sun.com/source/819-0079/dgsecure.html
    http://docs.sun.com/source/819-0079/dgsecure.html#wp32713
    http://java.sun.com/security/jaas/doc/api.html
    http://java.sun.com/security/jaas/doc/module.html
    http://java.sun.com/j2se/1.4.2/docs/guide/security/jaas/tutorials/index.html
    I added a lot of log info in the JDBCLoginModule : authenticate() method.
    It seems to me like the authenticate() method is never called. Because nothing is
    logged from this method.
    Thanks a million
    Stephen

    I have not been able to figure this one out yet so put it on the
    back burner.
    I am still waiting for an answer.
    Did you find the answer?

Maybe you are looking for

  • How do I get my pic's off of I cloud

    after my pic's are backed up from the cloud how do I get them back?

  • Analyze table to flush cache

    Hi In the Oracle 8i Concepts book it states that "when the ANALYZE statement is used to update or delete the statistics of a table, cluster, or index, all shared SQL areas that contain statements referencing the analyzed schema object are flushed fro

  • What happened to Java2 SDK 1.4.0-beta3?

    I have Java2 SDK 1.4.0-beta3 on my computer. I was going to re-download this program because I suspect some files have become corrupted. But I don't see it anymore on the download page. Instead I see things called J2 JRE 1.4.0 or J2 SDK 1.3.0 or J2 1

  • Oracle Upgrade for Portal EP6 SP14

    Hi, I have upgraded oracle 9.2.0.6 to 10.2.0 and applied all the latest patch for Oracle. After upgrading the oracle when i try to logon to Portal iam getting error "Portal Runtime Error An exception occurred while processing a request for : iView :

  • Different user privileges in Rules Author

    In the Rules Author is there a way to specify users that have different privileges/rights? I want to create users that have the rights to create Rules using Facts and Variables, and other users who only have the rights to modify Variables but not Rul