温馨提示:本文翻译自stackoverflow.com,查看原文请点击:oauth 2.0 - Mule Box Connector
mule mule-studio oauth-2.0 box-api

oauth 2.0 - ule子盒连接器

发布于 2020-05-02 03:11:11

我正在尝试编写一个使用Box连接器的Mule流。我能够去http://localhost:8081/auth并成功授权。但是,一旦在Box帐户中创建文件,我就会收到“无法调用getEvents。消息有效载荷的类型为:字符串”。在根异常跟踪中,我得到:“无效的密钥类型”

ule子流(基于:https : //github.com/mulesoft/box-connector/blob/master/demo/src/main/app/box-connector-demo.xml

    <?xml version="1.0" encoding="UTF-8"?>

    <mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
        xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:box="http://www.mulesoft.org/schema/mule/box" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/scripting         http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
    http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/1.0/mule-objectstore.xsd
    http://www.mulesoft.org/schema/mule/box http://www.mulesoft.org/schema/mule/box/2.0/mule-box.xsd
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
        <box:config name="Box" clientId="removed" clientSecret="removed" doc:name="Box">
            <box:oauth-callback-config domain="localhost" localPort="8081" path="callback" remotePort="8081"/>
        </box:config>
<objectstore:config name="ObjectStore" objectStore-ref="_defaultInMemoryObjectStore" doc:name="ObjectStore"/>
        <flow name="Authorize" doc:name="Authorize">
            <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" path="auth"/>
            <box:authorize config-ref="Box" doc:name="Authorize" />

</flow>
    <flow name="longPolling" doc:name="longPolling">
            <box:listen-events config-ref="Box" doc:name="Box (Streaming)"/>
            <set-variable variableName="defaultValue" value="0" doc:name="Variable"/>
           <objectstore:retrieve config-ref="ObjectStore" key="streamPosition" defaultValue-ref="#[flowVars['defaultValue']]" doc:name="ObjectStore"/>
            <box:get-events config-ref="Box" streamPosition="#[payload]" accessTokenId="#[message.inboundProperties['boxAccessTokenId']]" doc:name="Box" />
            <objectstore:store config-ref="ObjectStore" key="streamPosition" value-ref="#[payload.nextStreamPosition]" overwrite="true" doc:name="ObjectStore"/>
            <scripting:transformer doc:name="Groovy">
        <scripting:script engine="Groovy"><![CDATA[return payload.entries.findAll{it.eventType =='ITEM_DOWNLOAD' || it.eventType == 'ITEM_PREVIEW'}
            ]]></scripting:script>
            </scripting:transformer>

    <scripting:transformer doc:name="Groovy">
                <scripting:script engine="Groovy"><![CDATA[return payload.findAll{it.source?.type == "file" && it.source?.parent.id == "0"}
            ]]></scripting:script>
            </scripting:transformer>

    <foreach doc:name="Foreach">
                <logger message="Box user #[payload.createdBy.login] has seen the file #[payload.source.name]" level="ERROR" doc:name="Logger"/>
            </foreach>


     </flow>
    </mule>

这是完整的错误:

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    + Started app 'boxtest'                                    +
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    WARN  2014-02-06 10:00:35,607 [Box Long Polling thread for endpont http://2.realtime.services.box.net/subscribe?channel=removed&stream_type=all] org.mule.DefaultMuleMessage: setProperty(key, value) called with null value; removing key: boxAccessTokenId; please report the following stack trace to dev@mule.codehaus.org
    java.lang.Throwable
        at org.mule.DefaultMuleMessage.setProperty(DefaultMuleMessage.java:457)
        at org.mule.DefaultMuleMessage.addProperties(DefaultMuleMessage.java:1249)
        at org.mule.DefaultMuleMessage.<init>(DefaultMuleMessage.java:174)
        at org.mule.modules.box.processors.AbstractListeningMessageProcessor.process(AbstractListeningMessageProcessor.java:76)
        at org.mule.modules.box.lp.LongPollingClient$1.run(LongPollingClient.java:63)
        at java.lang.Thread.run(Unknown Source)
    ERROR 2014-02-06 10:00:35,823 [[boxtest].longPolling.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
    ********************************************************************************
    Message               : Failed to invoke getEvents. Message payload is of type: String
    Code                  : MULE_ERROR--2
    --------------------------------------------------------------------------------
    Exception stack is:
    1. Invalid key type (java.lang.RuntimeException)
      org.mule.modules.box.oauth.BoxConnectorOAuthClientFactory:28 (null)
    2. Failed to invoke getEvents. Message payload is of type: String (org.mule.api.MessagingException)
      org.mule.modules.box.processors.GetEventsMessageProcessor:155 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
    --------------------------------------------------------------------------------
    Root Exception stack trace:
    java.lang.RuntimeException: Invalid key type
        at org.mule.modules.box.oauth.BoxConnectorOAuthClientFactory.makeObject(BoxConnectorOAuthClientFactory.java:28)
        at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:1179)
        at org.mule.modules.box.oauth.BoxConnectorOAuthManager.acquireAccessToken(BoxConnectorOAuthManager.java:339)
        + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
    ********************************************************************************

查看更多

提问者
Benjamin Bryan
被浏览
53
Anton Kupias 2014-02-07 07:58

这对我来说似乎是个错误:box:get-events应该使用属性boxAccessTokenId作为身份验证令牌,警告是由于空值而未设置该属性,当我查看BoxConnector的源代码时值的来源类,引用了从未设置的私有变量accessTokenIdentifier。我将此报告给了Mule开发人员地址。