diff options
author | nash <nash@13f79535-47bb-0310-9956-ffa450edef68> | 2008-07-25 12:14:10 +0000 |
---|---|---|
committer | nash <nash@13f79535-47bb-0310-9956-ffa450edef68> | 2008-07-25 12:14:10 +0000 |
commit | 1138973f5fbfeb3061b0b6b42bf83c03942f53f4 (patch) | |
tree | 897578d286673e69d011f033477a46a369fd2090 /java/sca/modules/binding-ws-axis2/src/main | |
parent | c2d02c05c8e0a886cdce693b1abd8341b23dc464 (diff) |
Fix TUSCANY-2480
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@679776 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/binding-ws-axis2/src/main')
2 files changed, 64 insertions, 50 deletions
diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java index 1b1867a1f1..1f2772aa14 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java +++ b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java @@ -65,7 +65,6 @@ import org.apache.axis2.description.WSDL2Constants; import org.apache.axis2.description.WSDLToAxisServiceBuilder; import org.apache.axis2.engine.ListenerManager; import org.apache.axis2.engine.MessageReceiver; -import org.apache.axis2.transport.http.server.HttpUtils; import org.apache.axis2.transport.jms.JMSConstants; import org.apache.axis2.transport.jms.JMSListener; import org.apache.axis2.transport.jms.JMSSender; @@ -124,7 +123,6 @@ public class Axis2ServiceProvider { private List<PolicyHandlerTuple> policyHandlerClassnames = null; private List<PolicyHandler> policyHandlerList = new ArrayList<PolicyHandler>(); private Map<String, Port> urlMap = new HashMap<String, Port>(); - private Map<String, String> addressMap = new HashMap<String, String>(); public static final QName QNAME_WSA_ADDRESS = new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_ADDRESS); @@ -199,6 +197,27 @@ public class Axis2ServiceProvider { } } + static String getPortAddress(Port port) { + Object ext = port.getExtensibilityElements().get(0); + if (ext instanceof SOAPAddress) { + return ((SOAPAddress)ext).getLocationURI(); + } + if (ext instanceof SOAP12Address) { + return ((SOAP12Address)ext).getLocationURI(); + } + return null; + } + + static void setPortAddress(Port port, String locationURI) { + Object ext = port.getExtensibilityElements().get(0); + if (ext instanceof SOAPAddress) { + ((SOAPAddress)ext).setLocationURI(locationURI); + } + if (ext instanceof SOAP12Address) { + ((SOAP12Address)ext).setLocationURI(locationURI); + } + } + private String computeEndpointURI(String uri, ServletHost servletHost) { if (uri == null) { @@ -347,13 +366,6 @@ public class Axis2ServiceProvider { } */ - // remove it from the Axis context - String modifiedURI = addressMap.remove(endpointURL); - for (Object port : wsBinding.getService().getPorts().values()) { - if (modifiedURI.equals(getPortAddress((Port)port))) { - setPortAddress((Port)port, endpointURL); - } - } configContext.getAxisConfiguration().removeService(stringURIPath); } } catch (URISyntaxException e) { @@ -494,13 +506,6 @@ public class Axis2ServiceProvider { // addresses. To work around this, compute the values here. Parameter modifyAddr = new Parameter("modifyUserWSDLPortAddress", "false"); axisService.addParameter(modifyAddr); - String modifiedURL = setIPAddress(endpointURL); - addressMap.put(endpointURL, modifiedURL); - for (Object p : wsBinding.getService().getPorts().values()) { - if (endpointURL.equals(getPortAddress((Port)p))) { - setPortAddress((Port)p, modifiedURL); - } - } return axisService; } @@ -575,39 +580,6 @@ public class Axis2ServiceProvider { } } - private String getPortAddress(Port port) { - Object ext = port.getExtensibilityElements().get(0); - if (ext instanceof SOAPAddress) { - return ((SOAPAddress)ext).getLocationURI(); - } - if (ext instanceof SOAP12Address) { - return ((SOAP12Address)ext).getLocationURI(); - } - return null; - } - - private void setPortAddress(Port port, String locationURI) { - Object ext = port.getExtensibilityElements().get(0); - if (ext instanceof SOAPAddress) { - ((SOAPAddress)ext).setLocationURI(locationURI); - } - if (ext instanceof SOAP12Address) { - ((SOAP12Address)ext).setLocationURI(locationURI); - } - } - - private static String setIPAddress(String uriString) { - try { - URI uriObj = new URI(uriString); - String ipAddr = HttpUtils.getIpAddress(); - String host = uriObj.getHost(); - return uriString.replace(host, ipAddr); - } catch (Exception e) { - // URI string not in expected format, so return it unmodified - return uriString; - } - } - protected void initAxisOperations(AxisService axisService) { for (Iterator<?> i = axisService.getOperations(); i.hasNext();) { AxisOperation axisOp = (AxisOperation)i.next(); diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java index 2342e7f6ef..21fef3e5d8 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java +++ b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.net.URI; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -52,6 +53,7 @@ import org.apache.axis2.description.AxisService; import org.apache.axis2.description.Parameter; import org.apache.axis2.description.PolicyInclude; import org.apache.axis2.transport.http.ListingAgent; +import org.apache.axis2.transport.http.server.HttpUtils; import org.apache.axis2.util.ExternalPolicySerializer; import org.apache.axis2.util.JavaUtils; import org.apache.axis2.wsdl.WSDLConstants; @@ -90,7 +92,8 @@ public class TuscanyListingAgent extends ListingAgent { /** * Override ?xsd processing so that WSDL documents with XSD imports * and includes work correctly. When we move to Axis2 1.4, we may - * be able to use SchemaSupplier to do this in a cleaner way. + * be able to use SchemaSupplier to do this in a cleaner way. Also + * ensure that the correct IP address and port are returned by ?wsdl. */ @Override public void processListService(HttpServletRequest req, @@ -99,6 +102,27 @@ public class TuscanyListingAgent extends ListingAgent { String url = req.getRequestURL().toString(); String query = req.getQueryString(); + + // for ?wsdl requests, need to update the WSDL with correct IPaddr and port + int wsdl = query.indexOf("wsdl"); + if (wsdl >= 0) { + String serviceName = extractServiceName(url); + HashMap services = configContext.getAxisConfiguration().getServices(); + if ((services != null) && !services.isEmpty()) { + AxisService axisService = (AxisService)services.get(serviceName); + Parameter wsld4jdefinition = axisService.getParameter(WSDLConstants.WSDL_4_J_DEFINITION); + Definition definition = (Definition)wsld4jdefinition.getValue(); + for (Object s : definition.getServices().values()) { + for (Object p : ((Service)s).getPorts().values()) { + String endpointURL = Axis2ServiceProvider.getPortAddress((Port)p); + String modifiedURL = setIPAddress(endpointURL, url); + Axis2ServiceProvider.setPortAddress((Port)p, modifiedURL); + } + } + } + } + + // handle ?xsd requests here int xsd = query.indexOf("xsd"); if (xsd >= 0) { String serviceName = extractServiceName(url); @@ -127,6 +151,7 @@ public class TuscanyListingAgent extends ListingAgent { } } } + // in all other cases, delegate to the Axis2 code super.processListService(req, res); } @@ -193,4 +218,21 @@ public class TuscanyListingAgent extends ListingAgent { } } + private static String setIPAddress(String wsdlURI, String requestURI) { + try { + URI wsdlURIObj = new URI(wsdlURI); + String wsdlHost = wsdlURIObj.getHost(); + int wsdlPort = wsdlURIObj.getPort(); + String wsdlAddr = wsdlHost + (wsdlPort != -1 ? ":" + Integer.toString(wsdlPort) : ""); + URI requestURIObj = new URI(requestURI); + String ipAddr = HttpUtils.getIpAddress(); + int requestPort = requestURIObj.getPort(); + String newAddr = ipAddr + (requestPort != -1 ? ":" + Integer.toString(requestPort) : ""); + return wsdlURI.replace(wsdlAddr, newAddr); + } catch (Exception e) { + // URI string not in expected format, so return the WSDL URI unmodified + return wsdlURI; + } + } + } |