Mule ESB does not work with cookie

2019-08-20 06:37发布

I use mule esb 3.7.0.

I have application A which sends an http request to mule esb, which forwards it to application B. The application B sends response back to mule esb, and mule esb sends it back to the application A. Everything works fine.

Then at one day the application B sends http response with a cookie (JSESSIONID, but it does not matter), and the application A throws timeout exceptions. I debugged mule esb and found this.

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

This method fails. Line 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 has compilation errors. 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)

A similar question (not a duplicate because I have a different version of mule) NoSuchMethodError in Tomcat embedded MULE when executing http:set-cookie

Also I read this https://www.mulesoft.org/jira/browse/MULE-6705

标签: java http mule
1条回答
对你真心纯属浪费
2楼-- · 2019-08-20 07:18

It turns out, the problem is with libraries. We use Spring Boot, which has dependencies, and one of them overrides version of coyote.

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

enter image description here

With SpringBoot, it uses embedded-tomcat-core.

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

enter image description here

查看更多
登录 后发表回答