Unable to invoke an EJB deployed on JBoss 7.1 from JBoss ESB 4.10 - jboss

I'm trying to invoke an Stateless Session Bean (EJB 3) deployed on Jboss 7.1 Final from an remote instance of JBoss ESB 4.10.
In my jboss-esb.xml I have the following information:
<action name="EJBTestWithReturnValue" class="org.jboss.soa.esb.actions.EJBProcessor">
<property name="ejb3" value="true" />
<property name="method" value="login" />
<property name="jndi-name" value="gwtbatis-ear/gwtibatis-ejb/UserServiceEJB!com.aestasit.gwtibatis.UserServiceRemote" />
<property name="initial-context-factory" value="org.jnp.interfaces.NamingContextFactory" />
<property name="security-principal" value="xxxx" />
<property name="security-credentials" value="xxxx" />
<property name="provider-url" value="localhost:4447" />
<property name="ejb-params">
<arg0 type="java.lang.String">username</arg0>
<arg1 type="java.lang.String">password</arg1>
</property>
<property name="esb-out-var" value="org.jboss.soa.esb.message.defaultEntry"/>
Whatever JNDI binding I try I always get an error "invalid stream header: 00000018".
I successfully invoke the same EJB from a Java client but I use a different context factory ("org.jboss.naming.remote.client.InitialContextFactor").
Is there a way to invoke the remote EJB from ESB, without importing the client lib required by JBoss 7 and wriying my own EJB invoker?

Related

Configuring database connection in Jboss FUSE

One way I know to configure DB in JBOSS FUSE is to use blueprint.xml.
Below configuration in blueprint.xml works
<bean id="gemsDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="${gems_url}" />
<property name="username" value="${gems_username}" />
<property name="password" value="${gems_password}" />
<property name="maxIdle" value="5" />
<property name="minIdle" value="1" />
<property name="initialSize" value="1" />
</bean>
However, Is there any way to configure it in JBOSS container specific configuration file. For example - In JBOSS EAP we can configure it in standalone.xml. On similar lines can we configure it in JBOSS FUSE?
Jboss Fuse provides the integration with various data sources. You need to configure them bundle wise like you have used. But no such configuration is there on container level.
You can define a Datasource in a bundle and export it. In other bundles you import and use it like a service.
Prerequisites
Install these features
features:install jdbc
features:install jndi
Datasource bundle
Drop an XML file inside deploy folder with following content:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="dataSource" class="org.postgresql.jdbc3.Jdbc3SimpleDataSource">
<property name="url" value="jdbc:postgresql://localhost:5432/databasename"/>
<property name="user" value="username"/>
<property name="password" value="xxx"/>
</bean>
<service interface="javax.sql.DataSource" ref="dataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/yourdatabasename_ds"/>
</service-properties>
</service>
</blueprint>
This will export a service with javax.sql.DataSource interface and a JNDI name
Use Datasource service
When a bundle needs the datasource, ask OSGi to inject it.
<blueprint>
<reference id="yourDatabaseDs"
interface="javax.sql.DataSource"
availability="mandatory"
filter="(osgi.jndi.service.name=jdbc/yourdatabasename_ds)"/>
</blueprint>
The right Datasource is retrieved using the JNDI name you provided.
Using availability="mandatory" you can force your bundle to wait for the Datasource to become available. The bundle won't start without this reference.
You need the correct JDBC drivers for the database you are using.
Other goodies
You have a lot of commands in JBoss Fuse console to interact with the database now, like jdbc:datasources that will list all available datasources. With jdbc:query you can run any SQL against your DB (good for debugging issues and testing the connection)

Camel The application attempted to use a JMS session after it had closed the session

