WSO2 - 如何让调用中介忽略有效负载(比如它是空的,甚至不是空的)?

Posted

技术标签:

【中文标题】WSO2 - 如何让调用中介忽略有效负载(比如它是空的,甚至不是空的)?【英文标题】:WSO2 - how to make call mediator to ignore payload (like it is null, not even empty)? 【发布时间】:2020-03-30 16:12:33 【问题描述】:

我正在尝试这段代码:

         <sequence key="ssl-validation-sequence"/> <!-- returns valid json body -->


         <payloadFactory media-type="json">   <!-- Resetting payload -->
            <format/>
            <args/>
         </payloadFactory>
         <property name="NO_ENTITY_BODY" value="true" scope="axis2" type="BOOLEAN"/>
         <property name="FORCE_POST_PUT_NOBODY" value="true" scope="axis2" type="BOOLEAN"/>
         <property name="FORCE_HTTP_CONTENT_LENGTH" value="true" scope="axis2"/>
         <property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="false" scope="axis2"/>
         <header name="Accept" scope="transport" value="application/json"/>
         <header name="Content-Length" scope="transport" value="0"/>

         <!-- call further api -->

               <call>
                  <endpoint>
                     <http method="POST" uri-template="http://10.208.35.57:8280/medium/getemployees"/>
                  </endpoint>
               </call>

/medium/getemployees 上的进一步 api 调用 wso2ei 数据库服务:

         <!-- Call data-service -->

         <header name="Accept" scope="transport" value="application/json"/>
         <call>
            <endpoint>
               <http method="GET" uri-template="http://localhost:8280/services/employee_DataService/employees"/>
            </endpoint>
         </call>

/employee_DataService/employees 返回有效的 json-body。

在没有 ssl-validation 的情况下一切正常,它返回 json-body,在这种情况下,只需要 Accept 标头即可通过数据库服务返回 json 有效负载。

但只要任何 json 有效负载出现在数据服务调用之前,那么任何数据服务调用都会失败。

从 wso2ei 得到的错误:

[2020-03-30 17:25:10,533] [] ERROR - JsonStreamFormatter Error occurred while writing to application/json
java.lang.reflect.InvocationTargetException
        at sun.reflect.GeneratedMethodAccessor115.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.wso2.carbon.integrator.core.json.JsonStreamFormatter.writeTo(JsonStreamFormatter.java:107)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.submitResponse(PassThroughHttpSender.java:626)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:285)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
        at org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.invokeBusinessLogic(AbstractInOutSyncMessageReceiver.java:45)
        at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:338)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:159)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: charsetName
        at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:99)
        at org.apache.axis2.json.gson.JsonFormatter.writeTo(JsonFormatter.java:61)
        ... 16 more
[2020-03-30 17:25:10,543] [] ERROR - PassThroughHttpSender Failed to submit the response
org.apache.axis2.AxisFault
        at org.wso2.carbon.integrator.core.json.JsonStreamFormatter.writeTo(JsonStreamFormatter.java:113)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.submitResponse(PassThroughHttpSender.java:626)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:285)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
        at org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.invokeBusinessLogic(AbstractInOutSyncMessageReceiver.java:45)
        at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:338)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:159)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
[2020-03-30 17:25:10,549] [] ERROR - ServerWorker Error processing GET request for : /services/employee_DataService/employees
org.apache.axis2.AxisFault: Failed to submit the response
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.handleException(PassThroughHttpSender.java:688)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:287)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
        at org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.invokeBusinessLogic(AbstractInOutSyncMessageReceiver.java:45)
        at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:338)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:159)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.axis2.AxisFault
        at org.wso2.carbon.integrator.core.json.JsonStreamFormatter.writeTo(JsonStreamFormatter.java:113)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.submitResponse(PassThroughHttpSender.java:626)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:285)
        ... 10 more

作为回应:

<faultstring>Failed to submit the response</faultstring>

有没有办法让它工作?

谢谢。

【问题讨论】:

【参考方案1】:

解决了!

这很好用:

     <property name="NO_ENTITY_BODY" value="true" scope="axis2" type="BOOLEAN"/>
     <property name="TRANSPORT_HEADERS" scope="axis2" action="remove"/>
     <header name="Accept" scope="transport" value="application/json"/>

           <call>
              <endpoint>
                 <http method="POST" uri-template="http://10.208.35.57:8280/medium/getemployees"/>
              </endpoint>
           </call>

【讨论】:

以上是关于WSO2 - 如何让调用中介忽略有效负载(比如它是空的,甚至不是空的)?的主要内容,如果未能解决你的问题,请参考以下文章

WSO2 AM 1.9 - 将CDATA保留在有效负载工厂中

wso2 无法保存 JSON 有效负载。找到无效的输入流

WSO2 APIM - 在 JWT 有效负载中添加用户角色

任何人都可以解释下面wso2 esb synapse.xml文件的语法和功能。消息中介发生了

在 WSDL 中介 WSO2 中为 URI 使用变量

可以在wso2 esb或ei中缓存中介组相同的请求吗?