在WSO2 ESB中的REST API中返回空响应

时间:2016-06-28 10:32:32

标签: rest wso2 wso2esb

我在WSO2 ESB 4.9.0中有一个API工件,提供简单的PUT REST服务。

PUT服务简化了传入请求的日志,然后应该在没有任何内容的情况下响应HTTP代码200。

这是API资源:

<api xmlns="http://ws.apache.org/ns/synapse" name="myapi" context="/context">
    <resource methods="PUT" uri-template="/resource">
        <inSequence>
            <log level="custom">
                <property name="PUT" value="/v1/updateWorkflowData" />
            </log>
            <property name="NO_ENTITY_BODY" value="true" scope="axis2" />
            <property name="HTTP_SC" value="200" scope="axis2" />
            <respond />
        </inSequence>
    </resource>
</api>

使用属性&#34; NO_ENTITY_BODY&#34;为true(在GET请求中使用)我得到以下异常:

    [2016-06-28 12:27:27,524] ERROR - PassThroughHttpSSLSender Failed to submit the response
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.submitResponse(PassThroughHttpSender.java:468)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:267)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
        at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:212)
        at org.apache.synapse.mediators.builtin.RespondMediator.mediate(RespondMediator.java:28)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:149)
        at org.apache.synapse.rest.Resource.process(Resource.java:297)
        at org.apache.synapse.rest.API.process(API.java:378)
        at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:97)
        at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:65)
        at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:266)
        at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:83)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:317)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:363)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:142)
        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:745)
[2016-06-28 12:27:27,555] ERROR - Axis2Sender Accept-Encoding:gzip,deflate,Content-Type:application/json,Host:localhost:8243,<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope> Unexpected error sending message back
org.apache.axis2.AxisFault: Failed to submit the response
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.handleException(PassThroughHttpSender.java:610)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:269)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
        at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:212)
        at org.apache.synapse.mediators.builtin.RespondMediator.mediate(RespondMediator.java:28)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:149)
        at org.apache.synapse.rest.Resource.process(Resource.java:297)
        at org.apache.synapse.rest.API.process(API.java:378)
        at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:97)
        at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:65)
        at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:266)
        at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:83)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:317)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:363)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:142)
        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:745)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.submitResponse(PassThroughHttpSender.java:468)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:267)
        ... 20 more

我的问题现在是:

  1. 常规:如果请求确实包含某些内容,如何将响应设置为空?
  2. 我的解决方案是&#34; NO_ENTITY_BODY&#34;错了,不起作用?

2 个答案:

答案 0 :(得分:0)

1)您可以使用脚本调解器将响应正文替换为空字符串。还有其他方法可以做到这一点。脚本调解员是一种选择。

2)"NO_ENTITY_BODY“用于指定您希望来自没有正文的请求的响应。例如GET请求。

答案 1 :(得分:0)

NO_ENTITY_BODY期望为布尔值,因此您必须添加type属性:

<property name="NO_ENTITY_BODY" value="true" scope="axis2" type="BOOLEAN" />