cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1300261 - in /cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport: http_jetty/JettyHTTPDestination.java https_jetty/CXFJettySslSocketConnector.java https_jetty/JettySslConnectorFactory.java
Date Tue, 13 Mar 2012 18:04:06 GMT
Author: dkulp
Date: Tue Mar 13 18:04:05 2012
New Revision: 1300261

URL: http://svn.apache.org/viewvc?rev=1300261&view=rev
Log:
Use some reflection magic to allow code compiled with Jetty 7.5 to work
with Jetty 7.6

Modified:
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/CXFJettySslSocketConnector.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java?rev=1300261&r1=1300260&r2=1300261&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
Tue Mar 13 18:04:05 2012
@@ -34,6 +34,7 @@ import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.configuration.jsse.TLSServerParameters;
 import org.apache.cxf.configuration.security.CertificateConstraintsType;
 import org.apache.cxf.continuations.ContinuationProvider;
@@ -52,7 +53,9 @@ import org.apache.cxf.transport.https.Ce
 import org.apache.cxf.transports.http.QueryHandler;
 import org.apache.cxf.transports.http.QueryHandlerRegistry;
 import org.apache.cxf.transports.http.StemMatchingQueryHandler;
-import org.eclipse.jetty.server.HttpConnection;
+import org.eclipse.jetty.io.AbstractConnection;
+import org.eclipse.jetty.server.AsyncHttpConnection;
+import org.eclipse.jetty.server.BlockingHttpConnection;
 import org.eclipse.jetty.server.Request;
 
 public class JettyHTTPDestination extends AbstractHTTPDestination {
@@ -211,6 +214,15 @@ public class JettyHTTPDestination extend
                              HttpServletResponse resp) throws IOException {
         doService(servletContext, req, resp);
     }
+    
+    static AbstractConnection getConnectionForRequest(Request r) {
+        try {
+            return (AbstractConnection)r.getClass().getMethod("getConnection").invoke(r);
+        } catch (Exception ex) {
+            return null;
+        }
+    }
+    
     protected void doService(ServletContext context,
                              HttpServletRequest req,
                              HttpServletResponse resp) throws IOException {
@@ -218,14 +230,18 @@ public class JettyHTTPDestination extend
             context = servletContext;
         }
         Request baseRequest = (req instanceof Request) 
-            ? (Request)req : HttpConnection.getCurrentConnection().getRequest();
+            ? (Request)req : getCurrentRequest();
             
         if (!"HEAD".equals(req.getMethod())) {
             //bug in Jetty with persistent connections that if a HEAD is
             //sent, a _head flag is never reset
-            HttpConnection c = baseRequest.getConnection();
+            AbstractConnection c = getConnectionForRequest(baseRequest);
             if (c != null) {
-                c.getGenerator().setHead(false);
+                if (c instanceof AsyncHttpConnection) {
+                    ((AsyncHttpConnection)c).getGenerator().setHead(false);
+                } else if (c instanceof BlockingHttpConnection) {
+                    ((BlockingHttpConnection)c).getGenerator().setHead(false);
+                }
             }
         }
         if (getServer().isSetRedirectURL()) {
@@ -300,7 +316,7 @@ public class JettyHTTPDestination extend
                                   final HttpServletResponse resp)
         throws IOException {
         Request baseRequest = (req instanceof Request) 
-            ? (Request)req : HttpConnection.getCurrentConnection().getRequest();
+            ? (Request)req : getCurrentRequest();
         
         if (LOG.isLoggable(Level.FINE)) {
             LOG.fine("Service http request on thread: " + Thread.currentThread());
@@ -363,4 +379,25 @@ public class JettyHTTPDestination extend
                       new JettyContinuationProvider(req, resp, inMessage));
         }
     }
+    
+    private AbstractConnection getCurrentConnection() {
+        Class<?> cls = AsyncHttpConnection.class.getSuperclass();
+        // AbstractHttpConnection on Jetty 7.6, HttpConnection on Jetty <=7.5
+        try {
+            return (AbstractConnection)ReflectionUtil
+                .setAccessible(cls.getMethod("getCurrentConnection")).invoke(null);
+        } catch (Exception e) {
+            //ignore
+        }
+        return null;
+    }
+    private Request getCurrentRequest() {
+        AbstractConnection con = getCurrentConnection();
+        if (con instanceof AsyncHttpConnection) {
+            return ((AsyncHttpConnection)con).getRequest();
+        } else if (con instanceof BlockingHttpConnection) {
+            return ((BlockingHttpConnection)con).getRequest();
+        }
+        return null;
+    }
 }

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/CXFJettySslSocketConnector.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/CXFJettySslSocketConnector.java?rev=1300261&r1=1300260&r2=1300261&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/CXFJettySslSocketConnector.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/CXFJettySslSocketConnector.java
Tue Mar 13 18:04:05 2012
@@ -28,6 +28,7 @@ import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ReflectionInvokationHandler;
 import org.apache.cxf.configuration.security.ClientAuthentication;
 import org.apache.cxf.configuration.security.FiltersType;
 import org.apache.cxf.transport.https.SSLUtils;
