HTTP 502 - 在处理程序处于不一致状态REQUEST_READY时尝试写入响应主体

时间:2017-02-13 15:27:25

标签: wso2 wso2-am

我从我的API收到了很多502回复:

TID: [-1234] [] [2017-02-13 15:15:13,802] DEBUG {org.wso2.carbon.apimgt.gateway.handlers.security.APIKeyValidator} -  Found resource in Cache for key: /Proxy/Temporary/1.0.0/1.0.0/AMQP/{uid}/{topic}:POST {org.wso2.carbon.apimgt.gateway.handlers.security.APIKeyValidator}
TID: [-1234] [] [2017-02-13 15:15:13,802] DEBUG {org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler} -  Authenticated API, authentication response relieved: API call failed reason=API_authentication_failure transactionId=urn:uuid:159bd2ab-e1d0-4bc9-9ff1-8458a04165a5 with accessToken=Bearer f9621dbc78f8bcc4a442ab5050c26069 for requestURI=/Proxy/Temporary/1.0.0/AMQP/2d5ccea7-0280-413b-aab2-1c7bac999875/00000004 at time=Mon Feb 13 15:15:13 WET 2017 from clientIP=192.168.11.86, elapsedTimeInMilliseconds=0 {org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler}
TID: [-1234] [] [2017-02-13 15:15:13,902] DEBUG {org.apache.synapse.transport.passthru.connections.SourceConnections} -  Shutting down connection forcefully http-incoming-1457 {org.apache.synapse.transport.passthru.connections.SourceConnections}
TID: [] [] [2017-02-13 15:15:13,902]  WARN {org.apache.synapse.transport.passthru.SourceHandler} -  Illegal incoming connection state: CLOSED . Possibly two send backs are happening for the same request {org.apache.synapse.transport.passthru.SourceHandler}
TID: [] [] [2017-02-13 15:15:13,903]  WARN {org.apache.synapse.transport.passthru.SourceHandler} -  Trying to write response body while the handler is in an inconsistent state CLOSED {org.apache.synapse.transport.passthru.SourceHandler}
TID: [] [] [2017-02-13 15:15:13,904] DEBUG {org.apache.synapse.transport.passthru.connections.SourceConnections} -  Shutting down connection forcefully http-incoming-1457 {org.apache.synapse.transport.passthru.connections.SourceConnections}
TID: [] [] [2017-02-13 15:15:13,904] ERROR {org.apache.synapse.transport.passthru.SourceHandler} -  Unexpected I/O error: java.nio.channels.ClosedChannelException {org.apache.synapse.transport.passthru.SourceHandler}
java.nio.channels.ClosedChannelException
        at sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:270)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:461)
        at org.apache.http.nio.reactor.ssl.SSLIOSession.sendEncryptedData(SSLIOSession.java:343)
        at org.apache.http.nio.reactor.ssl.SSLIOSession.outboundTransport(SSLIOSession.java:431)
        at org.apache.http.impl.nio.reactor.AbstractIODispatch.outputReady(AbstractIODispatch.java:152)
        at org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:180)
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:342)
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:316)
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:277)
        at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:105)
        at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:586)
        at java.lang.Thread.run(Thread.java:745)
TID: [] [] [2017-02-13 15:15:13,906] DEBUG {org.apache.synapse.transport.passthru.connections.SourceConnections} -  Shutting down connection forcefully http-incoming-1457 {org.apache.synapse.transport.passthru.connections.SourceConnections}
TID: [] [] [2017-02-13 15:15:13,906] DEBUG {org.apache.synapse.transport.passthru.SourceHandler} -  http-incoming-1457: Keep-Alive connection was closed: http-incoming-1457 {org.apache.synapse.transport.passthru.SourceHandler}
TID: [] [] [2017-02-13 15:15:13,906] DEBUG {org.apache.synapse.transport.passthru.connections.SourceConnections} -  Shutting down connection forcefully http-incoming-1457 {org.apache.synapse.transport.passthru.connections.SourceConnections}

虽然这看起来似乎需要花费很长时间,但在大多数情况下,这种反应会伴随着300ms的往返,有时甚至更少。与有效回复大致相同。

我的API有JavaScript序列,脚本一直执行到最后。

我在这里做错了什么?

这是我的API定义:

