camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [5/6] camel git commit: Separate classes between jetty versions
Date Fri, 12 Dec 2014 17:23:45 GMT
Separate classes between jetty versions


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/95b16c53
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/95b16c53
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/95b16c53

Branch: refs/heads/temp-jetty9
Commit: 95b16c53380bc559f9528532e0e81c266fdf274f
Parents: abde35a
Author: Christian Schneider <chris@die-schneider.net>
Authored: Fri Dec 12 18:16:36 2014 +0100
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Fri Dec 12 18:16:36 2014 +0100

----------------------------------------------------------------------
 .../camel/component/jetty/CamelHttpClient.java  |  71 +----
 .../camel/component/jetty/CamelHttpClient8.java |  50 +++
 .../camel/component/jetty/CamelHttpClient9.java |  41 +++
 .../component/jetty/JettyContentExchange.java   | 276 +++--------------
 .../component/jetty/JettyContentExchange9.java  | 302 +++++++++++++++++++
 .../component/jetty/JettyHttpComponent.java     |  14 +-
 .../component/jetty/JettyHttpComponent8.java    |  11 +
 .../component/jetty/JettyHttpComponent9.java    |  11 +
 .../component/jetty/JettyHttpProducer.java      |   2 +-
 .../services/org/apache/camel/component/jetty   |   2 +-
 .../JettyComponentSpringConfiguredTest.xml      |   2 +-
 .../camel/component/jetty/jetty-https.xml       |   2 +-
 12 files changed, 466 insertions(+), 318 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
index 45f09ba..3018f1f 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
@@ -16,42 +16,23 @@
  */
 package org.apache.camel.component.jetty;
 
-import java.util.Collection;
 import java.util.concurrent.Executor;
 
 import javax.net.ssl.SSLContext;
 
 import org.apache.camel.util.ObjectHelper;
 import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
-import org.eclipse.jetty.util.thread.ThreadPool;
 
