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 2010/04/10 12:49:35 UTC
svn commit: r932690 [1/3] - in /camel/trunk/components/camel-http: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/camel/ src/main/java/org/apache/camel/component/
src/main/java/org/apache/camel/co...
Author: davsclaus
Date: Sat Apr 10 10:49:33 2010
New Revision: 932690
URL: http://svn.apache.org/viewvc?rev=932690&view=rev
Log:
CAMEL-2608: Restoring old camel-http component.
Added:
camel/trunk/components/camel-http/
camel/trunk/components/camel-http/pom.xml (with props)
camel/trunk/components/camel-http/src/
camel/trunk/components/camel-http/src/main/
camel/trunk/components/camel-http/src/main/java/
camel/trunk/components/camel-http/src/main/java/org/
camel/trunk/components/camel-http/src/main/java/org/apache/
camel/trunk/components/camel-http/src/main/java/org/apache/camel/
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/ProxyHttpClientConfigurer.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStream.java (with props)
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/package.html (with props)
camel/trunk/components/camel-http/src/main/resources/
camel/trunk/components/camel-http/src/main/resources/META-INF/
camel/trunk/components/camel-http/src/main/resources/META-INF/LICENSE.txt (with props)
camel/trunk/components/camel-http/src/main/resources/META-INF/NOTICE.txt (with props)
camel/trunk/components/camel-http/src/main/resources/META-INF/services/
camel/trunk/components/camel-http/src/main/resources/META-INF/services/org/
camel/trunk/components/camel-http/src/main/resources/META-INF/services/org/apache/
camel/trunk/components/camel-http/src/main/resources/META-INF/services/org/apache/camel/
camel/trunk/components/camel-http/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
camel/trunk/components/camel-http/src/main/resources/META-INF/services/org/apache/camel/component/
camel/trunk/components/camel-http/src/main/resources/META-INF/services/org/apache/camel/component/http
camel/trunk/components/camel-http/src/main/resources/META-INF/services/org/apache/camel/component/https
camel/trunk/components/camel-http/src/test/
camel/trunk/components/camel-http/src/test/java/
camel/trunk/components/camel-http/src/test/java/org/
camel/trunk/components/camel-http/src/test/java/org/apache/
camel/trunk/components/camel-http/src/test/java/org/apache/camel/
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpGetTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpGetWithHeadersTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpGetWithPathHeaderTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpGetWithQueryParamsTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpHeaderFilterStrategyTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpPostWithBodyTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpReferenceParameterTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpsGetTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/GZIPHelperTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/HttpProducerHelperTest.java (with props)
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStreamTest.java (with props)
camel/trunk/components/camel-http/src/test/resources/
camel/trunk/components/camel-http/src/test/resources/log4j.properties (with props)
Added: camel/trunk/components/camel-http/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/pom.xml?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/pom.xml (added)
+++ camel/trunk/components/camel-http/pom.xml Sat Apr 10 10:49:33 2010
@@ -0,0 +1,85 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>2.3-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-http</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: HTTP</name>
+ <description>Camel HTTP support</description>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.http.*</camel.osgi.export.pkg>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-servlet_2.4_spec</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- to allow Spring annotations (jmx) to be tested -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <optional>true</optional>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <optional>true</optional>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: camel/trunk/components/camel-http/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/pom.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-http/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,48 @@
+/**
+ * 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.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.NTCredentials;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+
+public class BasicAuthenticationHttpClientConfigurer implements HttpClientConfigurer {
+ private final String username;
+ private final String password;
+ private final String domain;
+ private final String host;
+
+ public BasicAuthenticationHttpClientConfigurer(String user, String pwd, String domain, String host) {
+ username = user;
+ password = pwd;
+ this.domain = domain;
+ this.host = host;
+ }
+
+ public void configureHttpClient(HttpClient client) {
+ Credentials defaultcreds;
+ if (domain != null) {
+ defaultcreds = new NTCredentials(username, password, host, domain);
+ } else {
+ defaultcreds = new UsernamePasswordCredentials(username, password);
+ }
+ client.getState().setCredentials(AuthScope.ANY, defaultcreds);
+ }
+
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,95 @@
+/**
+ * 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 java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.impl.DefaultExchange;
+
+/**
+ * @version $Revision$
+ */
+public class CamelServlet extends HttpServlet {
+
+ private static final long serialVersionUID = -7061982839117697829L;
+
+ private ConcurrentHashMap<String, HttpConsumer> consumers = new ConcurrentHashMap<String, HttpConsumer>();
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ try {
+
+ // Is there a consumer registered for the request.
+ HttpConsumer consumer = resolve(request);
+ if (consumer == null) {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+
+ // Have the camel process the HTTP exchange.
+ DefaultExchange exchange = new DefaultExchange(consumer.getEndpoint(), ExchangePattern.InOut);
+ exchange.setIn(new HttpMessage(exchange, request, response));
+ consumer.getProcessor().process(exchange);
+
+ // HC: The getBinding() is interesting because it illustrates the
+ // impedance miss-match between
+ // HTTP's stream oriented protocol, and Camels more message oriented
+ // protocol exchanges.
+
+ // now lets output to the response
+ consumer.getBinding().writeResponse(exchange, response);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ServletException(e);
+ }
+ }
+
+ protected HttpConsumer resolve(HttpServletRequest request) {
+ String path = request.getPathInfo();
+ if (path == null) {
+ return null;
+ }
+ HttpConsumer answer = consumers.get(path);
+
+ if (answer == null) {
+ for (String key : consumers.keySet()) {
+ if (consumers.get(key).getEndpoint().isMatchOnUriPrefix() && path.startsWith(key)) {
+ answer = consumers.get(key);
+ break;
+ }
+ }
+ }
+ return answer;
+ }
+
+ public void connect(HttpConsumer consumer) {
+ consumers.put(consumer.getPath(), consumer);
+ }
+
+ public void disconnect(HttpConsumer consumer) {
+ consumers.remove(consumer.getPath());
+ }
+
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,56 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.httpclient.HttpClient;
+
+public class CompositeHttpConfigurer implements HttpClientConfigurer {
+
+ private List<HttpClientConfigurer> configurers = new ArrayList<HttpClientConfigurer>();
+
+ public void addConfigurer(HttpClientConfigurer configurer) {
+ if (configurer != null) {
+ configurers.add(configurer);
+ }
+ }
+
+ public void removeConfigurer(HttpClientConfigurer configurer) {
+ configurers.remove(configurer);
+ }
+
+ public void configureHttpClient(HttpClient client) {
+ for (HttpClientConfigurer configurer : configurers) {
+ configurer.configureHttpClient(client);
+ }
+ }
+
+ public static CompositeHttpConfigurer combineConfigurers(HttpClientConfigurer oldConfigurer, HttpClientConfigurer newConfigurer) {
+ if (oldConfigurer instanceof CompositeHttpConfigurer) {
+ ((CompositeHttpConfigurer)oldConfigurer).addConfigurer(newConfigurer);
+ return (CompositeHttpConfigurer)oldConfigurer;
+ } else {
+ CompositeHttpConfigurer answer = new CompositeHttpConfigurer();
+ answer.addConfigurer(newConfigurer);
+ answer.addConfigurer(oldConfigurer);
+ return answer;
+ }
+ }
+
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,272 @@
+/**
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.util.Enumeration;
+import java.util.Map;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.apache.camel.component.http.helper.GZIPHelper;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.MessageHelper;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * Binding between {@link HttpMessage} and {@link HttpServletResponse}.
+ *
+ * @version $Revision$
+ */
+public class DefaultHttpBinding implements HttpBinding {
+
+ private boolean useReaderForPayload;
+ private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
+
+ public DefaultHttpBinding() {
+ }
+
+ public DefaultHttpBinding(HeaderFilterStrategy headerFilterStrategy) {
+ this.headerFilterStrategy = headerFilterStrategy;
+ }
+
+ public void readRequest(HttpServletRequest request, HttpMessage message) {
+ // lets parser the parameterMap first to avoid consuming the POST parameters as InputStream
+ Map parameterMap = request.getParameterMap();
+
+ // lets force a parse of the body and headers
+ message.getBody();
+ // populate the headers from the request
+ Map<String, Object> headers = message.getHeaders();
+
+ String contentType = "";
+ //apply the headerFilterStrategy
+ Enumeration names = request.getHeaderNames();
+ while (names.hasMoreElements()) {
+ String name = (String)names.nextElement();
+ Object value = request.getHeader(name);
+ // mapping the content-type
+ if (name.toLowerCase().equals("content-type")) {
+ name = Exchange.CONTENT_TYPE;
+ contentType = (String) value;
+ }
+ if (headerFilterStrategy != null
+ && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) {
+ headers.put(name, value);
+ }
+ }
+
+ //we populate the http request parameters without checking the request method
+
+ names = request.getParameterNames();
+ while (names.hasMoreElements()) {
+ String name = (String)names.nextElement();
+ Object value = request.getParameter(name);
+ if (headerFilterStrategy != null
+ && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) {
+ headers.put(name, value);
+ }
+ }
+
+ // store the method and query and other info in headers
+ headers.put(Exchange.HTTP_METHOD, request.getMethod());
+ headers.put(Exchange.HTTP_QUERY, request.getQueryString());
+ headers.put(Exchange.HTTP_URL, request.getRequestURL());
+ headers.put(Exchange.HTTP_URI, request.getRequestURI());
+ headers.put(Exchange.HTTP_PATH, request.getPathInfo());
+ headers.put(Exchange.CONTENT_TYPE, request.getContentType());
+ headers.put(Exchange.HTTP_CHARACTER_ENCODING, request.getCharacterEncoding());
+ }
+
+ public void writeResponse(Exchange exchange, HttpServletResponse response) throws IOException {
+ if (exchange.isFailed()) {
+ if (exchange.getException() != null) {
+ doWriteExceptionResponse(exchange.getException(), response);
+ } else {
+ // it must be a fault, no need to check for the fault flag on the message
+ doWriteFaultResponse(exchange.getOut(), response, exchange);
+ }
+ } else {
+ // just copy the protocol relates header
+ copyProtocolHeaders(exchange.getIn(), exchange.getOut());
+ Message out = exchange.getOut();
+ if (out != null) {
+ doWriteResponse(out, response, exchange);
+ }
+ }
+ }
+
+ private void copyProtocolHeaders(Message request, Message response) {
+ if (request.getHeader(Exchange.CONTENT_ENCODING) != null) {
+ String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING, String.class);
+ response.setHeader(Exchange.CONTENT_ENCODING, contentEncoding);
+ }
+ }
+
+ public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException {
+ response.setStatus(500); // 500 for internal server error
+ response.setContentType("text/plain");
+
+ // append the stacktrace as response
+ PrintWriter pw = response.getWriter();
+ exception.printStackTrace(pw);
+
+ pw.flush();
+ }
+
+ public void doWriteFaultResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
+ doWriteResponse(message, response, exchange);
+ }
+
+ public void doWriteResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
+ // set the status code in the response. Default is 200.
+ if (message.getHeader(Exchange.HTTP_RESPONSE_CODE) != null) {
+ int code = message.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
+ response.setStatus(code);
+ }
+ // set the content type in the response.
+ String contentType = MessageHelper.getContentType(message);
+ if (MessageHelper.getContentType(message) != null) {
+ response.setContentType(contentType);
+ }
+
+ // append headers
+ for (String key : message.getHeaders().keySet()) {
+ String value = message.getHeader(key, String.class);
+ if (headerFilterStrategy != null
+ && !headerFilterStrategy.applyFilterToCamelHeaders(key, value, exchange)) {
+ response.setHeader(key, value);
+ }
+ }
+
+ // write the body.
+ if (message.getBody() != null) {
+ if (GZIPHelper.isGzip(message)) {
+ doWriteGZIPResponse(message, response, exchange);
+ } else {
+ doWriteDirectResponse(message, response, exchange);
+ }
+ }
+ }
+
+ protected void doWriteDirectResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
+ InputStream is = null;
+ if (checkChucked(message, exchange)) {
+ is = message.getBody(InputStream.class);
+ }
+ if (is != null) {
+ ServletOutputStream os = response.getOutputStream();
+ try {
+ // copy directly from input stream to output stream
+ IOHelper.copy(is, os);
+ } finally {
+ try {
+ os.close();
+ } catch (Exception e) {
+ // ignore, maybe client have disconnected or timed out
+ }
+ try {
+ is.close();
+ } catch (Exception e) {
+ // ignore, maybe client have disconnected or timed out
+ }
+ }
+ } else {
+ // not convertable as a stream so try as a String
+ String data = message.getBody(String.class);
+ if (data != null) {
+ // set content length before we write data
+ response.setContentLength(data.length());
+ response.getWriter().print(data);
+ response.getWriter().flush();
+ }
+ }
+ }
+
+ protected boolean checkChucked(Message message, Exchange exchange) {
+ boolean answer = true;
+ if (message.getHeader(Exchange.HTTP_CHUNKED) == null) {
+ // check the endpoint option
+ Endpoint endpoint = exchange.getFromEndpoint();
+ if (endpoint instanceof HttpEndpoint) {
+ answer = ((HttpEndpoint)endpoint).isChunked();
+ }
+ } else {
+ answer = message.getHeader(Exchange.HTTP_CHUNKED, boolean.class);
+ }
+ return answer;
+ }
+
+ protected void doWriteGZIPResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
+ byte[] bytes;
+ try {
+ bytes = message.getMandatoryBody(byte[].class);
+ } catch (InvalidPayloadException e) {
+ throw ObjectHelper.wrapRuntimeCamelException(e);
+ }
+
+ byte[] data = GZIPHelper.compressGZIP(bytes);
+ ServletOutputStream os = response.getOutputStream();
+ try {
+ response.setContentLength(data.length);
+ os.write(data);
+ os.flush();
+ } finally {
+ os.close();
+ }
+ }
+
+ public Object parseBody(HttpMessage httpMessage) throws IOException {
+ // lets assume the body is a reader
+ HttpServletRequest request = httpMessage.getRequest();
+ // Need to handle the GET Method which has no inputStream
+ if ("GET".equals(request.getMethod())) {
+ return null;
+ }
+ if (isUseReaderForPayload()) {
+ return request.getReader();
+ } else {
+ // otherwise use input stream
+ return HttpConverter.toInputStream(request);
+ }
+ }
+
+ public boolean isUseReaderForPayload() {
+ return useReaderForPayload;
+ }
+
+ public void setUseReaderForPayload(boolean useReaderForPayload) {
+ this.useReaderForPayload = useReaderForPayload;
+ }
+
+ public HeaderFilterStrategy getHeaderFilterStrategy() {
+ return headerFilterStrategy;
+ }
+
+ public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) {
+ this.headerFilterStrategy = headerFilterStrategy;
+ }
+
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,134 @@
+/**
+ * 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 java.io.IOException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.spi.HeaderFilterStrategy;
+
+/**
+ * A plugable strategy for configuring the http binding so reading request and writing response
+ * can be customized using the Java Servlet API.
+ * <p/>
+ * This is also used by the camel-jetty by the JettyHttpConsumer.
+ *
+ * @version $Revision$
+ */
+public interface HttpBinding {
+
+ /**
+ * Strategy to read the given request and bindings it to the given message.
+ *
+ * @param request the request
+ * @param message the message to populate with data from request
+ */
+ void readRequest(HttpServletRequest request, HttpMessage message);
+
+ /**
+ * Parses the body from a {@link org.apache.camel.component.http.HttpMessage}
+ *
+ * @param httpMessage the http message
+ * @return the parsed body returned as either a {@link java.io.InputStream} or a {@link java.io.Reader}
+ * depending on the {@link #setUseReaderForPayload(boolean)} property.
+ * @throws java.io.IOException can be thrown
+ */
+ Object parseBody(HttpMessage httpMessage) throws IOException;
+
+ /**
+ * Writes the exchange to the servlet response.
+ * <p/>
+ * Default implementation will delegate to the following methods depending on the status of the exchange
+ * <ul>
+ * <li>doWriteResponse - processing returns a OUT message </li>
+ * <li>doWriteFaultResponse - processing returns a fault message</li>
+ * <li>doWriteResponse - processing returns an exception and status code 500</li>
+ * </ul>
+ *
+ * @param exchange the exchange
+ * @param response the http response
+ * @throws java.io.IOException can be thrown from http response
+ */
+ void writeResponse(Exchange exchange, HttpServletResponse response) throws IOException;
+
+ /**
+ * Strategy method that writes the response to the http response stream when an exception occurred
+ *
+ * @param exception the exception occurred
+ * @param response the http response
+ * @throws java.io.IOException can be thrown from http response
+ */
+ void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException;
+
+ /**
+ * Strategy method that writes the response to the http response stream for a fault message
+ *
+ * @param message the fault message
+ * @param response the http response
+ * @param exchange the exchange to provide context for header filtering
+ * @throws java.io.IOException can be thrown from http response
+ */
+ void doWriteFaultResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException;
+
+ /**
+ * Strategy method that writes the response to the http response stream for an OUT message
+ *
+ * @param message the OUT message
+ * @param response the http response
+ * @param exchange the exchange to provide context for header filtering
+ * @throws java.io.IOException can be thrown from http response
+ */
+ void doWriteResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException;
+
+ /**
+ * Should reader by used instead of input stream.
+ *
+ * @see #setUseReaderForPayload(boolean) for more details
+ * @return <tt>true</tt> if reader should be used
+ */
+ boolean isUseReaderForPayload();
+
+ /**
+ * Should the {@link javax.servlet.http.HttpServletRequest#getReader()} be exposed as the payload of input messages in the Camel
+ * {@link org.apache.camel.Message#getBody()} or not. If false then the {@link javax.servlet.http.HttpServletRequest#getInputStream()} will be exposed.
+ * <p/>
+ * Is default <tt>false</tt>.
+ *
+ * @param useReaderForPayload whether to use reader or not
+ */
+ void setUseReaderForPayload(boolean useReaderForPayload);
+
+ /**
+ * Gets the header filter strategy
+ *
+ * @return the strategy
+ */
+ HeaderFilterStrategy getHeaderFilterStrategy();
+
+ /**
+ * Sets the header filter strategy to use.
+ * <p/>
+ * Will default use {@link org.apache.camel.component.http.HttpHeaderFilterStrategy}
+ *
+ * @param headerFilterStrategy the custom strategy
+ */
+ void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy);
+
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,34 @@
+/**
+ * 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.commons.httpclient.HttpClient;
+
+/**
+ * A plugable strategy for configuring the HttpClient used by this component
+ *
+ * @version $Revision$
+ */
+public interface HttpClientConfigurer {
+
+ /**
+ * Configure the HttpClient such as setting the authentication or proxying details
+ *
+ * @param client the client
+ */
+ void configureHttpClient(HttpClient client);
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: 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=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,186 @@
+/**
+ * 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 java.net.URI;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.impl.HeaderFilterStrategyComponent;
+import org.apache.camel.util.CastUtils;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.URISupport;
+import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.params.HttpClientParams;
+
+/**
+ * Defines the <a href="http://camel.apache.org/http.html">HTTP
+ * Component</a>
+ *
+ * @version $Revision$
+ */
+public class HttpComponent extends HeaderFilterStrategyComponent {
+ protected HttpClientConfigurer httpClientConfigurer;
+ protected HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
+ protected HttpBinding httpBinding;
+
+
+ /**
+ * Connects the URL specified on the endpoint to the specified processor.
+ *
+ * @param consumer the consumer
+ * @throws Exception can be thrown
+ */
+ public void connect(HttpConsumer consumer) throws Exception {
+ }
+
+ /**
+ * Disconnects the URL specified on the endpoint from the specified processor.
+ *
+ * @param consumer the consumer
+ * @throws Exception can be thrown
+ */
+ public void disconnect(HttpConsumer consumer) throws Exception {
+ }
+
+ /**
+ * Setting http binding and http client configurer according to the parameters
+ * Also setting the BasicAuthenticationHttpClientConfigurer if the username
+ * and password option are not null.
+ *
+ * @param parameters the map of parameters
+ */
+ protected void configureParameters(Map<String, Object> parameters) {
+ // lookup http binding in registry if provided
+ httpBinding = resolveAndRemoveReferenceParameter(
+ parameters, "httpBindingRef", HttpBinding.class);
+
+ // lookup http client front configurer in the registry if provided
+ httpClientConfigurer = resolveAndRemoveReferenceParameter(
+ parameters, "httpClientConfigurerRef", HttpClientConfigurer.class);
+
+ // check the user name and password for basic authentication
+ String username = getAndRemoveParameter(parameters, "username", String.class);
+ String password = getAndRemoveParameter(parameters, "password", String.class);
+ String domain = getAndRemoveParameter(parameters, "domain", String.class);
+ String host = getAndRemoveParameter(parameters, "host", String.class);
+ if (username != null && password != null) {
+ httpClientConfigurer = CompositeHttpConfigurer.combineConfigurers(
+ httpClientConfigurer,
+ new BasicAuthenticationHttpClientConfigurer(username, password, domain, host));
+ }
+
+ // check the proxy details for proxy configuration
+ String proxyHost = getAndRemoveParameter(parameters, "proxyHost", String.class);
+ Integer proxyPort = getAndRemoveParameter(parameters, "proxyPort", Integer.class);
+ if (proxyHost != null && proxyPort != null) {
+ String proxyUsername = getAndRemoveParameter(parameters, "proxyUsername", String.class);
+ String proxyPassword = getAndRemoveParameter(parameters, "proxyPassword", String.class);
+ String proxyDomain = getAndRemoveParameter(parameters, "proxyDomain", String.class);
+ String proxyNtHost = getAndRemoveParameter(parameters, "proxyNtHost", String.class);
+ if (proxyUsername != null && proxyPassword != null) {
+ httpClientConfigurer = CompositeHttpConfigurer.combineConfigurers(
+ httpClientConfigurer, new ProxyHttpClientConfigurer(proxyHost, proxyPort, proxyUsername, proxyPassword, proxyDomain, proxyNtHost));
+ } else {
+ httpClientConfigurer = CompositeHttpConfigurer.combineConfigurers(
+ httpClientConfigurer, new ProxyHttpClientConfigurer(proxyHost, proxyPort));
+ }
+ }
+
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+
+ // http client can be configured from URI options
+ HttpClientParams clientParams = new HttpClientParams();
+ IntrospectionSupport.setProperties(clientParams, parameters, "httpClient.");
+ // validate that we could resolve all httpClient. parameters as this component is lenient
+ validateParameters(uri, parameters, "httpClient.");
+
+ configureParameters(parameters);
+
+ // should we use an exception for failed error codes?
+ Boolean throwExceptionOnFailure = getAndRemoveParameter(parameters, "throwExceptionOnFailure", Boolean.class);
+
+ Boolean bridgeEndpoint = getAndRemoveParameter(parameters, "bridgeEndpoint", Boolean.class);
+
+ Boolean matchOnUriPrefix = Boolean.parseBoolean(getAndRemoveParameter(parameters, "matchOnUriPrefix", String.class));
+ // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
+ URI httpUri = URISupport.createRemainingURI(new URI(uri), CastUtils.cast(parameters));
+ uri = httpUri.toString();
+
+ // validate http uri that end-user did not duplicate the http part that can be a common error
+ String part = httpUri.getSchemeSpecificPart();
+ if (part != null) {
+ part = part.toLowerCase();
+ if (part.startsWith("//http//") || part.startsWith("//https//")) {
+ throw new ResolveEndpointFailedException(uri,
+ "The uri part is not configured correctly. You have duplicated the http(s) protocol.");
+ }
+ }
+
+ HttpEndpoint endpoint = new HttpEndpoint(uri, this, httpUri, clientParams, httpConnectionManager, httpClientConfigurer);
+ if (httpBinding != null) {
+ endpoint.setBinding(httpBinding);
+ }
+ setEndpointHeaderFilterStrategy(endpoint);
+ if (throwExceptionOnFailure != null) {
+ endpoint.setThrowExceptionOnFailure(throwExceptionOnFailure);
+ }
+ if (bridgeEndpoint != null) {
+ endpoint.setBridgeEndpoint(bridgeEndpoint);
+ }
+ if (matchOnUriPrefix != null) {
+ endpoint.setMatchOnUriPrefix(matchOnUriPrefix);
+ }
+ setProperties(endpoint, parameters);
+ return endpoint;
+ }
+
+ @Override
+ protected boolean useIntrospectionOnEndpoint() {
+ return false;
+ }
+
+ public HttpClientConfigurer getHttpClientConfigurer() {
+ return httpClientConfigurer;
+ }
+
+ public void setHttpClientConfigurer(HttpClientConfigurer httpClientConfigurer) {
+ this.httpClientConfigurer = httpClientConfigurer;
+ }
+
+ public HttpConnectionManager getHttpConnectionManager() {
+ return httpConnectionManager;
+ }
+
+ public void setHttpConnectionManager(HttpConnectionManager httpConnectionManager) {
+ this.httpConnectionManager = httpConnectionManager;
+ }
+
+ public HttpBinding getHttpBinding() {
+ return httpBinding;
+ }
+
+ public void setHttpBinding(HttpBinding httpBinding) {
+ this.httpBinding = httpBinding;
+ }
+
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,58 @@
+/**
+ * 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.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+
+/**
+ * @version $Revision$
+ */
+public class HttpConsumer extends DefaultConsumer {
+
+ private final HttpEndpoint endpoint;
+
+ public HttpConsumer(HttpEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ this.endpoint = endpoint;
+ }
+
+ @Override
+ public HttpEndpoint getEndpoint() {
+ return (HttpEndpoint)super.getEndpoint();
+ }
+
+ public HttpBinding getBinding() {
+ return endpoint.getBinding();
+ }
+
+ public String getPath() {
+ return endpoint.getPath();
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ endpoint.connect(this);
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ endpoint.disconnect(this);
+ super.doStop();
+ }
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,94 @@
+/**
+ * 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 java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.http.helper.GZIPHelper;
+
+/**
+ * Some converter methods making it easy to convert the body of a message to servlet types or to switch between
+ * the underlying {@link ServletInputStream} or {@link BufferedReader} payloads etc.
+ *
+ * @version $Revision$
+ */
+@Converter
+public final class HttpConverter {
+
+ private HttpConverter() {
+ }
+
+ @Converter
+ public static HttpServletRequest toServletRequest(Message message) {
+ if (message == null) {
+ return null;
+ }
+ return message.getHeader(Exchange.HTTP_SERVLET_REQUEST, HttpServletRequest.class);
+ }
+
+ @Converter
+ public static HttpServletResponse toServletResponse(Message message) {
+ if (message == null) {
+ return null;
+ }
+ return message.getHeader(Exchange.HTTP_SERVLET_RESPONSE, HttpServletResponse.class);
+ }
+
+
+
+ @Converter
+ public static ServletInputStream toServletInputStream(HttpMessage message) throws IOException {
+ HttpServletRequest request = toServletRequest(message);
+ if (request != null) {
+ return request.getInputStream();
+ }
+ return null;
+ }
+
+ @Converter
+ public static InputStream toInputStream(HttpMessage message) throws Exception {
+ return toInputStream(toServletRequest(message));
+ }
+
+ @Converter
+ public static BufferedReader toReader(HttpMessage message) throws IOException {
+ HttpServletRequest request = toServletRequest(message);
+ if (request != null) {
+ return request.getReader();
+ }
+ return null;
+ }
+
+ @Converter
+ public static InputStream toInputStream(HttpServletRequest request) throws IOException {
+ if (request == null) {
+ return null;
+ }
+ String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING);
+ return GZIPHelper.toGZIPInputStream(contentEncoding, request.getInputStream());
+ }
+
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: 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=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,246 @@
+/**
+ * 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 java.net.URI;
+import java.net.URISyntaxException;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultPollingEndpoint;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.spi.HeaderFilterStrategyAware;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.params.HttpClientParams;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Represents a <a href="http://camel.apache.org/http.html">HTTP endpoint</a>
+ *
+ * @version $Revision$
+ */
+public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilterStrategyAware {
+
+ private static final transient Log LOG = LogFactory.getLog(HttpEndpoint.class);
+ private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
+ private HttpBinding binding;
+ private HttpComponent component;
+ private URI httpUri;
+ private HttpClientParams clientParams;
+ private HttpClientConfigurer httpClientConfigurer;
+ private HttpConnectionManager httpConnectionManager;
+ private boolean throwExceptionOnFailure = true;
+ private boolean bridgeEndpoint;
+ private boolean matchOnUriPrefix;
+ private boolean chunked = true;
+
+ public HttpEndpoint() {
+ }
+
+ public HttpEndpoint(String endPointURI, HttpComponent component, URI httpURI) throws URISyntaxException {
+ this(endPointURI, component, httpURI, null);
+ }
+
+ public HttpEndpoint(String endPointURI, HttpComponent component, URI httpURI, HttpConnectionManager httpConnectionManager) throws URISyntaxException {
+ this(endPointURI, component, httpURI, new HttpClientParams(), httpConnectionManager, null);
+ }
+
+ public HttpEndpoint(String endPointURI, HttpComponent component, URI httpURI, HttpClientParams clientParams,
+ HttpConnectionManager httpConnectionManager, HttpClientConfigurer clientConfigurer) throws URISyntaxException {
+ super(endPointURI, component);
+ this.component = component;
+ this.httpUri = httpURI;
+ this.clientParams = clientParams;
+ this.httpClientConfigurer = clientConfigurer;
+ this.httpConnectionManager = httpConnectionManager;
+ }
+
+ public Producer createProducer() throws Exception {
+ return new HttpProducer(this);
+ }
+
+ public PollingConsumer createPollingConsumer() throws Exception {
+ return new HttpPollingConsumer(this);
+ }
+
+ /**
+ * 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());
+
+ // configure http proxy from camelContext
+ if (ObjectHelper.isNotEmpty(getCamelContext().getProperties().get("http.proxyHost")) && ObjectHelper.isNotEmpty(getCamelContext().getProperties().get("http.proxyPort"))) {
+ String host = getCamelContext().getProperties().get("http.proxyHost");
+ int port = Integer.parseInt(getCamelContext().getProperties().get("http.proxyPort"));
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("CamelContext properties http.proxyHost and http.proxyPort detected. Using http proxy host: "
+ + host + " port: " + port);
+ }
+ answer.getHostConfiguration().setProxy(host, port);
+ }
+
+ answer.setHttpConnectionManager(httpConnectionManager);
+ HttpClientConfigurer configurer = getHttpClientConfigurer();
+ if (configurer != null) {
+ configurer.configureHttpClient(answer);
+ }
+ return answer;
+ }
+
+ public void connect(HttpConsumer consumer) throws Exception {
+ component.connect(consumer);
+ }
+
+ public void disconnect(HttpConsumer consumer) throws Exception {
+ component.disconnect(consumer);
+ }
+
+ public boolean isLenientProperties() {
+ // true to allow dynamic URI options to be configured and passed to external system for eg. the HttpProducer
+ 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.
+ */
+ public HttpClientParams getClientParams() {
+ return clientParams;
+ }
+
+ /**
+ * Provide access to the client parameters used on new {@link HttpClient} instances
+ * used by producers or consumers of this endpoint.
+ */
+ public void setClientParams(HttpClientParams clientParams) {
+ this.clientParams = clientParams;
+ }
+
+ public HttpClientConfigurer getHttpClientConfigurer() {
+ return httpClientConfigurer;
+ }
+
+ /**
+ * Register a custom configuration strategy for new {@link HttpClient} instances
+ * created by producers or consumers such as to configure authentication mechanisms etc
+ *
+ * @param httpClientConfigurer the strategy for configuring new {@link HttpClient} instances
+ */
+ public void setHttpClientConfigurer(HttpClientConfigurer httpClientConfigurer) {
+ this.httpClientConfigurer = httpClientConfigurer;
+ }
+
+ public HttpBinding getBinding() {
+ if (binding == null) {
+ binding = new DefaultHttpBinding(getHeaderFilterStrategy());
+ }
+ return binding;
+ }
+
+ public void setBinding(HttpBinding binding) {
+ this.binding = binding;
+ }
+
+ public String getPath() {
+ return httpUri.getPath();
+ }
+
+ public int getPort() {
+ if (httpUri.getPort() == -1) {
+ if ("https".equals(getProtocol())) {
+ return 443;
+ } else {
+ return 80;
+ }
+ }
+ return httpUri.getPort();
+ }
+
+ public String getProtocol() {
+ return httpUri.getScheme();
+ }
+
+ 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;
+ }
+
+ public boolean isThrowExceptionOnFailure() {
+ return throwExceptionOnFailure;
+ }
+
+ public void setThrowExceptionOnFailure(boolean throwExceptionOnFailure) {
+ this.throwExceptionOnFailure = throwExceptionOnFailure;
+ }
+
+ public boolean isBridgeEndpoint() {
+ return bridgeEndpoint;
+ }
+
+ public void setBridgeEndpoint(boolean bridge) {
+ this.bridgeEndpoint = bridge;
+ }
+
+ public boolean isMatchOnUriPrefix() {
+ return matchOnUriPrefix;
+ }
+
+ public void setMatchOnUriPrefix(boolean match) {
+ this.matchOnUriPrefix = match;
+ }
+
+ public boolean isChunked() {
+ return this.chunked;
+ }
+
+ public void setChunked(boolean chunked) {
+ this.chunked = chunked;
+ }
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,51 @@
+/**
+ * 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.impl.DefaultHeaderFilterStrategy;
+
+/**
+ * @version $Revision$
+ */
+public class HttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
+
+ public HttpHeaderFilterStrategy() {
+ initialize();
+ }
+
+ protected void initialize() {
+ getOutFilter().add("content-length");
+ getOutFilter().add("content-type");
+ // Add the filter for the Generic Message header
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
+ getOutFilter().add("cache-control");
+ getOutFilter().add("connection");
+ getOutFilter().add("date");
+ getOutFilter().add("pragma");
+ getOutFilter().add("trailer");
+ getOutFilter().add("transfer-encoding");
+ getOutFilter().add("upgrade");
+ getOutFilter().add("via");
+ getOutFilter().add("warning");
+
+ setLowerCase(true);
+
+ // filter headers begin with "Camel" or "org.apache.camel"
+ // must ignore case for Http based transports
+ setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+ }
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java Sat Apr 10 10:49:33 2010
@@ -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.http;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.DefaultMessage;
+
+/**
+ * @version $Revision$
+ */
+public class HttpMessage extends DefaultMessage {
+
+ private HttpServletRequest request;
+ private HttpServletResponse response;
+
+ public HttpMessage(Exchange exchange, HttpServletRequest request, HttpServletResponse response) {
+ setExchange(exchange);
+ this.request = request;
+ this.response = response;
+ // Put the request and response into the message header
+ this.setHeader(Exchange.HTTP_SERVLET_REQUEST, request);
+ this.setHeader(Exchange.HTTP_SERVLET_RESPONSE, response);
+
+ // use binding to read the request allowing end users to use their
+ // implementation of the binding
+ getEndpoint().getBinding().readRequest(request, this);
+ }
+
+ public HttpServletRequest getRequest() {
+ return request;
+ }
+
+ public HttpServletResponse getResponse() {
+ return response;
+ }
+
+ @Override
+ protected Object createBody() {
+ try {
+ return getEndpoint().getBinding().parseBody(this);
+ } catch (IOException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
+
+ private HttpEndpoint getEndpoint() {
+ return (HttpEndpoint) getExchange().getFromEndpoint();
+ }
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,61 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.methods.OptionsMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.TraceMethod;
+
+public enum HttpMethods implements Expression {
+
+ GET(GetMethod.class), POST(PostMethod.class), PUT(PutMethod.class), DELETE(DeleteMethod.class), HEAD(
+ HeadMethod.class), OPTIONS(OptionsMethod.class), TRACE(TraceMethod.class);
+
+ final Class<? extends HttpMethod> clazz;
+ final boolean entity;
+
+ HttpMethods(Class<? extends HttpMethod> clazz) {
+ this.clazz = clazz;
+ entity = EntityEnclosingMethod.class.isAssignableFrom(clazz);
+ }
+
+ public HttpMethod createMethod(String url) {
+ try {
+ return clazz.getDeclaredConstructor(String.class).newInstance(url);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public final boolean isEntityEnclosing() {
+ return entity;
+ }
+
+ public <T> T evaluate(Exchange exchange, Class<T> type) {
+ return ExpressionBuilder.constantExpression(name()).evaluate(exchange, type);
+ }
+
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMethods.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,75 @@
+/**
+ * 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 java.util.Map;
+
+import org.apache.camel.CamelException;
+import org.apache.camel.util.ObjectHelper;
+
+public class HttpOperationFailedException extends CamelException {
+ private static final long serialVersionUID = -8721487434390572634L;
+ private final String uri;
+ private final String redirectLocation;
+ private final int statusCode;
+ private final String statusText;
+ private final Map<String, String> responseHeaders;
+ private final String responseBody;
+
+ public HttpOperationFailedException(String uri, int statusCode, String statusText, String location, Map<String, String> responseHeaders, String responseBody) {
+ super("HTTP operation failed invoking " + uri + " with statusCode: " + statusCode + (location != null ? ", redirectLocation: " + location : ""));
+ this.uri = uri;
+ this.statusCode = statusCode;
+ this.statusText = statusText;
+ this.redirectLocation = location;
+ this.responseHeaders = responseHeaders;
+ this.responseBody = responseBody;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ public boolean isRedirectError() {
+ return statusCode >= 300 && statusCode < 400;
+ }
+
+ public boolean hasRedirectLocation() {
+ return ObjectHelper.isNotEmpty(redirectLocation);
+ }
+
+ public String getRedirectLocation() {
+ return redirectLocation;
+ }
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ public String getStatusText() {
+ return statusText;
+ }
+
+ public Map<String, String> getResponseHeaders() {
+ return responseHeaders;
+ }
+
+ public String getResponseBody() {
+ return responseBody;
+ }
+
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java?rev=932690&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java Sat Apr 10 10:49:33 2010
@@ -0,0 +1,127 @@
+/**
+ * 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 java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.http.helper.LoadingByteArrayOutputStream;
+import org.apache.camel.impl.PollingConsumerSupport;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+/**
+ * A polling HTTP consumer which by default performs a GET
+ *
+ * @version $Revision$
+ */
+public class HttpPollingConsumer extends PollingConsumerSupport {
+ private final HttpEndpoint endpoint;
+ private HttpClient httpClient;
+
+ public HttpPollingConsumer(HttpEndpoint endpoint) {
+ super(endpoint);
+ this.endpoint = endpoint;
+ httpClient = endpoint.createHttpClient();
+ }
+
+ public Exchange receive() {
+ return doReceive(-1);
+ }
+
+ public Exchange receive(long timeout) {
+ return doReceive((int) timeout);
+ }
+
+ public Exchange receiveNoWait() {
+ return doReceive(-1);
+ }
+
+ protected Exchange doReceive(int timeout) {
+ Exchange exchange = endpoint.createExchange();
+ HttpMethod method = createMethod();
+
+ // set optional timeout in millis
+ if (timeout > 0) {
+ method.getParams().setSoTimeout(timeout);
+ }
+
+ try {
+ int responseCode = httpClient.executeMethod(method);
+ // lets store the result in the output message.
+ LoadingByteArrayOutputStream bos = new LoadingByteArrayOutputStream();
+ InputStream is = method.getResponseBodyAsStream();
+ try {
+ IOHelper.copy(is, bos);
+ bos.flush();
+ } finally {
+ ObjectHelper.close(is, "input stream", null);
+ }
+ Message message = exchange.getIn();
+ message.setBody(bos.createInputStream());
+
+ // lets set the headers
+ Header[] headers = method.getResponseHeaders();
+ HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy();
+ for (Header header : headers) {
+ String name = header.getName();
+ String value = header.getValue();
+ if (strategy != null && !strategy.applyFilterToExternalHeaders(name, value, exchange)) {
+ message.setHeader(name, value);
+ }
+ }
+
+ message.setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode);
+ return exchange;
+ } catch (IOException e) {
+ throw new RuntimeCamelException(e);
+ } finally {
+ method.releaseConnection();
+ }
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public HttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ public void setHttpClient(HttpClient httpClient) {
+ this.httpClient = httpClient;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected HttpMethod createMethod() {
+ String uri = endpoint.getEndpointUri();
+ return new GetMethod(uri);
+ }
+
+ protected void doStart() throws Exception {
+ }
+
+ protected void doStop() throws Exception {
+ }
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date