Index: components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEndpointSetHttpTraceTest.java =================================================================== --- components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEndpointSetHttpTraceTest.java (revision 0) +++ components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEndpointSetHttpTraceTest.java (revision 0) @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.TraceMethod; +import org.junit.Test; + +/** + * @version + */ +public class JettyEndpointSetHttpTraceTest extends BaseJettyTest { + + private int portTraceOn = 8080; + private int portTraceOff = 8081; + + public JettyEndpointSetHttpTraceTest() { + portTraceOn = getNextPort(); + portTraceOff = getNextPort(); + } + + @Test + public void testTraceDisabled() throws Exception { + HttpClient httpclient = new HttpClient(); + TraceMethod trace = new TraceMethod("http://localhost:" + portTraceOff + "/myservice"); + httpclient.executeMethod(trace); + + // TRACE shouldn't be allowed by default + assertTrue(trace.getStatusCode() == 405); + trace.releaseConnection(); + } + + @Test + public void testTraceEnabled() throws Exception { + HttpClient httpclient = new HttpClient(); + TraceMethod trace = new TraceMethod("http://localhost:" + portTraceOn + "/myservice"); + httpclient.executeMethod(trace); + + // TRACE is now allowed + assertTrue(trace.getStatusCode() == 200); + trace.releaseConnection(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("jetty:http://localhost:" + portTraceOff + "/myservice").to("log:foo"); + from("jetty:http://localhost:" + portTraceOn + "/myservice?traceEnabled=true").to("log:bar"); + } + }; + } +} Index: components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java =================================================================== --- components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java (revision 1228204) +++ components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java (working copy) @@ -63,6 +63,10 @@ return; } + if ("TRACE".equals(request.getMethod()) && !consumer.isTraceEnabled()) { + response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); + } + final Exchange result = (Exchange) request.getAttribute(EXCHANGE_ATTRIBUTE_NAME); if (result == null) { // no asynchronous result so leverage continuation Index: components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java =================================================================== --- components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java (revision 1228204) +++ components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java (working copy) @@ -59,6 +59,7 @@ private int proxyPort; private String authMethodPriority; private boolean transferException; + private boolean traceEnabled; public HttpEndpoint() { } @@ -319,4 +320,12 @@ public void setTransferException(boolean transferException) { this.transferException = transferException; } + + public boolean isTraceEnabled() { + return this.traceEnabled; + } + + public void setTraceEnabled(boolean traceEnabled) { + this.traceEnabled = traceEnabled; + } } Index: components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java =================================================================== --- components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java (revision 1228204) +++ components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java (working copy) @@ -63,8 +63,8 @@ log.debug("No consumer to service request {}", request); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; - } - + } + // are we suspended? if (consumer.isSuspended()) { log.debug("Consumer suspended, cannot service request {}", request); @@ -72,6 +72,10 @@ return; } + if ("TRACE".equals(request.getMethod()) && !consumer.isTraceEnabled()) { + response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); + } + // create exchange and set data on it Exchange exchange = new DefaultExchange(consumer.getEndpoint(), ExchangePattern.InOut); if (consumer.getEndpoint().isBridgeEndpoint()) { Index: components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java =================================================================== --- components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java (revision 1228204) +++ components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java (working copy) @@ -26,9 +26,13 @@ public class HttpConsumer extends DefaultConsumer implements SuspendableService { private final HttpEndpoint endpoint; private volatile boolean suspended; + private boolean traceEnabled; public HttpConsumer(HttpEndpoint endpoint, Processor processor) { super(endpoint, processor); + if (endpoint.isTraceEnabled()) { + setTraceEnabled(true); + } this.endpoint = endpoint; } @@ -71,4 +75,11 @@ return suspended; } + public boolean isTraceEnabled() { + return this.traceEnabled; + } + + public void setTraceEnabled(boolean traceEnabled) { + this.traceEnabled = traceEnabled; + } }