Camel jetty组件,自定义标头过滤策略

时间:2013-07-09 14:10:03

标签: java jetty apache-camel

我使用camel框架处理jetty组件。

我有两个问题:

1)我使用大消息(大约1mb)和jetty组件将消息体读入camel exchange头。它会导致这样的错误:

WARN  header full: java.lang.RuntimeException: Header>6144

那么,我怎样才能使jetty组件不将HttpRequest主体放入标题?

2)当我试图覆盖默认的HeaderFilterStrategy时,我编写了这样一段代码:

SimpleRegistry registry = new SimpleRegistry();
CamelContext context = new DefaultCamelContext(registry);

HeaderFilterStrategy strategy = new NewHeaderFilterStrategy();

registry.put("str", strategy);
context.addRoutes(new RouteBuilder() {
  public void configure() {

    from("jetty:http://my.host:32278/general-nr/notify?headerFilterStrategy=str")
    .....
});

它引起了这样的例外:

Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route[[From[jetty:http://my.host:32278/general-nr/notify?hea... because of Failed to resolve endpoint: jetty://http://my.host:32278/general-nr/notify?headerFilterStrategy=str due to: Could not find a suitable setter for property: headerFilterStrategy as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.camel.spi.HeaderFilterStrategy with value str
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:177)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:722)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1789)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1575)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1444)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1412)
at org.apache.camel.example.jmstofile.ElfRouterExample.main(ElfRouterExample.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

引起:org.apache.camel.ResolveEndpointFailedException:无法解析端点:jetty:// http://my.host:32278/general-nr/notify?headerFilterStrategy=str由于:找不到合适的属性setter:headerFilterStrategy,因为没有setter方法相同类型:java.lang.String或类型转换可能:没有类型转换器可用于从类型:java.lang.String转换为所需类型:org.apache.camel.spi.HeaderFilterStrategy,其值为str     at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:479)     at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:50)     在org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:187)     at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:108)     at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:114)     at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:72)     at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:90)     在org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:857)     在org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:172)     ......还有12个 引起:java.lang.IllegalArgumentException:找不到合适的属性setter:headerFilterStrategy,因为没有相同类型的setter方法:java.lang.String也没有类型转换:没有类型转换器可用于转换类型: java.lang.String到所需类型:org.apache.camel.spi.HeaderFilterStrategy,其值为str     at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:347)     at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:367)     at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:297)     at org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:249)     at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:222)     at org.apache.camel.component.jetty.JettyHttpComponent.createEndpoint(JettyHttpComponent.java:226)     at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:91)     at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:461)     ......还有20个

我做错了什么?

问候,Evgeniy

1 个答案:

答案 0 :(得分:2)

我找到的唯一决定 - 它是在jetty组件中扩展DefaultHttpBinding类并覆盖poptyRequestParameters()方法,其中JettyComponent从HttpMessage填充HttpServletRequest。

问候,Evgeniy