Author: asoldano
Date: 2014-08-20 10:16:42 -0400 (Wed, 20 Aug 2014)
New Revision: 18851
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/addressRewrite/SoapAddressRewriteHelper.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/util/WSDLSoapAddressRewriteUtils.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java
Log:
[JBWS-3785] Refactoring Jim's changes: simplifying SoapAddressRewriteHelper, fixing
WSDLSoapAddressRewriteUtils and preparing bunch of code sections for [JBWS-3805]
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/addressRewrite/SoapAddressRewriteHelper.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/addressRewrite/SoapAddressRewriteHelper.java 2014-08-19
08:39:45 UTC (rev 18850)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/addressRewrite/SoapAddressRewriteHelper.java 2014-08-20
14:16:42 UTC (rev 18851)
@@ -25,9 +25,9 @@
import java.net.URI;
import java.net.URL;
+import java.util.Map;
import org.jboss.wsf.spi.management.ServerConfig;
-import org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData;
import org.jboss.wsf.stack.cxf.client.Constants;
/**
@@ -50,7 +50,7 @@
* @param serverConfig The current ServerConfig
* @return The rewritten soap:address to be used in the wsdl
*/
- public static String getRewrittenPublishedEndpointUrl(String wsdlAddress, String
epAddress, ServerConfig serverConfig, JBossWebservicesMetaData wsmd) {
+ public static String getRewrittenPublishedEndpointUrl(String wsdlAddress, String
epAddress, ServerConfig serverConfig, Map<String, String> props) {
if (wsdlAddress == null) {
return null;
}
@@ -58,14 +58,7 @@
{
final String origUriScheme = getUriScheme(wsdlAddress); //will be https if the
user wants a https address in the wsdl
final String newUriScheme = getUriScheme(epAddress); //will be https if the user
set confidential transport for the endpoint
- String uriScheme = (origUriScheme.equals(HTTPS) || newUriScheme.equals(HTTPS)) ?
HTTPS : HTTP;
- if (serverConfig.getWebServiceUriScheme() != null) {
- uriScheme = serverConfig.getWebServiceUriScheme();
- }
- if (uriScheme == null) {
- uriScheme = wsmd.getProperty(Constants.JBWS_CXF_WSDL_URI_SCHEME);
- }
- return rewriteSoapAddress(serverConfig, wsdlAddress, epAddress, uriScheme);
+ return rewriteSoapAddress(serverConfig, wsdlAddress, epAddress,
rewriteUriScheme(origUriScheme, newUriScheme, serverConfig, props));
}
else
{
@@ -73,11 +66,6 @@
}
}
- public static String getRewrittenPublishedEndpointUrl(String address, ServerConfig
serverConfig) {
- return getRewrittenPublishedEndpointUrl(address, serverConfig, null);
- }
-
-
/**
* Rewrite and get address to be used for CXF published endpoint url prop (rewritten
wsdl address).
* This method is to be used for code-first endpoints, when no wsdl is provided by the
user.
@@ -86,49 +74,22 @@
* @param serverConfig The current ServerConfig
* @return
*/
- public static String getRewrittenPublishedEndpointUrl(String address, ServerConfig
serverConfig, JBossWebservicesMetaData wsmd)
+ public static String getRewrittenPublishedEndpointUrl(String address, ServerConfig
serverConfig, Map<String, String> props)
{
try
{
- final URL tmpurl = new URL(address);
- String uriScheme = serverConfig.getWebServiceUriScheme();
- if (uriScheme == null && wsmd != null) {
- uriScheme = wsmd.getProperty(Constants.JBWS_CXF_WSDL_URI_SCHEME);
- }
- if (uriScheme != null) {
- 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;
- }
- }
-
- StringBuilder addressBuilder = new StringBuilder();
- addressBuilder.append(uriScheme);
- addressBuilder.append("://");
- addressBuilder.append(tmpurl.getHost());
- addressBuilder.append(port);
- addressBuilder.append(tmpurl.getPath());
- address = addressBuilder.toString();
-
- }
- final URL url = new URL(address);
- if (isPathRewriteRequired(serverConfig))
- {
+ if (isPathRewriteRequired(serverConfig) || isSchemeRewriteRequired(serverConfig,
props)) {
+ final URL url = new URL(address);
+ final String uriScheme = rewriteUriScheme(getUriScheme(address), null,
serverConfig, props);
+ final String port = getDotPortNumber(uriScheme, serverConfig);
+ final StringBuilder builder = new StringBuilder();
+ builder.append(uriScheme);
+ builder.append("://");
+ builder.append(url.getHost());
+ builder.append(port);
final String path = url.getPath();
- final String tmpPath =
SEDProcessor.newInstance(serverConfig.getWebServicePathRewriteRule()).processLine(path);
- final String newUrl=url.toString().replace(path, tmpPath);
+ builder.append(isPathRewriteRequired(serverConfig) ?
SEDProcessor.newInstance(serverConfig.getWebServicePathRewriteRule()).processLine(path) :
path);
+ final String newUrl = builder.toString();
ADDRESS_REWRITE_LOGGER.addressRewritten(address, newUrl);
return newUrl;
@@ -207,23 +168,7 @@
URL url = new URL(newAddress);
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 port = getDotPortNumber(uriScheme, serverConfig);
StringBuilder sb = new StringBuilder(uriScheme);
sb.append("://");
@@ -249,6 +194,27 @@
}
}
+ private static String getDotPortNumber(String uriScheme, ServerConfig serverConfig) {
+ 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;
+ }
+ }
+ return port;
+ }
+
private static String getUriScheme(String address)
{
try
@@ -271,4 +237,27 @@
final String pathRewriteRule = sc.getWebServicePathRewriteRule();
return pathRewriteRule != null && !pathRewriteRule.isEmpty();
}
+
+ public static boolean isSchemeRewriteRequired(ServerConfig sc, Map<String,
String> props) {
+ if (!sc.isModifySOAPAddress()) {
+ return false;
+ } //TODO also check modify soap address is enabled in wsmd
+ return sc.getWebServiceUriScheme() != null ||
props.get(Constants.JBWS_CXF_WSDL_URI_SCHEME) != null;
+ }
+
+ private static String rewriteUriScheme(final String origUriScheme, final String
newUriScheme, final ServerConfig serverConfig, final Map<String, String> props) {
+ //1) if either of orig URI or new URI uses HTTPS, use HTTPS
+ String uriScheme = (HTTPS.equals(origUriScheme) || HTTPS.equals(newUriScheme)) ?
HTTPS : HTTP;
+ //2) server configuration override
+ final String serverUriScheme = serverConfig.getWebServiceUriScheme();
+ if (serverUriScheme != null) {
+ uriScheme = serverUriScheme;
+ }
+ //3) deployment configuration override
+ final String mdUriScheme = props.get(Constants.JBWS_CXF_WSDL_URI_SCHEME);
+ if (mdUriScheme != null) {
+ uriScheme = mdUriScheme;
+ }
+ return uriScheme;
+ }
}
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java 2014-08-19
08:39:45 UTC (rev 18850)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java 2014-08-20
14:16:42 UTC (rev 18851)
@@ -22,6 +22,7 @@
package org.jboss.wsf.stack.cxf.configuration;
import java.security.AccessController;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -125,7 +126,7 @@
{
bus.setExtension(configurer, Configurer.class);
}
- Map<String, String> props = (wsmd == null) ? null : wsmd.getProperties();
+ Map<String, String> props = getProperties(wsmd);
setInterceptors(bus, props);
dep.addAttachment(Bus.class, bus);
@@ -163,6 +164,15 @@
}
}
+ private static Map<String, String> getProperties(JBossWebservicesMetaData wsmd)
{
+ Map<String, String> props;
+ if (wsmd != null) {
+ props = wsmd.getProperties();
+ } else {
+ props = Collections.emptyMap();
+ }
+ return props;
+ }
/**
* Performs close operations
@@ -206,8 +216,9 @@
bus.getInInterceptors().add(new HandlerAuthInterceptor());
}
- if (SoapAddressRewriteHelper.isPathRewriteRequired(getServerConfig())) {
- bus.getInInterceptors().add(WSDLSoapAddressRewriteInterceptor.INSTANCE);
+ final ServerConfig sc = getServerConfig();
+ if (SoapAddressRewriteHelper.isPathRewriteRequired(sc) ||
SoapAddressRewriteHelper.isSchemeRewriteRequired(sc, props)) {
+ bus.getInInterceptors().add(new WSDLSoapAddressRewriteInterceptor(props));
}
}
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2014-08-19
08:39:45 UTC (rev 18850)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2014-08-20
14:16:42 UTC (rev 18851)
@@ -201,7 +201,7 @@
} else {
//- wsdl-first handling
if (ei.getAddress().contains(ServerConfig.UNDEFINED_HOSTNAME)){
- String epurl =
SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(ei.getAddress(), servConfig);
+ String epurl =
SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(ei.getAddress(), servConfig,
null); //TODO [JBWS-3805]
ei.setAddress(epurl);
}
}
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java 2014-08-19
08:39:45 UTC (rev 18850)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java 2014-08-20
14:16:42 UTC (rev 18851)
@@ -21,6 +21,8 @@
*/
package org.jboss.wsf.stack.cxf.interceptor;
+import java.util.Map;
+
import org.apache.cxf.frontend.WSDLGetUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
@@ -33,19 +35,20 @@
* soap:address rewrite
*
* @author rsearls(a)redhat.com
+ * @author alessio.soldano(a)jboss.com
* @since 19-May-2014
*/
public class WSDLSoapAddressRewriteInterceptor extends
AbstractPhaseInterceptor<Message> {
- public static final WSDLSoapAddressRewriteInterceptor INSTANCE =
- new WSDLSoapAddressRewriteInterceptor();
+ private final WSDLGetUtils wsdlGetUtils;
- public WSDLSoapAddressRewriteInterceptor() {
+ public WSDLSoapAddressRewriteInterceptor(Map<String, String> props) {
// this must run before WSDLGetInterceptor which is in Phase.READ
super(Phase.POST_STREAM);
+ this.wsdlGetUtils = new WSDLSoapAddressRewriteUtils(props);
}
public void handleMessage(Message message) throws Fault {
- message.setContextualProperty(WSDLGetUtils.class.getName(), new
WSDLSoapAddressRewriteUtils());
+ message.setContextualProperty(WSDLGetUtils.class.getName(), wsdlGetUtils);
}
}
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/util/WSDLSoapAddressRewriteUtils.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/util/WSDLSoapAddressRewriteUtils.java 2014-08-19
08:39:45 UTC (rev 18850)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/util/WSDLSoapAddressRewriteUtils.java 2014-08-20
14:16:42 UTC (rev 18851)
@@ -22,6 +22,7 @@
package org.jboss.wsf.stack.cxf.interceptor.util;
import java.security.AccessController;
+import java.util.Map;
import javax.wsdl.Definition;
@@ -37,9 +38,17 @@
* when a path rewrite rule is specified in the server configuration.
*
* @author rsearls(a)redhat.com
+ * @author alessio.soldano(a)jboss.com
*
*/
public class WSDLSoapAddressRewriteUtils extends WSDLGetUtils {
+
+ private final Map<String, String> props;
+
+ public WSDLSoapAddressRewriteUtils(Map<String, String> props) {
+ super();
+ this.props = props;
+ }
@Override
public String getPublishableEndpointUrl(Definition def, String epurl,
@@ -51,9 +60,9 @@
} else {
// When using replacement path, must set replacement path in the active url.
final ServerConfig sc = getServerConfig();
- if (SoapAddressRewriteHelper.isPathRewriteRequired(sc)
+ if ((SoapAddressRewriteHelper.isPathRewriteRequired(sc) ||
SoapAddressRewriteHelper.isSchemeRewriteRequired(sc, props)) //TODO if we ended up here,
the checks are perhaps not needed (otherwise this won't have been installed)
&&
endpointInfo.getAddress().contains(ServerConfig.UNDEFINED_HOSTNAME)) {
- epurl = SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(epurl,
sc);
+ epurl = SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(epurl, sc,
props);
updatePublishedEndpointUrl(epurl, def, endpointInfo.getName());
}
}
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java 2014-08-19
08:39:45 UTC (rev 18850)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java 2014-08-20
14:16:42 UTC (rev 18851)
@@ -26,6 +26,7 @@
import java.net.URL;
import java.security.AccessController;
+import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -288,7 +289,7 @@
wsdlLocation = ddep.getAnnotationWsdlLocation();
}
final ServerConfig sc = getServerConfig();
- JBossWebservicesMetaData wsmd = dep.getAttachment(JBossWebservicesMetaData.class);
+ final Map<String, String> props =
getJBossWebServicesMetaDataProperties(dep);
if (wsdlLocation != null) {
URL wsdlUrl = dep.getResourceResolver().resolveFailSafe(wsdlLocation);
if (wsdlUrl != null) {
@@ -296,7 +297,7 @@
//do not try rewriting addresses for not-http binding
String wsdlAddress = parser.filterSoapAddress(ddep.getServiceName(),
ddep.getPortName(), SOAPAddressWSDLParser.SOAP_HTTP_NS);
- String rewrittenWsdlAddress =
SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(wsdlAddress, ddep.getAddress(),
sc, wsmd);
+ String rewrittenWsdlAddress =
SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(wsdlAddress, ddep.getAddress(),
sc, props);
//If "auto rewrite", leave "publishedEndpointUrl" unset
so that CXF does not force host/port values for
//wsdl imports and auto-rewrite them too; otherwise set the new address into
"publishedEndpointUrl",
//which causes CXF to override any address in the published wsdl.
@@ -310,11 +311,22 @@
//same comment as above regarding auto rewrite...
if (!SoapAddressRewriteHelper.isAutoRewriteOn(sc)) {
//force computed address for code first endpoints
-
ddep.setPublishedEndpointUrl(SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(ddep.getAddress(),
sc, wsmd));
+
ddep.setPublishedEndpointUrl(SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(ddep.getAddress(),
sc, props));
}
}
}
+ private static Map<String, String>
getJBossWebServicesMetaDataProperties(Deployment dep) {
+ JBossWebservicesMetaData wsmd = dep.getAttachment(JBossWebservicesMetaData.class);
+ Map<String, String> props;
+ if (wsmd != null) {
+ props = wsmd.getProperties();
+ } else {
+ props = Collections.emptyMap();
+ }
+ return props;
+ }
+
private SOAPAddressWSDLParser getCurrentSOAPAddressWSDLParser(URL wsdlUrl,
Map<String, SOAPAddressWSDLParser> soapAddressWsdlParsers) {
final String key = wsdlUrl.toString();
SOAPAddressWSDLParser parser = soapAddressWsdlParsers.get(key);