尝试通过TCP发布JSON请求。 WSO2 ESB已配置如下以使用TCP传输(在axis2.xml中)。
<transportReceiver class="org.apache.axis2.transport.tcp.TCPTransportListener" name="tcp"></transportReceiver>
添加了代理服务,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="TcpToHttpProxy" startOnLoad="true" transports="tcp" xmlns="http://ws.apache.org/ns/synapse">
<target>
<endpoint name="endpoint_urn_uuid_71d9f268-1f33-48f2-bd89-439ac88095d1">
<address uri="http://localhost:82/api/v1/reservations"/>
</endpoint>
<inSequence>
<log level="full"/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
<parameter name="transport.tcp.contentType">application/json</parameter>
<parameter name="transport.tcp.port">6060</parameter>
</proxy>
但是,在发布请求时收到以下错误:
[2017-01-16 17:48:52,094] INFO - LogMediator To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:25D317F2A1C891B19D1484569132104, Direction: request, Payload:
{"patient": {
"name": "John Doe",
"dob": "1940-03-19",
"ssn": "234-23-525",
"address": "California",
"phone": "8770586755",
"email": "johndoe@gmail.com"},
"doctor": "thomas collins",
"hospital": "abc"}
[2017-01-16 17:48:52,099] ERROR - JsonUtil #writeJsonStream. Could not write JSON stream. MessageID: urn:uuid:0109653d-e79c-4143-98b9-0053b565bb19. Error>> Stream closed.
[2017-01-16 17:48:52,099] INFO - AxisEngine [MessageContext: logID=5cdd488a83f3b09fc0c3e3f949982e3d155cbcf0d761edcd] Could not write JSON stream.
[2017-01-16 17:48:52,100] ERROR - AsyncCallback Could not write JSON stream.
org.apache.axis2.AxisFault: Could not write JSON stream.
at org.apache.synapse.commons.json.JsonUtil.writeAsJson(JsonUtil.java:249)
at org.apache.synapse.commons.json.JsonStreamFormatter.writeTo(JsonStreamFormatter.java:61)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.sendRequestContent(PassThroughHttpSender.java:389)
at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:256)
at org.apache.axis2.engine.AxisEngine$TransportNonBlockingInvocationWorker.run(AxisEngine.java:626)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.axis2.AxisFault: Could not write JSON stream.
at org.apache.synapse.commons.json.JsonUtil.writeJsonStream(JsonUtil.java:833)
at org.apache.synapse.commons.json.JsonUtil.writeAsJson(JsonUtil.java:237)
... 7 more
Caused by: java.io.IOException: Stream closed.
at java.net.AbstractPlainSocketImpl.available(Unknown Source)
at java.net.SocketInputStream.available(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1792)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1769)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1744)
at org.apache.synapse.commons.json.JsonUtil.writeJsonStream(JsonUtil.java:823)
... 8 more
[2017-01-16 17:48:52,101] WARN - AsyncCallback Executing fault handler due to exception encountered
[2017-01-16 17:48:52,101] WARN - EndpointContext Endpoint : endpoint_urn_uuid_71d9f268-1f33-48f2-bd89-439ac88095d1 with address http://localhost:82/api/v1/reservations will be marked SUSPENDED as it failed
[2017-01-16 17:48:52,102] WARN - EndpointContext Suspending endpoint : endpoint_urn_uuid_71d9f268-1f33-48f2-bd89-439ac88095d1 with address http://localhost:82/api/v1/reservations - current suspend duration is : 30000ms - Next retry after : Mon Jan 16 17:49:22 IST 2017
看起来JSON请求被传递给ESB,因为它正确记录了JSON对象。但是,它不会将JSON请求传递给后端服务(Web API)。
有人可以建议我解决这个问题吗?