on 11-07-2007 3:44 PM
Hello!
I have create a Composite Application (Development Component) with SAP NetWeaver CE 7.1. There I have create an Application Service. The special generated EJB and its interface have this code:
<b>EJB:</b>
package de.td.ir_as.modeled.appsrv.increcrfcconn;
@javax.ejb.Stateless(name = "de.td.ir_as.modeled.appsrv.increcrfcconn.IncRecRfcConn")
@javax.ejb.Local(value = { de.td.ir_as.modeled.appsrv.increcrfcconn.IncRecRfcConnServiceLocal.class })
@javax.interceptor.Interceptors(value = { com.sap.caf.rt.interceptors.LogInterceptor.class })
public class IncRecRfcConnBeanImpl extends de.td.ir_as.modeled.appsrv.increcrfcconn.IncRecRfcConnBean {
}
<b>Abstract Class:</b>
/* ***************************************************************************
* THIS FILE HAS BEEN GENERATED BY THE CAF CODE GENERATOR.
* ALL CHANGES WILL BE LOST IF THE FILE IS REGENERATED!
* ***************************************************************************/
//Application Service Template
package de.td.ir_as.modeled.appsrv.increcrfcconn;
public abstract class IncRecRfcConnBean implements de.td.ir_as.modeled.appsrv.increcrfcconn.IncRecRfcConnServiceLocal {
public static final String _PROVIDER = "sap.com";
public static final String _APPLICATION = "ir_as";
public static final String _APP_SRV_NAME = "IncRecRfcConn";
public static final String _OBJECT_NAME = _PROVIDER + "/" + _APPLICATION + "/" + _APP_SRV_NAME;
public static final String _JARM_REQUEST = "XAP:APPSERV:" + _OBJECT_NAME;
protected static final com.sap.tc.logging.Location _location = com.sap.tc.logging.Location.getLocation(IncRecRfcConnBean.class);
public IncRecRfcConnBean(){
}
...
}
<b>Interface:</b>
/* ***************************************************************************
* THIS FILE HAS BEEN GENERATED BY THE CAF CODE GENERATOR.
* ALL CHANGES WILL BE LOST IF THE FILE IS REGENERATED!
* ***************************************************************************/
//Application Service Template
package de.td.ir_as.modeled.appsrv.increcrfcconn;
public interface IncRecRfcConnServiceLocal{
...
}
I have created an other Development Component. It's a EJB Module. In this component I want to use via EJB invocation the developed Application Service. I use the @EJB invocation to use it:
@Stateless
public class IncRecRfcImplBean implements IncRecRfcImplLocal {
@EJB(beanName="de.td.ir_as.modeled.appsrv.increcrfcconn.IncRecRfcConn")
private IncRecRfcConnServiceLocal incRecRfcConn;
...
But if I instantiate a [/code]IncRecRfcImplBean
-object in an POJO the attribute [code]incRecRfcConn
will not be initialized at runtime.
What do I do wrong?
Regards,
Armin
> But if I instantiate a
>
IncRecRfcImplBean
-object in an POJO the
> attribute
incRecRfcConn
will not be
> initialized at runtime.
>
> What do I do wrong?
How exactly do you do that? If you simply call
new IncRecRfcImplBean()
it will not work as the EJB container doesn't know about this. Actually, you must never work directly with the bean class - this is managed by the container. The app developer works with the bean interfaces.
HTH!
-- Vladimir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I have a test class which uses the bean interface.
public class Test {
@EJB
private IncRecRfcImplLocal incRecRfcImpl;
public static void main(String[] args) {
Test test = new Test();
test.findPerson();
}
public PersonList findPerson() {
return incRecRfcImpl.findPerson(null, null, null);
}
}
I debug this class as Java Application but I get a NullPointerException:
Exception in thread "main" java.lang.NullPointerException
at de.td.increcejb.test.Test.findPerson(Test.java:23)
at de.td.increcejb.test.Test.main(Test.java:18)
Is this the right way to test the EJB?
Regards,
Armin
Hi Armin,
Definitely not. This is exactly the problem I described above. Dependency injection works only when there is a container that manages the respective class. In your case Test is just a standalone Java program, so nobody takes care to inject the reference into incRecRfcImpl.
You can test your EJB with a simple web app (JSP), application client, or a standalone Java program like yours (however in this case you have to do manual lookup of the EJB). For the latter two cases you can find more information <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/508d47ba-3878-2910-2aa1-ed752063993e">here</a> and <a href="http://help.sap.com/saphelp_nwce10/helpdata/en/45/e692b2cfaa5591e10000000a1553f7/frameset.htm">here</a>, respectively.
HTH!
-- Vladimir
Hello,
I implement the following client like described here https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/605ff5f2-e589-2910-3ead-e558376e...
[code]public class EjbClient {
public static void main(String[] args) {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sap.engine.services.jndi.InitialContextFactoryImpl");
props.put(Context.PROVIDER_URL, "vm-sapnwce:50004");
try {
Context ctx = new InitialContext(props);
Object o = ctx
.lookup("td.de/increcear/REMOTE/IncRecRfcImplBean/de.td.increcejb.increcrfcimpl.IncRecRfcImplRemote");
IncRecRfcImplRemote incRecRfc = (IncRecRfcImplRemote) PortableRemoteObject
.narrow(o, IncRecRfcImplRemote.class);
PersonList personList = incRecRfc.findPerson(null, null, null);
System.out.println("stop");
} catch (Exception e) {
e.printStackTrace();
}
}
}[/code]
But I got the following exception:
[code]com.sap.engine.services.jndi.persistent.exceptions.NamingException: Exception during lookup operation of object with name td.de/increcear/REMOTE/IncRecRfcImplBean/de.td.increcejb.increcrfcimpl.IncRecRfcImplRemote, cannot resolve object reference. [Root exception is javax.naming.NamingException: Error occurs while the EJB Object Factory trying to resolve JNDI reference Reference Class Name: de.td.increcejb.increcrfcimpl.IncRecRfcImplRemote
Type: clientAppName
Content: td.de/increcear
Type: interfaceType
Content: remote
Type: remote
Content: de.td.increcejb.increcrfcimpl.IncRecRfcImplRemote
Type: ejb-link
Content: IncRecRfcImplBean
javax.ejb.EJBException: nested exception is: java.rmi.RemoteException: [ERROR CODE DPL.DS.6125] Error occurred while starting application locally and wait.; nested exception is:
com.sap.engine.services.deploy.exceptions.ServerDeploymentException: [ERROR CODE DPL.DS.5082] Exception while preparing start of application td.de/increcear.
at com.sap.engine.services.ejb3.runtime.impl.DefaultContainerRepository.startApp(DefaultContainerRepository.java:236)
at com.sap.engine.services.ejb3.runtime.impl.DefaultContainerRepository.getEnterpriseBeanContainer(DefaultContainerRepository.java:105)
at com.sap.engine.services.ejb3.runtime.impl.DefaultRemoteObjectFactory.resolveReference(DefaultRemoteObjectFactory.java:53)
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:585)
at com.sap.engine.services.rmi_p4.P4DynamicSkeleton.dispatch(P4DynamicSkeleton.java:234)
at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:351)
at com.sap.engine.services.rmi_p4.server.ServerDispatchImpl.run(ServerDispatchImpl.java:70)
at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:62)
at com.sap.engine.services.rmi_p4.P4Message.execute(P4Message.java:37)
at com.sap.engine.services.cross.fca.FCAConnectorImpl.executeRequest(FCAConnectorImpl.java:872)
at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:53)
at com.sap.engine.services.cross.fca.MessageReader.run(MessageReader.java:58)
at com.sap.engine.core.thread.execution.Executable.run(Executable.java:108)
at com.sap.engine.core.thread.execution.CentralExecutor$SingleThread.run(CentralExecutor.java:304)
]
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:528)
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:637)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at de.td.increcejb.test.EjbClient.main(EjbClient.java:20)
Caused by: javax.naming.NamingException: Error occurs while the EJB Object Factory trying to resolve JNDI reference Reference Class Name: de.td.increcejb.increcrfcimpl.IncRecRfcImplRemote
Type: clientAppName
Content: td.de/increcear
Type: interfaceType
Content: remote
Type: remote
Content: de.td.increcejb.increcrfcimpl.IncRecRfcImplRemote
Type: ejb-link
Content: IncRecRfcImplBean
javax.ejb.EJBException: nested exception is: java.rmi.RemoteException: [ERROR CODE DPL.DS.6125] Error occurred while starting application locally and wait.; nested exception is:
com.sap.engine.services.deploy.exceptions.ServerDeploymentException: [ERROR CODE DPL.DS.5082] Exception while preparing start of application td.de/increcear.
at com.sap.engine.services.ejb3.runtime.impl.DefaultContainerRepository.startApp(DefaultContainerRepository.java:236)
at com.sap.engine.services.ejb3.runtime.impl.DefaultContainerRepository.getEnterpriseBeanContainer(DefaultContainerRepository.java:105)
at com.sap.engine.services.ejb3.runtime.impl.DefaultRemoteObjectFactory.resolveReference(DefaultRemoteObjectFactory.java:53)
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:585)
at com.sap.engine.services.rmi_p4.P4DynamicSkeleton.dispatch(P4DynamicSkeleton.java:234)
at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:351)
at com.sap.engine.services.rmi_p4.server.ServerDispatchImpl.run(ServerDispatchImpl.java:70)
at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:62)
at com.sap.engine.services.rmi_p4.P4Message.execute(P4Message.java:37)
at com.sap.engine.services.cross.fca.FCAConnectorImpl.executeRequest(FCAConnectorImpl.java:872)
at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:53)
at com.sap.engine.services.cross.fca.MessageReader.run(MessageReader.java:58)
at com.sap.engine.core.thread.execution.Executable.run(Executable.java:108)
at com.sap.engine.core.thread.execution.CentralExecutor$SingleThread.run(CentralExecutor.java:304)
at com.sap.engine.services.ejb3.runtime.impl.EJBObjectFactory.getObjectInstance(EJBObjectFactory.java:140)
at com.sap.engine.services.ejb3.runtime.impl.EJBObjectFactory.getObjectInstance(EJBObjectFactory.java:58)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:521)
... 3 more
[/code]
Regards,
Armin
I got this from JNDI Browser:
Objectname: td.de/increcear/REMOTE/IncRecRfcImplBean/de.td.increcejb.increcrfcimpl.IncRecRfcImplRemote
Reference Class Name: de.td.increcejb.increcrfcimpl.IncRecRfcImplRemote
Type: clientAppName
Content: td.de/increcear
Type: interfaceType
Content: remote
Type: remote
Content: de.td.increcejb.increcrfcimpl.IncRecRfcImplRemote
Type: ejb-link
Content: IncRecRfcImplBean
--
Armin
Hello,
I solved the problem:
The problem was that the deploying of the EJB module was done with warning.
In Development Infrastructure Perspective I add to the EAR-DC of the EJB Module a Dependency to the EAR-DC of the Application Service with Dependency Details: Deploy Time and Run Time.
After that the EJB module was deployed without warnings and I'm able to look up the EJB.
Anyway, thanks for your help.
Kind Regards,
Armin
Hi Armin,
Isn't your local interface, IncRecRfcConnServiceLocal, missing the @Local annotation before the interface declaration?
package de.td.ir_as.modeled.appsrv.increcrfcconn;
@Local
public interface IncRecRfcConnServiceLocal{
...
}
Best regards,
Dobrinka
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.