You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/02/11 15:20:12 UTC
svn commit: r743344 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/impl/
components/camel-http/src/main/java/org/apache/camel/component/http/
tests/camel-itest/src/test/java/org/apache/camel/itest/http/
tests/camel-itest/src/test/resource...
Author: davsclaus
Date: Wed Feb 11 14:20:11 2009
New Revision: 743344
URL: http://svn.apache.org/viewvc?rev=743344&view=rev
Log:
CAMEL-505: http endpoint can now be defined from spring xml.
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java (with props)
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?rev=743344&r1=743343&r2=743344&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java Wed Feb 11 14:20:11 2009
@@ -92,7 +92,7 @@
// if endpoint is strict (not lenient) and we have unknown parameters configured then
// fail if there are parameters that could not be set, then they are probably miss spelt or not supported at all
if (!endpoint.isLenientProperties()) {
- validateUnknownParameters(uri, parameters, null);
+ validateParameters(uri, parameters, null);
}
}
@@ -100,14 +100,14 @@
}
/**
- * Strategy for validation of unknown parameters not able to be resolved to any endpoint options.
+ * Strategy for validation of parameters, that was not able to be resolved to any endpoint options.
*
* @param uri the uri - the uri the end user provided untouched
* @param parameters the parameters, an empty map if no parameters given
* @param optionPrefix optional prefix to filter the parameters for validation. Use <tt>null</tt> for validate all.
* @throws ResolveEndpointFailedException should be thrown if the URI validation failed
*/
- protected void validateUnknownParameters(String uri, Map parameters, String optionPrefix) {
+ protected void validateParameters(String uri, Map parameters, String optionPrefix) {
Map param = parameters;
if (optionPrefix != null) {
param = IntrospectionSupport.extractProperties(parameters, optionPrefix);
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=743344&r1=743343&r2=743344&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 Wed Feb 11 14:20:11 2009
@@ -20,10 +20,8 @@
import java.util.Map;
import org.apache.camel.Endpoint;
-import org.apache.camel.HeaderFilterStrategyAware;
import org.apache.camel.ResolveEndpointFailedException;
import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.util.CamelContextHelper;
import org.apache.camel.util.IntrospectionSupport;
import org.apache.camel.util.URISupport;
@@ -37,16 +35,11 @@
*
* @version $Revision$
*/
-public class HttpComponent extends DefaultComponent implements HeaderFilterStrategyAware {
+public class HttpComponent extends DefaultComponent {
protected HttpClientConfigurer httpClientConfigurer;
protected HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
- protected HeaderFilterStrategy headerFilterStrategy;
protected HttpBinding httpBinding;
- public HttpComponent() {
- this.setHeaderFilterStrategy(new HttpHeaderFilterStrategy());
- }
-
/**
* Connects the URL specified on the endpoint to the specified processor.
*
@@ -102,7 +95,7 @@
HttpClientParams clientParams = new HttpClientParams();
IntrospectionSupport.setProperties(clientParams, parameters, "httpClient.");
// validate that we could resolve all httpClient. parameters as this component is lenient
- validateUnknownParameters(uri, parameters, "httpClient.");
+ validateParameters(uri, parameters, "httpClient.");
configureParameters(parameters);
@@ -120,7 +113,6 @@
}
}
-
HttpEndpoint endpoint = new HttpEndpoint(uri, this, httpUri, clientParams, httpConnectionManager, httpClientConfigurer);
if (httpBinding != null) {
endpoint.setBinding(httpBinding);
@@ -149,14 +141,6 @@
this.httpConnectionManager = httpConnectionManager;
}
- public HeaderFilterStrategy getHeaderFilterStrategy() {
- return headerFilterStrategy;
- }
-
- public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
- headerFilterStrategy = strategy;
- }
-
public HttpBinding getHttpBinding() {
return httpBinding;
}
Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?rev=743344&r1=743343&r2=743344&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java Wed Feb 11 14:20:11 2009
@@ -26,6 +26,8 @@
import org.apache.camel.ExchangePattern;
import org.apache.camel.PollingConsumer;
import org.apache.camel.Producer;
+import org.apache.camel.HeaderFilterStrategyAware;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.impl.DefaultPollingEndpoint;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.commons.httpclient.HttpClient;
@@ -38,8 +40,9 @@
*
* @version $Revision$
*/
-public class HttpEndpoint extends DefaultPollingEndpoint {
+public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilterStrategyAware {
+ private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
private HttpBinding binding;
private HttpComponent component;
private URI httpUri;
@@ -47,6 +50,9 @@
private HttpClientConfigurer httpClientConfigurer;
private HttpConnectionManager httpConnectionManager;
+ public HttpEndpoint() {
+ }
+
public HttpEndpoint(String endPointURI, HttpComponent component, URI httpURI, HttpConnectionManager httpConnectionManager) throws URISyntaxException {
this(endPointURI, component, httpURI, new HttpClientParams(), httpConnectionManager, null);
}
@@ -81,6 +87,9 @@
* Factory method used by producers and consumers to create a new {@link HttpClient} instance
*/
public HttpClient createHttpClient() {
+ ObjectHelper.notNull(clientParams, "clientParams");
+ ObjectHelper.notNull(httpConnectionManager, "httpConnectionManager");
+
HttpClient answer = new HttpClient(getClientParams());
answer.setHttpConnectionManager(httpConnectionManager);
HttpClientConfigurer configurer = getHttpClientConfigurer();
@@ -103,10 +112,14 @@
return true;
}
+ public boolean isSingleton() {
+ return true;
+ }
+
+
// Properties
//-------------------------------------------------------------------------
-
/**
* Provide access to the client parameters used on new {@link HttpClient} instances
* used by producers or consumers of this endpoint.
@@ -144,18 +157,10 @@
return binding;
}
- public HeaderFilterStrategy getHeaderFilterStrategy() {
- return component.getHeaderFilterStrategy();
- }
-
public void setBinding(HttpBinding binding) {
this.binding = binding;
}
- public boolean isSingleton() {
- return true;
- }
-
public String getPath() {
return httpUri.getPath();
}
@@ -178,4 +183,25 @@
public URI getHttpUri() {
return httpUri;
}
+
+ public void setHttpUri(URI httpUri) {
+ this.httpUri = httpUri;
+ }
+
+ public HttpConnectionManager getHttpConnectionManager() {
+ return httpConnectionManager;
+ }
+
+ public void setHttpConnectionManager(HttpConnectionManager httpConnectionManager) {
+ this.httpConnectionManager = httpConnectionManager;
+ }
+
+ public HeaderFilterStrategy getHeaderFilterStrategy() {
+ return headerFilterStrategy;
+ }
+
+ public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) {
+ this.headerFilterStrategy = headerFilterStrategy;
+ }
+
}
Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java?rev=743344&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java (added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java Wed Feb 11 14:20:11 2009
@@ -0,0 +1,31 @@
+package org.apache.camel.itest.http;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+
+@ContextConfiguration
+public class HttpEndpointTest extends AbstractJUnit38SpringContextTests {
+
+ @Autowired
+ protected CamelContext camelContext;
+
+ @EndpointInject(uri = "direct:start")
+ protected ProducerTemplate producer;
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint mock;
+
+ public void testMocksIsValid() throws Exception {
+ mock.expectedMessageCount(1);
+
+ producer.sendBody(null);
+
+ mock.assertIsSatisfied();
+ }
+
+}
\ No newline at end of file
Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpEndpointTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml?rev=743344&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml (added)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml Wed Feb 11 14:20:11 2009
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: e1 -->
+ <bean id="google" class="org.apache.camel.component.http.HttpEndpoint">
+ <property name="httpUri" value="http://www.google.com"/>
+ <property name="clientParams" ref="myParams"/>
+ <property name="httpConnectionManager" ref="myManager"/>
+ </bean>
+
+ <bean id="myParams" class="org.apache.commons.httpclient.params.HttpClientParams"/>
+
+ <bean id="myManager" class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"/>
+ <!-- END SNIPPET: e1 -->
+
+ <!-- START SNIPPET: e2 -->
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" trace="true">
+ <route>
+ <from uri="direct:start"/>
+ <to uri="google"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: e2 -->
+
+</beans>
Propchange: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/HttpEndpointTest-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml