You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/04/08 16:24:03 UTC
[1/4] git commit: CAMEL-7141 Avoiding the sideeffect of
setHeaderFilterStrategy of camel-netty-http component with thanks to Joe
Repository: camel
Updated Branches:
refs/heads/camel-2.12.x 17ed696d7 -> eab42aad9
refs/heads/camel-2.13.x c5e021f0e -> 30f430cc5
CAMEL-7141 Avoiding the sideeffect of setHeaderFilterStrategy of camel-netty-http component with thanks to Joe
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f0d8b967
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f0d8b967
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f0d8b967
Branch: refs/heads/camel-2.13.x
Commit: f0d8b9676dde39548e887eecaca25356c0fdc307
Parents: c5e021f
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Apr 8 20:45:01 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Apr 8 21:33:57 2014 +0800
----------------------------------------------------------------------
.../netty/http/DefaultNettyHttpBinding.java | 13 +++-
.../netty/http/NettyHttpComponent.java | 24 +++----
.../component/netty/http/NettyHttpEndpoint.java | 4 +-
...dpointUriCustomHeaderFilterStrategyTest.java | 70 ++++++++++++++++++++
4 files changed, 90 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f0d8b967/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
index 40bb99e..00eda1e 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
@@ -32,6 +32,7 @@ import java.util.Map;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.TypeConverter;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.util.ExchangeHelper;
@@ -55,10 +56,10 @@ import org.slf4j.LoggerFactory;
/**
* Default {@link NettyHttpBinding}.
*/
-public class DefaultNettyHttpBinding implements NettyHttpBinding {
+public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable {
private static final Logger LOG = LoggerFactory.getLogger(DefaultNettyHttpBinding.class);
- private HeaderFilterStrategy headerFilterStrategy;
+ private HeaderFilterStrategy headerFilterStrategy = new NettyHttpHeaderFilterStrategy();
public DefaultNettyHttpBinding() {
}
@@ -66,6 +67,14 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding {
public DefaultNettyHttpBinding(HeaderFilterStrategy headerFilterStrategy) {
this.headerFilterStrategy = headerFilterStrategy;
}
+
+ public DefaultNettyHttpBinding copy() {
+ try {
+ return (DefaultNettyHttpBinding)this.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
@Override
public Message toCamelMessage(HttpRequest request, Exchange exchange, NettyHttpConfiguration configuration) throws Exception {
http://git-wip-us.apache.org/repos/asf/camel/blob/f0d8b967/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
index 0e4ccae..e4142d7 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
@@ -49,6 +49,10 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
private NettyHttpSecurityConfiguration securityConfiguration;
public NettyHttpComponent() {
+ // use the http configuration and filter strategy
+ setConfiguration(new NettyHttpConfiguration());
+ setHeaderFilterStrategy(new NettyHttpHeaderFilterStrategy());
+ setNettyHttpBinding(new DefaultNettyHttpBinding(getHeaderFilterStrategy()));
}
@Override
@@ -95,8 +99,11 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
answer.setTimer(getTimer());
// set component options on endpoint as defaults
+ // As the component's NettyHttpBinding could be override by the setHeaderFilterStrategy
+ // Here we just create a new DefaultNettyHttpBinding here
if (answer.getNettyHttpBinding() == null) {
- answer.setNettyHttpBinding(getNettyHttpBinding());
+ DefaultNettyHttpBinding nettyHttpBinding = (DefaultNettyHttpBinding)getNettyHttpBinding();
+ answer.setNettyHttpBinding(nettyHttpBinding.copy());
}
if (answer.getHeaderFilterStrategy() == null) {
answer.setHeaderFilterStrategy(getHeaderFilterStrategy());
@@ -142,9 +149,6 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
}
public NettyHttpBinding getNettyHttpBinding() {
- if (nettyHttpBinding == null) {
- nettyHttpBinding = new DefaultNettyHttpBinding(getHeaderFilterStrategy());
- }
return nettyHttpBinding;
}
@@ -153,9 +157,6 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
}
public HeaderFilterStrategy getHeaderFilterStrategy() {
- if (headerFilterStrategy == null) {
- headerFilterStrategy = new NettyHttpHeaderFilterStrategy();
- }
return headerFilterStrategy;
}
@@ -194,15 +195,6 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
}
@Override
- protected void doStart() throws Exception {
- if (getConfiguration() == null) {
- setConfiguration(new NettyHttpConfiguration());
- }
-
- super.doStart();
- }
-
- @Override
protected void doStop() throws Exception {
super.doStop();
http://git-wip-us.apache.org/repos/asf/camel/blob/f0d8b967/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
index 7d68050..173aa25 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
@@ -137,9 +137,7 @@ public class NettyHttpEndpoint extends NettyEndpoint implements HeaderFilterStra
public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) {
this.headerFilterStrategy = headerFilterStrategy;
- if (getNettyHttpBinding() != null) {
- getNettyHttpBinding().setHeaderFilterStrategy(headerFilterStrategy);
- }
+ getNettyHttpBinding().setHeaderFilterStrategy(headerFilterStrategy);
}
public boolean isTraceEnabled() {
http://git-wip-us.apache.org/repos/asf/camel/blob/f0d8b967/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointUriCustomHeaderFilterStrategyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointUriCustomHeaderFilterStrategyTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointUriCustomHeaderFilterStrategyTest.java
new file mode 100644
index 0000000..ddbb06b
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointUriCustomHeaderFilterStrategyTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.netty.http;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultHeaderFilterStrategy;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Test;
+
+public class NettyHttpEndpointUriCustomHeaderFilterStrategyTest extends BaseNettyTest {
+
+ @Test
+ public void testEndpointUriWithCustomHeaderStrategy() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:outbound");
+ mock.expectedMessageCount(1);
+ mock.expectedHeaderReceived("Date", "31-03-2014");
+
+ Exchange out = template.request("direct:request", null);
+
+ assertMockEndpointsSatisfied();
+
+ String date = out.getOut().getHeader("sub-date", String.class);
+ assertNull(date);
+ }
+
+ @Override protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("customHeaderFilterStrategy", new CustomHeaderFilterStrategy());
+ return registry;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:request")
+ .setHeader("Date", constant("31-03-2014"))
+ .to("netty-http:http://localhost:{{port}}/myapp/mytest?headerFilterStrategy=#customHeaderFilterStrategy");
+
+ from("netty-http:http://localhost:{{port}}/myapp/mytest")
+ .to("mock:outbound")
+ .setHeader("sub-date", constant("31-05-2014"));
+ }
+ };
+ }
+
+ private class CustomHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
+ public CustomHeaderFilterStrategy() {
+ // allow all outbound headers to pass through but only filter out below inbound header
+ getInFilter().add("sub-date");
+ }
+ }
+}
[4/4] git commit: CAMEL-7349 cach the schema in JaxbDataFormate
Posted by ni...@apache.org.
CAMEL-7349 cach the schema in JaxbDataFormate
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/eab42aad
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/eab42aad
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/eab42aad
Branch: refs/heads/camel-2.12.x
Commit: eab42aad98d8bc77bf6efeeceb740181611a76ca
Parents: 0892953
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Apr 8 22:06:45 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Apr 8 22:22:35 2014 +0800
----------------------------------------------------------------------
.../camel/converter/jaxb/JaxbDataFormat.java | 70 ++++++++++++--------
1 file changed, 42 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/eab42aad/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
index c29ab2d..cf2d33b 100644
--- a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
+++ b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
@@ -92,6 +92,7 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, CamelC
private JaxbNamespacePrefixMapper namespacePrefixMapper;
private JaxbXmlStreamWriterWrapper xmlStreamWriterWrapper;
private TypeConverter typeConverter;
+ private volatile Schema cachedSchema;
public JaxbDataFormat() {
}
@@ -368,47 +369,60 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, CamelC
}
}
- protected Unmarshaller createUnmarshaller() throws JAXBException, SAXException, FileNotFoundException, MalformedURLException {
+ protected Unmarshaller createUnmarshaller() throws JAXBException, SAXException, FileNotFoundException,
+ MalformedURLException {
Unmarshaller unmarshaller = getContext().createUnmarshaller();
if (schema != null) {
- SchemaFactory factory = getOrCreateSchemaFactory();
- try {
- Schema newSchema = factory.newSchema(getSources());
- unmarshaller.setSchema(newSchema);
- unmarshaller.setEventHandler(new ValidationEventHandler() {
- public boolean handleEvent(ValidationEvent event) {
- // stop unmarshalling if the event is an ERROR or FATAL ERROR
- return event.getSeverity() == ValidationEvent.WARNING;
- }
- });
- } finally {
- returnSchemaFactory(factory);
- }
+ unmarshaller.setSchema(getCachedSchema());
+ unmarshaller.setEventHandler(new ValidationEventHandler() {
+ public boolean handleEvent(ValidationEvent event) {
+ // stop unmarshalling if the event is an ERROR or FATAL
+ // ERROR
+ return event.getSeverity() == ValidationEvent.WARNING;
+ }
+ });
+
}
return unmarshaller;
}
- protected Marshaller createMarshaller() throws JAXBException, SAXException, FileNotFoundException, MalformedURLException {
+ protected Marshaller createMarshaller() throws JAXBException, SAXException, FileNotFoundException,
+ MalformedURLException {
Marshaller marshaller = getContext().createMarshaller();
if (schema != null) {
- SchemaFactory factory = getOrCreateSchemaFactory();
- try {
- Schema newSchema = factory.newSchema(getSources());
- marshaller.setSchema(newSchema);
- marshaller.setEventHandler(new ValidationEventHandler() {
- public boolean handleEvent(ValidationEvent event) {
- // stop marshalling if the event is an ERROR or FATAL ERROR
- return event.getSeverity() == ValidationEvent.WARNING;
- }
- });
- } finally {
- returnSchemaFactory(factory);
- }
+ marshaller.setSchema(getCachedSchema());
+ marshaller.setEventHandler(new ValidationEventHandler() {
+ public boolean handleEvent(ValidationEvent event) {
+ // stop marshalling if the event is an ERROR or FATAL ERROR
+ return event.getSeverity() == ValidationEvent.WARNING;
+ }
+ });
+
}
return marshaller;
}
+
+ private Schema getCachedSchema() throws FileNotFoundException, MalformedURLException, SAXException {
+ if (cachedSchema == null) {
+ synchronized (this) {
+ if (cachedSchema == null) {
+ cachedSchema = createSchema(getSources());
+ }
+ }
+ }
+ return cachedSchema;
+ }
+
+ private Schema createSchema(Source[] sources) throws SAXException {
+ SchemaFactory factory = getOrCreateSchemaFactory();
+ try {
+ return factory.newSchema(sources);
+ } finally {
+ returnSchemaFactory(factory);
+ }
+ }
private Source[] getSources() throws FileNotFoundException, MalformedURLException {
// we support multiple schema by delimiting they by ','
[3/4] git commit: CAMEL-7349 cach the schema in JaxbDataFormate
Posted by ni...@apache.org.
CAMEL-7349 cach the schema in JaxbDataFormate
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/30f430cc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/30f430cc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/30f430cc
Branch: refs/heads/camel-2.13.x
Commit: 30f430cc55dfd53cce462f8b7326a3a9948d7300
Parents: f0d8b96
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Apr 8 22:06:45 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Apr 8 22:22:24 2014 +0800
----------------------------------------------------------------------
.../camel/converter/jaxb/JaxbDataFormat.java | 70 ++++++++++++--------
1 file changed, 42 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/30f430cc/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
index 1e866e1..d34836d 100644
--- a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
+++ b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
@@ -91,6 +91,7 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, CamelC
private JaxbNamespacePrefixMapper namespacePrefixMapper;
private JaxbXmlStreamWriterWrapper xmlStreamWriterWrapper;
private TypeConverter typeConverter;
+ private volatile Schema cachedSchema;
public JaxbDataFormat() {
}
@@ -367,47 +368,60 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, CamelC
}
}
- protected Unmarshaller createUnmarshaller() throws JAXBException, SAXException, FileNotFoundException, MalformedURLException {
+ protected Unmarshaller createUnmarshaller() throws JAXBException, SAXException, FileNotFoundException,
+ MalformedURLException {
Unmarshaller unmarshaller = getContext().createUnmarshaller();
if (schema != null) {
- SchemaFactory factory = getOrCreateSchemaFactory();
- try {
- Schema newSchema = factory.newSchema(getSources());
- unmarshaller.setSchema(newSchema);
- unmarshaller.setEventHandler(new ValidationEventHandler() {
- public boolean handleEvent(ValidationEvent event) {
- // stop unmarshalling if the event is an ERROR or FATAL ERROR
- return event.getSeverity() == ValidationEvent.WARNING;
- }
- });
- } finally {
- returnSchemaFactory(factory);
- }
+ unmarshaller.setSchema(getCachedSchema());
+ unmarshaller.setEventHandler(new ValidationEventHandler() {
+ public boolean handleEvent(ValidationEvent event) {
+ // stop unmarshalling if the event is an ERROR or FATAL
+ // ERROR
+ return event.getSeverity() == ValidationEvent.WARNING;
+ }
+ });
+
}
return unmarshaller;
}
- protected Marshaller createMarshaller() throws JAXBException, SAXException, FileNotFoundException, MalformedURLException {
+ protected Marshaller createMarshaller() throws JAXBException, SAXException, FileNotFoundException,
+ MalformedURLException {
Marshaller marshaller = getContext().createMarshaller();
if (schema != null) {
- SchemaFactory factory = getOrCreateSchemaFactory();
- try {
- Schema newSchema = factory.newSchema(getSources());
- marshaller.setSchema(newSchema);
- marshaller.setEventHandler(new ValidationEventHandler() {
- public boolean handleEvent(ValidationEvent event) {
- // stop marshalling if the event is an ERROR or FATAL ERROR
- return event.getSeverity() == ValidationEvent.WARNING;
- }
- });
- } finally {
- returnSchemaFactory(factory);
- }
+ marshaller.setSchema(getCachedSchema());
+ marshaller.setEventHandler(new ValidationEventHandler() {
+ public boolean handleEvent(ValidationEvent event) {
+ // stop marshalling if the event is an ERROR or FATAL ERROR
+ return event.getSeverity() == ValidationEvent.WARNING;
+ }
+ });
+
}
return marshaller;
}
+
+ private Schema getCachedSchema() throws FileNotFoundException, MalformedURLException, SAXException {
+ if (cachedSchema == null) {
+ synchronized (this) {
+ if (cachedSchema == null) {
+ cachedSchema = createSchema(getSources());
+ }
+ }
+ }
+ return cachedSchema;
+ }
+
+ private Schema createSchema(Source[] sources) throws SAXException {
+ SchemaFactory factory = getOrCreateSchemaFactory();
+ try {
+ return factory.newSchema(sources);
+ } finally {
+ returnSchemaFactory(factory);
+ }
+ }
private Source[] getSources() throws FileNotFoundException, MalformedURLException {
// we support multiple schema by delimiting they by ','
[2/4] git commit: CAMEL-7141 Avoiding the sideeffect of
setHeaderFilterStrategy of camel-netty-http component with thanks to Joe
Posted by ni...@apache.org.
CAMEL-7141 Avoiding the sideeffect of setHeaderFilterStrategy of camel-netty-http component with thanks to Joe
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/08929530
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/08929530
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/08929530
Branch: refs/heads/camel-2.12.x
Commit: 0892953016de8de8bb0db1bc1412806c3c57e823
Parents: 17ed696
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Apr 8 20:45:01 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Apr 8 21:34:32 2014 +0800
----------------------------------------------------------------------
.../netty/http/DefaultNettyHttpBinding.java | 13 +++-
.../netty/http/NettyHttpComponent.java | 24 +++----
.../component/netty/http/NettyHttpEndpoint.java | 4 +-
...dpointUriCustomHeaderFilterStrategyTest.java | 70 ++++++++++++++++++++
4 files changed, 90 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/08929530/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
index f6c6c45..e1d700a 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
@@ -32,6 +32,7 @@ import java.util.Map;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.TypeConverter;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.util.ExchangeHelper;
@@ -55,10 +56,10 @@ import org.slf4j.LoggerFactory;
/**
* Default {@link NettyHttpBinding}.
*/
-public class DefaultNettyHttpBinding implements NettyHttpBinding {
+public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable {
private static final Logger LOG = LoggerFactory.getLogger(DefaultNettyHttpBinding.class);
- private HeaderFilterStrategy headerFilterStrategy;
+ private HeaderFilterStrategy headerFilterStrategy = new NettyHttpHeaderFilterStrategy();
public DefaultNettyHttpBinding() {
}
@@ -66,6 +67,14 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding {
public DefaultNettyHttpBinding(HeaderFilterStrategy headerFilterStrategy) {
this.headerFilterStrategy = headerFilterStrategy;
}
+
+ public DefaultNettyHttpBinding copy() {
+ try {
+ return (DefaultNettyHttpBinding)this.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
@Override
public Message toCamelMessage(HttpRequest request, Exchange exchange, NettyHttpConfiguration configuration) throws Exception {
http://git-wip-us.apache.org/repos/asf/camel/blob/08929530/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
index 0e4ccae..e4142d7 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
@@ -49,6 +49,10 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
private NettyHttpSecurityConfiguration securityConfiguration;
public NettyHttpComponent() {
+ // use the http configuration and filter strategy
+ setConfiguration(new NettyHttpConfiguration());
+ setHeaderFilterStrategy(new NettyHttpHeaderFilterStrategy());
+ setNettyHttpBinding(new DefaultNettyHttpBinding(getHeaderFilterStrategy()));
}
@Override
@@ -95,8 +99,11 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
answer.setTimer(getTimer());
// set component options on endpoint as defaults
+ // As the component's NettyHttpBinding could be override by the setHeaderFilterStrategy
+ // Here we just create a new DefaultNettyHttpBinding here
if (answer.getNettyHttpBinding() == null) {
- answer.setNettyHttpBinding(getNettyHttpBinding());
+ DefaultNettyHttpBinding nettyHttpBinding = (DefaultNettyHttpBinding)getNettyHttpBinding();
+ answer.setNettyHttpBinding(nettyHttpBinding.copy());
}
if (answer.getHeaderFilterStrategy() == null) {
answer.setHeaderFilterStrategy(getHeaderFilterStrategy());
@@ -142,9 +149,6 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
}
public NettyHttpBinding getNettyHttpBinding() {
- if (nettyHttpBinding == null) {
- nettyHttpBinding = new DefaultNettyHttpBinding(getHeaderFilterStrategy());
- }
return nettyHttpBinding;
}
@@ -153,9 +157,6 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
}
public HeaderFilterStrategy getHeaderFilterStrategy() {
- if (headerFilterStrategy == null) {
- headerFilterStrategy = new NettyHttpHeaderFilterStrategy();
- }
return headerFilterStrategy;
}
@@ -194,15 +195,6 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
}
@Override
- protected void doStart() throws Exception {
- if (getConfiguration() == null) {
- setConfiguration(new NettyHttpConfiguration());
- }
-
- super.doStart();
- }
-
- @Override
protected void doStop() throws Exception {
super.doStop();
http://git-wip-us.apache.org/repos/asf/camel/blob/08929530/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
index 7d68050..173aa25 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
@@ -137,9 +137,7 @@ public class NettyHttpEndpoint extends NettyEndpoint implements HeaderFilterStra
public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) {
this.headerFilterStrategy = headerFilterStrategy;
- if (getNettyHttpBinding() != null) {
- getNettyHttpBinding().setHeaderFilterStrategy(headerFilterStrategy);
- }
+ getNettyHttpBinding().setHeaderFilterStrategy(headerFilterStrategy);
}
public boolean isTraceEnabled() {
http://git-wip-us.apache.org/repos/asf/camel/blob/08929530/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointUriCustomHeaderFilterStrategyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointUriCustomHeaderFilterStrategyTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointUriCustomHeaderFilterStrategyTest.java
new file mode 100644
index 0000000..ddbb06b
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpEndpointUriCustomHeaderFilterStrategyTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.netty.http;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultHeaderFilterStrategy;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Test;
+
+public class NettyHttpEndpointUriCustomHeaderFilterStrategyTest extends BaseNettyTest {
+
+ @Test
+ public void testEndpointUriWithCustomHeaderStrategy() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:outbound");
+ mock.expectedMessageCount(1);
+ mock.expectedHeaderReceived("Date", "31-03-2014");
+
+ Exchange out = template.request("direct:request", null);
+
+ assertMockEndpointsSatisfied();
+
+ String date = out.getOut().getHeader("sub-date", String.class);
+ assertNull(date);
+ }
+
+ @Override protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("customHeaderFilterStrategy", new CustomHeaderFilterStrategy());
+ return registry;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:request")
+ .setHeader("Date", constant("31-03-2014"))
+ .to("netty-http:http://localhost:{{port}}/myapp/mytest?headerFilterStrategy=#customHeaderFilterStrategy");
+
+ from("netty-http:http://localhost:{{port}}/myapp/mytest")
+ .to("mock:outbound")
+ .setHeader("sub-date", constant("31-05-2014"));
+ }
+ };
+ }
+
+ private class CustomHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
+ public CustomHeaderFilterStrategy() {
+ // allow all outbound headers to pass through but only filter out below inbound header
+ getInFilter().add("sub-date");
+ }
+ }
+}