<api context="/MyAPI/1.0.0" name="admin--MyAPI"
    transports="https" version="1.0.0" version-type="context">
    <resource faultSequence="fault" methods="POST" uri-template="/AMQP/{uid}/{topic}">
        <inSequence>
            <filter regex="PRODUCTION" source="$ctx:AM_KEY_TYPE">
                <then>
                    <property
                        expression="get-property('SYSTEM_TIME')" name="api.ut.backendRequestTime"/>
                    <send>
                        <endpoint name="admin--MyAPI_APIsandboxEndpoint_1">
                            <default/>
                        </endpoint>
                    </send>
                </then>
                <else>
                    <send>
                        <endpoint name="admin--MyAPI_APIsandboxEndpoint_1">
                            <default/>
                        </endpoint>
                    </send>
                </else>
            </filter>
        </inSequence>
        <outSequence>
            <class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
            <send/>
        </outSequence>
    </resource>
    <resource faultSequence="fault" methods="DELETE" uri-template="/AMQP/{uid}">
        <inSequence>
            <filter regex="PRODUCTION" source="$ctx:AM_KEY_TYPE">
                <then>
                    <property
                        expression="get-property('SYSTEM_TIME')" name="api.ut.backendRequestTime"/>
                    <send>
                        <endpoint name="admin--MyAPI_APIsandboxEndpoint_1">
                            <default/>
                        </endpoint>
                    </send>
                </then>
                <else>
                    <send>
                        <endpoint name="admin--MyAPI_APIsandboxEndpoint_1">
                            <default/>
                        </endpoint>
                    </send>
                </else>
            </filter>
        </inSequence>
        <outSequence>
            <class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
            <send/>
        </outSequence>
    </resource>
    <resource faultSequence="fault" methods="POST" url-mapping="/AMQP">
        <inSequence>
            <filter regex="PRODUCTION" source="$ctx:AM_KEY_TYPE">
                <then>
                    <property
                        expression="get-property('SYSTEM_TIME')" name="api.ut.backendRequestTime"/>
                    <respond/>
                </then>
                <else>
                    <send>
                        <endpoint name="admin--MyAPI_APIsandboxEndpoint_2">
                            <default/>
                        </endpoint>
                    </send>
                </else>
            </filter>
        </inSequence>
        <outSequence>
            <class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
            <send/>
        </outSequence>
    </resource>
    <handlers>
        <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
            <property name="apiImplementationType" value="ENDPOINT"/>
        </handler>
        <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
        <handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
            <property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
            <property name="policyKeyApplication" value="gov:/apimgt/applicationdata/app-tiers.xml"/>
            <property name="id" value="A"/>
            <property name="policyKeyResource" value="gov:/apimgt/applicationdata/res-tiers.xml"/>
        </handler>
        <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler"/>
        <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtGoogleAnalyticsTrackingHandler">
            <property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
        </handler>
        <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
    </handlers>
</api>

这是我的序列定义:

<sequence name="admin--MyAPI:v1.0.0--In">
    <property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/>
    <switch
        source="concat(get-property('axis2', 'HTTP_METHOD'), '-', get-property('axis2', 'REST_URL_POSTFIX'))" xmlns:ns3="http://org.apache.synapse/xsd">
        <case regex="^POST-/AMQP$">
            <script language="js">
            // code that executes without errors
            </script>
            <property name="messageType" scope="axis2" value="application/json"/>
            <property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
            <respond/>
        </case>
        <case regex="^DELETE-/AMQP/[^/]+$">
            <script language="js">
            // code that executes without errors
            </script>
            <respond/>
        </case>
        <case regex="^POST-/AMQP/[^/]+.*">
            <property expression="json-eval($.)" name="payload"/>
            <property
                expression="get-property('axis2', 'ContentType')" name="ContentType"/>
            <property
                expression="get-property('axis2', 'REST_URL_POSTFIX')" name="REST_URL_POSTFIX"/>
            <property
                expression="get-property('axis2', 'TRANSPORT_HEADERS')" name="TRANSPORT_HEADERS"/>
            <script language="js">
            // code that executes without errors
            </script>
            <property name="FORCE_SC_ACCEPTED" scope="axis2"
                type="STRING" value="true"/>
            <property name="HTTP_SC" scope="axis2" value="202"/><!-- otherwise won't always be 202 -->
            <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
            <respond/>
        </case>
        <default/>
    </switch>
</sequence>

0 个答案:

没有答案