Author: davsclaus
Date: Mon Apr 12 13:44:05 2010
New Revision: 933235
URL: http://svn.apache.org/viewvc?rev=933235&view=rev
Log:
CAMEL-2633: added test to ensure endpoints do not change component configured
settings.
Added:
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpEndpointOptionsNotChangeComponentTest.java
(with props)
camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java
(with props)
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?rev=933235&r1=933234&r2=933235&view=diff
==============================================================================
---
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
(original)
+++
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
Mon Apr 12 13:44:05 2010
@@ -67,8 +67,11 @@ public class HttpComponent extends Heade
*/
protected HttpClientConfigurer createHttpClientConfigurer(Map<String,
Object> parameters) {
// prefer to use endpoint configured over component configured
- HttpClientConfigurer configurer = resolveAndRemoveReferenceParameter(
- parameters, "httpClientConfigurerRef",
HttpClientConfigurer.class);
+ HttpClientConfigurer configurer =
resolveAndRemoveReferenceParameter(parameters, "httpClientConfigurerRef",
HttpClientConfigurer.class);
+ if (configurer == null) {
+ // try without ref
+ configurer = resolveAndRemoveReferenceParameter(parameters,
"httpClientConfigurer", HttpClientConfigurer.class);
+ }
if (configurer == null) {
// fallback to component configured
configurer = getHttpClientConfigurer();
@@ -110,6 +113,10 @@ public class HttpComponent extends Heade
// must extract well known parameters before we create the endpoint
HttpBinding binding = resolveAndRemoveReferenceParameter(parameters,
"httpBindingRef", HttpBinding.class);
+ if (binding == null) {
+ // try without ref
+ binding = resolveAndRemoveReferenceParameter(parameters,
"httpBinding", HttpBinding.class);
+ }
Boolean throwExceptionOnFailure = getAndRemoveParameter(parameters,
"throwExceptionOnFailure", Boolean.class);
Boolean bridgeEndpoint = getAndRemoveParameter(parameters,
"bridgeEndpoint", Boolean.class);
Boolean matchOnUriPrefix = getAndRemoveParameter(parameters,
"matchOnUriPrefix", Boolean.class);
Added:
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpEndpointOptionsNotChangeComponentTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpEndpointOptionsNotChangeComponentTest.java?rev=933235&view=auto
==============================================================================
---
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpEndpointOptionsNotChangeComponentTest.java
(added)
+++
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpEndpointOptionsNotChangeComponentTest.java
Mon Apr 12 13:44:05 2010
@@ -0,0 +1,74 @@
+/**
+ * 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.http;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * Having custom endpoint options should not override or change any component
configured options.
+ *
+ * @version $Revision$
+ */
+public class HttpEndpointOptionsNotChangeComponentTest extends
CamelTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ HttpComponent http = context.getComponent("http", HttpComponent.class);
+ http.setHttpBinding(new MyBinding());
+
+ return context;
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("other", new MyOtherBinding());
+ return jndi;
+ }
+
+ @Test
+ public void testDoNotMessWithComponent() throws Exception {
+ // get default
+ HttpEndpoint end = context.getEndpoint("http://www.google.com",
HttpEndpoint.class);
+ assertIsInstanceOf(MyBinding.class, end.getBinding());
+
+ // use a endpoint specific binding
+ HttpEndpoint end2 =
context.getEndpoint("http://www.google.com?httpBinding=#other",
HttpEndpoint.class);
+ assertIsInstanceOf(MyOtherBinding.class, end2.getBinding());
+
+ // and the default option has not been messed with
+ HttpEndpoint end3 = context.getEndpoint("http://www.google.com",
HttpEndpoint.class);
+ assertIsInstanceOf(MyBinding.class, end3.getBinding());
+ }
+
+ private class MyBinding extends DefaultHttpBinding {
+ }
+
+ private class MyOtherBinding extends DefaultHttpBinding {
+ }
+
+}
Propchange:
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpEndpointOptionsNotChangeComponentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpEndpointOptionsNotChangeComponentTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java?rev=933235&r1=933234&r2=933235&view=diff
==============================================================================
---
camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
(original)
+++
camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
Mon Apr 12 13:44:05 2010
@@ -88,8 +88,11 @@ public class HttpComponent extends Heade
*/
protected HttpClientConfigurer createHttpClientConfigurer(Map<String,
Object> parameters) {
// prefer to use endpoint configured over component configured
- HttpClientConfigurer configurer = resolveAndRemoveReferenceParameter(
- parameters, "httpClientConfigurerRef",
HttpClientConfigurer.class);
+ HttpClientConfigurer configurer =
resolveAndRemoveReferenceParameter(parameters, "httpClientConfigurerRef",
HttpClientConfigurer.class);
+ if (configurer == null) {
+ // try without ref
+ configurer = resolveAndRemoveReferenceParameter(parameters,
"httpClientConfigurer", HttpClientConfigurer.class);
+ }
if (configurer == null) {
// fallback to component configured
configurer = getHttpClientConfigurer();
@@ -133,6 +136,10 @@ public class HttpComponent extends Heade
// must extract well known parameters before we create the endpoint
HttpBinding binding = resolveAndRemoveReferenceParameter(parameters,
"httpBindingRef", HttpBinding.class);
+ if (binding == null) {
+ // try without ref
+ binding = resolveAndRemoveReferenceParameter(parameters,
"httpBinding", HttpBinding.class);
+ }
Boolean throwExceptionOnFailure = getAndRemoveParameter(parameters,
"throwExceptionOnFailure", Boolean.class);
Boolean bridgeEndpoint = getAndRemoveParameter(parameters,
"bridgeEndpoint", Boolean.class);
Boolean matchOnUriPrefix = getAndRemoveParameter(parameters,
"matchOnUriPrefix", Boolean.class);
Added:
camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java?rev=933235&view=auto
==============================================================================
---
camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java
(added)
+++
camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java
Mon Apr 12 13:44:05 2010
@@ -0,0 +1,76 @@
+/**
+ * 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.http4;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * Having custom endpoint options should not override or change any component
configured options.
+ *
+ * @version $Revision$
+ */
+public class HttpEndpointOptionsNotChangeComponentTest extends
CamelTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ HttpComponent http = context.getComponent("http4",
HttpComponent.class);
+ http.setHttpBinding(new MyBinding());
+ // must start component
+ http.start();
+
+ return context;
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("other", new MyOtherBinding());
+ return jndi;
+ }
+
+ @Test
+ public void testDoNotMessWithComponent() throws Exception {
+ // get default
+ HttpEndpoint end = context.getEndpoint("http4://www.google.com",
HttpEndpoint.class);
+ assertIsInstanceOf(MyBinding.class, end.getBinding());
+
+ // use a endpoint specific binding
+ HttpEndpoint end2 =
context.getEndpoint("http4://www.google.com?httpBinding=#other",
HttpEndpoint.class);
+ assertIsInstanceOf(MyOtherBinding.class, end2.getBinding());
+
+ // and the default option has not been messed with
+ HttpEndpoint end3 = context.getEndpoint("http4://www.google.com",
HttpEndpoint.class);
+ assertIsInstanceOf(MyBinding.class, end3.getBinding());
+ }
+
+ private class MyBinding extends DefaultHttpBinding {
+ }
+
+ private class MyOtherBinding extends DefaultHttpBinding {
+ }
+
+}
Propchange:
camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date