这是我的项目:
1得到json。
2将json转换为对象。
3和4股票变量。
5用于创建json的java组件发布(替换datamapper)。
7将json发布到Web服务。
9从数据库获取电子邮件并将其存入会话变量,然后构建响应
对于第二个流程,我尝试以json格式获得Web服务的响应,{"成功" =" 1"}表示Web服务已成功发送推送。如果没有,必须发送电子邮件。
我测试了我的代码的每一方,但是为了将json发送到Web服务并获得响应,我不知道问题是什么。
当我运行我的代码时,我收到此错误:
> > ERROR 2015-04-07 00:07:49,654 [[ws3].flows1Flow2.stage1.02]
> > org.mule.exception.DefaultMessagingExceptionStrategy:
> > ******************************************************************************** Message : Failed to transform from "json" to
> > "java.lang.Object" Code : MULE_ERROR-109
> > -------------------------------------------------------------------------------- Exception stack is:
> > 1. No content to map to Object due to end of input (java.io.EOFException) org.codehaus.jackson.map.ObjectMapper:2775
> > (null)
> > 2. Failed to transform from "json" to "java.lang.Object" (org.mule.api.transformer.TransformerException)
> > org.mule.module.json.transformers.JsonToObject:132
> > (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
> > -------------------------------------------------------------------------------- Root Exception stack trace: java.io.EOFException: No content to map to
> > Object due to end of input at
> > org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2775)
> > at
> > org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2718)
> > at
> > org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1886)
> > + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
> > ********************************************************************************
**错误已修复,因为我们必须向此网络服务发送参数而不是json,我试过这个:
<db:mysql-config name="MySQL_Configuration" host="localhost"
port="3306" user="root" database="mulesoft" doc:name="MySQL Configuration" />
<smtp:gmail-connector name="Gmail"
validateConnections="true" doc:name="Gmail" />
<flow name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8082" doc:name="HTTP"
contentType="application/json" path="getDetails" />
<json:json-to-object-transformer
returnClass="java.lang.Object" doc:name="JSON to Object" />
<set-session-variable variableName="tkn"
value="#[message.payload.token]" doc:name="token" />
<set-session-variable variableName="msg"
value="#[message.payload.msg]" doc:name="message" />
<component class="ws1.Transformer" doc:name="Java">
<method-entry-point-resolver>
<include-entry-point method="methhod" />
</method-entry-point-resolver>
</component>
<json:json-to-object-transformer
returnClass="java.lang.Object" doc:name="JSON to Object" />
<logger message=""I can get properties this is app"+#[message.payload.application]+"this is the type"+#[message.payload.type]"
level="INFO" doc:name="Logger" />
<set-property propertyName="application"
value="#[message.payload.application]" doc:name="Property" />
<set-property propertyName="token" value="#[sessionVars['tkn']]"
doc:name="Property" />
<set-property propertyName="user" value="#[message.payload.user]"
doc:name="Property" />
<set-property propertyName="type" value="#[message.payload.type]"
doc:name="Property" />
<set-property propertyName="message" value="#[sessionVars['msg']]"
doc:name="Property" />
<http:outbound-endpoint exchange-pattern="request-response"
method="POST" address="http://slice.WS.com/api.php/push/send_test_push" doc:name="HTTP" />
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select * from push where token = #[sessionVars['tkn']]]]></db:parameterized-query>
</db:select>
<foreach doc:name="For Each">
<set-session-variable variableName="email"
value="#[message.payload.email]" doc:name="Session Variable" />
</foreach>
<response>
<http:response-builder status="200" doc:name="HTTP Response Builder"/>
</response>
</flow>
<flow name="wsFlow">
<poll doc:name="Poll">
<http:outbound-endpoint exchange-pattern="request-response" method="GET" address="http://slice.WS.com/api.php/push/send_test_push" contentType="application/json" doc:name="HTTP"/>
</poll>
<logger message="#[message.payloadAs(java.lang.String)]+ "payload""
level="INFO" doc:name="Logger" />
<!-- json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/> -->
<choice doc:name="Choice">
<when expression="true">
<logger message="its ok" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<set-payload value="Dear Mail Crawler,
\n\n No spam to my email, please!" doc:name="Set Payload"/>
<smtp:outbound-endpoint host="smtp.gmail.com" port="587" user="myemail%40gmail.com" password="pass" connector-ref="Gmail" to="#[message.payload.email]" from="Rajeun" subject="Mule Test with Velocity Transformer" responseTimeout="10000" doc:name="SMTP"/>
</otherwise>
</choice>
</flow>
当我通过邮递员发送json进行测试时,我得到了这个:
INFO 2015-04-07 16:09:47,346 [[ws3].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: "I can get properties this is app"+91+"this is the type"+Android
INFO 2015-04-07 16:09:47,384 [[ws3].connector.http.mule.default.receiver.02] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest
INFO 2015-04-07 16:09:47,391 [[ws3].connector.http.mule.default.receiver.02] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default response transformer: org.mule.transport.http.transformers.MuleMessageToHttpResponse
INFO 2015-04-07 16:09:47,391 [[ws3].connector.http.mule.default.receiver.02] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest
INFO 2015-04-07 16:09:47,392 [[ws3].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.http.mule.default.dispatcher.1593171'. Object is: HttpClientMessageDispatcher
INFO 2015-04-07 16:09:47,395 [[ws3].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'connector.http.mule.default.dispatcher.1593171'. Object is: HttpClientMessageDispatcher
INFO 2015-04-07 16:09:48,122 [pool-19-thread-1] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest
INFO 2015-04-07 16:09:48,122 [pool-19-thread-1] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default response transformer: org.mule.transport.http.transformers.MuleMessageToHttpResponse
INFO 2015-04-07 16:09:48,122 [pool-19-thread-1] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest
INFO 2015-04-07 16:09:48,137 [pool-19-thread-1] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.http.mule.default.dispatcher.31829235'. Object is: HttpClientMessageDispatcher
INFO 2015-04-07 16:09:48,137 [pool-19-thread-1] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'connector.http.mule.default.dispatcher.31829235'. Object is: HttpClientMessageDispatcher
INFO 2015-04-07 16:09:48,642 [[ws3].wsFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: + "payload"
INFO 2015-04-07 16:09:48,647 [[ws3].wsFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: its ok
INFO 2015-04-07 16:09:49,691 [[ws3].wsFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: + "payload"
INFO 2015-04-07 16:09:49,692 [[ws3].wsFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: its ok
这意味着参数没有到达网络服务。