Author: davsclaus
Date: Fri Nov 21 10:59:05 2008
New Revision: 719673
URL: http://svn.apache.org/viewvc?rev=719673&view=rev
Log:
Merged revisions 719662 via svnmerge from
https://svn.apache.org/repos/asf/activemq/camel/trunk
........
r719662 | davsclaus | 2008-11-21 19:09:17 +0100 (fr, 21 nov 2008) | 7 lines
CAMEL-1107, CAMEL-1083, CAMEL-1095, CAMEL-1093: Major improvements to
camel-jetty and camel-http.
camel-jetty: Now properly returns fault and exception
camel-http: repsonse body is avaiable on HttpOperationFailedException
camel-jetty: introduce HttpBinding as interface and to be referenced in
Registry for end users to customize how response should be written
camel-jetty: now returns content-type and content-length if possible to
calculate
both: minor URI parsing so internal Camel options is not exposed
........
Added:
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
- copied unchanged from r719662,
activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
- copied unchanged from r719662,
activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
activemq/camel/branches/camel-1.x/components/camel-jetty/src/test/data/
- copied from r719662,
activemq/camel/trunk/components/camel-jetty/src/test/data/
activemq/camel/branches/camel-1.x/components/camel-jetty/src/test/data/logo.jpeg
- copied unchanged from r719662,
activemq/camel/trunk/components/camel-jetty/src/test/data/logo.jpeg
activemq/camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
- copied unchanged from r719662,
activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
activemq/camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBindingRefTest.java
- copied unchanged from r719662,
activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBindingRefTest.java
activemq/camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java
- copied unchanged from r719662,
activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java
activemq/camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java
- copied unchanged from r719662,
activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java
activemq/camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java
- copied unchanged from r719662,
activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java
Modified:
activemq/camel/branches/camel-1.x/ (props changed)
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
activemq/camel/branches/camel-1.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Nov 21 10:59:05 2008
@@ -1 +1 @@
-/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524
+/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662
Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
URL:
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?rev=719673&r1=719672&r2=719673&view=diff
==============================================================================
---
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
(original)
+++
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
Fri Nov 21 10:59:05 2008
@@ -24,7 +24,9 @@
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;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.params.HttpClientParams;
@@ -36,10 +38,10 @@
* @version $Revision$
*/
public class HttpComponent extends DefaultComponent<HttpExchange> implements
HeaderFilterStrategyAware {
-
- private HttpClientConfigurer httpClientConfigurer;
- private HttpConnectionManager httpConnectionManager = new
MultiThreadedHttpConnectionManager();
- private HeaderFilterStrategy headerFilterStrategy;
+ protected HttpClientConfigurer httpClientConfigurer;
+ protected HttpConnectionManager httpConnectionManager = new
MultiThreadedHttpConnectionManager();
+ protected HeaderFilterStrategy headerFilterStrategy;
+ protected HttpBinding httpBinding;
public HttpComponent() {
this.setHeaderFilterStrategy(new HttpHeaderFilterStrategy());
@@ -47,51 +49,55 @@
/**
* 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.
+ * 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 {
}
- 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;
- }
-
@Override
protected Endpoint<HttpExchange> createEndpoint(String uri, String
remaining, Map parameters)
throws Exception {
+
+ // http client can be configured from URI options
HttpClientParams params = new HttpClientParams();
IntrospectionSupport.setProperties(params, parameters, "httpClient.");
+ // lookup http binding in registry if provided
+ String ref = getAndRemoveParameter(parameters, "httpBindingRef",
String.class);
+ if (ref != null) {
+ httpBinding =
CamelContextHelper.mandatoryLookup(getCamelContext(), ref, HttpBinding.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), parameters);
+ uri = httpUri.toString();
+
// validate http uri that end-user did not duplicate the http part
that can be a common error
- URI httpUri = new URI(uri);
String part = httpUri.getSchemeSpecificPart();
if (part != null) {
part = part.toLowerCase();
- if (part.startsWith("//http://") || part.startsWith("//https://"))
{
+ 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.");
+ "The uri part is not configured correctly. You have
duplicated the http(s) protocol.");
}
}
- return new HttpEndpoint(uri, this, httpUri, params,
httpConnectionManager, httpClientConfigurer);
+ HttpEndpoint endpoint = new HttpEndpoint(uri, this, httpUri, params,
httpConnectionManager, httpClientConfigurer);
+ if (httpBinding != null) {
+ endpoint.setBinding(httpBinding);
+ }
+ return endpoint;
}
@Override
@@ -99,6 +105,22 @@
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 HeaderFilterStrategy getHeaderFilterStrategy() {
return headerFilterStrategy;
}
@@ -106,4 +128,12 @@
public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
headerFilterStrategy = strategy;
}
+
+ public HttpBinding getHttpBinding() {
+ return httpBinding;
+ }
+
+ public void setHttpBinding(HttpBinding httpBinding) {
+ this.httpBinding = httpBinding;
+ }
}
Modified:
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?rev=719673&r1=719672&r2=719673&view=diff
==============================================================================
---
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
(original)
+++
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
Fri Nov 21 10:59:05 2008
@@ -140,7 +140,7 @@
public HttpBinding getBinding() {
if (binding == null) {
- binding = new HttpBinding(getHeaderFilterStrategy());
+ binding = new DefaultHttpBinding(getHeaderFilterStrategy());
}
return binding;
}
Modified:
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
URL:
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java?rev=719673&r1=719672&r2=719673&view=diff
==============================================================================
---
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
(original)
+++
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
Fri Nov 21 10:59:05 2008
@@ -35,9 +35,9 @@
setExchange(exchange);
this.request = request;
- // lets force a parse of the body and headers
- getBody();
- getHeaders();
+ // use binding to read the request allowing end users to use their
+ // implementation of the binding
+ getExchange().getEndpoint().getBinding().readRequest(request, this);
}
@Override
Modified:
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
URL:
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java?rev=719673&r1=719672&r2=719673&view=diff
==============================================================================
---
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
(original)
+++
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpOperationFailedException.java
Fri Nov 21 10:59:05 2008
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.http;
+import java.io.InputStream;
+
import org.apache.camel.CamelException;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.httpclient.StatusLine;
@@ -24,6 +26,7 @@
private final String redirectLocation;
private final int statusCode;
private final StatusLine statusLine;
+ private InputStream responseBody;
public HttpOperationFailedException(int statusCode, StatusLine statusLine,
String location) {
super("HTTP operation failed with statusCode: " + statusCode + ",
status: " + statusLine + (location != null ? ", redirectLocation: " + location
: ""));
@@ -56,4 +59,11 @@
return statusCode;
}
+ public InputStream getResponseBody() {
+ return responseBody;
+ }
+
+ public void setResponseBody(InputStream responseBody) {
+ this.responseBody = responseBody;
+ }
}
\ No newline at end of file
Modified:
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL:
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=719673&r1=719672&r2=719673&view=diff
==============================================================================
---
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
(original)
+++
activemq/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
Fri Nov 21 10:59:05 2008
@@ -43,6 +43,7 @@
import org.apache.commons.logging.LogFactory;
import static org.apache.camel.component.http.HttpMethods.HTTP_METHOD;
+
/**
* @version $Revision$
*/
@@ -103,18 +104,26 @@
}
} else {
HttpOperationFailedException exception = null;
- if (responseCode < 400 && responseCode >= 300) {
+ if (responseCode >= 300 && responseCode < 400) {
String redirectLocation;
Header locationHeader =
method.getResponseHeader("location");
if (locationHeader != null) {
redirectLocation = locationHeader.getValue();
exception = new
HttpOperationFailedException(responseCode, method.getStatusLine(),
redirectLocation);
+ } else {
+ // no redirect location
+ exception = new
HttpOperationFailedException(responseCode, method.getStatusLine());
}
} else {
+ // internal server error (error code 500)
exception = new HttpOperationFailedException(responseCode,
method.getStatusLine());
}
- throw exception;
+ if (exception != null) {
+ // set also the response body as well
+ exception.setResponseBody(extractResponseBody(method));
+ throw exception;
+ }
}
} finally {
@@ -122,14 +131,6 @@
}
}
- public HttpClient getHttpClient() {
- return httpClient;
- }
-
- public void setHttpClient(HttpClient httpClient) {
- this.httpClient = httpClient;
- }
-
/**
* Strategy when executing the method (calling the remote server).
*
@@ -141,12 +142,23 @@
return httpClient.executeMethod(method);
}
+ /**
+ * Extracts the response from the method as a InputStream.
+ *
+ * @param method the method that was executed
+ * @return the response as a stream
+ * @throws IOException can be thrown
+ */
protected static InputStream extractResponseBody(HttpMethod method) throws
IOException {
LoadingByteArrayOutputStream bos = null;
InputStream is = null;
try {
bos = new LoadingByteArrayOutputStream();
is = method.getResponseBodyAsStream();
+ // in case of no response stream
+ if (is == null) {
+ return null;
+ }
IOUtils.copy(is, bos);
bos.flush();
return bos.createInputStream();
@@ -156,6 +168,12 @@
}
}
+ /**
+ * Creates the HttpMethod to use to call the remote server, either its GET
or POST.
+ *
+ * @param exchange the exchange
+ * @return the created method as either GET or POST
+ */
protected HttpMethod createMethod(Exchange exchange) {
// is a query string provided in the endpoint URI or in a header
(header overrules endpoint)
String queryString = exchange.getIn().getHeader(QUERY, String.class);
@@ -182,7 +200,7 @@
if (uri == null) {
uri = ((HttpEndpoint)getEndpoint()).getHttpUri().toString();
}
-
+
HttpMethod method = methodToUse.createMethod(uri);
if (queryString != null) {
@@ -195,6 +213,12 @@
return method;
}
+ /**
+ * Creates a holder object for the data to send to the remote server.
+ *
+ * @param exchange the exchange with the IN message with data to send
+ * @return the data holder
+ */
protected RequestEntity createRequestEntity(Exchange exchange) {
Message in = exchange.getIn();
if (in.getBody() == null) {
@@ -219,4 +243,12 @@
}
}
+ public HttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ public void setHttpClient(HttpClient httpClient) {
+ this.httpClient = httpClient;
+ }
+
}
Modified:
activemq/camel/branches/camel-1.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
URL:
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=719673&r1=719672&r2=719673&view=diff
==============================================================================
---
activemq/camel/branches/camel-1.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
(original)
+++
activemq/camel/branches/camel-1.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
Fri Nov 21 10:59:05 2008
@@ -22,10 +22,14 @@
import org.apache.camel.Endpoint;
import org.apache.camel.component.http.CamelServlet;
+import org.apache.camel.component.http.HttpBinding;
import org.apache.camel.component.http.HttpComponent;
import org.apache.camel.component.http.HttpConsumer;
import org.apache.camel.component.http.HttpEndpoint;
import org.apache.camel.component.http.HttpExchange;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.URISupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mortbay.jetty.Connector;
@@ -68,20 +72,40 @@
}
}
- private static final Log LOGGER =
LogFactory.getLog(JettyHttpComponent.class);
+ private static final transient Log LOG =
LogFactory.getLog(JettyHttpComponent.class);
- private Server server;
- private HashMap<String, ConnectorRef> connectors = new HashMap<String,
ConnectorRef>();
- private HttpClient httpClient;
- private String sslKeyPassword;
- private String sslPassword;
- private String sslKeystore;
- private SslSocketConnector sslSocketConnector;
+ protected Server server;
+ protected HashMap<String, ConnectorRef> connectors = new HashMap<String,
ConnectorRef>();
+ protected HttpClient httpClient;
+ protected String sslKeyPassword;
+ protected String sslPassword;
+ protected String sslKeystore;
+ protected SslSocketConnector sslSocketConnector;
@Override
protected Endpoint<HttpExchange> createEndpoint(String uri, String
remaining, Map parameters) throws Exception {
- URI httpURL = uri.startsWith("jetty:") ? new URI(remaining) : new
URI(uri);
- JettyHttpEndpoint result = new JettyHttpEndpoint(this, uri, httpURL,
getHttpConnectionManager());
+ uri = uri.startsWith("jetty:") ? remaining : uri;
+
+ // http client can be configured from URI options
+ if (httpClient == null) {
+ httpClient = createHttpClient();
+ }
+ IntrospectionSupport.setProperties(httpClient, parameters,
"httpClient.");
+
+ // lookup http binding in registry if provided
+ String ref = getAndRemoveParameter(parameters, "httpBindingRef",
String.class);
+ if (ref != null) {
+ httpBinding =
CamelContextHelper.mandatoryLookup(getCamelContext(), ref, HttpBinding.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), parameters);
+ uri = httpUri.toString();
+
+ JettyHttpEndpoint result = new JettyHttpEndpoint(this, uri, httpUri,
getHttpConnectionManager());
+ if (httpBinding != null) {
+ result.setBinding(httpBinding);
+ }
setProperties(result, parameters);
return result;
}
@@ -93,7 +117,6 @@
*/
@Override
public void connect(HttpConsumer consumer) throws Exception {
-
// Make sure that there is a connector for the requested endpoint.
JettyHttpEndpoint endpoint = (JettyHttpEndpoint)consumer.getEndpoint();
String connectorKey = endpoint.getProtocol() + ":" +
endpoint.getHttpUri().getHost() + ":" + endpoint.getPort();
@@ -110,7 +133,7 @@
connector.setPort(endpoint.getPort());
connector.setHost(endpoint.getHttpUri().getHost());
if
("localhost".equalsIgnoreCase(endpoint.getHttpUri().getHost())) {
- LOGGER.warn("You use localhost interface! It means that no
external connections will be available. Don't you want to use 0.0.0.0 instead
(all network interfaces)?");
+ LOG.warn("You use localhost interface! It means that no
external connections will be available. Don't you want to use 0.0.0.0 instead
(all network interfaces)?");
}
getServer().addConnector(connector);