cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r825579 - in /cxf/trunk/rt/transports/http-jetty/src/main: java/org/apache/cxf/transport/http_jetty/ java/org/apache/cxf/transport/http_jetty/spring/ java/org/apache/cxf/transport/https_jetty/ resources/schemas/configuration/
Date Thu, 15 Oct 2009 17:32:58 GMT
Author: dkulp
Date: Thu Oct 15 17:32:57 2009
New Revision: 825579

URL: http://svn.apache.org/viewvc?rev=825579&view=rev
Log:
[CXF-2437] Allow jetty to bind to particular host
Patch from   Didier Gutacker applied.

Modified:
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyConnectorFactory.java
    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/http_jetty/JettyHTTPServerEngine.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java
    cxf/trunk/rt/transports/http-jetty/src/main/resources/schemas/configuration/http-jetty.xsd

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyConnectorFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyConnectorFactory.java?rev=825579&r1=825578&r2=825579&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyConnectorFactory.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyConnectorFactory.java
Thu Oct 15 17:32:57 2009
@@ -32,4 +32,12 @@
      * @param port the listen port
      */
     AbstractConnector createConnector(int port);
+
+    /**
+     * Create a Listener.
+     * 
+     * @param host the host to bind to.  IP address or hostname is allowed. null to bind
to all hosts.
+     * @param port the listen port
+     */
+    AbstractConnector createConnector(String host, int port);
 }

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=825579&r1=825578&r2=825579&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
Thu Oct 15 17:32:57 2009
@@ -112,9 +112,9 @@
             serverEngineFactory.retrieveJettyHTTPServerEngine(nurl.getPort());
         if (engine == null) {
             engine = serverEngineFactory.
-                createJettyHTTPServerEngine(nurl.getPort(), nurl.getProtocol());
+                createJettyHTTPServerEngine(nurl.getHost(), nurl.getPort(), nurl.getProtocol());
         }
-        
+
         assert engine != null;
         
         // When configuring for "http", however, it is still possible that

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java?rev=825579&r1=825578&r2=825579&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
Thu Oct 15 17:32:57 2009
@@ -85,6 +85,11 @@
     private int port;
     
     /**
+     * This is the network address for which this engine is allocated.
+     */
+    private String host;
+
+    /**
      * This field holds the protocol for which this engine is 
      * enabled, i.e. "http" or "https".
      */
@@ -125,9 +130,11 @@
     public JettyHTTPServerEngine(
         JettyHTTPServerEngineFactory fac, 
         Bus bus,
+        String host,
         int port) {
         this.bus     = bus;
         this.factory = fac;
+        this.host    = host;
         this.port    = port;
     }
     
@@ -142,6 +149,10 @@
     public void setPort(int p) {
         port = p;
     }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
     
     public void setContinuationsEnabled(boolean enabled) {
         continuationsEnabled = enabled;
@@ -180,6 +191,13 @@
         return port;
     }
     
