Author: alessio.soldano(a)jboss.com
Date: 2012-12-05 12:53:30 -0500 (Wed, 05 Dec 2012)
New Revision: 17053
Modified:
thirdparty/cxf/branches/cxf-2.4.10/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
Log:
[JBPAPP6-1694] Adding autoRewriteSoapAddressForAllServices option (CXF-4677)
Modified:
thirdparty/cxf/branches/cxf-2.4.10/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.4.10/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java 2012-12-05
14:46:09 UTC (rev 17052)
+++
thirdparty/cxf/branches/cxf-2.4.10/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java 2012-12-05
17:53:30 UTC (rev 17053)
@@ -82,6 +82,7 @@
public static final WSDLGetInterceptor INSTANCE = new WSDLGetInterceptor();
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";
private static final String WSDLS_KEY = WSDLGetInterceptor.class.getName() +
".WSDLs";
@@ -302,7 +303,6 @@
Map<String, SchemaReference> smp,
Message message) {
List<Element> elementList = null;
- Object rewriteSoapAddress = message.getContextualProperty(AUTO_REWRITE_ADDRESS);
try {
elementList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(),
@@ -348,7 +348,18 @@
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");
@@ -385,6 +396,25 @@
soapAddress.setAttribute("location", base);
}
}
+
+ 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
+ }
+ }
+ }
static String resolveWithCatalogs(OASISCatalogManager catalogs, String start, String
base) {
try {