Author: rsearls
Date: 2014-05-22 16:49:08 -0400 (Thu, 22 May 2014)
New Revision: 18689
Removed:
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java
Modified:
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/addressRewrite/SoapAddressRewriteHelper.java
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java
stack/cxf/branches/rsearls/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2150/JBWS2150TestCaseForked.java
Log:
support for code-first soap address rewrite
Modified:
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/addressRewrite/SoapAddressRewriteHelper.java
===================================================================
---
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/addressRewrite/SoapAddressRewriteHelper.java 2014-05-22
07:19:21 UTC (rev 18688)
+++
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/addressRewrite/SoapAddressRewriteHelper.java 2014-05-22
20:49:08 UTC (rev 18689)
@@ -182,4 +182,33 @@
}
}
+
+ public static String rewriteSoapAddress(ServerConfig serverConfig, String address,
String contextRoot)
+ {
+ try
+ {
+ final String additionalCcontext = serverConfig.getWebServicePath();
+ if (serverConfig.isModifySOAPAddress() && (additionalCcontext != null
&& additionalCcontext.length() > 0))
+ {
+ final URL url = new URL(address);
+ final String path = url.getPath();
+ final String tmpAdditionalCcontext =
additionalCcontext.startsWith("/") ? additionalCcontext : "/" +
additionalCcontext;
+ final String tmpPath = path.replace(contextRoot, tmpAdditionalCcontext);
+ 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;
+ }
+ }
+
}
Modified:
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java
===================================================================
---
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2014-05-22
07:19:21 UTC (rev 18688)
+++
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2014-05-22
20:49:08 UTC (rev 18689)
@@ -21,27 +21,32 @@
*/
package org.jboss.wsf.stack.cxf.deployment;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-
import org.apache.cxf.Bus;
import org.apache.cxf.configuration.Configurer;
import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.frontend.WSDLGetInterceptor;
-import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.frontend.WSDLGetUtils;
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.interceptor.WSDLSoapAddressRewriteInterceptor;
+import org.jboss.wsf.stack.cxf.addressRewrite.SoapAddressRewriteHelper;
+import javax.xml.namespace.QName;
+import java.io.IOException;
+import java.net.URL;
+import java.security.AccessController;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.jboss.wsf.stack.cxf.Loggers.ADDRESS_REWRITE_LOGGER;
+
/**
* An extension of @see org.apache.cxf.jaxws.EndpointImpl for dealing with
* JBossWS integration needs.
@@ -70,23 +75,7 @@
{
super.getServerFactory().setBlockPostConstruct(true);
super.doPublish(addr);
- /**/
- //-- rls test start
- Collection<Endpoint> epList = super.getService().getEndpoints().values();
- for(Endpoint ep: epList){
- List<Interceptor<? extends Message>> inList =
ep.getInInterceptors();
- for(Interceptor in: inList){
- if (in instanceof org.apache.cxf.frontend.WSDLGetInterceptor){
- int index = inList.indexOf(in);
- if (index > -1){
- inList.remove(index);
- inList.add(index, WSDLSoapAddressRewriteInterceptor.INSTANCE);
- }
- }
- }
- }
- //-- rls test end
- /**/
+
//allow for configuration so that the wsdlPublisher can be set be the
JBossWSCXFConfigurer
configureObject(this);
setupConfigHandlers();
@@ -150,6 +139,7 @@
if (wsdlLocation == null) {
JaxWsImplementorInfo info = new
JaxWsImplementorInfo(getImplementorClass());
wsdlLocation = info.getWsdlLocation();
+ updateCodeFirstSoapAddress();
}
wsdlPublisher.publishWsdlFiles(service.getName(), wsdlLocation,
this.getBus(), service.getServiceInfos());
}
@@ -195,4 +185,31 @@
this.wsdlPublisher = wsdlPublisher;
}
+ /**
+ * In the code-first scenario, reset the endpoint address so that it is
+ * written to the generated wsdl file.
+ */
+ private void updateCodeFirstSoapAddress() {
+ ServerConfig servConfig = getServerConfig();
+ if (!SoapAddressRewriteHelper.isAutoRewriteOn(servConfig)) {
+ //- 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);
+ }
+ }
+ }
+ }
+ }
+
+ private static ServerConfig getServerConfig() {
+ if(System.getSecurityManager() == null) {
+ return AbstractServerConfig.getServerIntegrationServerConfig();
+ }
+ return
AccessController.doPrivileged(AbstractServerConfig.GET_SERVER_INTEGRATION_SERVER_CONFIG);
+ }
}
Deleted:
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java
===================================================================
---
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java 2014-05-22
07:19:21 UTC (rev 18688)
+++
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java 2014-05-22
20:49:08 UTC (rev 18689)
@@ -1,126 +0,0 @@
-package org.jboss.wsf.stack.cxf.interceptor;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.util.UrlUtils;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.frontend.WSDLGetInterceptor;
-import org.apache.cxf.frontend.WSDLGetOutInterceptor;
-import org.apache.cxf.frontend.WSDLGetUtils;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.interceptor.MessageSenderInterceptor;
-import org.apache.cxf.interceptor.OutgoingChainInterceptor;
-import org.apache.cxf.interceptor.StaxOutInterceptor;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor;
-import org.w3c.dom.Document;
-
-
-/**
- * This is a customization of org.apache.cxf.frontend.WSDLGetInterceptor. It
- * enables the handling of rewriting the path of a URL.
- * Date: 5/19/14
- */
-public class WSDLSoapAddressRewriteInterceptor extends
AbstractPhaseInterceptor<Message> {
- public static final WSDLSoapAddressRewriteInterceptor INSTANCE =
- new WSDLSoapAddressRewriteInterceptor();
- private static final String TRANSFORM_SKIP = "transform.skip";
- private Interceptor<Message> wsdlGetOutInterceptor =
WSDLGetOutInterceptor.INSTANCE;
-
- public WSDLSoapAddressRewriteInterceptor() {
- super(Phase.READ);
- getAfter().add(EndpointSelectionInterceptor.class.getName());
- }
-
- public WSDLSoapAddressRewriteInterceptor(Interceptor<Message> outInterceptor) {
- this();
- // Let people override the wsdlGetOutInterceptor
- wsdlGetOutInterceptor = outInterceptor;
- }
-
- public void handleMessage(Message message) throws Fault {
- String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
- String query = (String)message.get(Message.QUERY_STRING);
-
- if (!"GET".equals(method) || StringUtils.isEmpty(query)) {
- return;
- }
-
- String baseUri = (String)message.get(Message.REQUEST_URL);
- String ctx = (String)message.get(Message.PATH_INFO);
-
- Map<String, String> map = UrlUtils.parseQueryString(query);
- if (isRecognizedQuery(map, baseUri, ctx,
message.getExchange().getEndpoint().getEndpointInfo())) {
- Document doc = getDocument(message, baseUri, map, ctx);
-
- Endpoint e = message.getExchange().get(Endpoint.class);
- Message mout = new MessageImpl();
- mout.setExchange(message.getExchange());
- mout = e.getBinding().createMessage(mout);
-
mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
- message.getExchange().setOutMessage(mout);
-
- mout.put(WSDLGetInterceptor.DOCUMENT_HOLDER, doc);
- mout.put(Message.CONTENT_TYPE, "text/xml");
-
- // just remove the interceptor which should not be used
- cleanUpOutInterceptors(mout);
-
- // notice this is being added after the purge above, don't swap the order!
- mout.getInterceptorChain().add(wsdlGetOutInterceptor);
-
- message.getExchange().put(TRANSFORM_SKIP, Boolean.TRUE);
- // skip the service executor and goto the end of the chain.
- message.getInterceptorChain().doInterceptStartingAt(
- message,
- OutgoingChainInterceptor.class.getName());
- }
- }
-
- protected void cleanUpOutInterceptors(Message outMessage) {
- // TODO - how can I improve this to provide a specific interceptor chain that just
has the
- // stax, gzip and message sender components, while also ensuring that GZIP is only
provided
- // if its already configured for the endpoint.
- Iterator<Interceptor<? extends Message>> iterator =
outMessage.getInterceptorChain().iterator();
- while (iterator.hasNext()) {
- Interceptor<? extends Message> inInterceptor = iterator.next();
- if (!inInterceptor.getClass().equals(StaxOutInterceptor.class)
- && !inInterceptor.getClass().equals(GZIPOutInterceptor.class)
- && !inInterceptor.getClass().equals(MessageSenderInterceptor.class))
{
- outMessage.getInterceptorChain().remove(inInterceptor);
- }
- }
-
- }
-
- private Document getDocument(Message message, String base, Map<String, String>
params, String ctxUri) {
- // cannot have two wsdl's being generated for the same endpoint at the same
- // time as the addresses may get mixed up
- // For WSDL's the WSDLWriter does not share any state between documents.
- // For XSD's, the WSDLSoapAddressRewriteUtils makes a copy of any XSD schema
documents before updating
- // any addresses and returning them, so for both WSDL and XSD this is the only part
that needs
- // to be synchronized.
- synchronized (message.getExchange().getEndpoint()) {
- return new WSDLGetUtils().getDocument(message, base, params, ctxUri,
- message.getExchange().getEndpoint().getEndpointInfo());
- }
- }
-
- private boolean isRecognizedQuery(Map<String, String> map, String baseUri,
String ctx,
- EndpointInfo endpointInfo) {
-
- if (map.containsKey("wsdl") || map.containsKey("xsd")) {
- return true;
- }
- return false;
- }
-
-}
Modified:
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java
===================================================================
---
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java 2014-05-22
07:19:21 UTC (rev 18688)
+++
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/MetadataBuilder.java 2014-05-22
20:49:08 UTC (rev 18689)
@@ -21,25 +21,6 @@
*/
package org.jboss.wsf.stack.cxf.metadata;
-import static org.jboss.wsf.stack.cxf.Loggers.METADATA_LOGGER;
-import static org.jboss.wsf.stack.cxf.Messages.MESSAGES;
-
-import java.net.URL;
-import java.security.AccessController;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Stack;
-import java.util.StringTokenizer;
-
-import javax.jws.WebService;
-import javax.xml.namespace.QName;
-import javax.xml.ws.BindingType;
-import javax.xml.ws.WebServiceProvider;
-import javax.xml.ws.soap.MTOM;
-import javax.xml.ws.soap.SOAPBinding;
-
import org.jboss.ws.common.JavaUtils;
import org.jboss.ws.common.deployment.SOAPAddressWSDLParser;
import org.jboss.ws.common.management.AbstractServerConfig;
@@ -59,6 +40,19 @@
import org.jboss.wsf.stack.cxf.metadata.services.DDBeans;
import org.jboss.wsf.stack.cxf.metadata.services.DDEndpoint;
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingType;
+import javax.xml.ws.WebServiceProvider;
+import javax.xml.ws.soap.MTOM;
+import javax.xml.ws.soap.SOAPBinding;
+import java.net.URL;
+import java.security.AccessController;
+import java.util.*;
+
+import static org.jboss.wsf.stack.cxf.Loggers.METADATA_LOGGER;
+import static org.jboss.wsf.stack.cxf.Messages.MESSAGES;
+
/**
* Builds the DDBeans metadata used for generating the jboss-cxf.xml deployment
descriptor
*
@@ -308,7 +302,9 @@
} else {
//same comment as above regarding auto rewrite...
if (!SoapAddressRewriteHelper.isAutoRewriteOn(sc)) {
- ddep.setPublishedEndpointUrl(ddep.getAddress()); //force computed address for
code first endpoints
+ //- code-first handling
+ String base = SoapAddressRewriteHelper.rewriteSoapAddress(sc,
ddep.getAddress(), dep.getService().getContextRoot());
+ ddep.setPublishedEndpointUrl(base); //force computed address for code first
endpoints
}
}
}
@@ -363,5 +359,5 @@
return sb.toString();
}
-
+
}
Modified:
stack/cxf/branches/rsearls/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2150/JBWS2150TestCaseForked.java
===================================================================
---
stack/cxf/branches/rsearls/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2150/JBWS2150TestCaseForked.java 2014-05-22
07:19:21 UTC (rev 18688)
+++
stack/cxf/branches/rsearls/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2150/JBWS2150TestCaseForked.java 2014-05-22
20:49:08 UTC (rev 18689)
@@ -530,8 +530,7 @@
}
/**
- *
- *
+ * Test soap:address rewrite. The new address contains the webServicePath setting.
* @throws Exception
*/
public void testRewriteContext() throws Exception
@@ -576,7 +575,65 @@
}
/**
- * This is not passing, as the auto rewrite mechanism clashes with the context rewrite
one
+ * Test soap:address rewrite. The new address contains the webServicePath setting.
+ * @throws Exception
+ */
+ public void testRewriteCodeFirstContext() throws Exception
+ {
+ setModifySOAPAddress(true);
+ final String addContext = "xx/jaxws-jbws2150-codefirst";
+ setWebServicePath(addContext);
+ deploy("jaxws-jbws2150-codefirst.war");
+ try
+ {
+ final String testHost = getServerHost();
+ final String expectedWsdlHost = getServerHost();
+ final String addr = "http://" + testHost +
":8080/jaxws-jbws2150-codefirst/CodeFirstService";
+ final String wsdlLocation = addr + "?wsdl";
+
+ Definition definition = getWSDLDefinition(wsdlLocation);
+ String address = getPortAddress(definition, "CodeFirstService",
"CodeFirstPort");
+ assertEquals("http://" + expectedWsdlHost + ":8080/" +
addContext +"/CodeFirstService", address);
+ }
+ finally
+ {
+ undeploy("jaxws-jbws2150-codefirst.war");
+ }
+ }
+
+ /**
+ * Test soap:address rewrite. The address does not change because of the
+ * webServiceHost setting.
+ * @throws Exception
+ */
+ public void testAutoRewriteCodeFirstContext() throws Exception
+ {
+ setModifySOAPAddress(true);
+ final String addContext = "jaxws-jbws2150-codefirst";
+ setWebServicePath("xx/" + addContext);
+ setWebServiceHost(ServerConfig.UNDEFINED_HOSTNAME);
+ deploy("jaxws-jbws2150-codefirst.war");
+ try
+ {
+ final String testHost = getServerHost();
+ final String expectedWsdlHost = getServerHost();
+ final String addr = "http://" + testHost +
":8080/jaxws-jbws2150-codefirst/CodeFirstService";
+ final String wsdlLocation = addr + "?wsdl";
+
+ Definition definition = getWSDLDefinition(wsdlLocation);
+ String address = getPortAddress(definition, "CodeFirstService",
"CodeFirstPort");
+ assertEquals("http://" + expectedWsdlHost + ":8080/" +
addContext +"/CodeFirstService", address);
+
+ }
+ finally
+ {
+ undeploy("jaxws-jbws2150-codefirst.war");
+ }
+ }
+
+ /**
+ * Test soap:address rewrite. The addresses should not be rewritten because
+ * of the webServiceHost setting.
* (see MetadataBuilder#processAddressRewrite)
*
* @throws Exception
@@ -638,7 +695,7 @@
}
assertEquals(endpoint.echo("hello"), "hello");
}
-
+
private static boolean isTestsuiteServerHostLocalhost() {
return "localhost".equals(getServerHost());
}