Author: alessio.soldano(a)jboss.com
Date: 2010-05-07 11:42:12 -0400 (Fri, 07 May 2010)
New Revision: 12196
Added:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/AddressRewritingEndpointInfo.java
Modified:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/SoapTransportFactoryExt.java
stack/cxf/branches/jbossws-cxf-3.1.2/modules/testsuite/test-excludes-jboss510.txt
Log:
[JBPAPP-4245] Endpoint address rewrite and multiple virtual host support (merge revisions
10401,10440,10462,10464,10600)
Copied:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/AddressRewritingEndpointInfo.java
(from rev 10462,
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/AddressRewritingEndpointInfo.java)
===================================================================
---
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/AddressRewritingEndpointInfo.java
(rev 0)
+++
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/AddressRewritingEndpointInfo.java 2010-05-07
15:42:12 UTC (rev 12196)
@@ -0,0 +1,214 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.tools.common.extensions.soap.SoapAddress;
+import org.jboss.logging.Logger;
+import org.jboss.wsf.spi.management.ServerConfig;
+
+/**
+ * A custom EndpointInfo that updates the SoapAddress extension
+ * coming from the wsdl definition according to the JBossWS
+ * soap address rewrite rules.
+ *
+ * @see org.apache.cxf.binding.soap.SoapTransportFactory.SoapEndpointInfo
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 03-Aug-2009
+ *
+ */
+public class AddressRewritingEndpointInfo extends EndpointInfo
+{
+ private static Logger log = Logger.getLogger(AddressRewritingEndpointInfo.class);
+
+ private ServerConfig serverConfig;
+ SoapAddress saddress;
+
+ AddressRewritingEndpointInfo(ServiceInfo serv, String trans, ServerConfig
serverConfig)
+ {
+ super(serv, trans);
+ this.serverConfig = serverConfig;
+ }
+
+ /**
+ * This is the method responsible for both setting the EndpointInfo address and
+ * setting the soap:address in the wsdl.
+ * While the former action is straightforward, the latter is performed according
+ * to the JBossWS configuration: every time CXF updates the EndpointInfo address
+ * (which usually happens twice) this makes sure a proper address is updated in
+ * the wsdl.
+ *
+ * {@inheritDoc}
+ */
+ public void setAddress(String s)
+ {
+ String previousAddress = super.getAddress();
+ super.setAddress(s);
+ boolean setNewAddress = false;
+ if (previousAddress == null)
+ {
+ setNewAddress = true;
+ }
+ else if (isRewriteAllowed(s) && isRewriteRequired(s, previousAddress))
+ {
+ String uriScheme = getUriScheme(s);
+ //we set https if the transport guarantee is CONFIDENTIAL or the previous
address already used https
+ //(if the original wsdl soap:address uses https we can't overwrite it with
http)
+ if ("https".equalsIgnoreCase(getUriScheme(previousAddress)))
+ {
+ uriScheme = "https";
+ }
+ if (uriScheme == null)
+ {
+ uriScheme = "http";
+ }
+ //rewrite the candidate new address
+ s = rewriteSoapAddress(s, uriScheme);
+ setNewAddress = true;
+ }
+ if (setNewAddress && saddress != null)
+ {
+ log.info("Setting new service endpoint address in wsdl: " + s);
+ saddress.setLocationURI(s);
+ }
+ }
+
+ public void addExtensor(Object el)
+ {
+ super.addExtensor(el);
+ if (el instanceof SoapAddress)
+ {
+ saddress = (SoapAddress)el;
+ }
+ }
+
+ protected boolean isRewriteAllowed(String address)
+ {
+ //exclude non http addresses
+ return (address != null &&
address.trim().toLowerCase().startsWith("http"));
+ }
+
+
+ protected boolean isRewriteRequired(String address, String previousAddress)
+ {
+ //check config prop forcing address rewrite
+ if (serverConfig.isModifySOAPAddress())
+ {
+ log.debug("Rewrite required because of configuration");
+ return true;
+ }
+ //check if the previous address is not valid
+ if (isInvalidAddress(previousAddress))
+ {
+ log.debug("Rewrite required because of invalid url");
+ return true;
+ }
+ log.debug("Rewrite not required");
+ return false;
+ }
+
+ protected boolean isInvalidAddress(String address)
+ {
+ if (address == null)
+ {
+ return true;
+ }
+ String s = address.trim();
+ if (s.length() == 0 || s.contains("REPLACE_WITH_ACTUAL_URL"))
+ {
+ return true;
+ }
+ try
+ {
+ new URL(s);
+ }
+ catch (Exception e)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Rewrite the provided address according to the current server
+ * configuration and always using the specified uriScheme.
+ *
+ * @param s The source address
+ * @param uriScheme The uriScheme to use for rewrite
+ * @return The obtained address
+ */
+ protected String rewriteSoapAddress(String s, String uriScheme)
+ {
+ try
+ {
+ URL url = new URL(s);
+ String path = url.getPath();
+ String host = serverConfig.getWebServiceHost();
+ String port = "";
+ if ("https".equals(uriScheme))
+ {
+ int portNo = serverConfig.getWebServiceSecurePort();
+ if (portNo != 443)
+ {
+ port = ":" + portNo;
+ }
+ }
+ else
+ {
+ int portNo = serverConfig.getWebServicePort();
+ if (portNo != 80)
+ {
+ port = ":" + portNo;
+ }
+ }
+ String urlStr = uriScheme + "://" + host + port + path;
+ log.debug("Rewritten new candidate service endpoint address '" + s
+ "' to '" + urlStr + "'");
+ return urlStr;
+ }
+ catch (Exception e)
+ {
+ log.debug("Invalid url provided, using it without rewriting: " + s);
+ return s;
+ }
+ }
+
+ private static String getUriScheme(String address)
+ {
+ try
+ {
+ URI addrURI = new URI(address);
+ String scheme = addrURI.getScheme();
+ return scheme;
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Modified:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java
===================================================================
---
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java 2010-05-07
15:39:32 UTC (rev 12195)
+++
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java 2010-05-07
15:42:12 UTC (rev 12196)
@@ -36,13 +36,6 @@
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.binding.soap.SoapTransportFactory;
-import org.apache.cxf.configuration.Configurer;
-import org.apache.cxf.endpoint.Server;
-import org.apache.cxf.endpoint.ServerRegistry;
-import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
-import org.apache.cxf.jaxws.support.JaxWsImplementorInfo;
-import org.apache.cxf.management.InstrumentationManager;
-import org.apache.cxf.management.counters.CounterRepository;
import org.apache.cxf.resource.ResourceManager;
import org.apache.cxf.resource.ResourceResolver;
import org.apache.cxf.transport.DestinationFactoryManager;
@@ -102,7 +95,6 @@
ApplicationContext appCtx =
(ApplicationContext)svCtx.getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
Bus bus = getBus();
-
//Install our SoapTransportFactory to allow for proper soap address rewrite
DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
SoapTransportFactory factory = new SoapTransportFactoryExt();
Modified:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java
===================================================================
---
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java 2010-05-07
15:39:32 UTC (rev 12195)
+++
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java 2010-05-07
15:42:12 UTC (rev 12196)
@@ -39,6 +39,12 @@
import org.apache.cxf.transport.servlet.ServletTransportFactory;
import org.apache.cxf.transports.http.QueryHandler;
import org.apache.cxf.transports.http.QueryHandlerRegistry;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.management.EndpointMetrics;
+import org.jboss.wsf.spi.management.ServerConfig;
+import org.jboss.wsf.spi.management.ServerConfigFactory;
/**
* An extension to the CXF servlet controller
@@ -51,6 +57,7 @@
private ServletTransportFactory cxfTransport;
private ServletContext servletCtx;
private Bus bus;
+ private ServerConfig serverConfig;
public ServletControllerExt(ServletTransportFactory cxfTransport, ServletConfig
config, ServletContext servletCtx, Bus bus)
{
@@ -58,6 +65,8 @@
this.cxfTransport = cxfTransport;
this.servletCtx = servletCtx;
this.bus = bus;
+ SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ serverConfig = spiProvider.getSPI(ServerConfigFactory.class).getServerConfig();
}
/**
@@ -126,6 +135,10 @@
String ctxUri = req.getRequestURI();
String baseUri = req.getRequestURL().toString() + "?" +
req.getQueryString();
EndpointInfo endpointInfo = dest.getEndpointInfo();
+ if (ServerConfig.UNDEFINED_HOSTNAME.equals(serverConfig.getWebServiceHost()))
+ {
+ endpointInfo.setProperty("autoRewriteSoapAddress", true);
+ }
for (QueryHandler queryHandler :
bus.getExtension(QueryHandlerRegistry.class).getHandlers())
{
Modified:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/SoapTransportFactoryExt.java
===================================================================
---
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/SoapTransportFactoryExt.java 2010-05-07
15:39:32 UTC (rev 12195)
+++
stack/cxf/branches/jbossws-cxf-3.1.2/modules/server/src/main/java/org/jboss/wsf/stack/cxf/SoapTransportFactoryExt.java 2010-05-07
15:42:12 UTC (rev 12196)
@@ -52,7 +52,6 @@
*/
public class SoapTransportFactoryExt extends SoapTransportFactory
{
- private static Logger log = Logger.getLogger(SoapTransportFactoryExt.class);
private ServerConfig serverConfig;
public EndpointInfo createEndpointInfo(ServiceInfo serviceInfo, BindingInfo b, Port
port)
@@ -64,7 +63,7 @@
transportURI = sbi.getTransportURI();
}
ServerConfig config = getServerConfig();
- EndpointInfo info = new CustomSoapEndpointInfo(serviceInfo, transportURI, config !=
null && config.isModifySOAPAddress());
+ EndpointInfo info = new AddressRewritingEndpointInfo(serviceInfo, transportURI,
config);
if (port != null)
{
List ees = port.getExtensibilityElements();
@@ -97,64 +96,4 @@
}
return serverConfig;
}
-
- /**
- * A custom EndpointInfo that updates the SoapAddress extension
- * coming from the wsdl definition according to the JBossWS
- * soap address rewrite rules.
- *
- */
- private class CustomSoapEndpointInfo extends EndpointInfo
- {
- boolean alwaysModifyWsdl;
- SoapAddress saddress;
-
- CustomSoapEndpointInfo(ServiceInfo serv, String trans, boolean alwaysModifyWsdl)
- {
- super(serv, trans);
- this.alwaysModifyWsdl = alwaysModifyWsdl;
- }
-
- public void setAddress(String s)
- {
- boolean currentInvalid = isCurrentAddressInvalid();
- super.setAddress(s);
- if (alwaysModifyWsdl || currentInvalid)
- {
- log.info("Setting new address: " + s);
- if (saddress != null)
- {
- saddress.setLocationURI(s);
- }
- }
- }
-
- public void addExtensor(Object el)
- {
- super.addExtensor(el);
- if (el instanceof SoapAddress)
- {
- saddress = (SoapAddress)el;
- }
- }
-
- private boolean isCurrentAddressInvalid()
- {
- String address = super.getAddress();
- if (address != null)
- {
- try
- {
- new URL(address);
- }
- catch (MalformedURLException e)
- {
- log.info("Forcing rewrite of invalid address: " + address);
- return true;
- }
- }
- return false;
- }
- }
-
}
Modified:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/testsuite/test-excludes-jboss510.txt
===================================================================
---
stack/cxf/branches/jbossws-cxf-3.1.2/modules/testsuite/test-excludes-jboss510.txt 2010-05-07
15:39:32 UTC (rev 12195)
+++
stack/cxf/branches/jbossws-cxf-3.1.2/modules/testsuite/test-excludes-jboss510.txt 2010-05-07
15:42:12 UTC (rev 12196)
@@ -8,9 +8,6 @@
# [CXF-1511] WrappedMessageContext does not implement SOAPMessageContext
org/jboss/test/ws/jaxws/binding/**
-# [CXF-1514][JBWS-2247] Generated WSDL does not take 'transport-guarantee' in
web.xml into account
-org/jboss/test/ws/jaxws/jbws1190/**
-
# [CXF-1516] Type inheritance with document/literal/bare
org/jboss/test/ws/jaxws/jbws1702/**
@@ -29,9 +26,6 @@
# [EJBTHREE-1152] service-ref in ejb-jar.xml is ignored
org/jboss/test/ws/jaxws/samples/serviceref/ServiceRefEJBTestCase.*
-# [JBWS-1655] Add support for endpoint address rewriting
-org/jboss/test/ws/jaxws/jbws2150/**
-
# [JBWS-2596] Resource injection in jaxws endpoints and handlers
org/jboss/test/ws/jaxws/jbws2074/**
org/jboss/test/ws/jaxws/jbws2634/**
@@ -42,9 +36,6 @@
# [JBWS-2571] Mode.INOUT parameter not generated
org/jboss/test/ws/jaxws/holder/**
-# [JBWS-2227] Investigate why multiple virtual hosts test fails on CXF
-org/jboss/test/ws/jaxws/jbws1178/**
-
# [JBWS-2480] Soap attachments are dropped on server response
org/jboss/test/ws/jaxws/jbws1283/**