cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject svn commit: r1417426 - /cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
Date Wed, 05 Dec 2012 14:05:40 GMT
Author: asoldano
Date: Wed Dec  5 14:05:40 2012
New Revision: 1417426

URL: http://svn.apache.org/viewvc?rev=1417426&view=rev
Log:
[CXF-4677] Adding 'autoRewriteSoapAddressForAllServices' option for updating all services/ports
soap:address values (except for path) in the doc returned to wsdl queries; this is basically
an extension to the existing 'autoRewriteSoapAddress'

Modified:
    cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java

Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java?rev=1417426&r1=1417425&r2=1417426&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java Wed
Dec  5 14:05:40 2012
@@ -72,6 +72,7 @@ import org.apache.cxf.wsdl11.ServiceWSDL
 public class WSDLGetUtils {
     
     public static final String AUTO_REWRITE_ADDRESS = "autoRewriteSoapAddress";
+    public static final String AUTO_REWRITE_ADDRESS_ALL = "autoRewriteSoapAddressForAllServices";
     public static final String PUBLISHED_ENDPOINT_URL = "publishedEndpointUrl";
     public static final String WSDL_CREATE_IMPORTS = "org.apache.cxf.wsdl.create.imports";
     
@@ -283,7 +284,6 @@ public class WSDLGetUtils {
                            Map<String, SchemaReference> smp,
                            Message message) {        
         List<Element> elementList = null;
-        Object rewriteSoapAddress = message.getContextualProperty(AUTO_REWRITE_ADDRESS);
         
         try {
             elementList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(),
@@ -330,7 +330,18 @@ public class WSDLGetUtils {
                     base), e);
         }
 
-        if (rewriteSoapAddress == null || MessageUtils.isTrue(rewriteSoapAddress)) {
+        boolean rewriteAllSoapAddress = MessageUtils.isTrue(message.getContextualProperty(AUTO_REWRITE_ADDRESS_ALL));
+        if (rewriteAllSoapAddress) {
+            List<Element> portList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(),
+                                                                         "http://schemas.xmlsoap.org/wsdl/",
+                                                                         "port");
+            for (Element el : portList) {
+                rewriteAddressProtocolHostPort(base, el, "http://schemas.xmlsoap.org/wsdl/soap/");
+                rewriteAddressProtocolHostPort(base, el, "http://schemas.xmlsoap.org/wsdl/soap12/");
+            }
+        }
+        Object rewriteSoapAddress = message.getContextualProperty(AUTO_REWRITE_ADDRESS);
+        if (rewriteSoapAddress == null || MessageUtils.isTrue(rewriteSoapAddress) || rewriteAllSoapAddress)
{
             List<Element> serviceList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(),
                                                               "http://schemas.xmlsoap.org/wsdl/",
                                                               "service");
@@ -344,7 +355,6 @@ public class WSDLGetUtils {
                         String name = el.getAttribute("name");
                         if (name.equals(message.getExchange().getEndpoint().getEndpointInfo()
                                             .getName().getLocalPart())) {
-                            
                             rewriteAddress(base, el, "http://schemas.xmlsoap.org/wsdl/soap/");
                             rewriteAddress(base, el, "http://schemas.xmlsoap.org/wsdl/soap12/");
                         }
@@ -368,6 +378,25 @@ public class WSDLGetUtils {
         }
     }
 
+    protected void rewriteAddressProtocolHostPort(String base, Element el, String soapNS)
{
+        List<Element> sadEls = DOMUtils.findAllElementsByTagNameNS(el,
+                                             soapNS,
+                                             "address");
+        for (Element soapAddress : sadEls) {
+            try {
+                String location = soapAddress.getAttribute("location").trim();
+                URL locUrl = new URL(location);
+                URL baseUrl = new URL(base);
+                StringBuilder sb = new StringBuilder(baseUrl.getProtocol());
+                sb.append("://").append(baseUrl.getHost()).append(":").append(baseUrl.getPort())
+                    .append(locUrl.getPath());
+                soapAddress.setAttribute("location", sb.toString());
+            } catch (Exception e) {
+                //ignore
+            }
+        }
+    }
+
     protected String resolveWithCatalogs(OASISCatalogManager catalogs, String start, String
base) {
         try {
             return new OASISCatalogManagerHelper().resolve(catalogs, start, base);



Mime
View raw message