-public class CamelHttpClient extends HttpClient {
+public abstract class CamelHttpClient extends HttpClient {
     
     private boolean supportRedirect;
-    
-    public CamelHttpClient() {
-        super();
-        setConnectorTypeJetty8();
-    }
-    
+
     public CamelHttpClient(SslContextFactory sslContextFactory) {
         super(sslContextFactory);
-        setConnectorTypeJetty8();
     }
-    
-    private void setConnectorTypeJetty8() {
-        if (Server.getVersion().startsWith("8")) {
-            try {
-                HttpClient.class.getMethod("setConnectorType", Integer.TYPE).invoke(this,
2);
-            } catch (Throwable t) {
-                throw new RuntimeException(t);
-            }
-        }
-    }
-    
+
     @Deprecated
     /**
      * It does nothing here, please setup SslContextFactory directly, it will be removed
in Camel 2.16.0
@@ -76,51 +57,11 @@ public class CamelHttpClient extends HttpClient {
         super.doStart();
     }
  
-    private boolean hasThreadPool() {
-        try {
-            return getClass().getMethod("getExecutor").invoke(this) != null;
-        } catch (Exception ex) {
-            try {
-                return getClass().getMethod("getThreadPool").invoke(this) != null;
-            } catch (Exception ex2) {
-                throw new RuntimeException(ex);
-            }
-        }
-    }
+    protected abstract boolean hasThreadPool();
 
-    void setThreadPoolOrExecutor(Executor pool) {
-        try {
-            getClass().getMethod("setExecutor", Executor.class).invoke(this, pool);
-        } catch (Exception ex) {
-            try {
-                getClass().getMethod("setThreadPool", ThreadPool.class).invoke(this, pool);
-            } catch (Exception ex2) {
-                throw new RuntimeException(ex);
-            }
-        }
-    }
+    protected abstract void setThreadPoolOrExecutor(Executor pool);
     
-    public void setProxy(String host, int port) {
-        try {
-            if (Server.getVersion().startsWith("8")) {
-                //setProxy(new org.eclipse.jetty.client.Address(host, port));
-                Class<?> c = Class.forName("org.eclipse.jetty.client.Address");
-                Object o = c.getConstructor(String.class, Integer.TYPE).newInstance(host,
port);
-                this.getClass().getMethod("setProxy", c).invoke(this, o);
-            } else {
-                //getProxyConfiguration().getProxies().add(new org.eclipse.jetty.client.HttpProxy(host,
port));
-                Object o = this.getClass().getMethod("getProxyConfiguration").invoke(this);
-                @SuppressWarnings("unchecked")
-                Collection<Object> c = (Collection<Object>)o.getClass().getMethod("getProxies").invoke(o);
-                c.clear();
-                Class<?> cls = Class.forName("org.eclipse.jetty.client.HttpProxy");
-                o = cls.getConstructor(String.class, Integer.TYPE).newInstance(host, port);
-                c.add(o);
-            }
-        } catch (Throwable t) {
-            throw new RuntimeException(t);
-        }
-    }
+    public abstract void setProxy(String host, int port);
     
     public boolean isSupportRedirect() {
         return supportRedirect;

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient8.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient8.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient8.java
new file mode 100644
index 0000000..993f52a
--- /dev/null
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient8.java
@@ -0,0 +1,50 @@
+package org.apache.camel.component.jetty;
+
+import java.util.concurrent.Executor;
+
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+import org.eclipse.jetty.util.thread.ThreadPool;
+
+public class CamelHttpClient8 extends CamelHttpClient {
+
+    public CamelHttpClient8(SslContextFactory sslContextFactory) {
+        super(sslContextFactory);
+        setConnectorType();
+    }
+    
+    private void setConnectorType() {
+        try {
+            HttpClient.class.getMethod("setConnectorType", Integer.TYPE).invoke(this, 2);
+        } catch (Throwable t) {
+            throw new RuntimeException(t);
+        }
+    }
+    
+    protected boolean hasThreadPool() {
+        try {
+            return getClass().getMethod("getThreadPool").invoke(this) != null;
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    protected void setThreadPoolOrExecutor(Executor pool) {
+        try {
+            getClass().getMethod("setThreadPool", ThreadPool.class).invoke(this, pool);
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+    
+    public void setProxy(String host, int port) {
+        try {
+            // setProxy(new org.eclipse.jetty.client.Address(host, port));
+            Class<?> c = Class.forName("org.eclipse.jetty.client.Address");
+            Object o = c.getConstructor(String.class, Integer.TYPE).newInstance(host, port);
+            this.getClass().getMethod("setProxy", c).invoke(this, o);
+        } catch (Throwable t) {
+            throw new RuntimeException(t);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient9.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient9.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient9.java
new file mode 100644
index 0000000..8ca7729
--- /dev/null
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient9.java
@@ -0,0 +1,41 @@
+/**
+ * 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.concurrent.Executor;
+
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+
+public class CamelHttpClient9 extends CamelHttpClient {
+    
+    public CamelHttpClient9(SslContextFactory sslContextFactory) {
+        super(sslContextFactory);
+    }
+
+    protected boolean hasThreadPool() {
+        return getExecutor() != null;
+    }
+
+    protected void setThreadPoolOrExecutor(Executor pool) {
+        setExecutor(pool);
+    }
+    
+    public void setProxy(String host, int port) {
+        getProxyConfiguration().getProxies().add(new org.eclipse.jetty.client.HttpProxy(host,
port));
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
index 212fde9..046caa8 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
@@ -1,254 +1,46 @@
-/**
- * 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.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
 import java.util.Collection;
 import java.util.Map;
-import java.util.TreeMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 
 import org.apache.camel.AsyncCallback;
-import org.apache.camel.CamelExchangeException;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangeTimedOutException;
 import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.client.api.Request;
-import org.eclipse.jetty.client.api.Response;
-import org.eclipse.jetty.client.api.Result;
-import org.eclipse.jetty.client.util.BufferingResponseListener;
-import org.eclipse.jetty.client.util.BytesContentProvider;
-import org.eclipse.jetty.client.util.InputStreamContentProvider;
-import org.eclipse.jetty.client.util.StringContentProvider;
-import org.eclipse.jetty.http.HttpFields;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Jetty specific exchange which keeps track of the the request and response.
- *
- * @version 
- */
-public class JettyContentExchange {
-
-    private static final Logger LOG = LoggerFactory.getLogger(JettyContentExchange.class);
-
-    private volatile Exchange exchange;
-    private volatile AsyncCallback callback;
-    private volatile JettyHttpBinding jettyBinding;
-    private volatile HttpClient client;
-    private final CountDownLatch done = new CountDownLatch(1);
-    private Request request;
-    private Response response;
-    private byte[] responseContent;
-
-    private String requestContentType;
-
-    private boolean supportRedirect;
-
-    public JettyContentExchange(Exchange exchange, JettyHttpBinding jettyBinding, 
-                                final HttpClient client) {
-        super(); // keep headers by default
-        this.exchange = exchange;
-        this.jettyBinding = jettyBinding;
-        this.client = client;
-    }
-
-    public void setCallback(AsyncCallback callback) {
-        this.callback = callback;
-    }
-
-    protected void onRequestComplete() {
-        LOG.trace("onRequestComplete");
-        closeRequestContentSource();
-    }
-
-    protected void onResponseComplete(Result result, byte[] content, String contentType)
{
-        LOG.trace("onResponseComplete");
-        done.countDown();
-        this.response = result.getResponse();
-        this.responseContent = content;
-        if (callback == null) {
-            // this is only for the async callback
-            return;
-        }
-        try {
-            jettyBinding.populateResponse(exchange, this);
-        } catch (Exception e) {
-            exchange.setException(e);
-        } finally {
-        	callback.done(false);
-        }
-    }
-
-    protected void onExpire() {
-        LOG.trace("onExpire");
-
-        // need to close the request input stream
-        closeRequestContentSource();
-        doTaskCompleted(new ExchangeTimedOutException(exchange, client.getConnectTimeout()));
-    }
-
-    protected void onException(Throwable ex) {
-        LOG.trace("onException {}", ex);
-
-        // need to close the request input stream
-        closeRequestContentSource();
-        doTaskCompleted(ex);
-    }
-
-    protected void onConnectionFailed(Throwable ex) {
-        LOG.trace("onConnectionFailed {}", ex);
-
-        // need to close the request input stream
-        closeRequestContentSource();
-        doTaskCompleted(ex);
-    }
-
-    public byte[] getBody() {
-        // must return the content as raw bytes
-        return getResponseContentBytes();
-    }
-
-    public String getUrl() {
-        try {
-            return this.request.getURI().toURL().toExternalForm();
-        } catch (MalformedURLException e) {
-                throw new IllegalStateException(e.getMessage(), e);
-        }
-    }
-    
-    protected void closeRequestContentSource() {
-        tryClose(this.request.getContent());
-    }
-    
-    private void tryClose(Object obj) {
-        if (obj instanceof Closeable) {
-            try {
-                ((Closeable)obj).close();
-            } catch (IOException e) {
-                // Ignore
-            }
-        }
-    }
-
-    protected void doTaskCompleted(Throwable ex) {
-        if (ex instanceof TimeoutException) {
-            exchange.setException(new ExchangeTimedOutException(exchange, request.getTimeout()));
-        } else {
-            exchange.setException(new CamelExchangeException("JettyClient failed cause by:
" + ex.getMessage(), exchange, ex));
-        }
-        done.countDown();
-
-        if (callback != null) {
-            // now invoke callback to indicate we are done async
-            callback.done(false);
-        }
-    }
-
-    public void setRequestContentType(String contentType) {
-        this.requestContentType = contentType;
-    }
-
-    public int getResponseStatus() {
-        return this.response.getStatus();
-    }
-
-    public void setMethod(String method) {
-        this.request.method(method);
-    }
-    
-    public void setTimeout(long timeout) {
-    	this.request.timeout(timeout, TimeUnit.MILLISECONDS);
-    }
-    
-    public void setURL(String url) {
-        this.request = client.newRequest(url);
-    }
-
-    public void setRequestContent(byte[] byteArray) {
-    	this.request.content(new BytesContentProvider(byteArray), this.requestContentType);
-    }
-
-    public void setRequestContent(String data, String charset) throws UnsupportedEncodingException
{
-    	StringContentProvider cp = charset != null ? new StringContentProvider(data, charset)
: new StringContentProvider(data);
-    	this.request.content(cp, this.requestContentType);
-    }
-    public void setRequestContent(InputStream ins) {
-        this.request.content(new InputStreamContentProvider(ins), this.requestContentType);
       
-    }
-
-    public void addRequestHeader(String key, String s) {
-        this.request.header(key, s);
-    }
-
-    public void send(HttpClient client) throws IOException {
-        org.eclipse.jetty.client.api.Request.Listener listener = new Request.Listener.Adapter()
{
-
-            @Override
-            public void onSuccess(Request request) {
-                onRequestComplete();
-            }
-
-            @Override
-            public void onFailure(Request request, Throwable failure) {
-                onConnectionFailed(failure);
-            }
-
-        };
-        BufferingResponseListener responseListener = new BufferingResponseListener() {
-
-            @Override
-            public void onComplete(Result result) {
-                if (result.isFailed()) {
-                    doTaskCompleted(result.getFailure());
-                } else {
-                    onResponseComplete(result, getContent(), getMediaType());
-                }
-            }
-        };
-        request.followRedirects(supportRedirect).listener(listener).send(responseListener);
-    }
-
-    protected void setResponse(Response response) {
-        this.response = response;
-    }
-
-    public byte[] getResponseContentBytes() {
-        return responseContent;
-    }
-    
-    public Map<String, Collection<String>> getResponseHeaders() {
-        final HttpFields f = response.getHeaders();
-        Map<String, Collection<String>> ret = new TreeMap<String, Collection<String>>(String.CASE_INSENSITIVE_ORDER);
-        for (String n : f.getFieldNamesCollection()) {
-            ret.put(n,  f.getValuesList(n));
-        }
-        return ret;
-    }
-
-    public void setSupportRedirect(boolean supportRedirect) {
-        this.supportRedirect = supportRedirect;
-    }
+
+public interface JettyContentExchange {
+
+    void setCallback(AsyncCallback callback);
+
+    byte[] getBody();
+
+    String getUrl();
+
+    void setRequestContentType(String contentType);
+
+    int getResponseStatus();
+
+    void setMethod(String method);
+
+    void setTimeout(long timeout);
+
+    void setURL(String url);
+
+    void setRequestContent(byte[] byteArray);
+
+    void setRequestContent(String data, String charset) throws UnsupportedEncodingException;
+
+    void setRequestContent(InputStream ins);
+
+    void addRequestHeader(String key, String s);
+
+    void send(HttpClient client) throws IOException;
+
+    byte[] getResponseContentBytes();
+
+    Map<String, Collection<String>> getResponseHeaders();
+
+    void setSupportRedirect(boolean supportRedirect);
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange9.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange9.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange9.java
new file mode 100644
index 0000000..1a49413
--- /dev/null
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange9.java
@@ -0,0 +1,302 @@
+/**
+ * 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.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangeTimedOutException;
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.client.api.Request;
+import org.eclipse.jetty.client.api.Response;
+import org.eclipse.jetty.client.api.Result;
+import org.eclipse.jetty.client.util.BufferingResponseListener;
+import org.eclipse.jetty.client.util.BytesContentProvider;
+import org.eclipse.jetty.client.util.InputStreamContentProvider;
+import org.eclipse.jetty.client.util.StringContentProvider;
+import org.eclipse.jetty.http.HttpFields;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Jetty specific exchange which keeps track of the the request and response.
+ *
+ * @version 
+ */
+public class JettyContentExchange9 implements JettyContentExchange {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JettyContentExchange9.class);
+
+    private volatile Exchange exchange;
+    private volatile AsyncCallback callback;
+    private volatile JettyHttpBinding jettyBinding;
+    private volatile HttpClient client;
+    private final CountDownLatch done = new CountDownLatch(1);
+    private Request request;
+    private Response response;
+    private byte[] responseContent;
+
+    private String requestContentType;
+
+    private boolean supportRedirect;
+
+    public JettyContentExchange9(Exchange exchange, JettyHttpBinding jettyBinding, 
+                                final HttpClient client) {
+        super(); // keep headers by default
+        this.exchange = exchange;
+        this.jettyBinding = jettyBinding;
+        this.client = client;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#setCallback(org.apache.camel.AsyncCallback)
+     */
+    public void setCallback(AsyncCallback callback) {
+        this.callback = callback;
+    }
+
+    protected void onRequestComplete() {
+        LOG.trace("onRequestComplete");
+        closeRequestContentSource();
+    }
+
+    protected void onResponseComplete(Result result, byte[] content, String contentType)
{
+        LOG.trace("onResponseComplete");
+        done.countDown();
+        this.response = result.getResponse();
+        this.responseContent = content;
+        if (callback == null) {
+            // this is only for the async callback
+            return;
+        }
+        try {
+            jettyBinding.populateResponse(exchange, this);
+        } catch (Exception e) {
+            exchange.setException(e);
+        } finally {
+        	callback.done(false);
+        }
+    }
+
+    protected void onExpire() {
+        LOG.trace("onExpire");
+
+        // need to close the request input stream
+        closeRequestContentSource();
+        doTaskCompleted(new ExchangeTimedOutException(exchange, client.getConnectTimeout()));
+    }
+
+    protected void onException(Throwable ex) {
+        LOG.trace("onException {}", ex);
+
+        // need to close the request input stream
+        closeRequestContentSource();
+        doTaskCompleted(ex);
+    }
+
+    protected void onConnectionFailed(Throwable ex) {
+        LOG.trace("onConnectionFailed {}", ex);
+
+        // need to close the request input stream
+        closeRequestContentSource();
+        doTaskCompleted(ex);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#getBody()
+     */
+    public byte[] getBody() {
+        // must return the content as raw bytes
+        return getResponseContentBytes();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#getUrl()
+     */
+    public String getUrl() {
+        try {
+            return this.request.getURI().toURL().toExternalForm();
+        } catch (MalformedURLException e) {
+                throw new IllegalStateException(e.getMessage(), e);
+        }
+    }
+    
+    protected void closeRequestContentSource() {
+        tryClose(this.request.getContent());
+    }
+    
+    private void tryClose(Object obj) {
+        if (obj instanceof Closeable) {
+            try {
+                ((Closeable)obj).close();
+            } catch (IOException e) {
+                // Ignore
+            }
+        }
+    }
+
+    protected void doTaskCompleted(Throwable ex) {
+        if (ex instanceof TimeoutException) {
+            exchange.setException(new ExchangeTimedOutException(exchange, request.getTimeout()));
+        } else {
+            exchange.setException(new CamelExchangeException("JettyClient failed cause by:
" + ex.getMessage(), exchange, ex));
+        }
+        done.countDown();
+
+        if (callback != null) {
+            // now invoke callback to indicate we are done async
+            callback.done(false);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#setRequestContentType(java.lang.String)
+     */
+    public void setRequestContentType(String contentType) {
+        this.requestContentType = contentType;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#getResponseStatus()
+     */
+    public int getResponseStatus() {
+        return this.response.getStatus();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#setMethod(java.lang.String)
+     */
+    public void setMethod(String method) {
+        this.request.method(method);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#setTimeout(long)
+     */
+    public void setTimeout(long timeout) {
+    	this.request.timeout(timeout, TimeUnit.MILLISECONDS);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#setURL(java.lang.String)
+     */
+    public void setURL(String url) {
+        this.request = client.newRequest(url);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#setRequestContent(byte[])
+     */
+    public void setRequestContent(byte[] byteArray) {
+    	this.request.content(new BytesContentProvider(byteArray), this.requestContentType);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#setRequestContent(java.lang.String,
java.lang.String)
+     */
+    public void setRequestContent(String data, String charset) throws UnsupportedEncodingException
{
+    	StringContentProvider cp = charset != null ? new StringContentProvider(data, charset)
: new StringContentProvider(data);
+    	this.request.content(cp, this.requestContentType);
+    }
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#setRequestContent(java.io.InputStream)
+     */
+    public void setRequestContent(InputStream ins) {
+        this.request.content(new InputStreamContentProvider(ins), this.requestContentType);
       
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#addRequestHeader(java.lang.String,
java.lang.String)
+     */
+    public void addRequestHeader(String key, String s) {
+        this.request.header(key, s);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#send(org.eclipse.jetty.client.HttpClient)
+     */
+    public void send(HttpClient client) throws IOException {
+        org.eclipse.jetty.client.api.Request.Listener listener = new Request.Listener.Adapter()
{
+
+            @Override
+            public void onSuccess(Request request) {
+                onRequestComplete();
+            }
+
+            @Override
+            public void onFailure(Request request, Throwable failure) {
+                onConnectionFailed(failure);
+            }
+
+        };
+        BufferingResponseListener responseListener = new BufferingResponseListener() {
+
+            @Override
+            public void onComplete(Result result) {
+                if (result.isFailed()) {
+                    doTaskCompleted(result.getFailure());
+                } else {
+                    onResponseComplete(result, getContent(), getMediaType());
+                }
+            }
+        };
+        request.followRedirects(supportRedirect).listener(listener).send(responseListener);
+    }
+
+    protected void setResponse(Response response) {
+        this.response = response;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#getResponseContentBytes()
+     */
+    public byte[] getResponseContentBytes() {
+        return responseContent;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#getResponseHeaders()
+     */
+    public Map<String, Collection<String>> getResponseHeaders() {
+        final HttpFields f = response.getHeaders();
+        Map<String, Collection<String>> ret = new TreeMap<String, Collection<String>>(String.CASE_INSENSITIVE_ORDER);
+        for (String n : f.getFieldNamesCollection()) {
+            ret.put(n,  f.getValuesList(n));
+        }
+        return ret;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.camel.component.jetty.JettyContentExchangeI#setSupportRedirect(boolean)
+     */
+    public void setSupportRedirect(boolean supportRedirect) {
+        this.supportRedirect = supportRedirect;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index 92ad01c..27374da 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -95,7 +95,8 @@ import org.slf4j.LoggerFactory;
  *
  * @version 
  */
-public class JettyHttpComponent extends HttpComponent implements RestConsumerFactory {
+@SuppressWarnings("deprecation")
+public abstract class JettyHttpComponent extends HttpComponent implements RestConsumerFactory
{
     public static final String TMP_DIR = "CamelJettyTempDir";
     
     protected static final HashMap<String, ConnectorRef> CONNECTORS = new HashMap<String,
ConnectorRef>();
@@ -528,6 +529,7 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
             SslContextFactory con = sslSocketConnectors.get(endpoint.getPort());
             if (con != null) {
                     SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(con,
null);
+                    @SuppressWarnings("resource")
                     ServerConnector sc = new ServerConnector(server, sslConnectionFactory);
                     sc.setPort(endpoint.getPort());
                     sc.setHost(endpoint.getHttpUri().getHost());
@@ -788,12 +790,8 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
      * @param ssl        option SSL parameters
      */
     public CamelHttpClient createHttpClient(JettyHttpEndpoint endpoint, Integer minThreads,
Integer maxThreads, SSLContextParameters ssl) throws Exception {
-        CamelHttpClient httpClient = null;
-        if (ssl != null) {
-            httpClient = new CamelHttpClient(createSslContextFactory(ssl));
-        } else {
-            httpClient = new CamelHttpClient();
-        }
+        SslContextFactory sslContextFactory = (ssl != null) ? createSslContextFactory(ssl)
: null;
+        CamelHttpClient httpClient = createCamelHttpClient(sslContextFactory);
         
         CamelContext context = endpoint.getCamelContext();
 
@@ -843,6 +841,8 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
         return httpClient;
     }
 
+    protected abstract CamelHttpClient createCamelHttpClient(SslContextFactory sslContextFactory);
+
     public Integer getHttpClientMinThreads() {
         return httpClientMinThreads;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent8.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent8.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent8.java
new file mode 100644
index 0000000..c144d1a
--- /dev/null
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent8.java
@@ -0,0 +1,11 @@
+package org.apache.camel.component.jetty;
+
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+
+public class JettyHttpComponent8 extends JettyHttpComponent {
+
+    protected CamelHttpClient createCamelHttpClient(SslContextFactory sslContextFactory)
{
+        return new CamelHttpClient8(sslContextFactory);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent9.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent9.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent9.java
new file mode 100644
index 0000000..f8d256d
--- /dev/null
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent9.java
@@ -0,0 +1,11 @@
+package org.apache.camel.component.jetty;
+
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+
+public class JettyHttpComponent9 extends JettyHttpComponent {
+
+    protected CamelHttpClient createCamelHttpClient(SslContextFactory sslContextFactory)
{
+        return new CamelHttpClient9(sslContextFactory);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
index 8384a02..ab2bb20 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
@@ -120,7 +120,7 @@ public class JettyHttpProducer extends DefaultProducer implements AsyncProcessor
         HttpMethods methodToUse = HttpHelper.createMethod(exchange, getEndpoint(), exchange.getIn().getBody()
!= null);
         String method = methodToUse.createMethod(url).getName();
 
-        JettyContentExchange httpExchange = new JettyContentExchange(exchange, getBinding(),
client);
+        JettyContentExchange httpExchange = new JettyContentExchange9(exchange, getBinding(),
client);
         httpExchange.setURL(url); // Url has to be set first
         httpExchange.setMethod(method);
         

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/main/resources/META-INF/services/org/apache/camel/component/jetty
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/resources/META-INF/services/org/apache/camel/component/jetty
b/components/camel-jetty/src/main/resources/META-INF/services/org/apache/camel/component/jetty
index 99a15df..e0d1a23 100644
--- a/components/camel-jetty/src/main/resources/META-INF/services/org/apache/camel/component/jetty
+++ b/components/camel-jetty/src/main/resources/META-INF/services/org/apache/camel/component/jetty
@@ -14,4 +14,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-class=org.apache.camel.component.jetty.JettyHttpComponent
\ No newline at end of file
+class=org.apache.camel.component.jetty.JettyHttpComponent9
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.xml
b/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.xml
index 3e6bc99..2235752 100644
--- a/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.xml
+++ b/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.xml
@@ -22,7 +22,7 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-	<bean id="jetty2" class="org.apache.camel.component.jetty.JettyHttpComponent">
+	<bean id="jetty2" class="org.apache.camel.component.jetty.JettyHttpComponent9">
 		<property name="enableJmx" value="true"/>
 		<property name="minThreads" value="10"/>
 		<property name="maxThreads" value="50"/>

http://git-wip-us.apache.org/repos/asf/camel/blob/95b16c53/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
b/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
index 763c0e8..ace8d82 100644
--- a/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
+++ b/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
@@ -21,7 +21,7 @@
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
-    <bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent">
+    <bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent9">
         <property name="sslPassword" value="changeit"/>
         <property name="sslKeyPassword" value="changeit"/>
         <property name="keystore" value="src/test/resources/jsse/localhost.ks"/>


Mime
View raw message