需要将请求(URl,标头,有效负载)和响应日志发送到其余的api。我们使用WSO2 Message Broker使用Message store和Message处理器。下面是我们配置的api。
<api xmlns="http://ws.apache.org/ns/synapse" name="plants-logging" context="/plants-logging">
<resource methods="POST GET DELETE PUT">
<inSequence>
<log level="custom">
<property name="HTTP_METHOD IS###########" expression="$axis2:HTTP_METHOD"></property>
<property name="ip address" expression="get-property('axis2','REMOTE_ADDR')"></property>
<property name="In Time : " expression="get-property('SYSTEM_TIME')"></property>
</log>
<property name="TIME_IN" expression="get-property('SYSTEM_TIME')" scope="default" type="LONG"></property>
<log level="custom">
<property name="Message Flow" value="ACCEPTED@"></property>
</log>
<send>
<endpoint>
<address uri="/test/api/"></address>
</endpoint>
</send>
<property name="messageType" value="application/json" scope="axis2"></property>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
<switch source="$axis2:HTTP_METHOD">
<case regex="POST">
<store messageStore="JMSMS"></store>
</case>
<case regex="PUT">
<store messageStore="JMSMS"></store>
</case>
</switch>
<property name="TIME_OUT" expression="get-property('SYSTEM_TIME')" scope="default" type="LONG"></property>
<script language="js">var time1 = mc.getProperty("TIME_IN");var time2 = mc.getProperty("TIME_OUT");var timeTaken = time2 - time1;mc.setProperty("RESPONSE_TIME", timeTaken);</script>
<log level="custom">
<property name="Time Duration in ms:" expression="get-property('RESPONSE_TIME') "></property>
</log>
</inSequence>
<outSequence>
<log level="custom">
<property name="Out Sequence" value="ACCEPTED@"></property>
</log>
<switch source="$axis2:HTTP_METHOD">
<case regex="GET">
<property name="messageType" value="application/json" scope="axis2"></property>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
<store messageStore="JMSMS"></store>
</case>
</switch>
</outSequence>
<faultSequence>
<log level="custom">
<property name="Fault Sequence" value="ACCEPTED@"></property>
</log>
<property name="messageType" value="application/json" scope="axis2"></property>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
<store messageStore="JMSMS"></store>
</faultSequence>
</resource>
</api>
对于POST请求,有效负载能够成功发送到我们的api api。但是对于我们得到的回应。
org.apache.axis2.AxisFault: Payload could not be written as JSON.
at org.apache.synapse.commons.json.JsonUtil.writeAsJson(JsonUtil.java:109)
at org.apache.synapse.commons.json.JsonStreamFormatter.writeTo(JsonStreamFormatter.java:60)
at org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:84)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:622)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:451)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:278)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:430)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.synapse.message.senders.blocking.BlockingMsgSender.sendReceive(BlockingMsgSender.java:217)
at org.apache.synapse.message.senders.blocking.BlockingMsgSender.send(BlockingMsgSender.java:146)
at org.apache.synapse.message.processor.impl.forwarder.ForwardingService.dispatch(ForwardingService.java:288)
at org.apache.synapse.message.processor.impl.forwarder.ForwardingService.execute(ForwardingService.java:128)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
[2014-11-28 18:27:33,615]错误 - 消息处理器[SMFP]的ForwardingService BlockingMessageSender无法向端点发送消息 [2014-11-28 18:27:33,615] WARN - ForwardingService无法通过故障序列发送消息,序列名称null不存在。 [2014-11-28 18:27:37,634]错误 - JsonUtil #writeAsJson。 Payload无法写为JSON。消息ID:urn:uuid:20310054-7f03-4e7e-853e-9bc98f27a063 [2014-11-28 18:27:37,634]错误 - JsonUtil #writeAsJson。 Payload无法写为JSON。消息ID:urn:uuid:20310054-7f03-4e7e-853e-9bc98f27a063
请帮我解决这个问题。