cancel
Showing results for 
Search instead for 
Did you mean: 

Resource Injection EJB

Former Member
0 Kudos

Hi,

I’m getting an error message (see below)

javax.xml.ws.soap.SOAPFaultException: javax.ejb.EJBException: Exception in getMethodReady() for stateless bean sap.com/dts-ws-earxml|dts-ws.jarxml|MarketMessageServiceImplBean; nested exception is: com.sap.engine.services.ejb3.util.pool.PoolException: javax.ejb.EJBException: Cannot perform injection over bean instance com.amtsybex.dts.ws.MarketMessageServiceImplBean@4cd4a51 for bean sap.com/dts-ws-earxml|dts-ws.jarxml|MarketMessageServiceImplBean; nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field jmsConnFactory of instance com.amtsybex.dts.ws.MarketMessageServiceImplBean@4cd4a51 failed. Could not get a value to be injected from the factory.

at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:188)

at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:116)

at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)

at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)

at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)

when injecting resources into my java bean. I’ve tried different combinations on ejb-jar – using mapped-name, injection target etc. But it seems to be ignoring whatever I try. In the code I’m looking to reference the resources using @Resource annotation:

@Resource (name = "jms/dts/unregisteredFiles") javax.jms.Queue jmsDestQ;

@Resource (mappedName="jmsfactory/default/jms/dts/queueConnectionFactory", type=javax.jms.XAQueueConnectionFactory.class) javax.jms.XAQueueConnectionFactory jmsConnFactory;

I’ve also tried using mapped names and specifying the resource type – with no luck.

The ejb-jar looks like this:

<enterprise-beans>

<session>

<resource-ref>

<res-ref-name>jmsConnFactory</res-ref-name>

<res-type>javax.jms.XAQueueConnectionFactory</res-type>

<res-auth>Container</res-auth>

<mapped-name>jmsfactory/default/jms/dts/queueConnectionFactory</mapped-name>

<injection-target>

<injection-target-class>com.amtsybex.dts.ws.MarketMessageServiceImplBean</injection-target-class>

<injection-target-name>jmsConnFactory</injection-target-name>

</injection-target>

</resource-ref>

<resource-env-ref>

<resource-env-ref-name>jms/dts/unregisteredFiles</resource-env-ref-name>

<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>

<mapped-name>jmsqueues/default/jms/dts/unregisteredFiles</mapped-name>

<injection-target>

<injection-target-class>com.amtsybex.dts.ws.MarketMessageServiceImplBean

</injection-target-class>

<injection-target-name>jmsDestQ</injection-target-name>

</injection-target>

</resource-env-ref>

</session>

</enterprise-beans>

Does anyone have any pointers?

Regards,

Andrew

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

I don't know if this helps but I had the same error and was stuck retrying my data sourse aliases etc. to no avail. I eventually looked in the default trace file to find it was a problem with a precompiled SQL Query. Check your default trace for a further nested exception.

ivo_simeonov
Explorer
0 Kudos

Hi Andrew,

The jms-resources.xml should be in the same application as the ejb/war modules which use them. The resources defined in a jms-resource.xml are visible only to the components within the same application.

HTH

Ivo

Former Member
0 Kudos

Ivo,

many thanks for your reply -

I think I know what you mean, in that we should deploy the queues and connection factory with our application. However, why would it work one way (initial context) and not the other(injection)?

We shall do this and let you know the outcome.

Regards,

Andrew

Former Member
0 Kudos

Ivo,

We just tried that, and it failed with the same error.

Regards,

Andrew

Vlado
Advisor
Advisor
0 Kudos

Hi Andrew,

The name or mappedName attribute should refer exactly to the name of the resource as specified in the jms-resources.xml. Otherwise you would need to maintain this mapping in the ejb-j2ee-engine.xml - by means of the <res-link> and <jndi-name> elements.

So, I guess the easiest way to get this work in your case would be to change the annotations as following:


@Resource (name = "jms/dts/unregisteredFiles") javax.jms.Queue jmsDestQ;

@Resource (name = "jms/dts/queueConnectionFactory") javax.jms.XAQueueConnectionFactory jmsConnFactory;

and delete the entries in the ejb-jar.xml.

HTH!

\-- Vladimir

Former Member
0 Kudos

Hi Vladimir,

I've tried the advised method, but it comes back with the same error. When I use the context lookup – it works ok:

InitialContext jmsContext = new InitialContext();

Destination dest = (Destination) jmsContext.lookup(“jmsqueues/default/jms/dts/unregisteredFiles”);

ConnectionFactory connectionFactory = jmsContext.lookup(“jmsfactory/default/jms/dts/queueConnectionFactory”);

However, when injecting directly into fields as you have advised – it fails.

The resources are declared in another development component and I can see them in the resource admin tool.

Any ideas?

Regards,

Andrew

Vlado
Advisor
Advisor
0 Kudos

Hi Andrew,

That usage of the lookup is wrong, e.g. transactions would not be handled the way one might expect.

Please look into the defaultTrace.trc for the nested exception of the com.sap.engine.lib.injection.InjectionException. What does it say?

Former Member
0 Kudos

Vladimir,

We have tried every combination of string for lookup including long and short names.

We still get the exception.

If we use the initialcontext and look it up it finds the resource, but when injecting via the @Resource annotation it throws the following error:

Caused by: com.sap.engine.lib.injection.InjectionException: Injection on field jmsConnFactory of instance com.amtsybex.dts.ws.MarketMessageServiceImplBean@16bbde55 failed. Could not get a value to be injected from the factory.

at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:115)

at com.sap.engine.lib.injection.InjectionMatrix.inject(InjectionMatrix.java:45)

at com.sap.engine.services.ejb3.runtime.impl.Interceptors_DependencyInjection.invoke(Interceptors_DependencyInjection.java:22)

... 64 more

Caused by: com.sap.engine.services.connector.exceptions.BaseResourceException: ConnectionFactory "jms/dts/queueConnectionFactory" does not exist. Possible reasons: the adapter in which ConnectionFactory "jms/dts/queueConnectionFactory" is defined is not deployed or not started.

at com.sap.engine.services.connector.ResourceObjectFactory.getObjectInstance(ResourceObjectFactory.java:244)

at com.sap.engine.lib.injection.ReferenceObjectFactory.getObject(ReferenceObjectFactory.java:65)

at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:113)

... 66 more

Regards,

Andrew