I am new to camel and I am attempting to write an app that bridges Websphere MQ and Active MQ on JBoss EAP 7. The app deploys successfully works, I can drop messages on the Websphere queue, and it gets picked up by Active MQ. However I see error messages in the log showing it is attempting to use a connection after it is open.
15:48:57,814 ERROR [org.jboss.jca.core.connectionmanager.listener.TxConnectionListener] (Camel (camel) thread #1 - JmsConsumer[I0_TEST]) IJ000315: Pool IbmMQQueueFactory has 1 active handles
15:48:57,819 INFO [org.jboss.as.connector.deployers.RaXmlDeployer] (Camel (camel) thread #1 - JmsConsumer[I0_TEST]) wmq.jmsra.rar: MQJCA4016:Unregistered connection handle being closed: 'com.ibm.mq.connector.outbound.ConnectionWrapper#214da401'.
15:49:02,819 WARN [org.apache.camel.component.jms.DefaultJmsMessageListenerContainer] (Camel (camel) thread #1 - JmsConsumer[I0_TEST]) Setup of JMS message listener invoker failed for destination 'I0_TEST' - trying to recover. Cause: Local JMS transaction failed to commit; nested exception is com.ibm.msg.client.jms.DetailedIllegalStateException: MQJCA1020: The session is closed.
The application attempted to use a JMS session after it had closed the session.
Modify the application so that it closes the JMS session only after it has finished using the session.
Here is my applicationContext.xml
<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:/ConnectionFactory" />
<property name="lookupOnStartup" value="false" />
<property name="cache" value="true" />
<property name="proxyInterface" value="javax.jms.ConnectionFactory" />
</bean>
<bean id="jmsTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:/TransactionManager" />
</bean>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="transacted" value="true" />
<property name="transactionManager" ref="jmsTransactionManager" />
</bean>
<bean id="wmqConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:/jms/IbmMQMsgQCF" />
<property name="lookupOnStartup" value="false" />
<property name="cache" value="true" />
<property name="proxyInterface" value="javax.jms.ConnectionFactory" />
</bean>
<bean id="wmqTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:/TransactionManager" />
</bean>
<bean id="wmq" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="wmqConnectionFactory" />
<property name="transacted" value="true" />
<property name="transactionManager" ref="wmqTransactionManager" />
</bean>
<bean id="routerlogger" class="org.jboss.as.quickstarts.mdb.RoutLogger" />
<camelContext trace="true" id="camel"
xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="wmq:websphereQueue"/>
<setExchangePattern pattern="InOnly"/>
<to uri="jms:activeQueue" pattern="InOnly" />
</route>
</camelContext>
Its a simple app, trying to determine what I'm missing.
I found this JBossDeveloper bug "JBEAP-2344: UserTransaction commit(), rollback() closes connection in Websphere MQ 7.5" which looks like it describes your issue and has comments pointing to documentation update "JBEAP-3535: Documentation: Add note about connection close on commit() and rollback() to Deploy the WebSphere MQ Resource Adapter subchapter".
Could you please add a note, that setting tracking="false", solves
problem with WebSphere MQ 7.5 and 8, where method commit() or
rollback() on UserTransaction closes any JMS connections which was
part of this transaction. This part is related to documenting known
limitation of WebSphere MQ in
JBEAP-3142.

Error with Spring ldap pooling

i build async jersey web services, and now i need to make some operations with ldap.
I have configure Spring beam.xml in this mode:
<bean id="contextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="${ldap.url}" />
<property name="base" value="${ldap.base}" />
<property name="userDn" value="${ldap.userDn}" />
<property name="password" value="${ldap.password}" />
<property name="pooled" value="false" />
</bean>
<bean id="contextSource"
class="org.springframework.ldap.pool.factory.PoolingContextSource">
<property name="contextSource" ref="contextSourceTarget" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="ldapTreeBuilder" class="com.me.ldap.LdapTreeBuilder">
<constructor-arg ref="ldapTemplate" />
</bean>
<bean id="personDao" class="com.me.ldap.PersonDaoImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
But when i try to use ldap i have this error:
Error creating bean with name 'contextSource' defined in class path resource [config/Beans.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedPoolableObjectFactory
In my project i have commons-pool2-2.2.jar lib, but still i have this error..i try to add commons-pool2-2.2.jar in TOMCAT_PATH/lib but not works..
UPDATE:
If i put commons-pool-1.6.jar it works.. but if i want to use pool2 how i can do? only i must change class inn commons-pool2-2.2.jar?
Updated Answer:
Since at least Spring LDAP 2.3.2 you can now use commons-pool2. Spring LDAP now provides two classes:
For commons-pool 1.x:
org.springframework.ldap.pool.factory.PoolingContextSource
For commons-pool 2.x:
org.springframework.ldap.pool2.factory.PooledContextSource
Details can be found here:
https://github.com/spring-projects/spring-ldap/issues/351#issuecomment-586551591
Original Answer:
Unfortunately Spring-Ldap uses commons-pool and not commons-pool2. As you have found the class org.apache.commons.pool.KeyedPoolableObjectFactory does not exist in commons-pool2 (it has a different package structure), hence the error.
There is a Jira issue for the Spring-ldap project asking them to upgrade/support commons-pool2:
https://jira.spring.io/browse/LDAP-316
Until that has been completed you will have to use commons-pool 1.6.

Use a remote JMS queue with Spring and JBoss EAP 6.2

Is it possible (if yes, with what configuration?) to have a Spring application running on one JBoss instance connect to a JMS queue defined on a different JBoss instance? I read a few pages about how to do it programmatically, but is it possible to have the queue injected in the Spring app so the application is not aware of the remote location of the queue and not required to do an explicit lookup?
Ideally, to have the JNDI name of the queue being resolved to a remote queue by the "client JBoss". An acceptable option would be to have the client application define the queue as remote in the <jms:listener> configuration.
Software: JBoss EAP 6.2, Spring 3.x
Yes you can use remoting NettyConnectionFactory
<bean name="liveTransportConfiguration" class="org.hornetq.api.core.TransportConfiguration">
<constructor-arg value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
<constructor-arg>
<map key-type="java.lang.String" value-type="java.lang.Object">
<entry key="port" value="5445"></entry>
<entry key="host" value="ip of server"></entry>
</map>
</constructor-arg>
</bean>
<bean name="connectionFactory" class="com.kp.KPHornetQJMSConnectionFactory"
destroy-method="close">
<constructor-arg name="ha" type="boolean" value="false" />
<constructor-arg>
<array>
<ref bean="liveTransportConfiguration"></ref>
</array>
</constructor-arg>
<property name="clientFailureCheckPeriod" value="5000" />
<property name="retryInterval" value="1000" />
<property name="retryIntervalMultiplier" value="1.0" />
<property name="reconnectAttempts" value="-1" />
<property name="confirmationWindowSize" value="-1" />
</bean>
<bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"></property>
</bean>
<bean name="kpListener" class="Your jms MessageListener">
<property name="jmsTemplate" ref="jmsTemplate"></property>
</bean>
<jms:listener-container connection-factory="connectionFactory" concurrency="1">
<jms:listener destination="myqueue" ref="kpListener" method="onMessage" />
</jms:listener-container>
KPHornetQJMSConnectionFactory.java class
public class KPHornetQJMSConnectionFactory extends HornetQJMSConnectionFactory {
private static final long serialVersionUID = -712113311282964108L;
public KPHornetQJMSConnectionFactory(final boolean ha,
org.hornetq.api.core.TransportConfiguration transportConfiguration) {
super(ha, transportConfiguration);
super.setUseGlobalPools(false);
}
}

JNDI DataSource with Tomcat 6 and Eclipse

I can't get my DataSource working with JNDI and Tomcat 6, while running it from Eclipse. I've added a context.xml to my /META-INF with the following content:
<Context>
<Resource name="jdbc/myDB" auth="Container" type="javax.sql.DataSource"
username="root"
password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/database"
maxActive="15"
maxIdle="7"
validationQuery="Select 1" />
</Context>
And configured my Spring Bean as follows:
<bean id="UserDatabase" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myDB"></property>
<property name="lookupOnStartup" value="true"></property>
<property name="cache" value="true"></property>
<property name="proxyInterface" value="javax.sql.DataSource"></property>
</bean>
I've also added this lines to my web.xml:
<resource-ref>
<description>Connection Pool</description>
<res-ref-name>jdbc/myDB</res-ref-name>
<res-type>javax.sql.Datasource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
But for some reason I still get this error:
javax.naming.NameNotFoundException: The name jdbc is not associated to this context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
I can't understand why this is not working... Any idea?
I changed the following and now it works:
In my context.xml completed the Context tag with:
<Context docBase="myApp" path="/myApp" reloadable="true" source="org.eclipse.jst.jee.server:app">
And in the Connection URL the character & caused the Cannot create resource error, don't know why, so my URL now is like:
jdbc:mysql://localhost/database?useUnicode=true&characterEncoding=utf-8
Please note the & int the URL...
If I remember correctly you should access it as
<property name="jndiName" value="java:comp/env/jdbc/myDB"/>
In the Spring appcontext, replace your definition with:
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"
value="java:comp/env/jdbc/myDB"/>
<property name="resourceRef"
value="true" />
</bean>