You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2007/06/09 06:02:37 UTC

svn commit: r545689 - in /incubator/cxf/trunk/rt/transports/http-jetty/src: main/java/org/apache/cxf/transport/http_jetty/ test/java/org/apache/cxf/transport/http_jetty/ test/java/org/apache/cxf/transport/http_jetty/spring/

Author: ningjiang
Date: Fri Jun  8 21:02:36 2007
New Revision: 545689

URL: http://svn.apache.org/viewvc?view=rev&rev=545689
Log:
CXF-718 applied polar's patch for forcing the JettyHTTPTransportFactory to create a JettyHTTPServerEnginFactory

Added:
    incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java   (with props)
    incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory.cxf   (with props)
Modified:
    incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPTransportFactory.java
    incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
    incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/ApplicationContextTest.java

Modified: incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPTransportFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPTransportFactory.java?view=diff&rev=545689&r1=545688&r2=545689
==============================================================================
--- incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPTransportFactory.java (original)
+++ incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPTransportFactory.java Fri Jun  8 21:02:36 2007
@@ -34,12 +34,6 @@
 
 public class JettyHTTPTransportFactory extends AbstractHTTPTransportFactory {
 
-    /**
-     * This field contains the JettyHTTPServerEngineFactory.
-     * It holds a cache of engines that may be used for particular ports.
-     */
-    protected JettyHTTPServerEngineFactory serverEngineFactory;
-    
     private Map<String, JettyHTTPDestination> destinations = 
         new HashMap<String, JettyHTTPDestination>();
     
@@ -54,18 +48,24 @@
 
     @PostConstruct
     public void finalizeConfig() {
-        // empty
+        // This call will register the server engine factory
+        // with the Bus.
+        getJettyHTTPServerEngineFactory();
     }
     
     /**
      * This method returns the Jetty HTTP Server Engine Factory.
      */
     protected JettyHTTPServerEngineFactory getJettyHTTPServerEngineFactory() {
-        if (this.serverEngineFactory == null) {
-            serverEngineFactory =
+        // We have got to *always* get this off the bus, because it may have 
+        // been overridden by Spring Configuration initially.
+        // Spring Configuration puts it on the correct bus.
+        JettyHTTPServerEngineFactory serverEngineFactory =
                 getBus().getExtension(JettyHTTPServerEngineFactory.class);
-        }
-        if (this.serverEngineFactory == null) {
+        // If it's not there, then create it and register it.
+        // Spring may override it later, but we need it here for default
+        // with no spring configuration.
+        if (serverEngineFactory == null) {
             serverEngineFactory = new JettyHTTPServerEngineFactory();
             serverEngineFactory.setBus(getBus());
             serverEngineFactory.finalizeConfig();

Modified: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java?view=diff&rev=545689&r1=545688&r2=545689
==============================================================================
--- incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java (original)
+++ incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java Fri Jun  8 21:02:36 2007
@@ -424,6 +424,7 @@
         
 
         transportFactory = new JettyHTTPTransportFactory() {
+            JettyHTTPServerEngineFactory serverEngineFactory;
             @Override
             public JettyHTTPServerEngineFactory getJettyHTTPServerEngineFactory() {
                 if (serverEngineFactory == null) {

Added: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java?view=auto&rev=545689
==============================================================================
--- incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java (added)
+++ incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java Fri Jun  8 21:02:36 2007
@@ -0,0 +1,127 @@
+/**
+ * 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.cxf.transport.http_jetty;
+
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusException;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.transport.DestinationFactory;
+import org.apache.cxf.transport.DestinationFactoryManager;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+
+public class JettyHTTPServerEngineFactoryTest
+        extends Assert {
+    Bus bus;
+    
+    @BeforeClass
+    public static void classUp() {
+        // Get rid of any notion of a default bus set by other 
+        // rogue tests.
+        BusFactory.setDefaultBus(null);
+    }
+    
+    @AfterClass
+    public static void classDown() {
+        // Clean up.
+        BusFactory.setDefaultBus(null);
+    }
+    
+    @After
+    public void tearDown() {
+        if (bus != null) {
+            bus.shutdown(false);
+            bus = null;
+        }
+    }
+    
+    /**
+     * This test makes sure that a default Spring initialized bus will 
+     * have the JettyHTTPServerEngineFactory (absent of <httpj:engine-factory>
+     * configuration.
+     */
+    @Test
+    public void testMakeSureTransportFactoryHasEngineFactory() {
+        bus = BusFactory.getDefaultBus(true);
+        
+        assertNotNull("Cannot get bus", bus);
+        
+        try {
+            // Make sure we got the Transport Factory.
+            DestinationFactoryManager destFM = 
+                bus.getExtension(DestinationFactoryManager.class);
+            assertNotNull("Cannot get DestinationFactoryManager", destFM);
+            DestinationFactory destF = 
+                destFM.getDestinationFactory(
+                        "http://schemas.xmlsoap.org/soap/http");
+            assertNotNull("No DestinationFactory", destF);
+            assertTrue(JettyHTTPTransportFactory.class.isInstance(destF));
+        } catch (BusException e) {
+            fail("Asserting Transport Factory" + e);
+        }
+        // And the JettyHTTPServerEngineFactory should be there.
+        JettyHTTPServerEngineFactory factory =
+            bus.getExtension(JettyHTTPServerEngineFactory.class);
+        assertNotNull("EngineFactory is not configured.", factory);
+    }
+    
+    /**
+     * This test makes sure that with a <httpj:engine-factory bus="cxf">
+     * that the bus is configured with the rightly configured Jetty
+     * HTTP Server Engine Factory.  Port 1234 should have be configured
+     * for TLS.
+     */
+    @Test
+    public void testMakeSureTransportFactoryHasEngineFactoryConfigured() {
+        
+        // This file configures the factory to configure
+        // port 1234 with default TLS.
+        
+        URL config = getClass().getResource("server-engine-factory.cxf");
+        
+        bus = new SpringBusFactory().createBus(config, true);
+        
+        JettyHTTPServerEngineFactory factory =
+            bus.getExtension(JettyHTTPServerEngineFactory.class);
+        
+        assertNotNull("EngineFactory is not configured.", factory);
+        
+        // The Engine for port 1234 should be configured for TLS.
+        // This will throw an error if it is not.
+        JettyHTTPServerEngine engine = null;
+        try {
+            engine = factory.createJettyHTTPSServerEngine(1234);
+        } catch (Exception e) {
+            fail("Error getting factory" + e);
+        }
+        assertNotNull("Engine is not available.", engine);
+        assertEquals(1234, engine.getPort());
+        assertEquals("Not https", "https", engine.getProtocol());
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory.cxf
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory.cxf?view=auto&rev=545689
==============================================================================
--- incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory.cxf (added)
+++ incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory.cxf Fri Jun  8 21:02:36 2007
@@ -0,0 +1,49 @@
+<?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-2.0.xsd">
+
+  
+  <httpj:engine-factory bus="cxf">
+	 <httpj:engine port="1234">
+	     <httpj:tlsServerParameters>
+	         <sec:clientAuthentication want="true" required="true"/>
+	    </httpj:tlsServerParameters>
+	  </httpj:engine>
+   </httpj:engine-factory>
+  
+   <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl">
+   </bean> 
+
+</beans>

Propchange: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory.cxf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory.cxf
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/server-engine-factory.cxf
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/ApplicationContextTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/ApplicationContextTest.java?view=diff&rev=545689&r1=545688&r2=545689
==============================================================================
--- incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/ApplicationContextTest.java (original)
+++ incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/spring/ApplicationContextTest.java Fri Jun  8 21:02:36 2007
@@ -23,6 +23,7 @@
 import org.xml.sax.SAXParseException;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.configuration.Configurer;
 import org.apache.cxf.configuration.spring.ConfigurerImpl;
 import org.apache.cxf.service.model.EndpointInfo;
@@ -35,7 +36,9 @@
 import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.cxf.transport.http_jetty.JettyHTTPDestination;
 import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine;
+import org.junit.AfterClass;
 import org.junit.Assert;
+import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
@@ -49,6 +52,16 @@
         ApplicationContextTest.class.getResource("/META-INF/cxf/cxf-extension-http.xml").toString();
     private static final String S3 = 
         ApplicationContextTest.class.getResource("/META-INF/cxf/cxf-extension-http-jetty.xml").toString();
+    
+    @BeforeClass
+    public static void classUp() {
+        BusFactory.setDefaultBus(null);
+    }
+    
+    @AfterClass
+    public static void classDown() {
+        BusFactory.setDefaultBus(null);
+    }
     
     @Ignore
     @Test