@@ -87,31 +88,31 @@ public class CXFJettySslSocketConnector 
      * configures an HTTP Destination.
      */
     protected void setClientAuthentication(ClientAuthentication clientAuth) {
-        getSslContextFactory().setWantClientAuth(true);
+        getCxfSslContextFactory().setWantClientAuth(true);
         if (clientAuth != null) {
             if (clientAuth.isSetWant()) {
-                getSslContextFactory().setWantClientAuth(clientAuth.isWant());
+                getCxfSslContextFactory().setWantClientAuth(clientAuth.isWant());
             }
             if (clientAuth.isSetRequired()) {
-                getSslContextFactory().setNeedClientAuth(clientAuth.isRequired());
+                getCxfSslContextFactory().setNeedClientAuth(clientAuth.isRequired());
             }
         }
     }
     
     protected void doStart() throws Exception {
         // setup the create SSLContext on the SSLContextFactory
-        getSslContextFactory().setSslContext(createSSLContext());
+        getCxfSslContextFactory().setSslContext(createSSLContext());
         super.doStart();
     }
     
     protected SSLContext createSSLContext() throws Exception  {
-        String proto = getSslContextFactory().getProtocol() == null
+        String proto = getCxfSslContextFactory().getProtocol() == null
             ? "TLS"
-                : getSslContextFactory().getProtocol();
+                : getCxfSslContextFactory().getProtocol();
  
-        SSLContext context = getSslContextFactory().getProvider() == null
+        SSLContext context = getCxfSslContextFactory().getProvider() == null
             ? SSLContext.getInstance(proto)
-                : SSLContext.getInstance(proto, getSslContextFactory().getProvider());
+                : SSLContext.getInstance(proto, getCxfSslContextFactory().getProvider());
             
         context.init(keyManagers, trustManagers, secureRandom);
 
@@ -122,8 +123,38 @@ public class CXFJettySslSocketConnector 
                     cipherSuitesFilter,
                     LOG, true);
         
-        getSslContextFactory().setExcludeCipherSuites(cs);
+        getCxfSslContextFactory().setExcludeCipherSuites(cs);
         
         return context;
     }
+    
+    public CxfSslContextFactory getCxfSslContextFactory() {
+        try {
+            Object o = getClass().getMethod("getSslContextFactory").invoke(this);
+            return ReflectionInvokationHandler.createProxyWrapper(o, CxfSslContextFactory.class);
+        } catch (Exception e) {
+            //ignore, the NPE is fine
+        }
+        
+        return null;
+    }
+    
+    interface CxfSslContextFactory {
+        void setExcludeCipherSuites(String ... cs);
+
+        String getProtocol();
+        
+        String getProvider();
+        
+        void setSslContext(SSLContext createSSLContext);
+
+        void setNeedClientAuth(boolean required);
+
+        void setWantClientAuth(boolean want);
+
+        void setProtocol(String secureSocketProtocol);
+
+        void setProvider(String jsseProvider);
+    }
+    
 }

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java?rev=1300261&r1=1300260&r2=1300261&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java
Tue Mar 13 18:04:05 2012
@@ -83,10 +83,11 @@ public final class JettySslConnectorFact
         con.setSecureRandom(tlsServerParameters.getSecureRandom());
         con.setClientAuthentication(
                 tlsServerParameters.getClientAuthentication());
-        con.getSslContextFactory().setProtocol(tlsServerParameters.getSecureSocketProtocol());
-        con.getSslContextFactory().setProvider(tlsServerParameters.getJsseProvider());
+        con.getCxfSslContextFactory().setProtocol(tlsServerParameters.getSecureSocketProtocol());
+        con.getCxfSslContextFactory().setProvider(tlsServerParameters.getJsseProvider());
         con.setCipherSuites(tlsServerParameters.getCipherSuites());
         con.setCipherSuitesFilter(tlsServerParameters.getCipherSuitesFilter());
     }
-    
+
+
 }



Mime
View raw message