cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [4/4] git commit: JettyHTTPDestination works with both Jetty 8 and Jetty 9
Date Tue, 05 Aug 2014 17:53:43 GMT
JettyHTTPDestination works with both Jetty 8 and Jetty 9


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/88adfaf2
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/88adfaf2
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/88adfaf2

Branch: refs/heads/master
Commit: 88adfaf2ad97b4968b0dc47194b29c717b138d7a
Parents: 944eb0b
Author: Daniel Kulp <dkulp@apache.org>
Authored: Tue Aug 5 13:12:08 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Tue Aug 5 13:12:08 2014 -0400

----------------------------------------------------------------------
 .../http_jetty/JettyHTTPDestination.java        | 53 +++++++++++++++-----
 1 file changed, 41 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/88adfaf2/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
index 3907b26..eef3492 100644
--- a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
+++ b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
@@ -23,6 +23,7 @@ import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.GeneralSecurityException;
@@ -51,8 +52,7 @@ import org.apache.cxf.transport.http.DestinationRegistry;
 import org.apache.cxf.transport.http_jetty.continuations.JettyContinuationProvider;
 import org.apache.cxf.transport.https.CertConstraintsJaxBUtils;
 import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
-import org.eclipse.jetty.server.AbstractHttpConnection;
-import org.eclipse.jetty.server.AbstractHttpConnection.Output;
+import org.eclipse.jetty.server.HttpOutput;
 import org.eclipse.jetty.server.Request;
 
 
@@ -261,8 +261,8 @@ public class JettyHTTPDestination extends AbstractHTTPDestination {
     
     private OutputStream wrapOutput(OutputStream out) {
         try {
-            if (out instanceof Output) {
-                out = new JettyOutputStream((Output)out);
+            if (out instanceof HttpOutput) {
+                out = new JettyOutputStream((HttpOutput)out);
             }
         } catch (Throwable t) {
             //ignore
@@ -272,20 +272,36 @@ public class JettyHTTPDestination extends AbstractHTTPDestination {
     
     
     static class JettyOutputStream extends FilterOutputStream implements CopyingOutputStream
{
-        final Output out;
+        final HttpOutput out;
         boolean written;
-        public JettyOutputStream(Output o) {
+        public JettyOutputStream(HttpOutput o) {
             super(o);
             out = o;
         }
 
+        private boolean sendContent(Class<?> type, InputStream c) throws IOException
{
+            try {
+                out.getClass().getMethod("sendContent", type).invoke(out, c);
+            } catch (InvocationTargetException ioe) {
+                if (ioe.getTargetException() instanceof IOException) {
+                    throw (IOException)ioe.getTargetException();
+                }
+                return false;
+            } catch (Exception e) {
+                return false;
+            }
+            return true;
+        }
         @Override
         public int copyFrom(InputStream in) throws IOException {
             if (written) {
                 return IOUtils.copy(in, out);
             }
             CountingInputStream c = new CountingInputStream(in);
-            out.sendContent(c);
+            if (!sendContent(InputStream.class, c)
+                && !sendContent(Object.class, c)) {
+                IOUtils.copy(c, out);
+            }
             return c.getCount();
         }
         public void write(int b) throws IOException {
@@ -356,11 +372,24 @@ public class JettyHTTPDestination extends AbstractHTTPDestination {
         }
     }
     
-    private AbstractHttpConnection getCurrentConnection() {
-        return AbstractHttpConnection.getCurrentConnection();
-    }
     private Request getCurrentRequest() {
-        AbstractHttpConnection con = getCurrentConnection();
-        return con.getRequest();
+        try {
+            //Jetty 8
+            Object con = ClassLoaderUtils.loadClass("org.eclipse.jetty.server.AbstractHttpConnection",
+                                                    getClass()).getMethod("getCurrentConnection").invoke(null);
+            return (Request)con.getClass().getMethod("getRequest").invoke(con);
+        } catch (Throwable t) {
+            //
+        }
+        try {
+            //Jetty 9
+            Object con = ClassLoaderUtils.loadClass("org.eclipse.jetty.server.HttpConnection",
+                                                    getClass()).getMethod("getCurrentConnection").invoke(null);
+            Object channel = con.getClass().getMethod("getHttpChannel").invoke(con);
+            return (Request)channel.getClass().getMethod("getRequest").invoke(channel);
+        } catch (Throwable t) {
+            //
+        }
+        return null;
     }
 }


Mime
View raw message