使用WSO2 ESB将JSON返回到代理

时间:2015-03-11 10:15:58

标签: json proxy wso2 wso2esb esb

我是WSO2 esb的新手,开始时我想与外部REST API建立http连接并返回JSON响应。 要调用代理我正在使用Postman并且请求已成功,但json结果不会显示在postman中,仅在Log中显示。 然后我添加了一个发送调解器,但产生如下异常:

ERROR - NativeWorkerPool Uncaught exception
java.lang.NullPointerException
    at org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer.java:210)
    at org.apache.coyote.http11.InternalNioOutputBuffer.commit(InternalNioOutputBuffer.java:202)
    at org.apache.coyote.http11.AbstractHttp11Processor.action(AbstractHttp11Processor.java:765)
    at org.apache.coyote.Response.action(Response.java:173)
    at org.apache.coyote.Response.sendHeaders(Response.java:353)
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:330)
    at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:283)
    at org.apache.catalina.connector.CoyoteOutputStream.close(CoyoteOutputStream.java:108)
    at org.apache.synapse.transport.passthru.PassThroughHttpSender.sendUsingOutputStream(PassThroughHttpSender.java:298)
    at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:261)
    at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
    at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:163)
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:321)
    at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:94)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:268)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:488)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:170)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:225)
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

这是我的代理代码:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy" transports="http https" startOnLoad="true" trace="enable">
    <target>
        <inSequence>
            <property name="uri.var.name" value="Luca" scope="default" type="STRING"/>
            <send>
                <endpoint key="HelloWorld"/>
            </send>
        </inSequence>
        <outSequence>
            <log level="custom">
                <property name="content" expression="json-eval($.)"/>
            </log>
            <send description=""/>
        </outSequence>
        <faultSequence/>
    </target>
</proxy>

我做错了什么? 感谢

3 个答案:

答案 0 :(得分:0)

配置错误。 使用方法如下; 如果要将json响应发送回客户端,请将<send/>设置为outsequence。 例如:

<property name="messageType" value="application/json" scope="axis2"/>

例如:

<outSequence>
  <property name="messageType" value="application/json" scope="axis2"/>
      <send/>
 </outSequence>

答案 1 :(得分:0)

确保您正在点击服务的正确端口。 如果您已经通过了“尝试服务”。链接并将其复制到您的工具 - 然后您将访问错误的端口,它将导致NullPointerException。点击服务名称==您应该看到“服务信息中心(代理)&#39;页。然后在“终点”部分&#39;将有您服务的端点的网址列表。

答案 2 :(得分:0)

有时,当客户端使用Servlet传输端口(默认为9443)而不是传递传输端口(默认为8243)时会发生此问题。检查您是否使用正确的端口访问该服务。服务呼叫应通过ESB中的直通传输。