cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [2/2] cxf git commit: Start working on trying to support Jetty 9.3.15+
Date Mon, 06 Mar 2017 20:57:59 GMT
Start working on trying to support Jetty 9.3.15+


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

Branch: refs/heads/master
Commit: 09fb22b25333c66514f06652ceaf7fc11bde51cc
Parents: 821d8c7
Author: Daniel Kulp <dkulp@apache.org>
Authored: Mon Mar 6 15:53:42 2017 -0500
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Mon Mar 6 15:57:40 2017 -0500

----------------------------------------------------------------------
 .../jetty9/Jetty9WebSocketDestination.java      | 26 ++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/09fb22b2/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty9/Jetty9WebSocketDestination.java
----------------------------------------------------------------------
diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty9/Jetty9WebSocketDestination.java
b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty9/Jetty9WebSocketDestination.java
index 106525c..1b49d95 100644
--- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty9/Jetty9WebSocketDestination.java
+++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty9/Jetty9WebSocketDestination.java
@@ -23,6 +23,8 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.net.URL;
 import java.nio.ByteBuffer;
 import java.security.Principal;
@@ -43,6 +45,7 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.http.DestinationRegistry;
 import org.apache.cxf.transport.http_jetty.JettyHTTPDestination;
@@ -56,8 +59,10 @@ import org.apache.cxf.transport.websocket.jetty.WebSocketVirtualServletRequest;
 import org.apache.cxf.transport.websocket.jetty.WebSocketVirtualServletResponse;
 import org.apache.cxf.workqueue.WorkQueueManager;
 import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.handler.ContextHandler;
 import org.eclipse.jetty.websocket.api.Session;
 import org.eclipse.jetty.websocket.api.WebSocketAdapter;
+import org.eclipse.jetty.websocket.api.WebSocketPolicy;
 import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
 import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
 import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
@@ -88,7 +93,16 @@ public class Jetty9WebSocketDestination extends JettyHTTPDestination implements
                            WebSocketServletFactory.class).newInstance();
 
         } catch (InstantiationException | IllegalAccessException | ClassNotFoundException
e) {
-            throw new RuntimeException(e);
+            try {
+                //jetty >9.3.14 - yes.. they change API's in a patch release
+                Method m = ReflectionUtil.getDeclaredMethod(WebSocketServletFactory.Loader.class,
"load", 
+                                                                ServletContext.class, WebSocketPolicy.class);
+                ReflectionUtil.setAccessible(m);
+                webSocketFactory = (WebSocketServletFactory)m.invoke(null, new ContextHandler.StaticContext(),
null);
+            } catch (NoSuchMethodException | IllegalAccessException 
+                | IllegalArgumentException | InvocationTargetException e2) {
+                throw new RuntimeException(e);
+            }            
         }
         webSocketFactory.setCreator(new Creator());
 
@@ -138,7 +152,15 @@ public class Jetty9WebSocketDestination extends JettyHTTPDestination
implements
     @Override
     public void shutdown() {
         try {
-            webSocketFactory.cleanup();
+            Method m;
+            try {
+                //jetty <9.3.14
+                m = ReflectionUtil.getDeclaredMethod(webSocketFactory.getClass(), "cleanup");
+            } catch (Throwable t) {
+                //jetty >= 9.3.14
+                m = ReflectionUtil.getDeclaredMethod(webSocketFactory.getClass(), "stop");
+            }
+            m.invoke(webSocketFactory);
         } catch (Exception e) {
             // ignore
         } finally {


Mime
View raw message