EJB remote call from standalone client to JBoss server is not working in Multi threading - spring

I am using spring container in a batch operation that realize many calls to an remote EJB. When the operation is single-thread everything works fine but when try to use multi-threading to gain performance it throws:
Exception in thread "taskExecutor-1" javax.ejb.EJBException: java.io.IOException: Channel Channel ID e9c80c0d (outbound) of Remoting connection 18f42160 to servername/ip:port has been closed
My stand-alone cliente dependecy is:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<type>pom</type>
<version>7.2.0.Final</version>
</dependency>
I'm also using spring's SimpleRemoteStatelessSessionProxyFactory to inject the lookup beans
<bean id="jndiProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="file:/path/jboss-ejb-client.properties" />
</bean>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment" ref="jndiProperties" />
</bean>
<bean id="operation" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
<property name="jndiName" value="ejb:remote/interface/location" />
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="businessInterface" value="com.MyBussinesInterfae" />
</bean>
In my tests I verified that if a Thread-A creates the InitContext and does the JNDI EJB lookup and creates the instance of the EJB remote inferface (under the SRSSPFBean) it can invoke methods via the EJB remote interface, but if an Thread-B gets the reference of the EJB remote interface and tries to invoke a method the exception is thrown.
The only similiar problem found on my search is here and seems related to bugs on Jboss AS 7. I am using Jboss eap 6.2.
Thanks in advance for any help.

Related

JaxWsPortProxyFactoryBean to bypass SSL checks

