Mule ESB不适用于Cookie [英] Mule ESB does not work with cookie

查看:78
本文介绍了Mule ESB不适用于Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是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包含编译错误.

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子) 执行http:set-cookie时,Tomcat嵌入式MULE中的 NoSuchMethodError

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

解决方案

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

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

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

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

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.

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

解决方案

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'

With SpringBoot, it uses embedded-tomcat-core.

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

这篇关于Mule ESB不适用于Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