Author: rsearls
Date: 2014-08-07 13:03:51 -0400 (Thu, 07 Aug 2014)
New Revision: 18830
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/deployment/EndpointImpl.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java
Log:
[JBWS-3750] code addition and corresponding test
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-07
14:56:37 UTC (rev 18829)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/addressRewrite/SoapAddressRewriteHelper.java 2014-08-07
17:03:51 UTC (rev 18830)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2014, 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.
*
@@ -32,6 +32,7 @@
* Helper for rewriting soap:address in published wsdl
*
* @author alessio.soldano(a)jboss.com
+ * @author rsears(a)redhat.com
* @since 30-Nov-2012
*/
public class SoapAddressRewriteHelper
@@ -64,6 +65,41 @@
}
}
+ /**
+ * 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.
+ *
+ * @param address The container computed endpoint address
+ * @param serverConfig The current ServerConfig
+ * @return
+ */
+ public static String getRewrittenPublishedEndpointUrl(String address, ServerConfig
serverConfig)
+ {
+ try
+ {
+ if (isPathRewriteRequired(serverConfig))
+ {
+ final URL url = new URL(address);
+ final String path = url.getPath();
+ final String tmpPath =
SEDProcessor.newInstance(serverConfig.getWebServicePathRewriteRule()).processLine(path);
+ final String newUrl=url.toString().replace(path, tmpPath);
+
+ ADDRESS_REWRITE_LOGGER.addressRewritten(address, newUrl);
+ return newUrl;
+ }
+ else
+ {
+ ADDRESS_REWRITE_LOGGER.rewriteNotRequired(address);
+ return address;
+ }
+ }
+ catch (Exception e)
+ {
+ ADDRESS_REWRITE_LOGGER.invalidAddressProvidedUseItWithoutRewriting(address,
"");
+ return address;
+ }
+ }
+
public static boolean isAutoRewriteOn(ServerConfig serverConfig)
{
return serverConfig.isModifySOAPAddress() &&
ServerConfig.UNDEFINED_HOSTNAME.equals(serverConfig.getWebServiceHost());
@@ -142,7 +178,21 @@
port = ":" + portNo;
}
}
- String urlStr = uriScheme + "://" + host + port + path;
+
+ StringBuilder sb = new StringBuilder(uriScheme);
+ sb.append("://");
+ sb.append(host);
+ sb.append(port);
+
+ if (isPathRewriteRequired(serverConfig)) {
+
sb.append(SEDProcessor.newInstance(serverConfig.getWebServicePathRewriteRule()).processLine(path));
+ }
+ else
+ {
+ sb.append(path);
+ }
+ final String urlStr = sb.toString();
+
ADDRESS_REWRITE_LOGGER.addressRewritten(origAddress, urlStr);
return urlStr;
}
@@ -166,4 +216,13 @@
return HTTP;
}
}
+
+
+ public static boolean isPathRewriteRequired(ServerConfig sc){
+ if (!sc.isModifySOAPAddress()) {
+ return false;
+ }
+ final String pathRewriteRule = sc.getWebServicePathRewriteRule();
+ return pathRewriteRule != null && !pathRewriteRule.isEmpty();
+ }
}
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-07
14:56:37 UTC (rev 18829)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2014-08-07
17:03:51 UTC (rev 18830)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2014, 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.
*
@@ -22,7 +22,10 @@
package org.jboss.wsf.stack.cxf.deployment;
import java.io.IOException;
+import java.security.AccessController;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
@@ -30,12 +33,22 @@
import org.apache.cxf.Bus;
import org.apache.cxf.configuration.Configurer;
import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.frontend.WSDLGetUtils;
+import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.jaxws.support.JaxWsImplementorInfo;
+import org.apache.cxf.message.Message;
import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
import org.jboss.ws.common.configuration.ConfigHelper;
+import org.jboss.ws.common.management.AbstractServerConfig;
+import org.jboss.wsf.spi.management.ServerConfig;
import org.jboss.wsf.spi.metadata.config.CommonConfig;
import org.jboss.wsf.stack.cxf.Loggers;
+import org.jboss.wsf.stack.cxf.addressRewrite.SoapAddressRewriteHelper;
+import org.jboss.wsf.stack.cxf.interceptor.WSDLSoapAddressRewriteInterceptor;
+
/**
* An extension of @see org.apache.cxf.jaxws.EndpointImpl for dealing with
* JBossWS integration needs.
@@ -64,6 +77,11 @@
{
super.getServerFactory().setBlockPostConstruct(true);
super.doPublish(addr);
+
+ // A custom interceptor is required when the server config attributes for
rewriting
+ // the path in a WSDL URL (i.e., <soap:address location= ...) are set
+ replaceWSDLGetInterceptor();
+
//allow for configuration so that the wsdlPublisher can be set be the
JBossWSCXFConfigurer
configureObject(this);
setupConfigHandlers();
@@ -72,6 +90,18 @@
}
/**
+ * Add interceptor that enables the desired soap:address rewrite
+ */
+ private void replaceWSDLGetInterceptor(){
+ if (SoapAddressRewriteHelper.isPathRewriteRequired(getServerConfig())) {
+ List<Interceptor<? extends Message>> inInterceptors =
getInInterceptors();
+ if(!inInterceptors.contains(WSDLSoapAddressRewriteInterceptor.INSTANCE)){
+ inInterceptors.add(WSDLSoapAddressRewriteInterceptor.INSTANCE);
+ }
+ }
+ }
+
+ /**
* Sets the JAXWS endpoint config for the current endpoint. This is called by
configurer when
* org.apache.cxf.jaxws.EndpointImpl#getServer(..) executes
'configureObject(this)'
*
@@ -111,8 +141,7 @@
/**
* Publish the contract to a file using the configured wsdl publisher
- *
- * @param endpoint
+ *
*/
protected void publishContractToFilesystem()
{
@@ -128,6 +157,7 @@
JaxWsImplementorInfo info = new
JaxWsImplementorInfo(getImplementorClass());
wsdlLocation = info.getWsdlLocation();
}
+ updateCodeFirstSoapAddress();
wsdlPublisher.publishWsdlFiles(service.getName(), wsdlLocation,
this.getBus(), service.getServiceInfos());
}
catch (IOException ioe)
@@ -172,4 +202,38 @@
this.wsdlPublisher = wsdlPublisher;
}
+ /**
+ * For both code-first and wsdl-first scenarios, reset the endpoint address
+ * so that it is written to the generated wsdl file.
+ */
+ private void updateCodeFirstSoapAddress() {
+ ServerConfig servConfig = getServerConfig();
+ if (servConfig.isModifySOAPAddress()) {
+ //- code-first handling
+ List<ServiceInfo> sevInfos =
getServer().getEndpoint().getService().getServiceInfos();
+ for (ServiceInfo si: sevInfos){
+ Collection<EndpointInfo > epInfos = si.getEndpoints();
+ for(EndpointInfo ei: epInfos){
+ String publishedEndpointUrl =
(String)ei.getProperty(WSDLGetUtils.PUBLISHED_ENDPOINT_URL);
+ if (publishedEndpointUrl != null){
+ ei.setAddress(publishedEndpointUrl);
+ } else {
+ //- wsdl-first handling
+ if (ei.getAddress().contains(ServerConfig.UNDEFINED_HOSTNAME)){
+ String epurl =
SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(ei.getAddress(), servConfig);
+ ei.setAddress(epurl);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private static ServerConfig getServerConfig() {
+ if(System.getSecurityManager() == null) {
+ return AbstractServerConfig.getServerIntegrationServerConfig();
+ }
+ return
AccessController.doPrivileged(AbstractServerConfig.GET_SERVER_INTEGRATION_SERVER_CONFIG);
+ }
+
}
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-07
14:56:37 UTC (rev 18829)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java 2014-08-07
17:03:51 UTC (rev 18830)
@@ -293,7 +293,7 @@
SOAPAddressWSDLParser parser = getCurrentSOAPAddressWSDLParser(wsdlUrl,
soapAddressWsdlParsers);
//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);
//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",
@@ -307,7 +307,8 @@
} else {
//same comment as above regarding auto rewrite...
if (!SoapAddressRewriteHelper.isAutoRewriteOn(sc)) {
- ddep.setPublishedEndpointUrl(ddep.getAddress()); //force computed address for
code first endpoints
+ //force computed address for code first endpoints
+
ddep.setPublishedEndpointUrl(SoapAddressRewriteHelper.getRewrittenPublishedEndpointUrl(ddep.getAddress(),
sc));
}
}
}
@@ -362,5 +363,5 @@
return sb.toString();
}
-
+
}