cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject [1/2] cxf git commit: [CXF-7179]Unable to set ServerConnector in JettyHTTPServerEngine using jetty 9
Date Tue, 24 Jan 2017 05:20:06 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 57fcf8df2 -> f8cec430e


[CXF-7179]Unable to set ServerConnector in JettyHTTPServerEngine using jetty 9


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

Branch: refs/heads/master
Commit: c87613b800a5b2de25d861c3c74a0fb7dcf60862
Parents: dd81c1e
Author: Freeman Fang <freeman.fang@gmail.com>
Authored: Tue Jan 24 13:18:35 2017 +0800
Committer: Freeman Fang <freeman.fang@gmail.com>
Committed: Tue Jan 24 13:18:35 2017 +0800

----------------------------------------------------------------------
 .../http_jetty/JettyHTTPServerEngine.java       | 10 ++++-
 .../JettyHTTPServerEngineFactoryTest.java       | 36 ++++++++++++++-
 .../http_jetty/JettyHTTPServerEngineTest.java   | 43 ++++++++++++++++++
 .../server-engine-factory-jetty9-connector.xml  | 46 ++++++++++++++++++++
 4 files changed, 133 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c87613b8/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
index 8bcbbac..b37b90d 100644
--- a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
+++ b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
@@ -254,6 +254,7 @@ public class JettyHTTPServerEngine implements ServerEngine {
         return server;
     }
     
