Mule ESB不适用于Cookie

时间:2018-08-22 09:56:54

标签: java http mule

我使用的是ule esb 3.7.0。

我有一个应用程序A,它将HTTP请求发送到mule esb,然后将其转发到应用程序B。应用程序B将响应发送回给mule esb,然后mule esb将其发送回应用程序A。一切正常。

然后,有一天,应用程序B发送带有cookie的http响应(JSESSIONID,但没有关系),并且应用程序A抛出超时异常。我调试了ule esb并找到了它。

org.mule.transport.http.transformers.MuleMessageToHttpResponse->
    protected HttpResponse createResponse(Object src, String encoding, MuleMessage msg) throws IOException, TransformerException

此方法失败。第243行

    for (String headerName : headerNames) {
        if (HttpConstants.HEADER_COOKIE_SET.equals(headerName))
        {
            // TODO This have to be improved. We shouldn't have to look in all
            // scopes
            Object cookiesObject = msg.getInvocationProperty(headerName);
            if (cookiesObject == null)
            {
                cookiesObject = msg.getOutboundProperty(headerName);
            }
            if (cookiesObject == null)
            {
                cookiesObject = msg.getInboundProperty(headerName);
            }
            if (cookiesObject == null)
            {
                continue;
            }

            if (!(cookiesObject instanceof Cookie[]))
            {
                response.addHeader(new Header(headerName, cookiesObject.toString()));
            }
            else
            {
                Cookie[] arrayOfCookies = CookieHelper.asArrayOfCookies(cookiesObject);
                for (Cookie cookie : arrayOfCookies)
                {
                    /////////// THIS ONE FAILS
                    response.addHeader(new Header(headerName,
                        CookieHelper.formatCookieForASetCookieHeader(cookie)));
                }
            }
        }
        else
        {
            Object value = msg.getOutboundProperty(headerName);
            if (value == null)
            {
                value = msg.getInvocationProperty(headerName);
            }
            if (value != null)
            {
                response.setHeader(new Header(headerName, value.toString()));
            }
        }
   }

org.mule.transport.http.CookieHelper包含编译错误。 enter image description here

org.apache.tomcat.util.http.ServerCookie.appendCookieValue(Ljava/lang/StringBuffer;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZ)V
java.lang.NoSuchMethodError: org.apache.tomcat.util.http.ServerCookie.appendCookieValue(Ljava/lang/StringBuffer;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZ)V
    at org.mule.transport.http.CookieHelper.formatCookieForASetCookieHeader(CookieHelper.java:319)
    at org.mule.transport.http.transformers.MuleMessageToHttpResponse.createResponse(MuleMessageToHttpResponse.java:272)
    at org.mule.transport.http.transformers.MuleMessageToHttpResponse.transformMessage(MuleMessageToHttpResponse.java:109)
    at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:141)
    at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:89)
    at org.mule.DefaultMuleMessage.transformMessage(DefaultMuleMessage.java:1602)
    at org.mule.DefaultMuleMessage.applyAllTransformers(DefaultMuleMessage.java:1509)
    at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:1487)
    at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:1470)
    at org.mule.transport.AbstractMessageReceiver.applyResponseTransformers(AbstractMessageReceiver.java:260)
    at org.mule.transport.AbstractMessageReceiver.routeEvent(AbstractMessageReceiver.java:532)
    at org.mule.transport.AbstractTransportMessageProcessTemplate.routeEvent(AbstractTransportMessageProcessTemplate.java:72)
    at org.mule.execution.FlowProcessingPhase$1$1.process(FlowProcessingPhase.java:76)
    at org.mule.execution.FlowProcessingPhase$1$1.process(FlowProcessingPhase.java:63)
    at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
    at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:35)
    at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:22)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
    at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:67)
    at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
    at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
    at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
    at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
    at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
    at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
    at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
    at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:110)
    at org.mule.execution.FlowProcessingPhase$1.run(FlowProcessingPhase.java:62)
    at org.mule.transport.TrackingWorkManager$TrackeableWork.run(TrackingWorkManager.java:267)
    at org.mule.work.WorkerContext.run(WorkerContext.java:286)
    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)

类似的问题(因为我有不同版本的m子,所以不能重复) NoSuchMethodError in Tomcat embedded MULE when executing http:set-cookie

我也读过这篇 https://www.mulesoft.org/jira/browse/MULE-6705

1 个答案:

答案 0 :(得分:0)

事实证明,问题出在库中。我们使用的是Spring Boot,它具有依赖性,其中之一会覆盖土狼的版本。

provided group: 'org.apache.tomcat', name: 'coyote', version: '6.0.44'

enter image description here

使用SpringBoot,它使用Embedded-tomcat-core。

compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '8.0.28'

enter image description here