【问题标题】:Camel-jetty component : use of available options骆驼码头组件:使用可用选项
【发布时间】:2015-10-23 04:46:12
【问题描述】:

我在我的路线中使用了收件人列表标签,如下所示。 bean findCallbackUrl 将返回一个字符串,这是我的目标地址。即我将向此端点发出 POST 请求。例如,我可能有一个服务器在 http://localhost:8080/acceptcallbacks 监听。

 <recipientList>
     <method ref="findCallbackUrl"/> 
 </recipientList>

所以当 findCallbackUrl bean 返回的 String(destination) 是 jetty:http://localhost:8080/acceptcallback 时,POST 工作正常。

但是,当使用Camel-jetty component 中提到的某些选项时,就会出现问题。当返回的目的地是 jetty:http://localhost:8080/acceptcallbacks?enableJmx=false 或 jetty:http://localhost:8080/acceptcallbacks?disableStreamCache=false 时,POST 工作正常。但是,如果返回的字符串是 jetty:http://localhost:8080/acceptcallbacks?chunked=false ,则调用将变为 GET 请求。

不确定这里发生了什么。如果不按照上面使用的方式使用 Camel-jetty 选项,对于选项 enableJmx 或 disableStreamCache 或其他一些选项,生成的目标 URL 应该是 http://localhost:8080/acceptcallbacks?enableJmx=false,这是一个 GET 请求。

chunked=false 可以用于生产者和消费者端点还是仅用于消费者端点?

【问题讨论】:

    标签: apache-camel fuseesb jbossfuse


    【解决方案1】:

    jetty中http方法的选择取决于骆驼交换的In Body,或者CamelHttpMethod header。

    查看类org.apache.camel.component.http.helper.HttpHelper的源码,方法createMethod

    public static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
        // compute what method to use either GET or POST
        HttpMethods answer;
        HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
        if (m != null) {
            // always use what end-user provides in a header
            answer = m;
        } else if (hasPayload) {
            // use POST if we have payload
            answer = HttpMethods.POST;
        } else {
            // fallback to GET
            answer = HttpMethods.GET;
        }
    
        return answer;
    }
    

    现在看org.apache.camel.component.jetty.JettyHttpProducer类中这个方法的调用:

    HttpMethods methodToUse = HttpHelper.createMethod(exchange, getEndpoint(), exchange.getIn().getBody() != null);

    恕我直言,选项无关紧要。在请求 HTTP 之前检查exchange.getIn().getBody(),或者您可以重置标头CamelHttpMethod

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多