You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by as...@apache.org on 2012/12/05 16:37:26 UTC

svn commit: r1417485 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java

Author: asoldano
Date: Wed Dec  5 15:37:25 2012
New Revision: 1417485

URL: http://svn.apache.org/viewvc?rev=1417485&view=rev
Log:
Merged revisions 1417426 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1417426 | asoldano | 2012-12-05 15:05:40 +0100 (Wed, 05 Dec 2012) | 2 lines
  
  [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/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1417426

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java?rev=1417485&r1=1417484&r2=1417485&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java (original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java Wed Dec  5 15:37:25 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);