Author: davsclaus
Date: Fri Nov 6 15:08:20 2009
New Revision: 833429
URL:
http://svn.apache.org/viewvc?rev=833429&view=revLog:
CAMEL-2135: Added new jetty client as http producer as it supports async req/rep. However HTTP Client 4.0 is probably the best one. We will upgrade to this later as well. Work in progress.
Added:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java (with props)
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java (with props)
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyFutureGetBody.java (with props)
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpMessage.java (with props)
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpOperationFailedException.java (with props)
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java (with props)
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGoogleTest.java (with props)
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerHeaderBasedCBRTestTest.java (with props)
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java (with props)
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java (with props)
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java (with props)
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
camel/trunk/components/camel-jetty/pom.xml
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGetTest.java
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
Modified: 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=833429&r1=833428&r2=833429&view=diff==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java Fri Nov 6 15:08:20 2009
@@ -28,14 +28,14 @@
* 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 used by the camel-jetty.
+ * This is also used by the camel-jetty by the JettyHttpConsumer.
*
* @version $Revision$
*/
public interface HttpBinding {
/**
- * Startegy to read the given request and bindings it to the given message.
+ * 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
@@ -45,6 +45,7 @@
/**
* 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
@@ -96,20 +97,37 @@
*/
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 stratety to use.
+ * 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);
Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?rev=833429&r1=833428&r2=833429&view=diff==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java Fri Nov 6 15:08:20 2009
@@ -58,6 +58,10 @@
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);
}
Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=833429&r1=833428&r2=833429&view=diff==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java Fri Nov 6 15:08:20 2009
@@ -20,12 +20,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
-import java.net.URI;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.http.helper.GZIPHelper;
+import org.apache.camel.component.http.helper.HttpProducerHelper;
import org.apache.camel.converter.stream.CachedOutputStream;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.spi.HeaderFilterStrategy;
@@ -58,7 +58,7 @@
public void process(Exchange exchange) throws Exception {
HttpMethod method = createMethod(exchange);
Message in = exchange.getIn();
- HeaderFilterStrategy strategy = ((HttpEndpoint)getEndpoint()).getHeaderFilterStrategy();
+ HeaderFilterStrategy strategy = getEndpoint().getHeaderFilterStrategy();
// propagate headers as HTTP headers
for (String headerName : in.getHeaders().keySet()) {
@@ -95,6 +95,11 @@
}
}
+ @Override
+ public HttpEndpoint getEndpoint() {
+ return (HttpEndpoint) super.getEndpoint();
+ }
+
protected void populateResponse(Exchange exchange, HttpMethod method, Message in, HeaderFilterStrategy strategy, int responseCode) throws IOException {
Message answer = exchange.getOut();
@@ -193,61 +198,27 @@
* @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(Exchange.HTTP_QUERY, String.class);
- if (queryString == null) {
- queryString = ((HttpEndpoint)getEndpoint()).getHttpUri().getQuery();
- }
- RequestEntity requestEntity = createRequestEntity(exchange);
- // compute what method to use either GET or POST
- HttpMethods methodToUse;
- HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
- if (m != null) {
- // always use what end-user provides in a header
- methodToUse = m;
- } else if (queryString != null) {
- // if a query string is provided then use GET
- methodToUse = HttpMethods.GET;
- } else {
- // fallback to POST if data, otherwise GET
- methodToUse = requestEntity != null ? HttpMethods.POST : HttpMethods.GET;
- }
+ String url = HttpProducerHelper.createURL(exchange, getEndpoint());
- String uri = null;
- if (!((HttpEndpoint)getEndpoint()).isBridgeEndpoint()) {
- uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
- }
- if (uri == null) {
- uri = ((HttpEndpoint)getEndpoint()).getHttpUri().toString();
- }
-
- // append HTTP_PATH to HTTP_URI if it is provided in the header
- // when the endpoint is not working as a bridge
- String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
- if (path != null) {
- // make sure that there is exactly one "/" between HTTP_URI and
- // HTTP_PATH
- if (!uri.endsWith("/")) {
- uri = uri + "/";
- }
- if (path.startsWith("/")) {
- path = path.substring(1);
- }
- uri = uri.concat(path);
- }
-
- HttpMethod method = methodToUse.createMethod(uri);
+ RequestEntity requestEntity = createRequestEntity(exchange);
+ HttpMethods methodToUse = HttpProducerHelper.createMethod(exchange, getEndpoint(), requestEntity != null);
+ HttpMethod method = methodToUse.createMethod(url);
+ // is a query string provided in the endpoint URI or in a header (header overrules endpoint)
+ String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
+ if (queryString == null) {
+ queryString = getEndpoint().getHttpUri().getQuery();
+ }
if (queryString != null) {
method.setQueryString(queryString);
}
+
if (methodToUse.isEntityEnclosing()) {
((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
if (requestEntity != null && requestEntity.getContentType() == null) {
if (LOG.isDebugEnabled()) {
- LOG.debug("No Content-Type provided for URI: " + uri + " with exchange: " + exchange);
+ LOG.debug("No Content-Type provided for URL: " + url + " with exchange: " + exchange);
}
}
}
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java (added)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java Fri Nov 6 15:08:20 2009
@@ -0,0 +1,98 @@
+/**
+ * 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.helper;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.http.HttpEndpoint;
+import org.apache.camel.component.http.HttpMethods;
+
+/**
+ * Helper methods for HTTP producers.
+ *
+ * @version $Revision$
+ */
+public final class HttpProducerHelper {
+
+ private HttpProducerHelper() {
+ }
+
+ /**
+ * Creates the URL to invoke.
+ *
+ * @param exchange the exchange
+ * @param endpoint the endpoint
+ * @return the URL to invoke
+ */
+ public static String createURL(Exchange exchange, HttpEndpoint endpoint) {
+ String uri = null;
+ if (!(endpoint.isBridgeEndpoint())) {
+ uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
+ }
+ if (uri == null) {
+ uri = endpoint.getHttpUri().toString();
+ }
+
+ // append HTTP_PATH to HTTP_URI if it is provided in the header
+ // when the endpoint is not working as a bridge
+ String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
+ if (path != null) {
+ // make sure that there is exactly one "/" between HTTP_URI and
+ // HTTP_PATH
+ if (!uri.endsWith("/")) {
+ uri = uri + "/";
+ }
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+ uri = uri.concat(path);
+ }
+
+ return uri;
+ }
+
+ /**
+ * Creates the HttpMethod to use to call the remote server, often either its GET or POST.
+ *
+ * @param exchange the exchange
+ * @return the created method
+ */
+ public static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload) {
+ // is a query string provided in the endpoint URI or in a header (header
+ // overrules endpoint)
+ String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
+ if (queryString == null) {
+ queryString = endpoint.getHttpUri().getQuery();
+ }
+
+ // compute what method to use either GET or POST
+ HttpMethods answer;
+ HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
+ if (m != null) {
+ // always use what end-user provides in a header
+ answer = m;
+ } else if (queryString != null) {
+ // if a query string is provided then use GET
+ answer = HttpMethods.GET;
+ } else {
+ // fallback to POST if we have payload, otherwise GET
+ answer = hasPayload ? HttpMethods.POST : HttpMethods.GET;
+ }
+
+ return answer;
+ }
+
+}
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpProducerHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/components/camel-jetty/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/pom.xml?rev=833429&r1=833428&r2=833429&view=diff==============================================================================
--- camel/trunk/components/camel-jetty/pom.xml (original)
+++ camel/trunk/components/camel-jetty/pom.xml Fri Nov 6 15:08:20 2009
@@ -48,7 +48,11 @@
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-client</artifactId>
+ </dependency>
+
<!-- testing -->
<dependency>
<groupId>org.apache.camel</groupId>
Added: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java (added)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java Fri Nov 6 15:08:20 2009
@@ -0,0 +1,105 @@
+/**
+ * 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.jetty;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.mortbay.io.Buffer;
+import org.mortbay.jetty.HttpHeaders;
+import org.mortbay.jetty.client.ContentExchange;
+
+/**
+ * Jetty specific exchange which keeps track of the the request and response.
+ *
+ * @version $Revision$
+ */
+public class JettyContentExchange extends ContentExchange {
+
+ private CountDownLatch headersComplete = new CountDownLatch(1);
+ private CountDownLatch bodyComplete = new CountDownLatch(1);
+ private final Map<String, String> headers = new LinkedHashMap<String, String>();
+ private boolean failed;
+
+ public JettyContentExchange() {
+ // keep headers by default
+ super(true);
+ }
+
+ @Override
+ protected void onResponseHeader(Buffer name, Buffer value) throws IOException {
+ super.onResponseHeader(name, value);
+ headers.put(name.toString(), value.toString());
+ }
+
+ @Override
+ protected void onResponseHeaderComplete() throws IOException {
+ headersComplete.countDown();
+ }
+
+ @Override
+ protected void onResponseComplete() throws IOException {
+ bodyComplete.countDown();
+ }
+
+ @Override
+ protected void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException {
+ super.onResponseStatus(version, status, reason);
+ failed = status != 200;
+ }
+
+ public boolean isHeadersComplete() {
+ return headersComplete.getCount() == 0;
+ }
+
+ public boolean isBodyComplete() {
+ return bodyComplete.getCount() == 0;
+ }
+
+ public Map<String, String> getHeaders() {
+ return headers;
+ }
+
+ public String getBody() throws UnsupportedEncodingException {
+ return super.getResponseContent();
+ }
+
+ public void waitForHeadersToComplete() throws InterruptedException {
+ headersComplete.await();
+ }
+
+ public void waitForBodyToComplete() throws InterruptedException {
+ bodyComplete.await();
+ }
+
+ public boolean waitForBodyToComplete(long timeout, TimeUnit timeUnit) throws InterruptedException {
+ return bodyComplete.await(timeout, timeUnit);
+ }
+
+ public boolean isFailed() {
+ return failed;
+ }
+
+ public String getUrl() {
+ String params = getRequestFields().getStringField(HttpHeaders.CONTENT_ENCODING);
+ return getScheme() + "//" + getAddress().toString() + getURI() + (params != null ? "?" + params : "");
+ }
+}
Propchange: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyFutureGetBody.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyFutureGetBody.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyFutureGetBody.java (added)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyFutureGetBody.java Fri Nov 6 15:08:20 2009
@@ -0,0 +1,106 @@
+/**
+ * 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.jetty;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangeTimedOutException;
+
+/**
+ * A {@link Future} task which to be used to retrieve the HTTP response which comes back asynchronously.
+ *
+ * @version $Revision$
+ */
+public class JettyFutureGetBody implements Future<String>, Serializable {
+
+ private final Exchange exchange;
+ private final JettyContentExchange httpExchange;
+ private boolean cancelled;
+ private boolean throwExceptionOnFailure;
+
+ public JettyFutureGetBody(Exchange exchange, JettyContentExchange httpExchange, boolean throwExceptionOnFailure) {
+ this.exchange = exchange;
+ this.httpExchange = httpExchange;
+ this.throwExceptionOnFailure = throwExceptionOnFailure;
+ }
+
+ public boolean cancel(boolean mayInterrupt) {
+ httpExchange.cancel();
+ cancelled = true;
+ return true;
+ }
+
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ public boolean isDone() {
+ return httpExchange.isBodyComplete();
+ }
+
+ public String get() throws InterruptedException, ExecutionException {
+ // wait for body to be done
+ if (!isDone()) {
+ try {
+ httpExchange.waitForBodyToComplete();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ // ignore
+ }
+ }
+ return doGetBody();
+ }
+
+ public String get(long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
+ if (!isDone()) {
+ boolean done = httpExchange.waitForBodyToComplete(timeout, timeUnit);
+ if (done) {
+ return doGetBody();
+ } else {
+ ExchangeTimedOutException cause = new ExchangeTimedOutException(exchange, timeout);
+ throw new ExecutionException(cause);
+ }
+ }
+ return doGetBody();
+ }
+
+ private String doGetBody() throws ExecutionException {
+ try {
+ if (httpExchange.isFailed() && throwExceptionOnFailure) {
+ throw new JettyHttpOperationFailedException(httpExchange.getUrl(), httpExchange.getResponseStatus(), httpExchange.getBody());
+ } else {
+ return httpExchange.getBody();
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw new ExecutionException(e);
+ } catch (JettyHttpOperationFailedException e) {
+ throw new ExecutionException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "JettyFutureGetBody[" + httpExchange.getUrl() + "]";
+ }
+
+}
Propchange: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyFutureGetBody.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyFutureGetBody.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=833429&r1=833428&r2=833429&view=diff==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java (original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java Fri Nov 6 15:08:20 2009
@@ -37,6 +37,7 @@
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
+import org.mortbay.jetty.client.HttpClient;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.security.SslSocketConnector;
@@ -61,6 +62,7 @@
protected String sslPassword;
protected String sslKeystore;
protected Map<Integer, SslSocketConnector> sslSocketConnectors;
+ protected HttpClient httpClient;
class ConnectorRef {
Server server;
@@ -279,6 +281,14 @@
sslSocketConnectors = connectors;
}
+ public HttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ public void setHttpClient(HttpClient httpClient) {
+ this.httpClient = httpClient;
+ }
+
// Implementation methods
// -------------------------------------------------------------------------
protected CamelServlet createServletForConnector(Server server, Connector connector, List<Handler> handlers) throws Exception {
Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java?rev=833429&r1=833428&r2=833429&view=diff==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java (original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java Fri Nov 6 15:08:20 2009
@@ -28,13 +28,18 @@
import org.apache.camel.component.http.HttpEndpoint;
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;
import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.client.Address;
+import org.mortbay.jetty.client.HttpClient;
/**
* @version $Revision$
*/
public class JettyHttpEndpoint extends HttpEndpoint {
+ private static final transient Log LOG = LogFactory.getLog(JettyHttpEndpoint.class);
private boolean sessionSupport;
private List<Handler> handlers;
@@ -43,9 +48,18 @@
super(uri, component, httpURL, clientParams, httpConnectionManager, clientConfigurer);
}
+ public JettyHttpEndpoint(JettyHttpComponent component, String uri, URI httpURL) throws URISyntaxException {
+ super(uri, component, httpURL);
+ }
+
+ @Override
+ public JettyHttpComponent getComponent() {
+ return (JettyHttpComponent) super.getComponent();
+ }
+
@Override
public Producer createProducer() throws Exception {
- return super.createProducer();
+ return new JettyHttpProducer(this);
}
@Override
@@ -68,4 +82,31 @@
public void setHandlers(List<Handler> handlers) {
this.handlers = handlers;
}
+
+ /**
+ * Factory method used by producers and consumers to create a new {@link org.apache.commons.httpclient.HttpClient} instance
+ */
+ public HttpClient getJettyHttpClient() throws Exception {
+ HttpClient answer = getComponent().getHttpClient();
+ if (answer == null) {
+ answer = new HttpClient();
+ answer.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
+
+ if (System.getProperty("http.proxyHost") != null && System.getProperty("http.proxyPort") != null) {
+ String host = System.getProperty("http.proxyHost");
+ int port = Integer.parseInt(System.getProperty("http.proxyPort"));
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Java System Property http.proxyHost and http.proxyPort detected. Using http proxy host: "
+ + host + " port: " + port);
+ }
+ answer.setProxy(new Address(host, port));
+ }
+
+ // TODO: allow jetty producer configuration from uri
+
+ answer.start();
+ }
+ return answer;
+ }
+
}
Added: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpMessage.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpMessage.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpMessage.java (added)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpMessage.java Fri Nov 6 15:08:20 2009
@@ -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.jetty;
+
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultMessage;
+
+/**
+ * @version $Revision$
+ */
+public class JettyHttpMessage extends DefaultMessage {
+
+ private final JettyContentExchange httpExchange;
+ private final boolean throwExceptionOnFailure;
+
+ public JettyHttpMessage(Exchange exchange, JettyContentExchange httpExchange, boolean throwExceptionOnFailure) {
+ setExchange(exchange);
+ this.httpExchange = httpExchange;
+ this.throwExceptionOnFailure = throwExceptionOnFailure;
+ }
+
+ @Override
+ protected void populateInitialHeaders(Map<String, Object> map) {
+ if (httpExchange.isHeadersComplete()) {
+ map.putAll(httpExchange.getHeaders());
+ } else {
+ // wait for headers to be done
+ try {
+ httpExchange.waitForHeadersToComplete();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ // ignore
+ }
+ map.putAll(httpExchange.getHeaders());
+ }
+ }
+
+ @Override
+ protected Object createBody() {
+ // return a Future which by end user can use to obtain the response later
+ return new JettyFutureGetBody(getExchange(), httpExchange, throwExceptionOnFailure);
+ }
+
+}
+
Propchange: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpMessage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpMessage.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpOperationFailedException.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpOperationFailedException.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpOperationFailedException.java (added)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpOperationFailedException.java Fri Nov 6 15:08:20 2009
@@ -0,0 +1,52 @@
+/**
+ * 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.jetty;
+
+import org.apache.camel.CamelException;
+
+/**
+ * @version $Revision$
+ */
+public class JettyHttpOperationFailedException extends CamelException {
+
+ private final String url;
+ private final int statusCode;
+ private final String responseBody;
+
+ public JettyHttpOperationFailedException(String url, int statusCode, String responseBody) {
+ super("HTTP operation failed invoking " + url + " with statusCode: " + statusCode);
+ this.statusCode = statusCode;
+ this.url = url;
+ this.responseBody = responseBody;
+ }
+
+ public boolean isRedirectError() {
+ return statusCode >= 300 && statusCode < 400;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ public String getResponseBody() {
+ return responseBody;
+ }
+}
Propchange: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpOperationFailedException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpOperationFailedException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java (added)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java Fri Nov 6 15:08:20 2009
@@ -0,0 +1,106 @@
+/**
+ * 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.jetty;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.http.HttpMethods;
+import org.apache.camel.component.http.helper.HttpProducerHelper;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.URISupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mortbay.jetty.client.HttpClient;
+
+/**
+ * @version $Revision$
+ */
+public class JettyHttpProducer extends DefaultProducer {
+ private static final transient Log LOG = LogFactory.getLog(JettyHttpProducer.class);
+ private boolean throwException;
+
+ public JettyHttpProducer(Endpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public JettyHttpEndpoint getEndpoint() {
+ return (JettyHttpEndpoint) super.getEndpoint();
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ HttpClient client = getEndpoint().getJettyHttpClient();
+
+ JettyContentExchange httpExchange = createHttpExchange(exchange);
+
+ // set the body with the message holder
+ exchange.setOut(new JettyHttpMessage(exchange, httpExchange, getEndpoint().isThrowExceptionOnFailure()));
+
+ // will send it async
+ sendExchange(client, httpExchange);
+
+ // TODO: configuration of http client as getter/setters and URI on component
+ // TODO: support that bridge option
+ // TODO: more unit tests
+ }
+
+ protected void sendExchange(HttpClient client, JettyContentExchange httpExchange) throws IOException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Sending HTTP request to: " + httpExchange.getUrl());
+ }
+ client.send(httpExchange);
+ }
+
+ protected JettyContentExchange createHttpExchange(Exchange exchange) throws Exception {
+ String url = HttpProducerHelper.createURL(exchange, getEndpoint());
+ HttpMethods methodToUse = HttpProducerHelper.createMethod(exchange, getEndpoint(), exchange.getIn().getBody() != null);
+ String method = methodToUse.createMethod(url).getName();
+
+ JettyContentExchange httpExchange = new JettyContentExchange();
+ httpExchange.setMethod(method);
+ httpExchange.setURL(url);
+
+ doSetQueryParameters(exchange, httpExchange);
+
+ return httpExchange;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void doSetQueryParameters(Exchange exchange, JettyContentExchange httpExchange) throws URISyntaxException {
+ // is a query string provided in the endpoint URI or in a header (header
+ // overrules endpoint)
+ String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
+ if (queryString == null) {
+ queryString = getEndpoint().getHttpUri().getQuery();
+ }
+
+ if (ObjectHelper.isEmpty(queryString)) {
+ return;
+ }
+
+ Map<String, String> parameters = URISupport.parseQuery(queryString);
+ for (Map.Entry<String, String> entry : parameters.entrySet()) {
+ httpExchange.setRequestHeader(entry.getKey(), entry.getValue());
+ }
+ }
+
+}
Propchange: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGetTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGetTest.java?rev=833429&r1=833428&r2=833429&view=diff==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGetTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGetTest.java Fri Nov 6 15:08:20 2009
@@ -64,7 +64,7 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from("direct:start").to("jetty:
http://www.google.com").to("mock:results");
+ from("direct:start").to("
http://www.google.com").to("mock:results");
}
};
}
Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java?rev=833429&r1=833428&r2=833429&view=diff==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java Fri Nov 6 15:08:20 2009
@@ -106,7 +106,7 @@
public void testEndpointWithoutHttps() {
MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
try {
- template.sendBodyAndHeader("jetty:
http://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
+ template.sendBodyAndHeader("
http://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
fail("expect exception on access to https endpoint via http");
} catch (RuntimeCamelException expected) {
}
@@ -140,8 +140,8 @@
}
protected void invokeHttpEndpoint() throws IOException {
- template.sendBodyAndHeader("jetty:
https://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
- template.sendBodyAndHeader("jetty:
https://localhost:9090/test", expectedBody, "Content-Type", "application/xml");
+ template.sendBodyAndHeader("
https://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
+ template.sendBodyAndHeader("
https://localhost:9090/test", expectedBody, "Content-Type", "application/xml");
}
@Override
Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java?rev=833429&r1=833428&r2=833429&view=diff==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java Fri Nov 6 15:08:20 2009
@@ -16,8 +16,8 @@
*/
package org.apache.camel.component.jetty;
-import org.apache.camel.Endpoint;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpEndpoint;
import org.apache.camel.component.http.HttpProducer;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
@@ -30,7 +30,7 @@
@Test
public void testCustomHttpBinding() throws Exception {
// assert jetty was configured with our timeout
- JettyHttpEndpoint jettyEndpoint = (JettyHttpEndpoint) context.getEndpoint("jetty:
http://localhost:8080/myapp/myservice?httpClient.soTimeout=5555");
+ HttpEndpoint jettyEndpoint = context.getEndpoint("
http://localhost:8080/myapp/myservice?httpClient.soTimeout=5555", HttpEndpoint.class);
assertNotNull("Jetty endpoint should not be null ", jettyEndpoint);
HttpProducer producer = (HttpProducer)jettyEndpoint.createProducer();
assertEquals("Get the wrong http client parameter", 5555, producer.getHttpClient().getParams().getSoTimeout());
Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java?rev=833429&r1=833428&r2=833429&view=diff==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java Fri Nov 6 15:08:20 2009
@@ -104,7 +104,7 @@
public void testEndpointWithoutHttps() {
MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
try {
- template.sendBodyAndHeader("jetty:
http://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
+ template.sendBodyAndHeader("
http://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
fail("expect exception on access to https endpoint via http");
} catch (RuntimeCamelException expected) {
}
@@ -114,7 +114,7 @@
protected void invokeHttpEndpoint() throws IOException {
- template.sendBodyAndHeader("jetty:
https://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
+ template.sendBodyAndHeader("
https://localhost:9080/test", expectedBody, "Content-Type", "application/xml");
}
protected CamelContext createCamelContext() throws Exception {
Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGoogleTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGoogleTest.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGoogleTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGoogleTest.java Fri Nov 6 15:08:20 2009
@@ -0,0 +1,55 @@
+/**
+ * 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.jetty.jettyproducer;
+
+import java.util.concurrent.Future;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class JettyHttpProducerGoogleTest extends CamelTestSupport {
+
+ @Test
+ public void testGoogleFrontPage() throws Exception {
+ String reply = template.requestBody("direct:start", null, String.class);
+ assertNotNull(reply);
+ }
+
+ @Test
+ public void testGoogleFrontPageFutureTask() throws Exception {
+ Object body = null;
+ Future<String> reply = (Future<String>) template.requestBody("direct:start", body);
+ assertNotNull(reply);
+ assertNotNull(reply.get());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // to prevent redirect being thrown as an exception
+ from("direct:start").to("jetty://
http://www.google.com?throwExceptionOnFailure=false");
+ }
+ };
+ }
+}
+
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGoogleTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerGoogleTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerHeaderBasedCBRTestTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerHeaderBasedCBRTestTest.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerHeaderBasedCBRTestTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerHeaderBasedCBRTestTest.java Fri Nov 6 15:08:20 2009
@@ -0,0 +1,97 @@
+/**
+ * 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.jetty.jettyproducer;
+
+import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class JettyHttpProducerHeaderBasedCBRTestTest extends CamelTestSupport {
+
+ private String url = "jetty://
http://0.0.0.0:9123/foo";
+ private static String step;
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testSlowReplyCBRRoutedOnHeader() throws Exception {
+ step = "";
+
+ MockEndpoint gold = getMockEndpoint("mock:gold");
+ gold.expectedMessageCount(1);
+ gold.whenAnyExchangeReceived(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ // add the step when we received the message
+ step += "C";
+ }
+ });
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // let it wait for the body now using the future handle
+ // Note: we could just use getBody(String.class) and Camel will then automatic wait for you
+ Future<String> future = (Future<String>) gold.getReceivedExchanges().get(0).getIn().getBody();
+ assertEquals("Bye World", future.get());
+
+ // and ensure the we could CBR on the header before we got the reply body
+ assertEquals("ACB", step);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to(url)
+ .choice()
+ .when(header("customer").isEqualTo("gold")).to("mock:gold")
+ .otherwise().to("mock:unknown");
+
+ from(url).process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ HttpServletResponse res = exchange.getIn().getBody(HttpServletResponse.class);
+ res.setStatus(200);
+ res.setHeader("customer", "gold");
+
+ step += "A";
+
+ // write empty string to force flushing
+ res.getWriter().write("");
+ res.flushBuffer();
+
+ Thread.sleep(2000);
+
+ res.getWriter().write("Bye World");
+ res.flushBuffer();
+
+ step += "B";
+ }
+ });
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerHeaderBasedCBRTestTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerHeaderBasedCBRTestTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java Fri Nov 6 15:08:20 2009
@@ -0,0 +1,82 @@
+/**
+ * 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.jetty.jettyproducer;
+
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.JettyHttpOperationFailedException;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class JettyHttpProducerQueryParamTest extends CamelTestSupport {
+
+ private String url = "jetty://
http://0.0.0.0:9123/cheese";
+
+ @Test
+ public void testQueryParameters() throws Exception {
+ Exchange exchange = template.request(url + "?quote=Camel%20rocks", null);
+ assertNotNull(exchange);
+
+ String body = exchange.getOut().getBody(String.class);
+ Map headers = exchange.getOut().getHeaders();
+
+ assertEquals("Bye World", body);
+ assertEquals("Carlsberg", headers.get("beer"));
+ }
+
+ @Test
+ public void testQueryParametersWithHeader() throws Exception {
+ Exchange exchange = template.request(url, new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(Exchange.HTTP_QUERY, "quote=Camel rocks");
+ }
+ });
+ assertNotNull(exchange);
+
+ String body = exchange.getOut().getBody(String.class);
+ Map headers = exchange.getOut().getHeaders();
+
+ assertEquals("Bye World", body);
+ assertEquals("Carlsberg", headers.get("beer"));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(url).process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String quote = exchange.getIn().getHeader("quote", String.class);
+ assertEquals("Camel rocks", quote);
+
+ exchange.getOut().setBody("Bye World");
+ exchange.getOut().setHeader("beer", "Carlsberg");
+ }
+ });
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java Fri Nov 6 15:08:20 2009
@@ -0,0 +1,71 @@
+/**
+ * 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.jetty.jettyproducer;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.JettyHttpOperationFailedException;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class JettyHttpProducerSimulate404ErrorTest extends CamelTestSupport {
+
+ private String url = "jetty://
http://0.0.0.0:9123/bar";
+
+ @Test
+ public void test404() throws Exception {
+ Exchange exchange = template.request(url, null);
+ assertNotNull(exchange);
+
+ Future<String> future = exchange.getOut().getBody(Future.class);
+ assertNotNull(future);
+ assertEquals(false, future.isDone());
+
+ try {
+ future.get();
+ } catch (ExecutionException e) {
+ JettyHttpOperationFailedException cause = assertIsInstanceOf(JettyHttpOperationFailedException.class, e.getCause());
+ assertEquals(404, cause.getStatusCode());
+ assertEquals("http//0.0.0.0:9123/bar", cause.getUrl());
+ assertEquals("Page not found", cause.getResponseBody());
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(url).process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ Thread.sleep(1000);
+
+ exchange.getOut().setBody("Page not found");
+ exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 404);
+ }
+ });
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java?rev=833429&view=auto==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java Fri Nov 6 15:08:20 2009
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.jettyproducer;
+
+import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class JettyHttpProducerSlowResponseTest extends CamelTestSupport {
+
+ private String url = "jetty://
http://0.0.0.0:9123/foo";
+
+ @Test
+ public void testSlowReply() throws Exception {
+ Exchange exchange = template.request(url, null);
+ assertNotNull(exchange);
+
+ Future<String> future = exchange.getOut().getBody(Future.class);
+ assertNotNull(future);
+ assertEquals(false, future.isDone());
+
+ String reply = future.get();
+ assertEquals("Bye World", reply);
+
+ assertEquals(3, exchange.getOut().getHeaders().size());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(url).process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ HttpServletResponse res = exchange.getIn().getBody(HttpServletResponse.class);
+ res.setStatus(200);
+ res.setHeader("customer", "gold");
+
+ // write empty string to force flushing
+ res.getWriter().write("");
+ res.flushBuffer();
+
+ Thread.sleep(2000);
+
+ res.getWriter().write("Bye World");
+ res.flushBuffer();
+ }
+ });
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date