[jboss-svn-commits] JBossWS SVN: r1146 - in branches/tdiesler/jbossws-1.0/src: main/java/org/jboss/ws/server main/resources/jbossws.beans/META-INF test/ant test/java/org/jboss/test/ws/jaxws test/java/org/jboss/test/ws/jaxws/jbws1178
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 5 16:32:36 EDT 2006
Author: thomas.diesler at jboss.com
Date: 2006-10-05 16:32:21 -0400 (Thu, 05 Oct 2006)
New Revision: 1146
Added:
branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/
branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/JBWS1178TestCase.java
branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/TestEndpoint.java
Modified:
branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpoint.java
branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpointManager.java
branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpointManagerMBean.java
branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/WSDLRequestHandler.java
branches/tdiesler/jbossws-1.0/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml
branches/tdiesler/jbossws-1.0/src/test/ant/build-jars-jaxws.xml
Log:
[JBWS-1178] Multiple virtual host and soap:address problem
Modified: branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpoint.java
===================================================================
--- branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpoint.java 2006-10-05 17:48:45 UTC (rev 1145)
+++ branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpoint.java 2006-10-05 20:32:21 UTC (rev 1146)
@@ -36,6 +36,7 @@
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
+import org.jboss.kernel.Kernel;
import org.jboss.logging.Logger;
import org.jboss.ws.utils.DOMWriter;
import org.jboss.ws.Constants;
@@ -122,17 +123,23 @@
/** Handle a WSDL request or a request for an included resource
*/
- public void handleWSDLRequest(OutputStream outStream, URL requestURL, String resourcePath) throws IOException
+ public void handleWSDLRequest(OutputStream outStream, URL reqURL, String resPath) throws IOException
{
ServiceEndpointInfo sepInfo = getServiceEndpointInfo();
EndpointMetaData epMetaData = sepInfo.getServerEndpointMetaData();
- String urlString = requestURL.toExternalForm();
- String requestURI = requestURL.getPath();
- String hostPath = urlString.substring(0, urlString.indexOf(requestURI));
-
+ String wsdlHost = reqURL.getHost();
+
+ ServiceEndpointManagerFactory factory = ServiceEndpointManagerFactory.getInstance();
+ ServiceEndpointManager epManager = factory.getServiceEndpointManager();
+ if (epManager.getWebServiceHost().equals(ServiceEndpointManager.UNDEFINED_HOSTNAME) == false)
+ {
+ wsdlHost = epManager.getWebServiceHost();
+ }
+ log.debug("WSDL request, using host: " + wsdlHost);
+
WSDLRequestHandler wsdlRequestHandler = new WSDLRequestHandler(epMetaData);
- Document document = wsdlRequestHandler.getDocumentForPath(hostPath, requestURI, resourcePath);
+ Document document = wsdlRequestHandler.getDocumentForPath(reqURL, wsdlHost, resPath);
OutputStreamWriter writer = new OutputStreamWriter(outStream);
new DOMWriter(writer).setPrettyprint(true).print(document.getDocumentElement());
Modified: branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpointManager.java
===================================================================
--- branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpointManager.java 2006-10-05 17:48:45 UTC (rev 1145)
+++ branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpointManager.java 2006-10-05 20:32:21 UTC (rev 1146)
@@ -60,7 +60,6 @@
import org.jboss.ws.common.CommonMessageContext;
import org.jboss.ws.jaxrpc.handler.MessageContextJAXRPC;
import org.jboss.ws.jaxrpc.handler.SOAPMessageContextJAXRPC;
-import org.jboss.ws.metadata.EndpointMetaData;
import org.jboss.ws.metadata.HandlerMetaData;
import org.jboss.ws.metadata.ServerEndpointMetaData;
import org.jboss.ws.metadata.UnifiedMetaData;
@@ -81,14 +80,16 @@
// provide logging
private static final Logger log = Logger.getLogger(ServiceEndpointManager.class);
- // default bean name
+ // Default bean name
public static final String BEAN_NAME = "ServiceEndpointManager";
+ // The host name that is returned if there is no other defined
+ public static String UNDEFINED_HOSTNAME = "jbossws.undefined.host";
// maps serviceID to EndpointInfo
private Map<ObjectName, ServiceEndpoint> registry = new ConcurrentHashMap<ObjectName, ServiceEndpoint>();
// The webservice host name that will be used when updating the wsdl
- private String webServiceHost;
+ private String webServiceHost = UNDEFINED_HOSTNAME;
// The webservice port that will be used when updating the wsdl
private int webServicePort;
// The webservice port that will be used when updating the wsdl
@@ -124,21 +125,19 @@
return alwaysModifySOAPAddress;
}
- public void setWebServiceHost(String host)
+ public void setWebServiceHost(String host) throws UnknownHostException
{
+ if (host == null || host.trim().length() == 0)
+ {
+ log.debug("Using undefined host: " + UNDEFINED_HOSTNAME);
+ host = UNDEFINED_HOSTNAME;
+ }
if ("0.0.0.0".equals(host))
{
- try
- {
- InetAddress localHost = InetAddress.getLocalHost();
- host = localHost.getHostName();
- }
- catch (UnknownHostException e)
- {
- log.error("Cannot map host: " + host, e);
- }
+ InetAddress localHost = InetAddress.getLocalHost();
+ log.debug("Using local host: " + localHost.getHostName());
+ host = localHost.getHostName();
}
-
this.webServiceHost = host;
}
Modified: branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpointManagerMBean.java
===================================================================
--- branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpointManagerMBean.java 2006-10-05 17:48:45 UTC (rev 1145)
+++ branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/ServiceEndpointManagerMBean.java 2006-10-05 20:32:21 UTC (rev 1146)
@@ -21,6 +21,7 @@
*/
package org.jboss.ws.server;
+import java.net.UnknownHostException;
import java.util.List;
import javax.management.ObjectName;
@@ -38,7 +39,7 @@
static final ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss.ws:service=ServiceEndpointManager");
String getWebServiceHost();
- void setWebServiceHost(String host);
+ void setWebServiceHost(String host) throws UnknownHostException;
int getWebServicePort();
void setWebServicePort(int port);
Modified: branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/WSDLRequestHandler.java
===================================================================
--- branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/WSDLRequestHandler.java 2006-10-05 17:48:45 UTC (rev 1145)
+++ branches/tdiesler/jbossws-1.0/src/main/java/org/jboss/ws/server/WSDLRequestHandler.java 2006-10-05 20:32:21 UTC (rev 1146)
@@ -25,11 +25,12 @@
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import org.jboss.logging.Logger;
+import org.jboss.ws.metadata.EndpointMetaData;
import org.jboss.ws.utils.DOMUtils;
-import org.jboss.ws.metadata.EndpointMetaData;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -64,10 +65,10 @@
* <p/>
* Use path value of null to get the root document
*
- * @param resourcePath The wsdl resource to get, can be null for the top level wsdl
+ * @param resPath The wsdl resource to get, can be null for the top level wsdl
* @return A wsdl document, or null if it cannot be found
*/
- public Document getDocumentForPath(String hostPath, String requestURI, String resourcePath) throws IOException
+ public Document getDocumentForPath(URL reqURL, String wsdlHost, String resPath) throws IOException
{
String wsdlLocation = epMetaData.getServiceMetaData().getWsdlFile();
if (wsdlLocation == null)
@@ -79,7 +80,7 @@
URL wsdlURL = new URL(wsdlLocation);
// get the root wsdl
- if (resourcePath == null)
+ if (resPath == null)
{
Element wsdlElement = DOMUtils.parse(wsdlURL.openStream());
wsdlDoc = wsdlElement.getOwnerDocument();
@@ -88,21 +89,21 @@
// get some imported resource
else
{
- String resPath = new File(wsdlURL.getPath()).getParent() + File.separatorChar + resourcePath;
- File resFile = new File(resPath);
+ String impResourcePath = new File(wsdlURL.getPath()).getParent() + File.separatorChar + resPath;
+ File impResourceFile = new File(impResourcePath);
- Element wsdlElement = DOMUtils.parse(resFile.toURL().openStream());
+ Element wsdlElement = DOMUtils.parse(impResourceFile.toURL().openStream());
wsdlDoc = wsdlElement.getOwnerDocument();
}
- modifyImportLocations(hostPath, requestURI, resourcePath, wsdlDoc.getDocumentElement());
+ modifyAddressReferences(reqURL, wsdlHost, resPath, wsdlDoc.getDocumentElement());
return wsdlDoc;
}
/**
* Modify the location of wsdl and schema imports
*/
- private void modifyImportLocations(String hostPath, String requestURI, String resourcePath, Element element)
+ private void modifyAddressReferences(URL reqURL, String wsdlHost, String resPath, Element element) throws MalformedURLException
{
// map wsdl definition imports
NodeList nlist = element.getChildNodes();
@@ -123,23 +124,50 @@
{
String orgLocation = locationAttr.getNodeValue();
boolean isAbsolute = orgLocation.startsWith("http://") || orgLocation.startsWith("https://");
- if (isAbsolute == false && orgLocation.startsWith(requestURI) == false)
+ if (isAbsolute == false && orgLocation.startsWith(reqURL.getPath()) == false)
{
String newResourcePath = orgLocation;
- if (resourcePath != null && resourcePath.indexOf("/") > 0)
- newResourcePath = resourcePath.substring(0, resourcePath.lastIndexOf("/") + 1) + orgLocation;
+ if (resPath != null && resPath.indexOf("/") > 0)
+ newResourcePath = resPath.substring(0, resPath.lastIndexOf("/") + 1) + orgLocation;
- String newLocation = hostPath + requestURI + "?wsdl&resource=" + newResourcePath;
+ String reqProtocol = reqURL.getProtocol();
+ int reqPort = reqURL.getPort();
+ String hostAndPort = wsdlHost + (reqPort > 0 ? ":" + reqPort : "");
+ String reqPath = reqURL.getPath();
+
+ String newLocation = reqProtocol + "://" + hostAndPort + reqPath + "?wsdl&resource=" + newResourcePath;
locationAttr.setNodeValue(newLocation);
log.debug("Mapping import from '" + orgLocation + "' to '" + newLocation + "'");
}
}
}
+ else if ("address".equals(nodeName))
+ {
+ Attr locationAttr = childElement.getAttributeNode("location");
+ if (locationAttr != null)
+ {
+ String orgLocation = locationAttr.getNodeValue();
+
+ URL locURL = new URL(orgLocation);
+ String locProtocol = locURL.getProtocol();
+ String locPath = locURL.getPath();
+ if (reqURL.getProtocol().equals(locProtocol) && reqURL.getPath().equals(locPath))
+ {
+ int locPort = locURL.getPort();
+ String hostAndPort = wsdlHost + (locPort > 0 ? ":" + locPort : "");
+
+ String newLocation = locProtocol + "://" + hostAndPort + locPath;
+ locationAttr.setNodeValue(newLocation);
+
+ log.debug("Mapping address from '" + orgLocation + "' to '" + newLocation + "'");
+ }
+ }
+ }
else
{
- modifyImportLocations(hostPath, requestURI, resourcePath, childElement);
+ modifyAddressReferences(reqURL, wsdlHost, resPath, childElement);
}
}
}
Modified: branches/tdiesler/jbossws-1.0/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml
===================================================================
--- branches/tdiesler/jbossws-1.0/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml 2006-10-05 17:48:45 UTC (rev 1145)
+++ branches/tdiesler/jbossws-1.0/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml 2006-10-05 20:32:21 UTC (rev 1146)
@@ -9,8 +9,10 @@
The WSDL, that is a required deployment artifact for an endpoint, has a <soap:address>
element which points to the location of the endpoint. JBoss supports rewriting of that SOAP address.
- If the content of <soap:address> is a valid URL, JBossWS will not rewrite it unless AlwaysModifySOAPAddress is true.
- If the content of <soap:address> is not a valid URL, JBossWS will rewrite it using the attribute values given below.
+ If the content of <soap:address> is a valid URL, JBossWS will not rewrite it unless 'alwaysModifySOAPAddress' is true.
+ If the content of <soap:address> is not a valid URL, JBossWS will rewrite it using the attribute values given below.
+
+ If 'webServiceHost' is an empty string, JBossWS uses requesters host when rewriting the <soap:address>.
-->
<property name="webServiceHost">${jboss.bind.address}</property>
<property name="webServiceSecurePort">8443</property>
Modified: branches/tdiesler/jbossws-1.0/src/test/ant/build-jars-jaxws.xml
===================================================================
--- branches/tdiesler/jbossws-1.0/src/test/ant/build-jars-jaxws.xml 2006-10-05 17:48:45 UTC (rev 1145)
+++ branches/tdiesler/jbossws-1.0/src/test/ant/build-jars-jaxws.xml 2006-10-05 20:32:21 UTC (rev 1146)
@@ -69,13 +69,19 @@
</jar>
<!-- jaxws-jbws1123 -->
- <war destfile="${build.test.dir}/libs/jaxws-jbws1123.war"
- webxml="${build.test.dir}/resources/jaxws/jbws1123/WEB-INF/web.xml">
+ <war destfile="${build.test.dir}/libs/jaxws-jbws1123.war" webxml="${build.test.dir}/resources/jaxws/jbws1123/WEB-INF/web.xml">
<classes dir="${build.test.dir}/classes">
<include name="org/jboss/test/ws/jaxws/jbws1123/MessageBean.class"/>
</classes>
- </war>
+ </war>
+ <!-- jaxws-jbws1178 -->
+ <war destfile="${build.test.dir}/libs/jaxws-jbws1178.war" webxml="${build.test.dir}/resources/jaxws/jbws1178/WEB-INF/web.xml">
+ <classes dir="${build.test.dir}/classes">
+ <include name="org/jboss/test/ws/jaxws/jbws1178/TestEndpoint.class"/>
+ </classes>
+ </war>
+
<!-- jaxws-jsr181-complex -->
<war warfile="${build.test.dir}/libs/jaxws-jsr181-complex.war" webxml="${build.test.dir}/resources/jaxws/jsr181/complex/WEB-INF/web.xml">
<classes dir="${build.test.dir}/classes">
Added: branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/JBWS1178TestCase.java
===================================================================
--- branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/JBWS1178TestCase.java 2006-10-05 17:48:45 UTC (rev 1145)
+++ branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/JBWS1178TestCase.java 2006-10-05 20:32:21 UTC (rev 1146)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.jbws1178;
+
+import java.net.InetAddress;
+import java.net.URL;
+
+import javax.management.Attribute;
+import javax.management.ObjectName;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.Service;
+import javax.xml.rpc.ServiceFactory;
+
+import junit.framework.Test;
+
+import org.jboss.test.ws.JBossWSTest;
+import org.jboss.test.ws.JBossWSTestSetup;
+import org.jboss.ws.jaxrpc.CallImpl;
+
+/**
+ * Multiple virtual host and soap:address problem
+ *
+ * http://jira.jboss.org/jira/browse/JBWS-1178
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 05-Oct-2006
+ */
+public class JBWS1178TestCase extends JBossWSTest
+{
+ String webServiceHost;
+
+ public static Test suite()
+ {
+ return JBossWSTestSetup.newTestSetup(JBWS1178TestCase.class, "jaxws-jbws1178.war");
+ }
+
+ public void setUp() throws Exception
+ {
+ ObjectName objectName = new ObjectName("jboss.ws:service=ServiceEndpointManager");
+ webServiceHost = (String)getServer().getAttribute(objectName, "WebServiceHost");
+ // Setting the WebServiceHost to an empty string, causes the request host to be used
+ getServer().setAttribute(objectName, new Attribute("WebServiceHost", ""));
+ }
+
+ public void tearDown() throws Exception
+ {
+ ObjectName objectName = new ObjectName("jboss.ws:service=ServiceEndpointManager");
+ getServer().setAttribute(objectName, new Attribute("WebServiceHost", webServiceHost));
+ }
+
+ public void testHostAddress() throws Exception
+ {
+ InetAddress inetAddr = InetAddress.getByName(getServerHost());
+ System.out.println(inetAddr.getHostAddress());
+ URL wsdlURL = new URL("http://" + inetAddr.getHostAddress() + ":8080/jaxws-jbws1178?wsdl");
+
+ ServiceFactory factory = ServiceFactory.newInstance();
+ QName serviceName = new QName("http://org.jboss.ws/jbws1178", "TestEndpointService");
+ QName portName = new QName("http://org.jboss.ws/jbws1178", "TestEndpointPort");
+ Service service = factory.createService(wsdlURL, serviceName);
+ CallImpl call = (CallImpl)service.createCall(portName);
+ URL epURL = new URL(call.getEndpointMetaData().getEndpointAddress());
+
+ assertEquals(wsdlURL.getHost(), epURL.getHost());
+ }
+
+ public void testHostName() throws Exception
+ {
+ InetAddress inetAddr = InetAddress.getByName(getServerHost());
+ URL wsdlURL = new URL("http://" + inetAddr.getHostName() + ":8080/jaxws-jbws1178?wsdl");
+
+ ServiceFactory factory = ServiceFactory.newInstance();
+ QName serviceName = new QName("http://org.jboss.ws/jbws1178", "TestEndpointService");
+ QName portName = new QName("http://org.jboss.ws/jbws1178", "TestEndpointPort");
+ Service service = factory.createService(wsdlURL, serviceName);
+ CallImpl call = (CallImpl)service.createCall(portName);
+ URL epURL = new URL(call.getEndpointMetaData().getEndpointAddress());
+
+ assertEquals(wsdlURL.getHost(), epURL.getHost());
+ }
+}
Property changes on: branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/JBWS1178TestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/TestEndpoint.java
===================================================================
--- branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/TestEndpoint.java 2006-10-05 17:48:45 UTC (rev 1145)
+++ branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/TestEndpoint.java 2006-10-05 20:32:21 UTC (rev 1146)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.jbws1178;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+
+ at WebService(name = "TestEndpoint", targetNamespace = "http://org.jboss.ws/jbws1178")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+public class TestEndpoint
+{
+ @WebMethod
+ public String echo(String input)
+ {
+ return input;
+ }
+}
Property changes on: branches/tdiesler/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/jbws1178/TestEndpoint.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the jboss-svn-commits
mailing list