Author: dkulp Date: Thu Oct 15 17:43:27 2009 New Revision: 825584 URL: http://svn.apache.org/viewvc?rev=825584&view=rev Log: Merged revisions 825581 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.2.x-fixes
................ r825581 | dkulp | 2009-10-15 13:36:40 -0400 (Thu, 15 Oct 2009) | 10 lines Merged revisions 825579 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r825579 | dkulp | 2009-10-15 13:32:57 -0400 (Thu, 15 Oct 2009) | 2 lines [CXF-2437] Allow jetty to bind to particular host Patch from Didier Gutacker applied. ........ ................ Modified: cxf/branches/2.1.x-fixes/ (props changed) cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyConnectorFactory.java cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/resources/schemas/configuration/http-jetty.xsd Propchange: cxf/branches/2.1.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyConnectorFactory.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyConnectorFactory.java?rev=825584&r1=825583&r2=825584&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyConnectorFactory.java (original) +++ cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyConnectorFactory.java Thu Oct 15 17:43:27 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/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java?rev=825584&r1=825583&r2=825584&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java (original) +++ cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java Thu Oct 15 17:43:27 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/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java?rev=825584&r1=825583&r2=825584&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java (original) +++ cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java Thu Oct 15 17:43:27 2009 @@ -84,6 +84,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". */ @@ -124,9 +129,11 @@ public JettyHTTPServerEngine( JettyHTTPServerEngineFactory fac, Bus bus, + String host, int port) { this.bus = bus; this.factory = fac; + this.host = host; this.port = port; } @@ -141,6 +148,10 @@ public void setPort(int p) { port = p; } + + public void setHost(String host) { + this.host = host; + } public void setContinuationsEnabled(boolean enabled) { continuationsEnabled = enabled; @@ -179,6 +190,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 @@ -279,7 +297,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) { @@ -503,16 +528,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/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java?rev=825584&r1=825583&r2=825584&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java (original) +++ cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java Thu Oct 15 17:43:27 2009 @@ -165,12 +165,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) { @@ -178,7 +181,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(); @@ -189,8 +192,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. @@ -208,13 +219,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(); } @@ -240,6 +259,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/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java?rev=825584&r1=825583&r2=825584&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java (original) +++ cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java Thu Oct 15 17:43:27 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/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java?rev=825584&r1=825583&r2=825584&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java (original) +++ cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/https_jetty/JettySslConnectorFactory.java Thu Oct 15 17:43:27 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/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/resources/schemas/configuration/http-jetty.xsd URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/resources/schemas/configuration/http-jetty.xsd?rev=825584&r1=825583&r2=825584&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/resources/schemas/configuration/http-jetty.xsd (original) +++ cxf/branches/2.1.x-fixes/rt/transports/http-jetty/src/main/resources/schemas/configuration/http-jetty.xsd Thu Oct 15 17:43:27 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
