WSO2 EI-构建直通流时发生RelayUtils错误

时间:2018-08-14 14:27:44

标签: java api wso2 wso2esb esb

我正在使用WSO2 EI 6.3.0,我想从特定的Web服务获取数据并将此数据推送到另一个Web服务。

第一次,我必须从第一个Web服务获取JWT令牌,然后将其放入第二个调用中以获取数据。

因此,我创建了几个具有可重复使用序列的序列。 当我想将承载令牌标头注入我的端点以获取数据时出现错误。

按顺序排列

  • 在LogincheckSeq期间,我调用login_check api以获取JWT令牌。

  • 然后在createBearerTokenSeq期间,我仅使用从LoginCheckSeq恢复的令牌创建一个属性

  • 然后我们传入CreateBearerTokenSeq,以创建一个属性,并使用从LoginCheckEP的json响应中恢复过来的令牌

  • 最后,由于标头中提供了jwt令牌(授权:不记名令牌),我们传入了最后一个序列GetCustomerSeq以从json中的Web服务获取客户信息

这是我的CustomerAPI.xml:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/customers" name="CustomersAPI" 
xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST GET" uri-template="/">
        <inSequence>
            <log level="custom" separator="&#xa;">
                <property name="API CUSTOMER" value="START"/>
            </log>
            <sequence key="LoginCheckSeq"/>
            <sequence key="CreateBearerTokenSeq"/>
            <sequence key="GetCustomersSeq"/>
       </inSequence>
       <outSequence>
        <log>
            <property expression="$axis2:HTTP_SC" name="Status Code" xmlns:ns="http://org.apache.synapse/xsd"/>
        </log>
        </outSequence>
        <faultSequence>
        <log level="full"/>
        </faultSequence>
    </resource>
</api>

LoginCheckSeq.xml

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="LoginCheckSeq" trace="disable" 
xmlns="http://ws.apache.org/ns/synapse">
    <log level="custom" separator="&#xa;">
        <property name="Login SEQUENCE" value="START"/>
    </log>
    <property expression="json-eval($.username)" name="uri.var.username" scope="default" type="STRING"/>
    <property expression="json-eval($.password)" name="uri.var.password" scope="default" type="STRING"/>
    <log level="custom" separator=",">
        <property expression="fn:concat('Username : ', get-property('uri.var.username'), ' / Password : ',get-property('uri.var.password')) " name="PARAMS"/>
        </log>
        <call>
            <endpoint key="LoginCheckEP"/>
        </call>
</sequence>

CreateBearerToken.xml

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="CreateBearerTokenSeq" trace="disable" 
xmlns="http://ws.apache.org/ns/synapse">
    <log level="custom" separator="&#xa;">
        <property name="Create Bearer Token SEQUENCE" value="START"/>
    </log>
    <payloadFactory media-type="json">
        <format>{"token":"$1"}</format>
        <args>
            <arg evaluator="json" expression="$.token"/>
        </args>
    </payloadFactory>
    <property name="messageType" value="application/json" scope="axis2"/>
    <property expression="json-eval($.token)" name="uri.var.jwt.token" scope="default" type="STRING"/>
</sequence>

GetCustomerSeq.xml

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="GetCustomersSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <log description="" level="custom" separator="&#xa;">
        <property name="Get Customer SEQUENCE" value="START"/>
    </log>
    <log description="" level="custom" separator="##">
        <property expression="fn:concat('Bearer ', get-property('uri.var.jwt.token'))" name="JWT Token Created"/>
    </log>
    <header name="Authorization" expression="fn:concat('Bearer ', get-property('uri.var.jwt.token'))" scope="transport"/>
    <send>
        <endpoint key="GetCustomersEP"/>
    </send>
</sequence>

我从LoginCechkSeq中获得了JWT令牌,但是getCustomerSeq中有一个错误。

这是错误:

[2018-08-14 15:14:07,510] [EI-Core]  INFO - LogMediator API CUSTOMER = START
[2018-08-14 15:14:07,511] [EI-Core]  INFO - LogMediator Login SEQUENCE = START
[2018-08-14 15:14:07,511] [EI-Core]  INFO - LogMediator PARAMS = Username : test@test.fr / Password : Azerty123
[2018-08-14 15:14:08,586] [EI-Core]  INFO - LogMediator Create Bearer Token SEQUENCE = START
[2018-08-14 15:14:08,591] [EI-Core]  INFO - LogMediator Get Customer SEQUENCE = START
[2018-08-14 15:14:08,591] [EI-Core]  INFO - LogMediator JWT Token Created = Bearer eyJhbGciOiJSUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX1VTRVJfTUFUT09NQSIsIlJPTEVfVVNFUiJdLCJ1c2VybmFtZSI6InRlc3RAdGVzdC5mciIsImZpcnN0TmFtZSI6I    kxvXHUwMGVmYyIsImxhc3ROYW1lIjoiQ2FyaW91IiwiaWQiOjIwLCJpYXQiOjE1MzQyNTI0NDgsImV4cCI6MTUzNDI2Njg0OH0.Gx_cSwXE0rm1EZSPeI64cbOdysjXcLwj2NYjtNE4eh_gtUSwbCE2EUPL6sB-Rt_ayQOeOEx-w07Bkbh-Rr6rUd-mqnKXHuUCe76pOXWWW5ejV7k8n_    Tf3gk4upbzn77VMsyNALWJYNBSO4S8dDCyp413SRvnRaKuhkF1GgvkbZx7aJNUwkDA_ZuxG3IfOKQdao7GgDhWH9pltH9zIjXtjagbjRPgBaekcZiB2bxglQLF7RUMky2MVG_WEbcLFms14LiIEooG3lXao73Z2foYXSMxReHHAmhGPfSipw_wA9ohMolB_X5Ck13O0tSDUvsqvqdZHPZ    w8ITmn_4pKnJhTiCK6U58Ub_Nr6Royeiwf3_WN7ooqOczF0hbJr7ZFONo3BwKEhCj6gPv9gknK0ahSotnsRvQS56VsquWJm9ZwtXAI2D0J8tNjSmxMP9FWbmFMWap2wOayUEGpauYD3WA5W-CZexqulJTbLSPcMF92QWaKMoVtL5blgGt9vTb1YIVnQi4KALK9psJETgcvHCIbfsN    E_IcYMlotIHRuO4RR-j0I7WAxQVko9YNkIRpuDUftpUq95TbIxn5NeTFhWL_NoC2F3jO4khGYR-Hk2P2ZudygrrdmDMfezn7d5yArV7mlukSB6chwq38T261ktzqx_G_rHt1pjt0jXVhz1DPsY4
[2018-08-14 15:14:10,087] [EI-Core] ERROR - RelayUtils Error while building Passthrough stream
org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
    at org.apache.axiom.om.impl.llom.OMDocumentImpl.getOMDocumentElement(OMDocumentImpl.java:109)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:570)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:566)
    at org.apache.synapse.transport.passthru.util.DeferredMessageBuilder.getDocument(DeferredMessageBuilder.java:165)
    at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:163)
    at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:116)
    at org.apache.synapse.mediators.AbstractListMediator.buildMessage(AbstractListMediator.java:145)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:94)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:70)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
    at org.apache.synapse.rest.Resource.process(Resource.java:351)
    at org.apache.synapse.rest.API.process(API.java:338)
    at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:123)
    at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:101)
    at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:56)
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:303)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:570)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:193)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:263)
    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: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
    at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:639)
    at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2052)
    at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1134)
    at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next(XMLStreamReaderWrapper.java:225)
    at org.apache.axiom.util.stax.dialect.DisallowDoctypeDeclStreamReaderWrapper.next(DisallowDoctypeDeclStreamReaderWrapper.java:34)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:681)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:214)
    ... 24 more

我尝试了几件事,例如添加此行:

<messageBuilder contentType="application/json" class="org.wso2.carbon.integrator.core.json.JsonStreamBuilder"/>  

或添加名称为“ messageType”且值为“ application / json”的属性

但是没有什么可以解决我的问题... 如果有人已经遇到此问题,我正在采取解决方案=)

1 个答案:

答案 0 :(得分:1)

我找到了答案。 服务器响应的Content-Type为:application / ld + json。 因此WSO2无法识别编码。 我刚刚将此行添加到axis2.xml中:

<messageFormatter contentType="application/ld+json" class="org.wso2.carbon.integrator.core.json.JsonStreamFormatter"/>
....
<messageBuilder contentType="application/ld+json"
                   class="org.wso2.carbon.integrator.core.json.JsonStreamBuilder"/>

一切正常! =)