I have an Spring Proxy as a client to access some WS:
<bean id="clientPort" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
<property name="serviceInterface" value="com.acme.IClient"/>
<property name="serviceName" value="sercie"/>
<property name="endpointAddress" value="https://com.acme.IService"/>
<!-- ... -->
</bean>
<bean id="client" class="com.acme.Client">
<property name="theClientPort" ref="clientPort"/>
</bean>
Since it runs in JBoss, i know it uses CXF, now i want to bypass SSL checks, presumably with a HttpConduit, but i cannot setup system variables nor affect the configuration for the rest of CXF clients.
If i could access the object in code i would setup the HttpConduit, but ((Advised) proxy).getTargetSource().getTarget() returns null, (maybe i'm missing some configuration in web.xml)

Spring WorkManagerTaskExecutor cannot initialize in websphere

i want use Websphere work manager for executing async jobs in jee context but i have problem with creating spring WorkManager.
bean definition:
<bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor"> <property name="workManagerName" value="wm/default" /> </bean>
this definition i found in websphere help. But problem is this ends with noClassDefFound. I noticed pckg org.springframework.scheduling.commonj is missing from spring-context since version 2.x.x
Is it replaced with org.springframework.jca.work.WorkManagerTaskExecutor ?
when i use this other spring class, i get error:
Caused by: org.springframework.jndi.TypeMismatchNamingException:
Object of type [class com.ibm.ws.asynchbeans.WorkManagerImpl]
available at JNDI location [wm/default] is not assignable to
[javax.resource.spi.work.WorkManager]
so whats deal here? thx
was - 7.0.0.23
spring - 3.1.2
Class org.springframework.scheduling.commonj.WorkManagerTaskExecutor resides in spring-context-support-3.1.2.RELEASE.jar
Configuration succeeds with javax.resource.spi.work.WorkManager in applicationContext-service.xml in deployment.....
In my case deployment fails for bean injection org.springframework.scheduling.commonj.WorkManagerTaskExecutor as it fails to take WorkManager JNDI Configured in Application Server.... I just replaced javax.resource.spi.work.WorkManager. And so far it is success deployment.
I yet to see application works fine with it.
<bean id="taskExecutor" class="javax.resource.spi.work.WorkManager">
<property name="workManagerName" value="wm/default" />
</bean>
In our scenario we were managed it by ThreadPoolTaskExecutor instead of WorkManagerTaskExecutor
Here is configuration that comes in ApplicationContext.xml
<!--
<bean id="rtSenderTaskExecutor"
class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManagerName">
<value>${org.quartz.threadPool.jndi}</value>
</property>
</bean> -->
<!-- Local Thread Pool -->
<bean id="rtSenderTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="${org.quartz.threadPool.corePoolSize}" />
<property name="maxPoolSize" value="${org.quartz.threadPool.maxPoolSize}" />
<property name="queueCapacity" value="${org.quartz.threadPool.queueCapacity}" />
<property name="keepAliveSeconds" value="${org.quartz.threadPool.keepAliveSeconds}"></property>
</bean>

JNDI binding in JBOss for MQ

I need a little bit of help in configuring JBoss to work with MQ. I have created initial context in MQ using IBM MQ Explorer and have given a local directory for all bindings like file:/C:/jndi. I have created a connection factory for this initial context. Now JBoss documentation says to bind like this
<connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl"
jndi-name="java:jboss/MQ.CONNECTIONFACTORY.NAME"
pool-name="MQ.CONNECTIONFACTORY.NAME">
I think I am missing some point here. How do I tell Jboss that my InitialContext bindings are in a directory. I have tried most of the combinations. May be I am not getting the concept right. Any pointers ?
When I try to access this MQ.CONNECTIONFACTORY.NAME from a test servlet I wrote I get javax.naming.NameNotFoundException . If I follow same steps in Java SE environment I am successfully able to establish a connection. I am new to application servers and the question might be naive
Regards
The description of the resources created via MQExplorer suggest that these have been put into JNDI backed by a File System context. This is perfectly fine, but what in theory needs to be done now is get JBOSS to read objects out that JNDI context rather than the usual JNDI provider provided by JBOSS. The settings that are in the connection definition extract are using the standard JBOSS JNDI context.
As an example of using JBOSS with the WebSphere MQ Resoruce Adapter have a look here http://pic.dhe.ibm.com/infocenter/wmqv7/v7r5/topic/com.ibm.mq.dev.doc/q031810_.htm
This links to an example set of definitions that store WMQ JMS administered objects in the JBOSS JNDI context.
This is an important question. I have used Spring for this, like this:
<util:properties id="remoteEnv">
<prop key="java.naming.provider.url">file:${my.config.path}/bindings</prop>
<prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jboss.naming.remote.client</prop>
<prop key="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</prop>
<prop key="java.naming.security.principal">${mdb.user.name}</prop>
<prop key="java.naming.security.credentials">${mdb.user.pass}</prop>
</util:properties>
<bean id="remoteJNDITemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment" ref="remoteEnv" />
</bean>
<bean id="remoteJmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="remoteJNDITemplate" />
<property name="cache" value="true" />
</bean>
<jee:jndi-lookup id="senderQueue" jndi-name="MY_QUEUE_NAME" environment-ref="remoteEnv" />
<bean id="xamqconnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="remoteJNDITemplate"/>
</property>
<property name="jndiName" value="MYCONNECTIONFACTORYJNDINAME"/>
<property name="lookupOnStartup" value="false" />
<property name="proxyInterface" value="javax.jms.XAQueueConnectionFactory" />
</bean>
<bean id="xaMQSenderJMSTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="xamqconnectionFactory" />
</property>
<property name="pubSubDomain">
<value>false</value>
</property>
<property name="defaultDestination">
<ref bean="senderQueue" />
</property>
<property name="destinationResolver" ref="remoteJmsDestinationResolver" />
</bean>
however using the configuration above we bypass the resource adapter. That's no problem otherwise but it prevents transactions from joining the JBoss transaction, so JMS messages are send immediately, not with transaction commit. I haven't found a fix for that yet.
com.sun.jndi.fscontext.RefFSContextFactory, that is used to read .bindings file, can be found at this dependency:
<dependency>
<groupId>com.sun.messaging.mq</groupId>
<artifactId>fscontext</artifactId>
<version>4.6-b01</version>
</dependency>

Spring JNDI datasource not recognized after upgrade to ActiveMQ 5.6.0

I tested a ActiveMQ 5.5.0 (fuse version) app in AMQ 5.6.0 and noticed that our Spring JNDI configured Oracle datasources aren't being found.
The only thing I changed in my applications was the pom.xml versions of AMQ/Spring (to match the 5.6 versions). Otherwise, I'm using the identical application code and configuration (activemq.xml, jndi.xml, etc), but my Spring JDBC DAOs (v3.0.5) are failing to find them.
No errors in the logs otherwise, just this Spring Application Context initialization error...
javax.naming.NameNotFoundException; remaining name 'jdbc/myDataSource'
here is the relevant Spring jndi config (conf/jndi.xml, included in conf/activemq.xml)...
<bean id="jndi" class="org.apache.xbean.spring.jndi.SpringInitialContextFactory"
factory-method="makeInitialContext" scope="singleton">
<property name="entries" ref="jndiEntries" />
</bean>
<util:map id="jndiEntries">
<entry key="jdbc/myDataSource">
<bean id="myDBCPDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
...
then my application references it like this...
<bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/myDataSource</value>
</property>
</bean>
<bean id="messageDAO" class="com.mycompany.MessageDAOImpl">
<property name="dataSource" ref="myDataSource" />
</bean>
That said, I tested without using JNDI (instead just hardcoded the datasource in my app) and everything works as expected. So that should rule out everything except the Spring JNDI registration/lookup of the datasource, etc.
So, what am I missing?
ActiveMQ has a dependency into xbean-spring, which you are using as a JNDI provider. It is likely that the transitive Xbean dependency has changed because of the upgrade to ActiveMQ 5.6.0.
I found the issue, I added a jndi.properties file under the /conf directory containing the following and it works fine now (didn't need this under AMQ 5.5...strange)...
java.naming.factory.initial = org.apache.xbean.spring.jndi.SpringInitialContextFactory

How invoke a Spring Integration application from your CXF endpoint

i'm using Apache CXF web services and Spring Integration and i don't now how to invoke a Spring Integration application from your CXF endpoint.
I have experience working on Apache Camel and is very easy to resolve this problem...but in Spring Integration i don't have any idea....
My lines code are:
In webservices-definition-beans.xml:
<!-- Load CXF modules from cxf.jar -->
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<!--Exposing the HelloWorld service as a SOAP service -->
<bean id="jaxbBean"
class="org.apache.cxf.jaxb.JAXBDataBinding"
scope="prototype"/>
<bean id="jaxws-and-aegis-service-factory"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
scope="prototype">
<property name="dataBinding" ref="jaxbBean"/>
<property name="serviceConfigurations">
<list>
<bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration"/>
<bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration"/>
<bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration"/>
</list>
</property>
</bean>
<jaxws:endpoint id="helloWorld"
serviceName="HelloWorldService"
implementorClass="com.datys.cxf.HelloWorldService"
address="/HelloWorld">
<jaxws:serviceFactory>
<ref bean="jaxws-and-aegis-service-factory"/>
</jaxws:serviceFactory>
</jaxws:endpoint>
In service-definition-beans.xml:
<gateway id="HelloWorldService"
default-request-channel="requestStrings"
default-reply-channel="replyStrings"
service-interface="com.datys.cxf.HelloWorldService">
<method name="sayHello"/>
</gateway>
<channel id="requestStrings"/>
<channel id="replyStrings"/>
<!--<channel id="filesOut"/>-->
<service-activator input-channel="requestStrings"
output-channel="filesOut"
ref="handler" method="handleString"/>
<file:outbound-channel-adapter id="filesOut"
directory="file:D:/OUTPUT"/>
<beans:bean id="handler" class="org.springframework.integration.samples.filecopy.Handler"/>
But when i deploy and call web services with client-webservices return this error:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Could not instantiate service class com.datys.cxf.HelloWorldService because it is an interface.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:171)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:94)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:240)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:210)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:103)
at $Proxy29.sayHello(Unknown Source)
Probably the simplest option is to configure a <gateway>. That allows you to provide any interface that you can inject into your endpoint and invoke it to initiate a message flow. Under the covers, the interface is implemented in the same way as other "ProxyFactoryBean" implementations in Spring (e.g. remoting via RMI, HttpInvoker, etc).
Here's a relevant section from the reference manual:
http://static.springsource.org/spring-integration/docs/2.1.x/reference/htmlsingle/#gateway-proxy

Resources