EJB Client/Resource Injection

Hi,
could anyone explain to me why the field into which an EJB reference in an EJB client can be injected has to be static? I've read the following in the EJB3.0 tutorial (see below), but I don't know what "static context" means exactly. Care to explain, anyone?
Thanks, Michael
Creating a Reference to an Enterprise Bean Instance
"Java EE application clients refer to enterprise bean instances by annotating static fields with the @EJB annotation. The annotated static field represents the enterprise bean's business interface, which will resolve to the session bean instance when the application client container injects the resource references at runtime.
@EJB
private static Converter converter;
The field is static because the client class runs in a static context."

The question was about why the field needs to be marked static. mappedName is a separate issue. The reason injected fields/methods in Application Clients need to be marked static is because of the Application Client programming model. It has always been the case that for an Application Client component the developer writes a static void main() method as the entry point, much like a regular Java Client. This means that the Application Client container invokes the application code with a static invocation, i.e. there is no instance of the main class. Injection is only useful if it takes place before the application code runs, so to accomplish that without changing the Application Client programming model, the Java EE platform spec requires that injected fields/methods be marked static.
As for mappedName, it deals with how to map the ejb dependency to the target bean. By default in SUN's implementation, the remote @EJB dependency will map to the global JNDI name formed by taking the fully qualified type of the remote business interface, in this case <packagename>.Converter. That will work as long as the target Remote EJB has that global JNDI name. If the target Remote EJB's global JNDI name were "GlobalJNDIName", then you would need to explicitly assign that to the client's ejb dependency, as this example shows. That can be done either by using the mappedName() attribute or sun-application-client.xml.
--ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Injecting ejbs via @Resource

    Hi all,
    I have an ejb that injects a helper ejb like
    @EJB
    Helper help; and whose business method calls the helper beans business method. This works fine.
    Now I try to inject the helper ejb as
    @Resource(name="Helper") 
    Helper help; The first call of the ejb's business method from the client works fine, but the second one throws the following exception (extract):
    org.omg.CORBA.BAD_OPERATION: The delegate has not been set!
    Please, can someone, who has an ejb that injects another ejb, check if he gets the same problem when @EJB is replaced through something like @Resource(name = ...).
    Thanks in advance.
    I googled for the error message and found search results dating from around 2004 where the error was due to a bug in the Java-IDL mapping of an old java version. I'm working with glassfish v2 and java 1.6.

    Hi, thanks for your reply.
    Is there a particular behavior you would like that you don't think is available when using @EJB?No. I read in "EJB 3 in action", 5.2.1 that @Resource can "be used for [...] environment entries, ORB reference and even EJB references" and just tried it out.

  • When to use @Resource and when to use @EJB for dependency injection

    Hi,
    When do you use
    @Resource and when do you use @EJB for dependency injection?
    Thanks

    Captain obvious: Use @EJB for injection of EJBs, and @Resource for everything else.
    There was a discussion about this very topic quite recently, perhaps you can find it through the search.

  • Resource Injection in Web Tier (JSP and Servlets)

    Hi All
    I was wondering whether someone will be kind enough enough to clear this up for me as it causing me some confusion. I am using OC4J 10.1.3.4 and Java 5. I have been reading the documentation on OC4J and at one point it says that OC4J does not support resource injection(i.e. annotations) in the web tier and you'll have to use JNDI to access resources such as EJBs from the Web tier(see Sub heading Servlet or JSP Client on http://download.oracle.com/docs/cd/B25221_04/web.1013/b14428/usclient.htm) but at other points in the documentation, it seems to suggest that that resource injection is supported see(http://database.in2p3.fr/doc/oracle/Oracle_Application_Server_10_Release_3/web.1013/b28221/undejbs001.htm#CIHFEJAC).
    I am just wondering what the definitive answer is. Does OC4J support resource injection in the web client(in particular, JSP) or not. BTW I am trying to inject an EJB into a JSP client. It doesn't seem to work with resource injection but works OK with JNDI.
    Thanks

    Does any one have any sort of explanation on this?

  • Ejb Client

    I'm getting the following error in EJB CLient
    plz telle me some solutions ..
    NamingException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    Thanks in Adv
    Srini

    Please see the documentation
    Oracle Application Server Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (9.0.4) Part Number B10324-01
    http://download-uk.oracle.com/docs/cd/B10464_04/web.904/b10324/primer.htm#1020065
    Example 2-6 A Servlet Acting as a Local Client
    Example 2-7 A Java Client as a Remote Client
    Hope that helps.

  • EJB Client - basic programming principles

    Hello,
    I'm new to the EJB world, can someone please give me some giudelines on basic programming principles on how to write a simple EJB client ?
    Thanx people!
    Son

    We have some very simple "hello, world" examples here :
    https://glassfish.dev.java.net/javaee5/ejb/EJB30.html
    There is also an EJB FAQ :
    https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html
    Another resource is the Java EE 5 Tutorial :
    http://java.sun.com/javaee/5/docs/tutorial/doc/
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • EJB client session

    What is an EJB client session? How many are there? When does it start and when does it end? Who controls that?
    Thank you.

    You may be thinking of a Stateful Session Bean. Each stateful session bean has state that is tied to a
    particular client. In EJB 3.0, the stateful session bean is created when the client does a naming
    lookup or has the stateful session bean injected. The client can remove the stateful session bean at
    any time by calling a method annotated with the @Remove annotation.
    The container can also choose to remove a stateful session bean. Typically, the container vendor
    provides configuration options that specify the stateful session bean timeout parameters.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • [Jeveloper + EJB client - EJB on OAS] Problem connecting

    I having problems getting a simple client from within JDeveloper 3.0(Code snippet - OAS/EJB Client) talking to a simple EJB on OAS 4.0.8.
    I have deployed OK (red flag against status?) but when I run the client using port - 5512(ORB port)I get the message below
    Anybody any ideas?
    Creating an initial context
    Looking for the EJB published as 'MyOASApp/MyEJB'
    Naming exception occurred!
    Cause: This may be an unknown URL, or some classes required by the EJB are missing from your classpath, or your OAS host is short of resources
    Suggestion: Check the components of the URL, and make sure your project includes a library containing the EJB .jar files generated by the deployment utility.
    [Root exception is java.net.UnknownServiceException: no content-type]javax.naming.NamingException: Failure to access http://hfxcap4:5512/ows-bin/rmproxy.ior; listener inaccessible or configured wrongly
    at oracle.oas.jndi.oas.SiteResolver.getIOR(Compiled Code)
    at oracle.oas.jndi.oas.SiteResolver.resolveListenerURL(Compiled Code)
    at oracle.oas.jndi.oas.SiteResolver.resolveSiteContact(Compiled Code)
    at oracle.oas.jndi.oas.SiteResolver.resolveSiteContact(Compiled Code)
    at oracle.oas.jndi.oas.SiteResolver.resolveSiteObject(Compiled Code)
    at oracle.oas.jndi.oas.BeanInitialContext.resolve(Compiled Code)
    at oracle.oas.jndi.oas.BeanContext.lookup(Compiled Code)
    at oracle.oas.jndi.oas.BeanInitialContext.lookup(Compiled Code)
    at oracle.oas.jndi.oas.WrapperContext.lookup(Compiled Code)
    at oracle.oas.jndi.oas.BeanContext.lookup(Compiled Code)
    at javax.naming.InitialContext.lookup(Compiled Code)
    at package1.MyOASAppClient.main(Compiled Code)
    **************

    HI, I have the same problem that you had, maybe did you manage through ?? Thanks for all the help you could bring me.
    Nico
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by pFrooney:
    Back Again ...
    I have tried all ao the above
    now using this code below but it fails on the lookup with the error message below:
    ..created library with client stub, using 1.1.8, moved OASRuntime to top of included libraries
    Any suggestions
    String oasUrl = "oas://hfxcap4:80";
    String oasEJB = "MyOASApp/MyEJB" ;
    // Setup the environment
    Hashtable environment = new Hashtable();
    // Turn JNDI on to OAS
    environment.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "oracle.oas.naming.jndi.RemoteInitCtxFactory");
    // Lookup the URL
    conv_package.MyEJBHome homeInterface = null;
    try {
    System.out.println("Creating an initial context");
    // Get initial JNDI context
    Context site = (Context) ((new InitialContext(environment)).lookup(oasUrl));
    org.omg.CORBA.COMM_FAILURE:
    at oracle.oas.orb.CORBA.Request._invoke(Compiled Code)
    at oracle.oas.orb.CORBA.Delegate._invoke(Compiled Code)
    at org.omg.CORBA.portable.ObjectImpl._invoke(Compiled Code)
    at oracle.oas.orb.CORBA.Delegate.is_a(Compiled Code)
    at org.omg.CORBA.portable.ObjectImpl._is_a(Compiled Code)
    at oracle.oas.jndi.oas.BeanInitialContext.resolve(Compiled Code)
    at oracle.oas.jndi.oas.BeanContext.lookup(Compiled Code)
    at oracle.oas.jndi.oas.BeanInitialContext.lookup(Compiled Code)
    at oracle.oas.jndi.oas.WrapperContext.lookup(Compiled Code)
    at oracle.oas.jndi.oas.BeanContext.lookup(Compiled Code)
    at javax.naming.InitialContext.lookup(Compiled Code)
    at CClient_package.MyOASAppClient.main(Compiled Code)<HR></BLOCKQUOTE>
    null

  • Resource injection in tag handler

    I can't seem to find a straight answer for this anywhere. Using release 9.1 of the Sun Application Server, should resource injection in a tag handler be working? Tak something really simple like this:
    public class TestHandler extends SimpleTagSupport {
        @EJB SomeEJBLocal beanInstance;
        public void doTag() throws JspException {
    } When I try this, beanInstance is null. Is this a configuration issue or does this just not work yet?

    Found the answer myself. When the web module was being ported over, the web.xml was copied as-is. It still had version 2.4 as an attribute to the web-app element. Changing the attributes to match a newly created 2.5 version fixed the problem.

  • Using JarSettings to generate EJB client jar, but supported classes missed

    Appreciated for any comments in advance.
    I am using @jarSetting to generate EJB client jar file from workshop 9.2. The remote method of EJB has one input parameter that is defined as an interface. The interface is included in client jar, but the implementation of this interface is not.
    Please advise how I can add the implementation of this interface to client jar?
    Best Regards,
    James

    Hi James,
    I believe the algorithm for creating the client jar is to simply inspect the EJB interfaces using reflection and to include all user defined classes and exceptions that are referenced by the interfaces. In your case, it sounds like a class is not being included because it is not directly referenced by one of the EJB interfaces.
    I think the client jar creation algorithm can be described as "best effort" and unfortunately, it does not always end up including all classes needed by the client. I would recommend you add the additional classes manually using the jar tool.
    - Matt

  • How can I run EJB Client in other computer ?

    Hello,
    I'm trying to run converter examples.
    if ejb client pgm resides on a same machine with j2ee server , it works fine.
    But when I put client pgm on a different maching
    below message show.
    No application client descriptors defined for: ConverterClinet
    I put ConverterApp.ear, ConverterAppClient.jar and ConverterClient.class on the machine and
    set APPCPATH=ConverterAppClient.jar
    set VMARGS=-Dorg.omg.CORBA.ORBInitialHost=xxx.xxx.xx.xx
    What should I do to run ejb client on different machine?

    Hi SangHPark,
    I had the same problem but have solved it and it works.
    I ran the client remotely from a win98 box.
    Keep two things in mind
    1> Deploy the applications to an ip address and not to the local host using the deploy too. Use the deploy tool Gui to add a new server and then deploy the application to this ip address.
    2> I am running j2ee version 1.3 and jsdk 1.3
    Use the following code but instead of using "java:comp/env/ejb/SimpleConverter" use the jndi name of the object: "MyConverter" as specified in the tutorial.
    Properties prop = new Properties();
    prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sun.enterprise.naming.SerialInitContextFactory");
    prop.setProperty(Context.PROVIDER_URL,"IIOP://xxx.xx.x.xxx:1050");
    System.out.println("Attempting to create context...");
    Context initial = new InitialContext(prop);
    // Instead of this use the below line of code
    //Object objref = initial.lookup("java:comp/env/ejb/SimpleConverter");
    Object objref = initial.lookup("MyConverter");
    // MyConverter is the Jndi name of the ConverterBean as per the tutorial
    You need to do the following things.
    1> After making changes to the code recompile using Ant and redeploy it.
    2> Copy the j2ee.jar, ConverterAppClient.jar and ConverterClient.class file to the machine that u want to run the client from.
    3> create a directory called "config" on the remote machine where you copied the files in step two.
    4> Copy to this directory the files ejb.properties and security.properties from your j2ee_home\config\ directory.
    For example you copied the files in step 2 on the remote machine in the c:\test directory. Create c:\test\config directory and copy the files from step 4 into this directory.
    5> Run the following command from the directory where u copied the client files
    java -Dorg.omg.CORBA.ORBInitialHost="host name" -classpath .\j2ee.jar;.;.\ConverterAppClient.jar ConverterClient
    Monal

  • Error in running EJB Client on a remote machine

    I delploy my beans and can run the EJB Client locally. However when I try to run the Client on another machine, there are errors.
    Here is the errors
    Syntax error
    Out of environment space
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/enterprise/appclient/Main
    I have follow the step in the j2ee tutorial and set the env variables according. Here is the bat file I write
    set APPCPATH=CBSAppClient.jar
    set VMARGS=-Dj2eelogin.name=guest -Dj2eelogin.password=guest123 -Dorg.omg.CORBA.ORBInitialHost=192.168.0.2
    runclient -client CBSApp.ear -name CBSClient -textauth
    Do anyone facing the same problem with me?
    And how can I solve the problems?
    This is really URGENT, please help

    You are running on Windows 9x or Me, right? The darn OS has 300 or so bytes allocated for environment by default.
    Try setting the Initial environment to 4096 in the Properties|Memory tab for the batch file. That will get rid of "Out of environment space". The syntax error is another matter; Windows (except NT and derivatives) shells do not allow '=' in an environment variables value. You cannot overcome that. Some software (Sybase for instance) interprets # as = just because of that. Unfortunately, the JVM doesn't take such an approach.
    Better, grab copies of Unix utilities for Windows (www.gnu.org) including the wonderful shell 'bash' and write .sh scripts, which are inherently more powerful.

  • Steps to deploy an ejb application and running an ejb client in weblogic server6.1

    steps to deploy an ejb application and steps to run an ejb client in weblogic server6.1
    if the client is an simple java application and if the client is a servlet

    Hi.
    Check out the beanManaged example that ships with WLS and read the accompanying docs. This
    is a simple EJB with a servlet that invokes it.
    Michael
    shekhar sachdev wrote:
    steps to deploy an ejb application and steps to run an ejb client in weblogic server6.1
    if the client is an simple java application and if the client is a servlet--
    Michael Young
    Developer Relations Engineer
    BEA Support

  • EJB Client Access From JDeveloper9iR2

    I seem to be running into a lot of problems when trying to get a simple EJB client to talk to an EJB on our 9IAS platform. I have developed a simple session bean (just to test) which simply returns a string. When I create the default client code this works fine using the embedded OC4J server in Jdeveloper but I can't run a similar client against 9IAS when I deploy the code. When I go through the client wizard it seems to produce the same code as the standalone EJB OC4J client. I simply changed the name of the server (Context.PROVIDER_URL, "ormi://pe2500/). This is the parameter code I use:
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.SECURITY_PRINCIPAL, "admin");
    env.put(Context.SECURITY_CREDENTIALS, "welcome");
    env.put(Context.PROVIDER_URL, "ormi://pe2500:23891/MyEJBs");
    This is the output I receive:
    D:\jdeveloper9ir2\jdk\bin\javaw.exe -ojvm -classpath D:\javadev\ejbservlet\ejbservlet\WEB-INF\classes;D:\jdeveloper9ir2\jdev\lib\jdev-rt.jar;D:\jdeveloper9ir2\j2ee\home\lib\ojsp.jar;D:\jdeveloper9ir2\j2ee\home\jsp\lib\taglib\ojsputil.jar;D:\jdeveloper9ir2\j2ee\home\oc4j.jar;D:\jdeveloper9ir2\j2ee\home\lib\servlet.jar;D:\jdeveloper9ir2\jdev\lib\ojc.jar;D:\jdeveloper9ir2\j2ee\home\lib\activation.jar;D:\jdeveloper9ir2\j2ee\home\lib\ejb.jar;D:\jdeveloper9ir2\j2ee\home\lib\jaas.jar;D:\jdeveloper9ir2\j2ee\home\lib\jaxp.jar;D:\jdeveloper9ir2\j2ee\home\lib\jcert.jar;D:\jdeveloper9ir2\j2ee\home\lib\jdbc.jar;D:\jdeveloper9ir2\j2ee\home\lib\jms.jar;D:\jdeveloper9ir2\j2ee\home\lib\jndi.jar;D:\jdeveloper9ir2\j2ee\home\lib\jnet.jar;D:\jdeveloper9ir2\j2ee\home\lib\jsse.jar;D:\jdeveloper9ir2\j2ee\home\lib\jta.jar;D:\jdeveloper9ir2\j2ee\home\lib\mail.jar;D:\jdeveloper9ir2\j2ee\home\oc4j.jar;D:\jdeveloper9ir2\lib\xmlparserv2.jar;D:\jdeveloper9ir2\lib\xmlcomp.jar;D:\jdeveloper9ir2\j2ee\home\oc4j.jar;D:\jdeveloper9ir2\j2ee\home\lib\servlet.jar Samplemypackage6.ctejb1Client3
    javax.naming.NamingException: Lookup error: java.net.ConnectException: Connection refused: connect; nested exception is:
         java.net.ConnectException: Connection refused: connect
         java.lang.Object com.evermind.server.rmi.RMIContext.lookup(java.lang.String)
              RMIContext.java:134
         java.lang.Object javax.naming.InitialContext.lookup(java.lang.String)
              InitialContext.java:350
         void Samplemypackage6.ctejb1Client3.main(java.lang.String[])
              ctejb1Client3.java:18
    Process exited with exit code 0.
    Can anyone tell me if this is the correct communication method for client EJB's talking to the 9IAS server?
    Any help really appreciated.
    Chris Taylor

    hi Chris Taylor, did you find the solution for this error. i too get this error and i am looking for the answer. if you find any answer please share with me too. if i get any answer for this i will reply you too.

  • Ejb client error

    Hi, I use jdev 10g. I created a session bean with wizards and after that I created I Ejb client for that bean. When I start the embedded server and run the client java file I get the following error :
    com.evermind.server.rmi.OrionRemoteException: jazn.com/admin is not allowed to call this EJB method, check your security settings (method-permission in ejb-jar.xml and security-role-mapping in orion-application.xml).
         at denemeSessionHome_StatelessSessionHomeWrapper1.create(denemeSessionHome_StatelessSessionHomeWrapper1.java:41)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:124)
         at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
         at java.lang.Thread.run(Thread.java:534)
    at connection to localhost/127.0.0.1 as admin
         at com.evermind.server.rmi.RMIConnection.EXCEPTION_ORIGINATES_FROM_THE_REMOTE_SERVER(RMIConnection.java:1527)
         at com.evermind.server.rmi.RMIConnection.invokeMethod(RMIConnection.java:1480)
         at com.evermind.server.rmi.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:55)
         at com.evermind.server.rmi.RecoverableRemoteInvocationHandler.invoke(RecoverableRemoteInvocationHandler.java:22)
         at __Proxy0.create(Unknown Source)
         at ejbpackage.denemeSessionClient.main(denemeSessionClient.java:21)
    Process exited with exit code 0.
    all settings are the default ones.
    Anyone has any idea???

    hi
    There was no problem with that... the AdviceClient is not in the package... I needed j2ee.jar and AdviceAppClient.jar to run the client and hte AdviceClient is in C\java\Projects\Advice directory.... can anyone help me with what is wrong with my first command which didnt work ...
    java -classpath c:\Sun\AppServer\lib\j2ee.jar;c:\java\Projects\Advice;c:\java\Projects\AdviceAppClient.jar AdviceClient
    This one worked though....
    java -cp {$CLASSPATH}:"C:\java\Projects\Advice";AdviceAppClient.jar;c:\Sun\AppServer\lib\j2ee.jar; AdviceClient
    I dont know what makes the difference...
    vidhya

