I am working on a POC to design workflow for our company. we heavily use ActiveMQ in our system. I am working on integrating activiti and camel routes that has activeMQ queues inside it.when I run the process, it goes through the camel route containing the queues and creates the new queues but the messages is not passed from one queue to another.
I get this following message on the target queue:
Unknown message type [org.apache.activemq.command.ActiveMQMessage] ActiveMQMessage
below is the stack trace:
2:11:59.705 [Camel (camelContext) thread #0 - JmsConsumer[TESTQUEUE]] WARN o.a.c.c.jms.EndpointMessageListener - Execution of JMS message listener failed. Caused by: [org.apache.camel.RuntimeCamelException - org.activiti.engine.ActivitiIllegalArgumentException: Business key is null]
org.apache.camel.RuntimeCamelException: org.activiti.engine.ActivitiIllegalArgumentException: Business key is null
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1363) ~[camel-core-2.13.2.jar:2.13.2]
at org.apache.camel.component.jms.EndpointMessageListener$EndpointMessageListenerAsyncCallback.done(EndpointMessageListener.java:186) ~[camel-jms-2.13.1.jar:2.13.1]
at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:107) ~[camel-jms-2.13.1.jar:2.13.1]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562) ~[spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500) ~[spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468) ~[spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1101) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1093) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:990) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_40]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_40]
at java.lang.Thread.run(Thread.java:724) [na:1.7.0_40]
Caused by: org.activiti.engine.ActivitiIllegalArgumentException: Business key is null
Here is my camelRoute.bpmn file:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath"
targetNamespace="http://www.activiti.org/test">
<process id="SimpleCamelCallProcess" isExecutable="true">
<startEvent id="start"/>
<sequenceFlow id="flow1" sourceRef="start" targetRef="simpleCall"/>
<serviceTask id="simpleCall" activiti:type="camel"/>
<sequenceFlow id="flow2" sourceRef="simpleCall" targetRef="end"/>
<endEvent id="end"/>
</process>
</definitions>
Below is my camel route calling the bpmn:
public class CamelHelloRoute extends RouteBuilder {
private static final Logger logger = LoggerFactory.getLogger(CamelHelloRoute.class);
#Override
public void configure() throws Exception {
from("activemq:queue:TESTQUEUE")
.log(LoggingLevel.INFO, "Received message ")
.to("activiti:SimpleCamelCallProcess:simpleCall");
from("activiti:SimpleCamelCallProcess:simpleCall")
.log(LoggingLevel.INFO, "Received message on service task ")
.to("activemq:queue:TESTQUEUE3");
}
}
Below is my junit class:
public class ProcessTestSimpleCamelCallProcess {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-int.xml");
#Rule
public ActivitiRule activitiRule= (ActivitiRule) applicationContext.getBean("activitiRule");
public RepositoryService repositoryService=(RepositoryService) applicationContext.getBean("repositoryService");
#Test
public void startProcess() throws Exception {
repositoryService = activitiRule.getRepositoryService();
repositoryService.createDeployment().addClasspathResource("camelRoute.bpmn").deploy();
RuntimeService runtimeService = activitiRule.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("SimpleCamelCallProcess");
assertNotNull(processInstance.getId());
System.out.println("id " + processInstance.getId() + " "
+ processInstance.getProcessDefinitionId());
}
Below is my spring file "camel-int.xml":
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring-2.13.2.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/workflowtest"></property>
<property name="username" value="root"></property>
<property name="password" value="abc123"></property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="activitiRule" class="org.activiti.engine.test.ActivitiRule">
<property name="processEngine" ref="processEngine" />
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
<packageScan>
<package>com.activiti.camel</package>
</packageScan>
</camelContext>
</beans>
Related
I have a situation with my spring integration with rabbitmq. The messages are sent to the queues but end up in the ready state and one as unacknowledged but the consumer doesn't gets them.
Thx xml configuration is like this:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/amqp
http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:spring/prj-rabbitmq-context-thirdparty.properties" ignore-unresolvable="true" order="3"/>
<rabbit:connection-factory
id="prjRabbitmqConnectionFactory"
addresses="${rabbitmq.addresses}"
username="${rabbitmq.username}"
password="${rabbitmq.password}"
connection-timeout="5000" />
<bean id="rabbitTxManager"
class="org.springframework.amqp.rabbit.transaction.RabbitTransactionManager">
<property name="connectionFactory" ref="prjRabbitmqConnectionFactory"/>
</bean>
<rabbit:template
id="prjRabbitmqTemplate"
connection-factory="prjRabbitmqConnectionFactory"
message-converter="serializerMessageConverter"
retry-template="retryTemplate" />
<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
<property name="backOffPolicy">
<bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
<property name="initialInterval" value="1000" />
<property name="multiplier" value="3" />
<property name="maxInterval" value="10000" />
</bean>
</property>
</bean>
<rabbit:admin
id="prjRabbitmqAdmin"
auto-startup="true"
connection-factory="prjRabbitmqConnectionFactory" />
<rabbit:queue
id="prjSyncQueue"
name="${prj.sync.queue}"
durable="true">
<rabbit:queue-arguments>
<entry key="x-ha-policy" value="all" />
</rabbit:queue-arguments>
</rabbit:queue>
<rabbit:listener-container
connection-factory="prjRabbitmqConnectionFactory"
acknowledge="auto"
channel-transacted="true"
transaction-manager="rabbitTxManager"
task-executor="prjSyncExecutor"
concurrency="1"
max-concurrency="2"
requeue-rejected="true"
message-converter="serializerMessageConverter">
<rabbit:listener
ref="prjProcessorService"
queue-names="${prj.sync.queue}" method="processMessage" />
</rabbit:listener-container>
<task:executor id="prjSyncExecutor"
pool-size="${prj.sync.concurrency.min}-${prj.sync.concurrency.max}"
keep-alive="${prj.sync.concurrency.keep-alive}"
queue-capacity="${prj.sync.concurrency.queue}"
rejection-policy="CALLER_RUNS"/>
<int:channel
id="prjChannel" />
<int-amqp:outbound-channel-adapter
channel="prjChannel"
amqp-template="prjRabbitmqTemplate"
exchange-name="prjSyncExchange"
routing-key="prj-event"
default-delivery-mode="PERSISTENT" />
<rabbit:direct-exchange
name="prjSyncExchange">
<rabbit:bindings>
<rabbit:binding
queue="prjSyncQueue"
key="prj-event" />
</rabbit:bindings>
</rabbit:direct-exchange>
<int:gateway
id="prjGateway"
service-interface="ro.oss.niinoo.thirdparty.prj.gateway.prjEnrichmentGateway">
<int:method
name="send"
request-channel="prjChannel"/>
</int:gateway>
<bean id="prjProcessorService" class="ro.oss.niinoo.thirdparty.prj.processor.impl.prjEnrichmentProcessorImpl" />
<bean id="serializerMessageConverter" class="ro.oss.niinoo.thirdparty.prj.serializer.prjSerializer"/>
On the server restart the first one is picked up but on the next call the messages piles up in the queue. Do you have any idea why this might happen ?
Thanks
Daniel
EDIT:
The consumer code:
public class JsonEnrichmentService implements EnrichmentService {
#Resource
private UserQueryService userQueryService;
#Resource
private SecurityContextService securityContextService;
#Override
public void processMessage(POJO record) {
System.out.println(record);
}
This will call a new service that has a Transactional annotation to it.
In my experience, this is generally caused by the listener thread being "stuck" in user code someplace. Take a thread dump to see what the listener thread is doing.
How to enable logging in Spring Junit test? I think web.xml is not found when I do tests. Need to tell somehow to Junit where is web.xml with log configuration exists so logs will start working and I could bebug springs configuration errors.
My test class:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration("test-context.xml")
public class DSLCapacityTest {
private MockHttpServletRequest request;
private MockHttpServletResponse response;
#Autowired private DSLCapacity dc;
private AnnotationMethodHandlerAdapter adapter;
#Before
public void setUp() throws Exception {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
response.setOutputStreamAccessAllowed(true);
adapter = new AnnotationMethodHandlerAdapter();
}
#Test
#Repeat(2)
public void testGetIndex() throws Exception {
request.setRequestURI("/dashboard/dsl-capacity/");
request.setMethod("GET");
ModelAndView mv = adapter.handle(request, response, dc);
assertSame("Incorrect message", "dashboard/dsl-capacity/index", mv.getViewName());
}
And my test-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.2.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.8.0.xsd">
<bean id="portalAuthenticator" class="uk.co.powergroup.portal.security.Authenticator">
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:ignoreUnresolvablePlaceholders="false">
<property name="location">
<value>file:/etc/portal-frontend/config.properties</value>
</property>
</bean>
<sec:authentication-manager>
<sec:authentication-provider ref='portalAuthenticator'/>
</sec:authentication-manager>
<sec:http pattern="/favicon.ico" security="none"/>
<sec:http pattern="/static/**" security="none"/>
<sec:http pattern="/logged-out" security="none"/>
<sec:http pattern="/login" security="none"/>
<sec:http pattern="/**/nologin*" security="none"/>
<sec:http auto-config="false" use-expressions="true">
<sec:csrf disabled="true"/>
<sec:intercept-url pattern="/forgot-password" access="isAnonymous()"/>
<sec:intercept-url pattern="/**" access="isAuthenticated()" />
<sec:logout logout-url="/logout" logout-success-url="/logged-out"/>
<sec:form-login login-page="/login" login-processing-url="/login-security-check" authentication-failure-url="/login" />
<sec:custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrencyFilter" />
<sec:session-management session-authentication-strategy-ref="sas"/>
<sec:custom-filter ref="userValidator" after="FILTER_SECURITY_INTERCEPTOR" />
</sec:http>
<sec:global-method-security pre-post-annotations="enabled" secured-annotations="enabled">
<sec:expression-handler ref="expressionHandler"/>
</sec:global-method-security>
<bean id="userValidator" class="uk.co.powergroup.portal.security.UserValidator">
</bean>
<bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
<property name="permissionEvaluator" ref="myPermissionEvaluator"/>
</bean>
<bean id="myPermissionEvaluator" class="uk.co.powergroup.portal.security.PermissionChecker"/>
<bean id="concurrencyFilter" class="org.springframework.security.web.session.ConcurrentSessionFilter">
<constructor-arg name="sessionRegistry" ref="sessionRegistry" />
<constructor-arg name="expiredUrl" value="/login" />
</bean>
<bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl"/>
<bean id="sas" class="org.springframework.security.web.authentication.session.ConcurrentSessionControlAuthenticationStrategy">
<constructor-arg name="sessionRegistry" ref="sessionRegistry" />
<property name="maximumSessions" value="-1"/>
</bean>
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="PORTAL2DB"/>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="myEmf"/>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://10.10.10.249:3306/portal"/>
<property name="username" value="portal"/>
<property name="password" value="twink13s"/>
</bean>
<bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
destroy-method="stop">
<property name="connectionFactory">
<bean class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>${activemq.uri}</value>
</property>
<property name="password">
<value>${activemq.password}</value>
</property>
<property name="userName">
<value>${activemq.user}</value>
</property>
</bean>
</property>
<!-- Make this 2.5 minutes in case for some reason the JMS tester job stops (sends every minute so default of 30 seconds too short) -->
<property name="idleTimeout" value="150000"/>
</bean>
<!-- Spring JMS Template -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsFactory"/>
<property name="receiveTimeout" value="1000"/>
<property name="sessionTransacted" value="false"/>
</bean>
<bean id="jmsMessageListener" class="uk.co.powergroup.portal.jms.ReplyHandler"/>
<jms:listener-container container-type="default" connection-factory="jmsFactory" acknowledge="auto"
concurrency="2-5">
<jms:listener destination="${activemq.replyQueue}" ref="jmsMessageListener"/>
</jms:listener-container>
<bean id="threadPool" class="uk.co.powergroup.portal.helper.ThreadPool"/>
<bean name="retryTransactionsFilterBean" class="uk.co.powergroup.portal.helper.RetryFilter"/>
<bean id="conversionService"
class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="uk.co.powergroup.portal.converters.PermissionConverter"/>
<bean class="uk.co.powergroup.portal.converters.RoleConverter"/>
<bean class="uk.co.powergroup.portal.converters.SuiteConverter"/>
<bean class="uk.co.powergroup.portal.converters.DataCentreConverter"/>
<bean class="uk.co.powergroup.portal.converters.DataCentreLocationConverter"/>
<bean class="uk.co.powergroup.portal.converters.CompanyConverter"/>
<bean class="uk.co.powergroup.portal.converters.HardwareConverter"/>
<bean class="uk.co.powergroup.portal.converters.RackConverter"/>
<bean class="uk.co.powergroup.portal.converters.EquipmentConverter"/>
<bean class="uk.co.powergroup.portal.converters.PowerDistributionUnitTypeConverter"/>
<bean class="uk.co.powergroup.portal.converters.TimeZoneDOConverter"/>
<bean class="uk.co.powergroup.portal.converters.DslLnsBearerTypeConverter"/>
<bean class="uk.co.powergroup.portal.converters.DslLnsLocationConverter"/>
<bean class="uk.co.powergroup.portal.converters.DslLnsOrganisationConverter"/>
<bean class="uk.co.powergroup.portal.converters.DslLnsConverter"/>
<bean class="uk.co.powergroup.portal.converters.BigDecimalConverter"/>
<bean class="uk.co.powergroup.portal.converters.PstnNumberDDIConverter"/>
</set>
</property>
</bean>
<context:component-scan base-package="uk.co.powergroup.portal.dao.impl"
name-generator="uk.co.powergroup.portal.misc.BeanNameGeneratorImpl"/>
You can do configuration for log4j.properties in your test case file so it will create log for you.
#BeforeClass
public static void init() {
PropertyConfigurator.configure("src/configuration/log4j.properties");
}
Java web containers mainly used web.xml file and also web.xml file not belongs to Spring context configuration.
Hy there folks, i'm facing a problem here where I work, there is a project when initialized works with 1 SQL Server Instance, 2 DB2 instances.
The problem is, this project was based on another project to keep the similar structure, but on this new project we don't use the SQL Server instance who is in reference on some xml files, I tried to comment these references, when I start the project on Tomcat, the project show me few errors.
As a new on Spring, how can I remove this connection properly??
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
<jee:jndi-lookup id="IP_ICMS_RJ" jndi-name="java:comp/env/IP_ICMS_RJ" />
<jee:jndi-lookup id="USUARIO_ICMS_RJ" jndi-name="java:comp/env/USUARIO_ICMS_RJ" />
<jee:jndi-lookup id="SENHA_ICMS_RJ" jndi-name="java:comp/env/SENHA_ICMS_RJ" />
<jee:jndi-lookup id="IP_ICMS_SP" jndi-name="java:comp/env/IP_ICMS_SP" />
<jee:jndi-lookup id="USUARIO_ICMS_SP" jndi-name="java:comp/env/USUARIO_ICMS_SP" />
<jee:jndi-lookup id="SENHA_ICMS_SP" jndi-name="java:comp/env/SENHA_ICMS_SP" />
<jee:jndi-lookup id="PSACWSDocumentURL" jndi-name="java:comp/env/PSACWSDocumentURL" />
<jee:jndi-lookup id="PSACWSEndPoint" jndi-name="java:comp/env/PSACWSEndPoint" />
<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" />
<aop:aspectj-autoproxy/>
<bean id="FaleConoscoWSBean" class="br.com.embratel.faleconosco.ws.FaleConoscoWSBean">
</bean>
<bean id="RoboFaleConoscoWSBean" class="br.com.embratel.faleconosco.ws.RoboFaleConoscoWSBean">
</bean>
<!-- <bean id="faleConoscoDS" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/FaleConoscoDS" />
</bean> -->
<bean id="icmsRJDS" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/ICMS_RJ_DS" />
</bean>
<bean id="icmsSPDS" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/ICMS_SP_DS" />
</bean>
<bean id="icmsRJ" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
<constructor-arg ref="icmsRJDS" />
</bean>
<bean id="icmsSP" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
<constructor-arg ref="icmsSPDS" />
</bean>
<util:map id="icmsPropertiesMap">
<entry key="IP_RJ" value-ref="IP_ICMS_RJ" />
<entry key="USUARIO_RJ" value-ref="USUARIO_ICMS_RJ" />
<entry key="SENHA_RJ" value-ref="SENHA_ICMS_RJ" />
<entry key="IP_SP" value-ref="IP_ICMS_SP" />
<entry key="USUARIO_SP" value-ref="USUARIO_ICMS_SP" />
<entry key="SENHA_SP" value-ref="SENHA_ICMS_SP" />
</util:map>
<!-- Lista de processadores de OS -->
<util:list id="processors">
<bean class="br.com.embratel.faleconosco.ws.service.os.processor.ClienteProcessor" />
<bean class="br.com.embratel.faleconosco.ws.service.os.processor.ServicoEquipamentoProcessor" />
<bean class="br.com.embratel.faleconosco.ws.service.os.processor.SuspensaoProcessor" />
<bean class="br.com.embratel.faleconosco.ws.service.os.processor.SaldoProcessor" />
<bean class="br.com.embratel.faleconosco.ws.service.os.processor.DebitoAutomaticoProcessor" />
</util:list>
<context:annotation-config />
<context:component-scan base-package="br.com.embratel.faleconosco">
<context:include-filter type="annotation" expression="javax.jws.WebService" />
</context:component-scan>
<!-- <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="faleConoscoDS" />
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="SQL_SERVER" />
<property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" />
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="org.hibernate.type" value="true" />
<entry key="org.hibernate.transaction" value="true" />
</map>
</property>
</bean>
<bean id="jpaTemplate" class="br.com.embratel.faleconosco.ws.dao.JpaTemplateExt">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
enable the configuration of transactional behavior based on annotations
<tx:annotation-driven transaction-manager="transactionManager" /> -->
<bean id="ProtocoloWS" class="org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean" scope="prototype">
<property name="serviceFactoryClass">
<value>org.apache.axis.client.ServiceFactory</value>
</property>
<property name="wsdlDocumentUrl" ref="PSACWSDocumentURL" />
<property name="endpointAddress" ref="PSACWSEndPoint" />
<property name="serviceName">
<value>ProtocoloWSService</value>
</property>
<property name="namespaceUri">
<value>http://webservices.protocolounico.embratel.com.br/</value>
</property>
<property name="portName">
<value>ProtocoloWSPort</value>
</property>
<property name="portInterface">
<value>br.com.embratel.protocolounico.webservices.ProtocoloWS</value>
</property>
<property name="serviceInterface">
<value>br.com.embratel.protocolounico.webservices.ProtocoloWS</value>
</property>
<property name="customPropertyMap">
<map>
<entry>
<key><value type="java.lang.String">axis.connection.timeout</value></key>
<value type="java.lang.Integer">300000</value>
</entry>
</map>
</property>
</bean>
<bean id="LoggerAspect" class="br.com.embratel.faleconosco.ws.aop.LoggerAspect">
</bean>
<jaxws:endpoint xmlns:tns="http://ws.faleconosco.embratel.com.br/" id="faleconoscowsbean"
implementor="#FaleConoscoWSBean" wsdlLocation="wsdl/faleconoscowsbean.wsdl" endpointName="tns:FaleConoscoWSPort"
serviceName="tns:FaleConoscoWSService" address="/FaleConoscoWSPort">
<jaxws:features>
bean class="org.apache.cxf.feature.LoggingFeature" /
</jaxws:features>
</jaxws:endpoint>
<jaxws:endpoint xmlns:tns="http://ws.faleconosco.embratel.com.br/" id="robofaleconoscowsbean"
implementor="#RoboFaleConoscoWSBean" wsdlLocation="wsdl/robofaleconoscowsbean.wsdl"
endpointName="tns:RoboFaleConoscoWSPort" serviceName="tns:RoboFaleConoscoWSService" address="/RoboFaleConoscoWSPort">
<jaxws:features>
bean class="org.apache.cxf.feature.LoggingFeature" /
</jaxws:features>
</jaxws:endpoint>
</beans>
ERRORS
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FaleConoscoWSBean': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.embratel.faleconosco.ws.service.usuario.UsuarioService br.com.embratel.faleconosco.ws.FaleConoscoWSBean.usuarioService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usuarioServiceImpl': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.embratel.faleconosco.ws.service.email.EnviarEmailService br.com.embratel.faleconosco.ws.service.usuario.UsuarioServiceImpl.enviarEmailService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enviarEmailServiceImpl': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.embratel.faleconosco.ws.dao.JpaTemplateExt br.com.embratel.faleconosco.ws.service.BaseServiceImpl.jpaTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [br.com.embratel.faleconosco.ws.dao.JpaTemplateExt] is defined: Unsatisfied dependency of type [class br.com.embratel.faleconosco.ws.dao.JpaTemplateExt]: expected at least 1 matching bean
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at
Well I Studied better Spring and re create the xml.
I removed this part of the code from the code above.
Creating the file from the begining.
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="SQL_SERVER" />
<property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" />
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
</bean>
</property>
I have try to run simple spring jmstemplate example.Here goes for source code for sender,
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
public class MessageSender {
#Autowired
private JmsTemplate jmsTemplate;
public void setJmsTemplate(JmsTemplate jmsTemplate)
{
this.jmsTemplate = jmsTemplate;
}
public void sendMessage()
{
jmsTemplate.send(new MessageCreator() {
public Message createMessage(Session session)
{
TextMessage message = null;
try
{
message = session.createTextMessage();
message.setStringProperty("text", "Hello World");
}
catch (JMSException e)
{
e.printStackTrace();
}
return message;
}
});
}
}
Here is config file for integrating spring with jmstemplate.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!-- Spring AOP -->
<context:component-scan base-package="com.test"/>
<aop:aspectj-autoproxy />
<bean id="messageListener" class="com.test.QueuereceiverDB" />
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">jnp://localhost:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
</props>
</property>
</bean>
<bean id="queueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>ConnectionFactory</value>
</property>
</bean>
<bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="cache">
<value>true</value>
</property>
</bean>
<bean id="QueueTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="queueConnectionFactory" />
</property>
<property name="destinationResolver">
<ref bean="jmsDestinationResolver" />
</property>
</bean>
<bean id="jmsSender" class="com.test.MessageSender">
<property name="jmsTemplate"> <ref bean="QueueTemplate" />
</property>
</bean>
<bean id="Queue" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate"> <ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>queue/MyQueue</value>
</property>
</bean>
<!-- JmsTemplate Definition -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="queueConnectionFactory" />
<property name="defaultDestination" ref="Queue" />
</bean>
<bean id="jmscontainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="concurrentConsumers" value="5" />
<property name="connectionFactory" ref="queueConnectionFactory" />
<property name="destination" ref="Queue" />
<property name="messageListener" ref="messageListener" />
</bean>
</beans>
If i run the example below is the corresponding stacktrace
SEVERE [com.sun.jersey.spi.container.ContainerResponse] The RuntimeException could not be mapped to a response, re-throwing to the HTTP container: java.lang.NullPointerException
at com.test.MessageSender.sendMessage(MessageSender.java:30) [:]
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) [:]
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689) [:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [:3.1.0.RELEASE]
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:55) [:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) [:3.1.0.RELEASE]
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50) [:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) [:3.1.0.RELEASE]
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50) [:3.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) [:3.1.0.RELEASE]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80) [:3.1.0.RELEASE]
After i have debug the code,i have found issue where it is,jmsTemplate.send(new MessageCreator() { While executing this line Null pointer will shown.
I think we need to initialize jmstemplate from xml file.But i dont know how to achieve this?
Please help me someone.
I have configured queue in the following file which will be placed in jboss/server/default/server folder
mdb-hornetq-xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:hornetq"
xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd" >
<queue name="MyQueue2" >
<entry name="/queue/MyQueue" />
</queue>
</configuration>
I find it odd that you have two JmsTemplate beans declared. I have a much simpler configuration that works. There are two JNDI names involved, one is the destination (queue) name, and the other is the connection factory name.
Let's say your queue is MyQueue and your connection factory is MyCF. To send messages, you need to declare just two spring beans:
<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="MyCF"/>
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true"/>
<property name="proxyInterface" value="javax.jms.ConnectionFactory"/>
</bean>
<bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="jmsConnectionFactory"/>
</property>
<property name="defaultDestinationName" value="MyQueue" />
</bean>
The source code in the sender class would then contain:
#Autowired
private JmsTemplate jmsTemplate;
private void sendTextMessage(final String message)
MessageCreator messageCreator = new MessageCreator() {
#Override
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage(message);
}
};
jmsTemplate.send(messageCreator);
}
What is missing is the HornetQ configuration of que connection factory and the queue. That configuration defines the JNDI names. In my case, HornetQ runs embedded with JBoss Application Server. Therefore, I configured the connection factory and queue in the JBoss AS configuration (e.g., in the standalone.xml file). Here are the snippets:
<pooled-connection-factory name="hornetq-local">
<transaction mode="local"/>
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/MyCF"/>
</entries>
</pooled-connection-factory>
<jms-destinations>
<jms-queue name="MyQueue">
<entry name="java:jboss/queues/a/b/SomeQueue"/>
<durable>true</durable>
</jms-queue>
</jms-destinations>
I believe you're using HornetQ in standalone mode. It should be easy to map these settings to the factory and queue configuration there.
I m struggling with simple task with last two days.I have configured jms Message queue in Jboss6.x. I have configured jndi,jms MQ in spring using jmstemplate in applicationcontext.xml File,
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="messageListener" class="com.test.QueuereceiverDB" />
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">localhost:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
</props>
</property>
</bean>
<bean id="queueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>ConnectionFactory</value>
</property>
</bean>
<bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="cache">
<value>true</value>
</property>
</bean>
<bean id="QueueTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="queueConnectionFactory" />
</property>
<property name="destinationResolver">
<ref bean="jmsDestinationResolver" />
</property>
</bean>
<bean id="jmsSender" class="com.test.MessageSender">
<property name="jmsTemplate"> <ref bean="QueueTemplate" />
</property>
</bean>
<bean id="Queue" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate"> <ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>queue/MyQueue</value>
</property>
</bean>
<bean id="jmscontainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="concurrentConsumers" value="5" />
<property name="connectionFactory" ref="queueConnectionFactory" />
<property name="destination" ref="Queue" />
<property name="messageListener" ref="messageListener" />
</bean>
Below is Message sender
package com.test;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
public class MessageSender {
private JmsTemplate jmsTemplate;
public void setJmsTemplate(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
public void sendMesage() {
MessageCreator messageCreator=new MessageCreator() {
public Message createMessage(Session session) throws
JMSException {
return session.createTextMessage("I am sending Invoice message");}
};
jmsTemplate.send("queue/MyQueue", messageCreator);
}
}
Finally Message receiver class
public class QueuereceiverDB implements MessageListener {
/**
* Default constructor.
*/
public QueuereceiverDB() {
// TODO Auto-generated constructor stub
}
/**
* #see MessageListener#onMessage(Message)
*/
public void onMessage(Message message) {
try {
if (message instanceof TextMessage) {
System.out.println("Queue: I received a TextMessage at "
+ new Date());
TextMessage msg = (TextMessage) message;
System.out.println("Message is : " + msg.getText());
} else {
System.out.println("Not valid message for this Queue MDB");
}
} catch (JMSException e) {
e.printStackTrace();
}
}
I have loaded applicationcontext.xml file in web.xml file.
After that deploy the war file in jboss there was no error and also message not received.I dont know why the message was not received.Can someone help me.
After adding resourc-ref tag it shows following error
Caused by: java.lang.RuntimeException: Neither any mapped-name/lookup/jndi-name specified nor any ResourceProvider could process resource-ref named env/ConnectionFactory of type javax.jms.QueueConnectionFactory
at org.jboss.switchboard.mc.resource.provider.ResourceRefResourceProviderDelegator.provide(ResourceRefResourceProviderDelegator.java:125) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.resource.provider.ResourceRefResourceProviderDelegator.provide(ResourceRefResourceProviderDelegator.java:44) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.JndiEnvironmentProcessor.process(JndiEnvironmentProcessor.java:68) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.deployer.AbstractSwitchBoardDeployer.process(AbstractSwitchBoardDeployer.java:119) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.deployer.WebEnvironmentSwitchBoardDeployer.internalDeploy(WebEnvironmentSwitchBoardDeployer.java:66) [:1.0.0-alpha-15]
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55) [:2.2.0.GA]
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179) [:2.2.0.GA]
The following contains queue name details and deployed in jboss/server/default/deploy
mdb-hornetq.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:hornetq"
xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd" >
<queue name="MyQueue2" >
<entry name="/queue/MyQueue" />
</queue>
</configuration>
All is correct , can you verify that in your web.xml you have the ressources declared :
<resource-ref>
<res-ref-name>ConnectionFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>queue/MyQueue</res-ref-name>
<res-type>javax.jms.Queue</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>