gpt4 book ai didi

java - WSO2 EI - 构建直通流时出现 RelayUtils 错误

转载 作者:行者123 更新时间:2023-12-02 10:54:58 28 4
gpt4 key购买 nike

我正在使用 WSO2 EI 6.3.0,我想从特定的 Web 服务获取数据并将该数据推送到其他 Web 服务。

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

因此,我创建了多个序列以具有可重用的序列。当我想将不记名 token header 注入(inject)端点以获取数据时出现错误。

顺序步骤

  • 在 LogincheckSeq 期间,我调用 login_check api 来获取 JWT token 。

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

  • 然后我们传入CreateBearerTokenSeq,用之前从LoginCheckEP的json响应中恢复的 token 创建一个属性

  • 最后,我们传入最后一个序列 GetCustomerSeq,以便通过 header 中给出的 jwt token (授权:不记名 token )从 Web 服务获取 json 形式的客户信息

这是我的 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>

获取客户序列.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 token ,但在 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”的属性

但没有解决我的问题...如果有人已经遇到过这个问题,我正在采取解决方案=)

最佳答案

我找到了回复。服务器响应的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"/>

而且工作正常! =)

关于java - WSO2 EI - 构建直通流时出现 RelayUtils 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51843809/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com