我需要在Mule中公开REST Web服务。我在Mule中有以下流程: -
<flow name="MainService" doc:name="MainService">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
<logger message="RequestLog :- #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="RequestLogger"/>
<jms:outbound-endpoint queue="NewQueue" connector-ref="Active_MQ" doc:name="JMS" exchange-pattern="request-response"/>
</flow>
<flow name="testFlow1" doc:name="testFlow1" initialState="started">
<jms:inbound-endpoint connector-ref="Active_MQ" address="jms://tcp:NewQueue" doc:name="JMS" exchange-pattern="request-response" disableTemporaryReplyToDestinations="true" responseTimeout="90000"/>
<jersey:resources doc:name="REST">
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl"/>
</jersey:resources>
</flow>
现在我希望每当从休息客户端触发服务时,请求应首先进入 MainService流程和 testFlow1流程<中的ActiveMQ队列 NewQueue / strong>它将从 NewQueue 获取请求并执行它..
现在这个网络服务有两种方法: -
http://localhost:8082/getData/retrieve/?id=21
id .. 现在,当我触发该值时,我得到以下异常: -
INFO 2014-08-10 20:23:56,622 [[test].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'Active_MQ.dispatcher.2028594834'. Object is: EeJmsMessageDispatcher
INFO 2014-08-10 20:23:56,622 [[test].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'Active_MQ.dispatcher.2028594834'. Object is: EeJmsMessageDispatcher
ERROR 2014-08-10 20:23:56,709 [ActiveMQ Session Task-1] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Failed to invoke JerseyResourcesComponent{testFlow1.component.1820680768}. Component that caused exception is: JerseyResourcesComponent{testFlow1.component.1820680768}. Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. null (java.lang.NullPointerException)
org.mule.module.jersey.JerseyResourcesComponent:116 (null)
2. Failed to invoke JerseyResourcesComponent{testFlow1.component.1820680768}. Component that caused exception is: JerseyResourcesComponent{testFlow1.component.1820680768}. Message payload is of type: String (org.mule.component.ComponentException)
org.mule.component.AbstractComponent:144 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.NullPointerException
at org.mule.module.jersey.JerseyResourcesComponent.doInvoke(JerseyResourcesComponent.java:116)
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:122)
at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:57)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
ERROR 2014-08-10 20:23:57,746 [ActiveMQ Session Task-2] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : "Message with id "ID:ANIRBAN-PC-50216-1407682432183-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. "Message with id "ID:ANIRBAN-PC-50216-1407682432183-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage (org.mule.transport.jms.redelivery.MessageRedeliveredException)
org.mule.transport.jms.redelivery.JmsXRedeliveryHandler:81 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/jms/redelivery/MessageRedeliveredException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.transport.jms.redelivery.MessageRedeliveredException: "Message with id "ID:ANIRBAN-PC-50216-1407682432183-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage
at org.mule.transport.jms.redelivery.JmsXRedeliveryHandler.handleRedelivery(JmsXRedeliveryHandler.java:81)
at org.mule.transport.jms.MultiConsumerJmsMessageReceiver$JmsWorker.preProcessMessage(MultiConsumerJmsMessageReceiver.java:512)
at org.mule.transport.AbstractReceiverWorker$1$1.process(AbstractReceiverWorker.java:117)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
现在我觉得需要插入ActiveMQ队列NewQueue
的请求应该是 insertDataOperation 的字符串格式,因为请求是在BODY上...我不确定 retrieveDataOperation ,其在网址中包含值id ...
请让我知道如何解决这两种情况的例外情况......请帮忙
答案 0 :(得分:1)
最突出的问题是您只通过JMS端点发送HTTP请求的有效负载,这当然不足以让Jersey感到满意。
您需要将整个Mule消息序列化为XML(因此它的属性也会被转移)......
<xml:object-to-xml-transformer acceptMuleMessage="true" />
...然后通过JMS发送它,然后在Jersey组件之前反序列化它。
答案 1 :(得分:0)
根据David的建议,需要添加: -
<mulexml:object-to-xml-transformer acceptMuleMessage="true" doc:name="Object to XML"/>
更新的工作流程: -
<jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="MainService" doc:name="MainService">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
<logger message="RequestLog :- #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="RequestLogger"/>
<mulexml:object-to-xml-transformer acceptMuleMessage="true" doc:name="Object to XML"/>
<jms:outbound-endpoint queue="NewQueue" connector-ref="Active_MQ" doc:name="JMS" exchange-pattern="request-response"/>
</flow>
<flow name="testFlow1" doc:name="testFlow1" initialState="started">
<jms:inbound-endpoint connector-ref="Active_MQ" address="jms://tcp:NewQueue" doc:name="JMS" exchange-pattern="request-response" disableTemporaryReplyToDestinations="true" responseTimeout="90000"/>
<mulexml:xml-to-object-transformer doc:name="XML to Object"/>
<jersey:resources doc:name="REST">
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl"/>
</jersey:resources>
</flow>