[JBoss Messaging] - Camel/Spring integration between JBoss MQ-s
by Tamas Benke
Tamas Benke [https://community.jboss.org/people/tbenke] created the discussion
"Camel/Spring integration between JBoss MQ-s"
To view the discussion, visit: https://community.jboss.org/message/801818#801818
--------------------------------------------------------------
Hello Everybody!
I have worked for a while on a Camel route, between some JBoss MQ-s and other (file, Karaf log) endpoints.
I use Apache ServiceMix 4.4.2 (with Camel 2.8.5 and Spring 3.0.6.RELEASE inside), and JBoss [EAP] 5.1.1, under Microsoft Windows 7 Professional 64-bit SP1.
I had to shift (with +300) the port set of JBoss to avoid interference with ServiceMix and Oracle 11g database, so that I run JBoss with this command:
run.bat -Djboss.service.binding.set=ports-03
I have created two JBoss queue-s by means of the admin console of JBoss, with JNDI names queue/Test1 and queue/Test2.
I collected a set of JBoss dependency JARs, and OSGi-fied them with the BND tool:
concurrent.jar
javassist.jar
jboss-aop-client.jar
jboss-client.jar
jboss-common-core.jar
jboss-ha-client.jar
jboss-ha-legacy-client.jar
jboss-javaee.jar
jboss-logging-spi.jar
jboss-mdr.jar
jboss-messaging-client.jar
jboss-remoting.jar
jboss-security-spi.jar
jboss-serialization.jar
jmx-invoker-adaptor-client.jar
jnp-client.jar
trove.jar
I have used some other JARs as well, but I think, they didn't make any difference:
jbossmq.jar
jbossall-client.jar
jbossmq-client.jar
jboss-jmx.jar
I have used this Spring camel-context.xml (containing 3 route definitions):
*<?xml version="1.0" encoding="UTF-8"?>*
*<beans xmlns=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans"*
* xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance"*
* xmlns:camel=" http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring"*
* xsi:schemaLocation="*
* http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans*
* http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/beans/spring-beans.xsd*
* http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring*
* http://camel.apache.org/schema/spring/camel-spring.xsd http://camel.apache.org/schema/spring/camel-spring.xsd">*
* <camelContext xmlns=" http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring">*
* <!--route>*
* <from uri="file:c:/HELLO" />*
* <convertBodyTo type="String" charset="UTF-8" />*
* <to uri="jbossjms:queue:Test1" />*
* </route-->*
* <!--route>*
* <from uri="timer://foo?fixedRate=true&period=5s" />*
* <transform>*
* <simple>ABCdef</simple>*
* </transform>*
* <to uri="jbossjms:queue:Test1" />*
* </route-->*
* <route>*
* <from uri="jbossjms:queue:Test1" />*
* <to uri="log:Test1" />*
* </route>*
* </camelContext>*
* <bean name="jbossjms" class="org.apache.camel.component.jms.JmsComponent">*
* <property name="connectionFactory" ref="jbossJmsConnectionFactory"/>*
* </bean>*
* <bean name="jbossJmsConnectionFactory" id="jbossJmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">*
* <property name="jndiTemplate">*
* <ref bean="jbossJndiTemplate" />*
* </property>*
* <property name="jndiName">*
* <value>ConnectionFactory</value>*
* </property>*
* </bean>*
* <bean id="jbossJndiTemplate" class="org.springframework.jndi.JndiTemplate">*
* <property name="environment">*
* <props>*
* <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>*
* <prop key="java.naming.provider.url">jnp://localhost:1399</prop>*
* <prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>*
* <prop key="java.naming.security.principal">admin</prop>*
* <prop key="java.naming.security.credentials">admin</prop>*
* </props>*
* </property>*
* </bean>*
*</beans>*
The first (File >> JBoss MQ) and second (Timer >> JBoss MQ) routes are working properly, if I drop the
above mentioned dependencies and the camel-context.xml to ServiceMix's /deploy folder.
The third (JBoss MQ >> Karaf log) route does not process messages, despite the consumer appears on the Test1
JBoss queue, and the bundle/route status is Active/Started.
The automatic OSGi headers of the deployed camel-context.xml are:
*Manifest-Version = 2*
*Spring-Context = *;publish-context:=false;create-asynchronously:=true*
*Bundle-SymbolicName = test-jms.xml*
*Bundle-Version = 0.0.0*
*Bundle-ManifestVersion = 2*
*DynamicImport-Package =*
* **
*Import-Package =*
* org.apache.camel.component.jms,*
* org.springframework.jndi*
The imports of this camel-context.xml artifact are:
*System Bundle (0): org.osgi.service.packageadmin; version=1.2.0*
*System Bundle (0): org.xml.sax; version=0.0.0*
*System Bundle (0): org.apache.xerces.impl.dv.xs; version=2.11.0*
*System Bundle (0): org.apache.xerces.impl.dv.dtd; version=2.11.0*
*activemq-core (50): org.apache.activemq; version=5.5.1*
*activemq-core (50): org.apache.activemq.util; version=5.5.1*
*Spring Context (65): org.springframework.jndi; version=3.0.6.RELEASE*
*Spring Beans (66): org.springframework.beans.factory.xml; version=3.0.6.RELEASE*
*Spring Beans (66): org.springframework.beans.propertyeditors; version=3.0.6.RELEASE*
*camel-core (91): org.apache.camel.spi; version=2.8.5*
*camel-core (91): org.apache.camel; version=2.8.5*
*camel-jms (118): org.apache.camel.component.jms; version=2.8.5*
*jboss-common-core (463): org.jboss.util.propertyeditor; version=0.0.0*
*jboss-common-core (463): org.jboss.util.threadpool; version=0.0.0*
*jnp-client (464): org.jnp.interfaces; version=0.0.0*
*jboss-remoting (469): org.jboss.remoting; version=0.0.0*
*jboss-remoting (469): org.jboss.remoting.marshal; version=0.0.0*
*jboss-messaging-client (476): org.jboss.jms.client; version=0.0.0*
*jboss-messaging-client (476): org.jboss.jms.client.delegate; version=0.0.0*
*jboss-messaging-client (476): org.jboss.jms.client.remoting; version=0.0.0*
*jboss-messaging-client (476): org.jboss.jms.server.remoting; version=0.0.0*
*jboss-messaging-client (476): org.jboss.messaging.util; version=0.0.0*
Of course, there are no exports.
I made a complete OSGi bundle JAR from the mentioned camel-context.xml, with the following MANIFEST.MF:
*Manifest-Version: 1.0*
*DynamicImport-Package: **
*Bundle-Version: 1.0.0*
*Build-Jdk: 1.7.0_17*
*Built-By: U522971*
*Tool: Bnd-1.15.0*
*Bnd-LastModified: 1362746498060*
*Bundle-Name: A Camel Spring-DM Route*
*Bundle-ManifestVersion: 2*
*Created-By: Apache Maven Bundle Plugin*
*Import-Package: javax.jms,javax.naming,javax.naming.spi,javax.net,org.*
*apache.activemq,org.apache.camel.component.jms,org.jboss.mq,org.jboss*
*.mq.referenceable,org.jnp.interfaces,org.springframework.jms.core,org*
*.springframework.jndi;version="[2.5,4)"*
*Bundle-SymbolicName: jboss-route*
The org.jboss.mq package was missing, so I deployed jboss/jbossmq_3.2.3.jar (downloaded and bundlefied from a local Maven repository).
The bundle was immediately started, and the behavior of the routes was exactly the same as I mentioned above.
It looks wery cool and simple to write down, but in reality, I spent approximately 2.5 months with it,
and after all, I still don't have a Camel/Spring config to consume from a JBoss MQ!
I have read a number of resources (including official JBoss/Camel documentation); for example:
http://www.jboss.org/jbossas/docs http://www.jboss.org/jbossas/docs
https://issues.jboss.org/browse/JBBOOT-138 https://issues.jboss.org/browse/JBBOOT-138
http://www.coderanch.com/t/90486/JBoss/Failed-load-users-passwords-role http://www.coderanch.com/t/90486/JBoss/Failed-load-users-passwords-role
http://docs.jboss.org/jbossas/getting_started/v5/html/tour.html#d0e569 http://docs.jboss.org/jbossas/getting_started/v5/html/tour.html#d0e569
http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch6.chapt.html http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch6.chapt.html
http://www.mastertheboss.com/jboss-jms/jboss-jms-queue-example http://www.mastertheboss.com/jboss-jms/jboss-jms-queue-example
http://stackoverflow.com/questions/2478729/jboss-messaging-jms http://stackoverflow.com/questions/2478729/jboss-messaging-jms
http://onjava.com/pub/a/onjava/2006/02/22/asynchronous-messaging-with-spr... http://onjava.com/pub/a/onjava/2006/02/22/asynchronous-messaging-with-spr...
http://forum.springsource.org/showthread.php?17491-Failed-to-convert-SpyC... http://forum.springsource.org/showthread.php?17491-Failed-to-convert-SpyC...
http://integrationsphere.blogspot.hu/2011/07/camel-and-hornetq-as-jms-pro... http://integrationsphere.blogspot.hu/2011/07/camel-and-hornetq-as-jms-pro...
http://integrationsphere.blogspot.hu/2011/07/camel-and-hornetq-as-jms-pro... http://integrationsphere.blogspot.hu/2011/07/camel-and-hornetq-as-jms-pro...
http://java.dzone.com/articles/camel-and-hornetq-jms-provider http://java.dzone.com/articles/camel-and-hornetq-jms-provider
http://www.theserverside.com/discussions/thread.tss?thread_id=9653 http://www.theserverside.com/discussions/thread.tss?thread_id=9653
https://community.jboss.org/thread/29768 https://community.jboss.org/thread/29768
http://stackoverflow.com/questions/5256060/ejb-exception-while-try-to-run... http://stackoverflow.com/questions/5256060/ejb-exception-while-try-to-run...
http://docs.jboss.org/jbossmessaging/docs/userguide-1.4.2.GA/html/install... http://docs.jboss.org/jbossmessaging/docs/userguide-1.4.2.GA/html/install...
http://mavenhub.com/c/org/jnp/interfaces/namingcontextfactory/dependency http://mavenhub.com/c/org/jnp/interfaces/namingcontextfactory/dependency
https://community.jboss.org/thread/154570 https://community.jboss.org/thread/154570
https://community.jboss.org/message/207352#207352#207352 https://community.jboss.org/message/207352#207352
https://community.jboss.org/thread/175935 https://community.jboss.org/thread/175935
https://community.jboss.org/thread/162575 https://community.jboss.org/thread/162575
http://www.javamonamour.org/2011/03/me-jms-hermesjms-and-jboss.html http://www.javamonamour.org/2011/03/me-jms-hermesjms-and-jboss.html
http://forum.springsource.org/showthread.php?59005-JNDI-connection-factor... http://forum.springsource.org/showthread.php?59005-JNDI-connection-factor...
http://www.stevideter.com/2008/08/25/simplifying-spring%E2%80%99s-jms-con... http://www.stevideter.com/2008/08/25/simplifying-spring%E2%80%99s-jms-con...
http://www.mydeveloperconnection.com/html/Spring-JNDI-Datasource..htm http://www.mydeveloperconnection.com/html/Spring-JNDI-Datasource..htm
http://forum.springsource.org/showthread.php?60768-Configuring-Initial-Co... http://forum.springsource.org/showthread.php?60768-Configuring-Initial-Co...
http://forum.springsource.org/archive/index.php/t-124901.html http://forum.springsource.org/archive/index.php/t-124901.html
http://java.dzone.com/articles/bridging-between-jms-and http://java.dzone.com/articles/bridging-between-jms-and
http://mail-archives.apache.org/mod_mbox/camel-users/201111.mbox/%3C13222... http://mail-archives.apache.org/mod_mbox/camel-users/201111.mbox/%3C13222... mailto:rg/mod_mbox/camel-users/201111.mbox/%3C1322215472697-5022416.post@n5.nabble.com rg/mod_mbox/camel-users/201111.mbox/%3C1322215472697-5022416.post(a)n5.nabble.com%3E
http://72.2.112.194/tag/spring http://72.2.112.194/tag/spring
http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch23s0... http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch23s0...
http://www.mentby.com/Group/apache-camel/jms-transaction-in-jboss-camel-i... http://www.mentby.com/Group/apache-camel/jms-transaction-in-jboss-camel-i...
http://www.torsten-horn.de/techdocs/jee-jndi.htm http://www.torsten-horn.de/techdocs/jee-jndi.htm
http://karaf.922171.n3.nabble.com/Paxexam-karaf-startup-issue-td3914766.html http://karaf.922171.n3.nabble.com/Paxexam-karaf-startup-issue-td3914766.html
http://karaf.922171.n3.nabble.com/Paxexam-karaf-startup-issue-td3916549.html http://karaf.922171.n3.nabble.com/Paxexam-karaf-startup-issue-td3916549.html
http://www.castor.org/spring-orm-integration.html http://www.castor.org/spring-orm-integration.html
http://forum.springsource.org/showthread.php?120990-Error-on-using-Jndi-T... http://forum.springsource.org/showthread.php?120990-Error-on-using-Jndi-T...
http://fusesource.com/docs/esb/3.5/jms/ESBJMSConnectFactoryJNDI.html http://fusesource.com/docs/esb/3.5/jms/ESBJMSConnectFactoryJNDI.html
http://forum.springsource.org/showthread.php?58223-Using-JNDI-to-configur... http://forum.springsource.org/showthread.php?58223-Using-JNDI-to-configur...
https://community.jboss.org/thread/152456 https://community.jboss.org/thread/152456
http://grokbase.com/t/servicemix/users/068yn1azmv/jndi-and-jbossmq http://grokbase.com/t/servicemix/users/068yn1azmv/jndi-and-jbossmq
http://docs.oracle.com/javase/jndi/tutorial/TOC.html http://docs.oracle.com/javase/jndi/tutorial/TOC.html
http://activemq.2283324.n4.nabble.com/Route-messages-from-HornetQ-to-Acti... http://activemq.2283324.n4.nabble.com/Route-messages-from-HornetQ-to-Acti...
http://stackoverflow.com/questions/1974883/jboss-4-2-2-to-5-0-1-migration... http://stackoverflow.com/questions/1974883/jboss-4-2-2-to-5-0-1-migration...
http://docs.jboss.org/jbossremoting/2.5.4.SP2/userguide/html_single/ http://docs.jboss.org/jbossremoting/2.5.4.SP2/userguide/html_single/
http://docs.jboss.org/jbossremoting/2.5.3.SP1/html/ http://docs.jboss.org/jbossremoting/2.5.3.SP1/html/
http://stackoverflow.com/questions/8561622/jboss-as-7-simple-hello-world-... http://stackoverflow.com/questions/8561622/jboss-as-7-simple-hello-world-...
https://community.jboss.org/message/613171#613171 https://community.jboss.org/message/613171
http://www.mastertheboss.com/jboss-configuration/the-jndiproperty-pitfall http://www.mastertheboss.com/jboss-configuration/the-jndiproperty-pitfall
http://www.mastertheboss.com/jboss-configuration/jboss-port-configuration http://www.mastertheboss.com/jboss-configuration/jboss-port-configuration
http://www.mastertheboss.com/jboss-jms http://www.mastertheboss.com/jboss-jms
http://www.mastertheboss.com/jboss-jms/jboss-jms-configuration/page-2 http://www.mastertheboss.com/jboss-jms/jboss-jms-configuration/page-2
http://www.mastertheboss.com/jboss-jms/jboss-jms-queue-example http://www.mastertheboss.com/jboss-jms/jboss-jms-queue-example
https://issues.jboss.org/secure/attachmentzip/unzip/12400214/12330767%5B6... https://issues.jboss.org/secure/attachmentzip/unzip/12400214/12330767%5B6...
http://www.mastertheboss.com/jboss-jms/jboss-jms-configuration/page-2 http://www.mastertheboss.com/jboss-jms/jboss-jms-configuration/page-2
http://www.mastertheboss.com/jboss-jms/jboss-jms-queue-example http://www.mastertheboss.com/jboss-jms/jboss-jms-queue-example
http://stackoverflow.com/questions/11471679/spring-configure-the-datasour... http://stackoverflow.com/questions/11471679/spring-configure-the-datasour...
http://fusesource.com/forums/thread.jspa?messageID=7828 http://fusesource.com/forums/thread.jspa?messageID=7828
https://community.jboss.org/message/439509#439509#439509 https://community.jboss.org/message/439509#439509
http://docs.jboss.org/jbossmessaging/docs/userguide-1.4.0.SP3/html/instal... http://docs.jboss.org/jbossmessaging/docs/userguide-1.4.0.SP3/html/instal...
http://www.tutorials.de/enterprise-java-jee-j2ee-spring-co/355197-invalid... http://www.tutorials.de/enterprise-java-jee-j2ee-spring-co/355197-invalid...
http://integrationsphere.blogspot.hu/2011/07/camel-and-hornetq-as-jms-pro... http://integrationsphere.blogspot.hu/2011/07/camel-and-hornetq-as-jms-pro...
https://community.jboss.org/thread/128897 https://community.jboss.org/thread/128897
https://community.jboss.org/thread/1468 https://community.jboss.org/thread/1468
http://camel.apache.org/maven/current/camel-jms/apidocs/org/apache/camel/... http://camel.apache.org/maven/current/camel-jms/apidocs/org/apache/camel/... [JBoss JMS Component Javadoc]
http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch3.chapter.html http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch3.chapter.html
http://www.coderanch.com/t/459111/java/java/security-manager-rmi-class-lo... http://www.coderanch.com/t/459111/java/java/security-manager-rmi-class-lo...
https://community.jboss.org/message/197278#197278 https://community.jboss.org/message/197278
http://www.tutorials.de/enterprise-java-jee-j2ee-spring-co/355197-invalid... http://www.tutorials.de/enterprise-java-jee-j2ee-spring-co/355197-invalid...
http://s139.codeinspot.com/q/878267 http://s139.codeinspot.com/q/878267
http://forum.springsource.org/showthread.php?90417-Using-JMS-Namespace-Su... http://forum.springsource.org/showthread.php?90417-Using-JMS-Namespace-Su...
http://static.springsource.org/spring/docs/3.1.x/spring-framework-referen... http://static.springsource.org/spring/docs/3.1.x/spring-framework-referen...
I had many weird errors as well (later debugged), but I still cannot make my Camel route to consume from JBoss.
I have written three POJO's to send and receive from/to JBoss, as well.
*First is Sender.java:*
*package jBossMain;*
*import javax.jms.*;*
*import javax.naming.*;*
*import java.util.Hashtable;*
*public class Sender*
*{*
* public static final String JNDI_URL = "jnp://localhost:1399";*
* public static final String JNDI_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";*
* public static final String JMS_USER = null;*
* public static final String JMS_PASSWORD = null;*
* public static final String JMS_CONNECTION_FACTORY = "ConnectionFactory";*
* public static final String QUEUE_JNDI_NAME = "/queue/Test1";*
* public static void main( String[] args )*
* {*
* QueueConnection qConn = null;*
* QueueSession qSession = null;*
* QueueSender qSender = null;*
* try*
* {*
* //Context parameters*
* Hashtable<String, String> env = new Hashtable<String, String>();*
* env.put( Context.INITIAL_CONTEXT_FACTORY, JNDI_CONTEXT_FACTORY );*
* env.put( Context.PROVIDER_URL, JNDI_URL );*
* if( JMS_USER != null )*
* {*
* env.put( Context.SECURITY_PRINCIPAL, JMS_USER );*
* }*
* if( JMS_PASSWORD != null )*
* {*
* env.put( Context.SECURITY_CREDENTIALS, JMS_PASSWORD );*
* }*
* //Creating context*
* Context jndiContext = new InitialContext( env );*
* //Queue connection factory*
* QueueConnectionFactory cFactory = (QueueConnectionFactory) jndiContext.lookup(JMS_CONNECTION_FACTORY);*
* //Create Connection*
* if( JMS_USER == null || JMS_PASSWORD == null )*
* {*
* qConn = cFactory.createQueueConnection();*
* }*
* else*
* {*
* qConn = cFactory.createQueueConnection( JMS_USER, JMS_PASSWORD );*
* }*
* //Create Session*
* qSession = qConn.createQueueSession( false, Session.AUTO_ACKNOWLEDGE );*
* //Lookup Queue*
* Queue queue = (Queue) jndiContext.lookup(QUEUE_JNDI_NAME);*
* //Create Queue Sender*
* qSender = qSession.createSender( queue );*
* //Start receiving messages*
* qConn.start();*
* //Close JNDI context*
* jndiContext.close();*
* TextMessage msg = qSession.createTextMessage("Hello World!");*
* qSender.send(msg);*
* Thread.sleep(2000);*
* if(qSender != null) qSender.close();*
* if(qSession != null) qSession.close();*
* if(qConn != null) qConn.close();*
* }*
* catch( Exception e )*
* {*
* e.printStackTrace();*
* }*
* }*
*}*
*Second is SerialReceiver.java*, which can consume only 1 message per run:
*package jBossMain;*
*import javax.jms.*;*
*import javax.naming.*;*
*import java.util.Hashtable;*
*public class SerialReceiver*
*{*
* public static final String JNDI_URL = "jnp://localhost:1399";*
* public static final String JNDI_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";*
* public static final String JMS_USER = null;*
* public static final String JMS_PASSWORD = null;*
* public static final String JMS_CONNECTION_FACTORY = "ConnectionFactory";*
* public static final String QUEUE_JNDI_NAME = "/queue/Test1";*
* public static void main( String[] args )*
* {*
* QueueConnection qConn = null;*
* QueueSession qSession = null;*
* QueueReceiver qReceiver = null;*
* try*
* {*
* //Context parameters*
* Hashtable<String, String> env = new Hashtable<String, String>();*
* env.put( Context.INITIAL_CONTEXT_FACTORY, JNDI_CONTEXT_FACTORY );*
* env.put( Context.PROVIDER_URL, JNDI_URL );*
* if( JMS_USER != null )*
* {*
* env.put( Context.SECURITY_PRINCIPAL, JMS_USER );*
* }*
* if( JMS_PASSWORD != null )*
* {*
* env.put( Context.SECURITY_CREDENTIALS, JMS_PASSWORD );*
* }*
* //Creating context*
* Context jndiContext = new InitialContext( env );*
* //Queue connection factory*
* QueueConnectionFactory cFactory = (QueueConnectionFactory) jndiContext.lookup(JMS_CONNECTION_FACTORY);*
* //Create Connection*
* if( JMS_USER == null || JMS_PASSWORD == null )*
* {*
* qConn = cFactory.createQueueConnection();*
* }*
* else*
* {*
* qConn = cFactory.createQueueConnection( JMS_USER, JMS_PASSWORD );*
* }*
* //Create Session*
* qSession = qConn.createQueueSession( false, Session.AUTO_ACKNOWLEDGE );*
* //Lookup Queue*
* Queue queue = (Queue) jndiContext.lookup(QUEUE_JNDI_NAME);*
* //Create Queue Receiver*
* qReceiver = qSession.createReceiver( queue );*
* //Start receiving messages*
* qConn.start();*
* //Close JNDI context*
* jndiContext.close();*
* //javax.jms.TextMessage object, body can be extracted.*
* TextMessage msg = (TextMessage) qReceiver.receive();*
* Thread.sleep(2000);*
* if(qReceiver != null) qReceiver.close();*
* if(qSession != null) qSession.close();*
* if(qConn != null) qConn.close();*
* System.out.println( msg.toString() );*
* //Only available if msg is of type TextMessage:*
* System.out.println( msg.getText() );*
* }*
* catch( Exception e )*
* {*
* e.printStackTrace();*
* }*
* }*
*}*
*Third is ContinuousReceiver.java*, which will receive all messages from the queue while running:
*package jBossMain;*
*import javax.jms.*;*
*import javax.naming.*;*
*import java.util.Hashtable;*
*public class ContinuousReceiver implements MessageListener*
*{*
* public static final String JNDI_URL = "jnp://localhost:1399";*
* public static final String JNDI_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";*
* public static final String JMS_USER = null;*
* public static final String JMS_PASSWORD = null;*
* public static final String JMS_CONNECTION_FACTORY = "ConnectionFactory";*
* public static final String QUEUE_JNDI_NAME = "/queue/Test1";*
* public static void main( String[] args )*
* {*
* QueueConnection qConn = null;*
* QueueSession qSession = null;*
* QueueReceiver qReceiver = null;*
* try*
* {*
* //Context parameters*
* Hashtable<String, String> env = new Hashtable<String, String>();*
* env.put( Context.INITIAL_CONTEXT_FACTORY, JNDI_CONTEXT_FACTORY );*
* env.put( Context.PROVIDER_URL, JNDI_URL );*
* if( JMS_USER != null )*
* {*
* env.put( Context.SECURITY_PRINCIPAL, JMS_USER );*
* }*
* if( JMS_PASSWORD != null )*
* {*
* env.put( Context.SECURITY_CREDENTIALS, JMS_PASSWORD );*
* }*
* //Creating context*
* Context jndiContext = new InitialContext( env );*
* //Queue connection factory*
* QueueConnectionFactory cFactory = (QueueConnectionFactory) jndiContext.lookup(JMS_CONNECTION_FACTORY);*
* //Create Connection*
* if( JMS_USER == null || JMS_PASSWORD == null )*
* {*
* qConn = cFactory.createQueueConnection();*
* }*
* else*
* {*
* qConn = cFactory.createQueueConnection( JMS_USER, JMS_PASSWORD );*
* }*
* //Create Session*
* qSession = qConn.createQueueSession( false, Session.AUTO_ACKNOWLEDGE );*
* //Lookup Queue*
* Queue queue = (Queue) jndiContext.lookup(QUEUE_JNDI_NAME);*
* //Create Queue Receiver*
* qReceiver = qSession.createReceiver( queue );*
* ContinuousReceiver CR = new ContinuousReceiver();*
* qReceiver.setMessageListener( CR );*
* //Start receiving messages*
* qConn.start();*
* //Close JNDI context*
* jndiContext.close();*
* Thread.sleep(25000);*
* if(qReceiver != null) qReceiver.close();*
* if(qSession != null) qSession.close();*
* if(qConn != null) qConn.close();*
* }*
* catch( Exception e )*
* {*
* e.printStackTrace();*
* }*
* }*
* public void onMessage( Message message )*
* {*
* try*
* {*
* System.out.println( "The type of the received message is: " + message.getJMSType() );*
* if( message instanceof TextMessage )*
* {*
* TextMessage textMessage = ( TextMessage ) message;*
* System.out.println( "The text content: " + textMessage.getText() );*
* }*
* else*
* {*
* System.out.println( message.toString() );*
* }*
* }*
* catch(JMSException je)*
* {*
* je.printStackTrace();*
* }*
* }*
*}*
I have tried to embed these POJO-s, as Processor beans, into Camel routes, with no success.
I was not able to run them in ServiceMix. (They were originally running in Eclipse, so I bundlefied and deployed tose JBoss JARs, which were imported automatically by the IDE.)
It is rather funny to me, that only a number of forum topics deal with such a cardinal question: how to make Camel routes between
JBoss MQ-s, and something else. JBoss MQ-s are widely used...
Also, if there is a handful of topics on it, they do not conclude to anything, or they state some wrong,
stupid solutions, that doesn't work.
So I kindly ask, if there is a single man/woman on the Internet, who can solve this problem IN REALITY,
please tell the EXACT solution to me.
I am especially interested in:
- the exact Camel/Spring config,
- the JAr's Import-Package statements,
- and the dependency JARs GAV values.
[Perhaps my JBoss is not configured properly (I don't think so), or I missed some beans from the camel-context.xml...]
With best regards:
Tamás Benke
Junior Java developer, IOCC team
Lufthansa Systems Hungária Kft.
BUD LSYH - Airline Management Solutions
INFOPARK, Building E
Neumann János u. 1./E.
H-1117 Budapest
Hungary
E-mail: mailto:tamas.benke.U522971@LHsystems.com tamas.benke.U522971(a)LHsystems.com
www.LHsystems.com
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/801818#801818]
Start a new discussion in JBoss Messaging at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
13 years, 1 month
[Javassist] - javassist not injecting annotation on an existing field
by Ankur Gupta
Ankur Gupta [https://community.jboss.org/people/geekerebos] created the discussion
"javassist not injecting annotation on an existing field"
To view the discussion, visit: https://community.jboss.org/message/801815#801815
--------------------------------------------------------------
| 0 down vote favorite (http://stackoverflow.com/questions/15332399/javassist-not-injecting-annot...) |
I'm trying to inject JAXB annotation at runtime using Javassist. I have written following code:
public class AssistAnnotationInjector { public static void addAnnotationRunTime(String className, String fieldName) throws NotFoundException, CannotCompileException, IOException, ClassNotFoundException{ CtClass ctClass = ClassPool.getDefault().get(className); ClassFile ccFile = ctClass.getClassFile(); ConstPool constPool = ccFile.getConstPool(); AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag); Annotation annot = new Annotation("javax.xml.bind.annotation.XmlTransient",constPool); attr.addAnnotation(annot); CtField field = ctClass.getDeclaredField(fieldName); field.getFieldInfo().addAttribute(attr); System.out.println(field.getAnnotation(XmlTransient.class)); ccFile.setVersionToJava5(); ctClass.writeFile(); } public static void main (String args[]) throws CannotCompileException, NotFoundException, IOException, SecurityException, NoSuchMethodException, ClassNotFoundException, JAXBException, NoSuchFieldException{ Person<Student> p = new Person<Student>(); p.setName("XYZ"); Student s = new Student(); s.setName("ABC"); s.setId("239423"); p.setPayload(s); addAnnotationRunTime("RuntimeAnnotation.Person", "name"); Field f = p.getClass().getDeclaredField("name"); System.out.println(f.getAnnotation(XmlTransient.class)); JAXBContext context = JAXBContext.newInstance(p.getClass()); Marshaller mr = context.createMarshaller(); mr.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); mr.marshal(p, System.out); } }
And Person.java class is:
@XmlRootElement(name="Person") @XmlAccessorType(XmlAccessType.FIELD) @XmlSeeAlso({Student.class}) public class Person <T>{ private T payload; private String name; public void setPayload(T payload){ this.payload = payload; } public T getPayload(){ return payload; } public void setName(String name){ this.name = name; } public String getName(){ return name; } }
In AssistAnnotationInjector.java, I am trying to add XmlTransient annotation to 'name' field. But the name field is still coming in marshalling output. Why is it so?
PS: marshal output is :
@javax.xml.bind.annotation.XmlTransient null <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Person> <payload xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="student"> <name>ABC</name> <id>239423</id> </payload> **<name>XYZ</name>** </Person>
name tag was not expected to present in output.. |
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/801815#801815]
Start a new discussion in Javassist at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
13 years, 1 month
[JBoss Tools] - Getting "association error" when reverse-engineering an existing schema with Hibernate tools
by John Citizen
John Citizen [https://community.jboss.org/people/johnqcitizen] created the discussion
"Getting "association error" when reverse-engineering an existing schema with Hibernate tools"
To view the discussion, visit: https://community.jboss.org/message/801484#801484
--------------------------------------------------------------
I'm connecting to a production Oracle 10g database and attempting to generate a Hibernate configuration file using the hibernate3-maven-plugin running in Maven.
However when I run the hibernate3:hbm2java goal I get the following error: An association from the table FOO refers to the unmapped class com.whatever.domain.Bar
My maven project file looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>jdbcconfiguration</implementation>
<outputDirectory>target/classes</outputDirectory>
</component>
</components>
<componentProperties>
<propertyfile>src/main/resources/hibernate.properties</propertyfile>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>11.1.0.6.0</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
</dependencies>
</plugin>
My *hibernate.properties* file contains the following:
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:@<server>:<host>:<db>
hibernate.connection.username=<username>
hibernate.connection.password=<password>
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.default_schema=<schema>
Because this is a production database, then I assume that the schema is sound and expect the *hibernate3-maven-plugin* to extract that schema and generate annotated java files without error.
I've narrowed down the offending tables to the following:
* FOO*
- foreign key 'a' in BAR
- foreign key 'b' in BAR
- foreign key 'c' in QUUX
- primary key is composite of foreign keys 'a', 'b' in BAR and foreign key 'c' in QUUX
* BAR*
- foreign key 'a' in BAZ
- foreign key 'b' in QUX
- primary key is a composite of the foreign key 'a' in BAZ and foreign key 'b' in QUX
* BAZ*
- primary key 'a'
- no foreign keys
* QUX*
- primary key 'b'
- no foreign keys
* QUUX*
- primary key 'c'
- no foreign keys
If I specify the tables FOO, BAR and BAZ in a *reveng.xml* file, then the *hbm2java* goal is successful. If I specify the tables FOO, BAR, and QUX in a *reveng.xml* file, then the *hbm2java* goal is successful. But if tables FOO, BAR, BAZ, and QUX are specified then the *hbm2java* goal fails with the aforementoned association error between FOO and com.whatever.domain.Bar file. That is, if both tables representing the foreign keys in BAR are present, then the goal fails. If just one foreign key table is present, then the goal succeeds.
Any suggestions on what is causing the problem, and how to fix it?
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/801484#801484]
Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
13 years, 1 month
[Beginner's Corner] - update or insert taking too long...
by harikris
harikris [https://community.jboss.org/people/harikris] created the discussion
"update or insert taking too long..."
To view the discussion, visit: https://community.jboss.org/message/801789#801789
--------------------------------------------------------------
Hi All,
My setup is: JBOSS AS 7.1.1 and PostGreSql
When there are no or very less (a couple of hundred) records in the table, my inserts/updates completes very fast.
But when the number of records get to a couple of thousand, the inserts or updates take an extremely long time. For ex: inserting a record takes more than 1 or 2 seconds.
Not sure where the problem is or where to start.
My code to update the database looks like this -
public long updateRecord(long id, List<MyData> myDataList) {
Event eventFromDB = findById(id).get(0);
for(MyData myData : myDataList) {
eventFromDB.getMyData().add(myData);
}
em.merge(eventFromDB);
return 1L;
}
I am a newbie and have set up the jboss as to the best of my knowledge.
I haven't done any configuration settings on either the JBOSS AS or the PostGreSQL.
The JBOSS AS is running in the standalone mode using the standalone-full.xml config file.
Thanks in advance.
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/801789#801789]
Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
13 years, 1 month
[JBoss Portal] - how to make the popup login form display the saved username and password
by Wells guo
Wells guo [https://community.jboss.org/people/wguo] created the discussion
"how to make the popup login form display the saved username and password"
To view the discussion, visit: https://community.jboss.org/message/800525#800525
--------------------------------------------------------------
Hi guys ,
When i use the jboss portal , click the 'Sign in', it pop up a login form , then i enter the username and password and click login , then the browser display me to remember the password , click yes . And then logout , click 'Sign in' again , the login form appeares , but the username and password are not filled in the form , but if i don't close the login form , just refresh the page , the username and password were filled , so if there is any solution which can fill the username and password when i just click 'Sign in' .
Thanks !
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/800525#800525]
Start a new discussion in JBoss Portal at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
13 years, 1 month