+        
     /**
      * Set the jetty server instance 
      * @param s 
@@ -332,9 +333,16 @@ public class JettyHTTPServerEngine implements ServerEngine {
     
     private Server createServer() {
         Server s = null;
+        if (connector != null && connector.getServer() != null) {
+            s = connector.getServer();
+        }
         if (threadPool != null) {
             try {
-                s = new Server(threadPool);
+                if (s == null) {
+                    s = new Server(threadPool);
+                } else {
+                    s.addBean(threadPool);
+                }
             } catch (Exception e) {
                 //ignore
             }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c87613b8/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java
b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java
index 170ea61..4e4826a 100644
--- a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java
+++ b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java
@@ -19,7 +19,7 @@
 package org.apache.cxf.transport.http_jetty;
 
 import java.net.URL;
-
+import java.util.Collection;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -27,6 +27,10 @@ import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.transport.DestinationFactory;
 import org.apache.cxf.transport.DestinationFactoryManager;
 import org.apache.cxf.transport.http.HTTPTransportFactory;
+import org.eclipse.jetty.server.ConnectionFactory;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.HttpConfiguration;
+import org.eclipse.jetty.server.HttpConnectionFactory;
 
 import org.junit.After;
 import org.junit.AfterClass;
@@ -127,6 +131,36 @@ public class JettyHTTPServerEngineFactoryTest
     }
     
     @Test
+    public void testMakeSureJetty9ConnectorConfigured() throws Exception {
+        
+               
+        URL config = getClass().getResource("server-engine-factory-jetty9-connector.xml");
+        
+        bus = new SpringBusFactory().createBus(config, true);
+        
+        JettyHTTPServerEngineFactory factory =
+            bus.getExtension(JettyHTTPServerEngineFactory.class);
+        
+        assertNotNull("EngineFactory is not configured.", factory);
+        
+        JettyHTTPServerEngine engine = null;
+        engine = factory.createJettyHTTPServerEngine(1234, "http");
+        
+        assertNotNull("Engine is not available.", engine);
+        assertEquals(1234, engine.getPort());
+        assertEquals("Not http", "http", engine.getProtocol());
+        Connector connector = engine.getConnector();
+        Collection<ConnectionFactory> connectionFactories = connector.getConnectionFactories();

+        assertEquals("Has one HttpConnectionFactory", 1, connectionFactories.size());
+        ConnectionFactory connectionFactory = connectionFactories.iterator().next();
+        assertTrue(connectionFactory instanceof HttpConnectionFactory);
+        HttpConfiguration httpConfiguration = ((HttpConnectionFactory)connectionFactory).getHttpConfiguration();
+        assertEquals("Has one ForwardedRequestCustomizer", 1, httpConfiguration.getCustomizers().size());
+        assertTrue(httpConfiguration.getCustomizers().iterator().next() 
+                   instanceof org.eclipse.jetty.server.ForwardedRequestCustomizer);
+    }
+    
+    @Test
     public void testAnInvalidConfiguresfile() {
         
         // This file configures the factory to configure

http://git-wip-us.apache.org/repos/asf/cxf/blob/c87613b8/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineTest.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineTest.java
b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineTest.java
index 778c77b..257bc24 100644
--- a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineTest.java
+++ b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineTest.java
@@ -28,6 +28,7 @@ import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -44,8 +45,13 @@ import org.apache.cxf.management.InstrumentationManager;
 import org.apache.cxf.testutil.common.TestUtil;
 import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
+import org.eclipse.jetty.server.ConnectionFactory;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.HttpConfiguration;
+import org.eclipse.jetty.server.HttpConnectionFactory;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.server.handler.ContextHandler;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
 import org.eclipse.jetty.util.thread.ThreadPool;
@@ -60,6 +66,8 @@ public class JettyHTTPServerEngineTest extends Assert {
         = Integer.valueOf(TestUtil.getPortNumber(JettyHTTPServerEngineTest.class, 2));
     private static final int PORT3 
         = Integer.valueOf(TestUtil.getPortNumber(JettyHTTPServerEngineTest.class, 3));
+    private static final int PORT4 
+        = Integer.valueOf(TestUtil.getPortNumber(JettyHTTPServerEngineTest.class, 4));
     
 
     private Bus bus;
@@ -407,6 +415,41 @@ public class JettyHTTPServerEngineTest extends Assert {
 
         JettyHTTPServerEngineFactory.destroyForPort(PORT3);
     }
+    
+    @Test
+    public void testSetConnector() throws Exception {
+        URL url = new URL("http://localhost:" + PORT4 + "/hello/test");
+        JettyHTTPTestHandler handler1 = new JettyHTTPTestHandler("string1", true);
+        JettyHTTPTestHandler handler2 = new JettyHTTPTestHandler("string2", true);
+
+        JettyHTTPServerEngine engine = new JettyHTTPServerEngine();
+        engine.setPort(PORT4);
+        Server server = new Server();
+        ServerConnector connector = new ServerConnector(server); 
+        connector.setPort(PORT4);
+        HttpConfiguration httpConfig = new HttpConfiguration();
+        httpConfig.addCustomizer(new org.eclipse.jetty.server.ForwardedRequestCustomizer());
+        HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig);
+        Collection<ConnectionFactory> connectionFactories = new ArrayList<ConnectionFactory>();
+        connectionFactories.add(httpFactory);
+        connector.setConnectionFactories(connectionFactories);
+        engine.setConnector(connector);
+        List<Handler> handlers = new ArrayList<Handler>();
+        handlers.add(handler1);
+        engine.setHandlers(handlers);
+        engine.finalizeConfig();
+
+        engine.addServant(url, handler2);
+        String response = null;
+        try {
+            response = getResponse(url.toString());
+            assertEquals("the jetty http handler1 did not take effect", response, "string1string2");
+        } catch (Exception ex) {
+            fail("Can't get the reponse from the server " + ex);
+        }
+        engine.stop();
+        JettyHTTPServerEngineFactory.destroyForPort(PORT4);
+    }
 
     private String getResponse(String target) throws Exception {
         URL url = new URL(target);

http://git-wip-us.apache.org/repos/asf/cxf/blob/c87613b8/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory-jetty9-connector.xml
----------------------------------------------------------------------
diff --git a/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory-jetty9-connector.xml
b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory-jetty9-connector.xml
new file mode 100644
index 0000000..99ac231
--- /dev/null
+++ b/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory-jetty9-connector.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xsi:schemaLocation="                    http://cxf.apache.org/configuration/security     
                 http://cxf.apache.org/schemas/configuration/security.xsd            http://cxf.apache.org/transports/http/configuration
              http://cxf.apache.org/schemas/configuration/http-conf.xsd            http://cxf.apache.org/transports/http-jetty/configuration
              http://cxf.apache.org/schemas/configuration/http-jetty.xsd            http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
+    <httpj:engine-factory bus="cxf">
+        <httpj:engine port="1234">
+            <httpj:connector>
+		<bean id="connector" class="org.eclipse.jetty.server.ServerConnector">
+                    <constructor-arg ref="server"/>
+                    <constructor-arg ref="httpConnectionFactory"/>                
   
+	            <property name="port" value="1234" />                    
+		</bean>            
+	    </httpj:connector>          
+        </httpj:engine>
+    </httpj:engine-factory>
+
+    <bean id="server" class="org.eclipse.jetty.server.Server"/>
+
+    <bean id="httpConfiguration" class="org.eclipse.jetty.server.HttpConfiguration">
+        <property name="customizers">
+            <list>
+                <bean class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/>
+            </list>
+        </property>
+    </bean>
+    
+    <bean id="httpConnectionFactory" class="org.eclipse.jetty.server.HttpConnectionFactory">
+        <constructor-arg ref="httpConfiguration"/>
+    </bean>
+</beans>


Mime
View raw message