+    /**
+     * Returns the host for which this server engine was configured.
+     * @return
+     */
+    public String getHost() {
+        return host;
+    }
     
     /**
      * This method will shut down the server engine and
@@ -280,7 +298,14 @@
             // create a new jetty server instance if there is no server there           

             server = new Server();
             if (connector == null) {
-                connector = connectorFactory.createConnector(port);
+                connector = connectorFactory.createConnector(getHost(), getPort());
+                if (LOG.isLoggable(Level.FINER)) {
+                    LOG.finer("connector.host: " 
+                              + connector.getHost() == null 
+                                ? "null" 
+                                : "\"" + connector.getHost() + "\"");
+                    LOG.finer("connector.port: " + connector.getPort());
+                }
             } 
             server.addConnector(connector);            
             if (handlers != null && handlers.size() > 0) {
@@ -504,16 +529,22 @@
      * then it creates a TLS enabled one.
      */
     protected JettyConnectorFactory getHTTPConnectorFactory() {
-        return new JettyConnectorFactory() {                     
+        return new JettyConnectorFactory() {
             public AbstractConnector createConnector(int porto) {
+                return createConnector(null, porto);
+            }
+            public AbstractConnector createConnector(String hosto, int porto) {
                 // now we just use the SelectChannelConnector as the default connector
                 SelectChannelConnector result = 
                     new SelectChannelConnector();
                 
                 // Regardless the port has to equal the one
                 // we are configured for.
-                assert porto == port;                
-                
+                assert porto == port;
+                assert hosto == host;
+                if (hosto != null) {
+                    result.setHost(hosto);
+                }
                 result.setPort(porto);
                 return result;
             }

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java?rev=825579&r1=825578&r2=825579&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
Thu Oct 15 17:32:57 2009
@@ -156,12 +156,15 @@
      * This call sets TLSServerParameters for a JettyHTTPServerEngine
      * that will be subsequently created. It will not alter an engine
      * that has already been created for that network port.
+     * @param host       if not null, server will listen on this address/host, 
+     *                   otherwise, server will listen on all local addresses.
      * @param port       The network port number to bind to the engine.
      * @param tlsParams  The tls server parameters. Cannot be null.
      * @throws IOException 
      * @throws GeneralSecurityException 
      */
     public void setTLSServerParametersForPort(
+        String host,
         int port, 
         TLSServerParameters tlsParams) throws GeneralSecurityException, IOException {
         if (tlsParams == null) {
@@ -169,7 +172,7 @@
         }
         JettyHTTPServerEngine ref = retrieveJettyHTTPServerEngine(port);
         if (null == ref) {
-            ref = new JettyHTTPServerEngine(this, bus, port);
+            ref = new JettyHTTPServerEngine(this, bus, host, port);
             ref.setTlsServerParameters(tlsParams);
             portMap.put(port, ref);
             ref.finalizeConfig();
@@ -180,8 +183,16 @@
             ref.setTlsServerParameters(tlsParams);            
         }
     }
-            
-    
+
+    /**
+     * calls thru to {{@link #createJettyHTTPServerEngine(String, int, String)} with 'null'
for host value
+     */
+    public void setTLSServerParametersForPort(
+        int port, 
+        TLSServerParameters tlsParams) throws GeneralSecurityException, IOException {
+        setTLSServerParametersForPort(null, port, tlsParams);
+    }
+
     /**
      * This call retrieves a previously configured JettyHTTPServerEngine for the
      * given port. If none exists, this call returns null.
@@ -199,13 +210,21 @@
      * is already in use, a BindIOException will be thrown. If the 
      * engine is being Spring configured for TLS a GeneralSecurityException
      * may be thrown.
+     * 
+     * @param host if not null, server will listen on this host/address, otherwise
+     *        server will listen on all local addresses.
+     * @param port listen port for server
+     * @param protocol "http" or "https"
+     * @return
+     * @throws GeneralSecurityException
+     * @throws IOException
      */
-    public synchronized JettyHTTPServerEngine createJettyHTTPServerEngine(int port, String
protocol)
-        throws GeneralSecurityException, IOException {
+    public synchronized JettyHTTPServerEngine createJettyHTTPServerEngine(String host, int
port, 
+        String protocol) throws GeneralSecurityException, IOException {
         LOG.fine("Creating Jetty HTTP Server Engine for port " + port + ".");        
         JettyHTTPServerEngine ref = retrieveJettyHTTPServerEngine(port);
         if (null == ref) {
-            ref = new JettyHTTPServerEngine(this, bus, port);            
+            ref = new JettyHTTPServerEngine(this, bus, host, port);            
             portMap.put(port, ref);
             ref.finalizeConfig();
         } 
@@ -231,6 +250,13 @@
         return ref;
     }
 
+    /**
+     * Calls thru to {{@link #createJettyHTTPServerEngine(String, int, String)} with a 'null'
host value
+     */
+    public synchronized JettyHTTPServerEngine createJettyHTTPServerEngine(int port, 
+        String protocol) throws GeneralSecurityException, IOException {
+        return createJettyHTTPServerEngine(null, port, protocol);
+    }
     
     /**
      * This method removes the Server Engine from the port map and stops it.

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java?rev=825579&r1=825578&r2=825579&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
Thu Oct 15 17:32:57 2009
@@ -58,7 +58,12 @@
         
         String portStr = element.getAttribute("port");
         bean.addPropertyValue("port", portStr);
-               
+        
+        String hostStr = element.getAttribute("host");
+        if (hostStr != null && !"".equals(hostStr.trim())) {
+            bean.addPropertyValue("host", hostStr);
+        }
+
         String continuationsStr = element.getAttribute("continuationsEnabled");
         if (continuationsStr != null && continuationsStr.length() > 0) {
             bean.addPropertyValue("continuationsEnabled", continuationsStr);
@@ -152,8 +157,9 @@
         public SpringJettyHTTPServerEngine(
             JettyHTTPServerEngineFactory fac, 
             Bus bus,
+            String host,
             int port) {
-            super(fac, bus, port);
+            super(fac, bus, host, port);
         }
         
         public SpringJettyHTTPServerEngine() {

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=825579&r1=825578&r2=825579&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
Thu Oct 15 17:32:57 2009
@@ -35,17 +35,29 @@
     public JettySslConnectorFactory(TLSServerParameters params) {
         tlsServerParameters = params;
     }
-    
     /**
-     * Create a TLS/SSL Connector.
+     * Create a Listener.
      * 
-     * @param port The network port on which to listen.
+     * @param port the listen port
      */
     public AbstractConnector createConnector(int port) {
+        return createConnector(null, port);
+    }
+
+    /**
+     * Create a Listener.
+     * 
+     * @param host the host to bind to.  IP address or hostname is allowed. null to bind
to all hosts.
+     * @param port the listen port
+     */
+    public AbstractConnector createConnector(String host, int port) {
         assert tlsServerParameters != null;
         
         CXFJettySslSocketConnector secureConnector = 
             new CXFJettySslSocketConnector();
+        if (host != null) {
+            secureConnector.setHost(host);
+        }
         secureConnector.setPort(port);
         decorateCXFJettySslSocketConnector(secureConnector);
         return secureConnector;

Modified: cxf/trunk/rt/transports/http-jetty/src/main/resources/schemas/configuration/http-jetty.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/resources/schemas/configuration/http-jetty.xsd?rev=825579&r1=825578&r2=825579&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/resources/schemas/configuration/http-jetty.xsd
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/resources/schemas/configuration/http-jetty.xsd
Thu Oct 15 17:32:57 2009
@@ -130,6 +130,15 @@
                 set to 0 are used as the configuration for all Jetty listeners that are not
explicitly configured.</xs:documentation>
              </xs:annotation>
        </xs:attribute>
+       <xs:attribute name="host" type="xs:string">
+             <xs:annotation>
+                <xs:documentation>
+                  Specifies the listen address used by the Jetty instance.
+                  Value can be a hostname or ip address.
+                  If not specified, Jetty will listen on all local addresses.
+                </xs:documentation>
+             </xs:annotation>
+       </xs:attribute>
        <xs:attribute name="continuationsEnabled" type="xs:boolean">
            <xs:annotation>
                 <xs:documentation>Specifies if Jetty Continuations will be explicitly
supported



Mime
View raw message