Maybe you are looking for

  • Losing connection with wireless hp photosmart printer: tried everything

    Hi there, I'm a new Dutch guy here, so sorry if I appear newbie-ish and if my English is imperfect... I've recently bought an iMac (finally!) and a wireless HP Photosmart B210a printer. I'm having trouble with my printer, which is connected wirelessl

  • Corbaname:rir: doesn't work

    Hi all, as i couldn't find a dedicated forum for users of Sun's ORB (for pure CORBA with Java), i'm posting my question here. Has anybody ever sucessfully resolved an object bound in a Naming Service by invoking ORB.string_to_object with a "corbaname

  • Mac pro 13 (2014) or Mac Air (2014) for basic Photoshop use

    I am a college senior about to enter the advertising industry and want to get a Mac as it is the industry standard in the ad world and to brush up on my Photoshop skills. I am looking for a mac computer priced between $1,000-$1,500 with education dis

  • Critical Tickets in MM

    Dear Gurus I need some business critical tickets related mm. I goan thru sdn maximum querys. but, i am not able to finding the same tickets. Honestly, i don't have idea about critical tickets. if any body aware of this tickets pls give me reply urgen

  • My facebook share option does not appear in system preferences

    hi, when I enter the system preferences the facebook login optin does not appear, onely twitter. does any one know why?