Author: thomas.diesler(a)jboss.com
Date: 2008-02-25 09:53:32 -0500 (Mon, 25 Feb 2008)
New Revision: 5800
Added:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/JBWS1909TestCase.java
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/TestEndpoint.java
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/TestEndpointImpl.java
Modified:
stack/native/trunk/ant-import-tests/build-jars-jaxws.xml
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java
Log:
JBWS-1909 - RequestHandler.handlerWSDLResquest has dependency on Servlet API
Modified: stack/native/trunk/ant-import-tests/build-jars-jaxws.xml
===================================================================
--- stack/native/trunk/ant-import-tests/build-jars-jaxws.xml 2008-02-25 14:48:51 UTC (rev
5799)
+++ stack/native/trunk/ant-import-tests/build-jars-jaxws.xml 2008-02-25 14:53:32 UTC (rev
5800)
@@ -625,6 +625,14 @@
</fileset>
</jar>
+ <!-- jaxws-jbws1909 -->
+ <jar destfile="${tests.output.dir}/libs/jaxws-jbws1909.jar">
+ <fileset dir="${tests.output.dir}/classes">
+ <include name="org/jboss/test/ws/jaxws/jbws1909/*.class"/>
+ <exclude
name="org/jboss/test/ws/jaxws/jbws1909/*TestCase.class"/>
+ </fileset>
+ </jar>
+
<!-- jaxws-jbws1969 -->
<jar destfile="${tests.output.dir}/libs/jaxws-jbws1969.jar">
<fileset dir="${tests.output.dir}/classes">
Modified:
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java 2008-02-25
14:48:51 UTC (rev 5799)
+++
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java 2008-02-25
14:53:32 UTC (rev 5800)
@@ -28,6 +28,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
@@ -93,6 +94,7 @@
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.common.DOMWriter;
import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.common.IOUtils;
import org.w3c.dom.Document;
/**
@@ -521,37 +523,26 @@
}
}
- public void handleWSDLRequest(Endpoint endpoint, OutputStream outputStream,
InvocationContext context)
+ public void handleWSDLRequest(Endpoint endpoint, OutputStream outStream,
InvocationContext context)
{
log.debug("handleWSDLRequest: " + endpoint.getName());
- ServerEndpointMetaData epMetaData =
endpoint.getAttachment(ServerEndpointMetaData.class);
- if (epMetaData == null)
- throw new IllegalStateException("Cannot obtain endpoint meta data");
-
- ServletRequestContext reqContext = (ServletRequestContext)context;
- HttpServletRequest req = reqContext.getHttpServletRequest();
-
try
{
- // For the base document the resourcePath should be null
- String resPath = (String)req.getParameter("resource");
- URL reqURL = new URL(req.getRequestURL().toString());
-
- String wsdlHost = reqURL.getProtocol() + "://" + reqURL.getHost();
- if (reqURL.getPort() != -1)
- wsdlHost += ":" + reqURL.getPort();
-
- if (ServerConfig.UNDEFINED_HOSTNAME.equals(serverConfig.getWebServiceHost()) ==
false)
- wsdlHost = serverConfig.getWebServiceHost();
-
- log.debug("WSDL request, using host: " + wsdlHost);
-
- WSDLRequestHandler wsdlRequestHandler = new WSDLRequestHandler(epMetaData);
- Document document = wsdlRequestHandler.getDocumentForPath(reqURL, wsdlHost,
resPath);
-
- OutputStreamWriter writer = new OutputStreamWriter(outputStream);
- new
DOMWriter(writer).setPrettyprint(true).print(document.getDocumentElement());
+ if (context instanceof ServletRequestContext)
+ {
+ handleWSDLRequestFromServletContext(endpoint, outStream, context);
+ }
+ else
+ {
+ String epAddress = endpoint.getAddress();
+ if (epAddress == null)
+ throw new IllegalArgumentException("Invalid endpoint address: "
+ epAddress);
+
+ URL wsdlUrl = new URL(epAddress + "?wsdl");
+ InputStream inStream = wsdlUrl.openStream();
+ IOUtils.copyStream(outStream, inStream);
+ }
}
catch (RuntimeException rte)
{
@@ -563,6 +554,35 @@
}
}
+ private void handleWSDLRequestFromServletContext(Endpoint endpoint, OutputStream
outputStream, InvocationContext context) throws MalformedURLException, IOException
+ {
+ ServerEndpointMetaData epMetaData =
endpoint.getAttachment(ServerEndpointMetaData.class);
+ if (epMetaData == null)
+ throw new IllegalStateException("Cannot obtain endpoint meta data");
+
+ ServletRequestContext reqContext = (ServletRequestContext)context;
+ HttpServletRequest req = reqContext.getHttpServletRequest();
+
+ // For the base document the resourcePath should be null
+ String resPath = (String)req.getParameter("resource");
+ URL reqURL = new URL(req.getRequestURL().toString());
+
+ String wsdlHost = reqURL.getProtocol() + "://" + reqURL.getHost();
+ if (reqURL.getPort() != -1)
+ wsdlHost += ":" + reqURL.getPort();
+
+ if (ServerConfig.UNDEFINED_HOSTNAME.equals(serverConfig.getWebServiceHost()) ==
false)
+ wsdlHost = serverConfig.getWebServiceHost();
+
+ log.debug("WSDL request, using host: " + wsdlHost);
+
+ WSDLRequestHandler wsdlRequestHandler = new WSDLRequestHandler(epMetaData);
+ Document document = wsdlRequestHandler.getDocumentForPath(reqURL, wsdlHost,
resPath);
+
+ OutputStreamWriter writer = new OutputStreamWriter(outputStream);
+ new DOMWriter(writer).setPrettyprint(true).print(document.getDocumentElement());
+ }
+
private void handleException(Exception ex) throws ServletException
{
log.error("Error processing web service request", ex);
Added:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/JBWS1909TestCase.java
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/JBWS1909TestCase.java
(rev 0)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/JBWS1909TestCase.java 2008-02-25
14:53:32 UTC (rev 5800)
@@ -0,0 +1,58 @@
+/*
+ * 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.jbws1909;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import junit.framework.Test;
+
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestSetup;
+
+/**
+ * [JBWS-1909] RequestHandler.handlerWSDLResquest has dependency on Servlet API
+ *
+ *
http://jira.jboss.org/jira/browse/JBWS-1909
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 25-Feb-2007
+ */
+public class JBWS1909TestCase extends JBossWSTest
+{
+ public static Test suite()
+ {
+ return new JBossWSTestSetup(JBWS1909TestCase.class,
"jaxws-jbws1909.jar");
+ }
+
+ public void testWSDLSchema() throws Exception
+ {
+ URL wsdlURL = new URL("http://" + getServerHost() +
":8080/jaxws-jbws1909/TestEndpointImpl?wsdl");
+ QName serviceName = new QName("http://org.jboss.ws/jbws1909",
"TestEndpointService");
+ Service service = Service.create(wsdlURL, serviceName);
+ TestEndpoint port = service.getPort(TestEndpoint.class);
+ String retStr = port.echo("hello");
+ assertEquals("hello|TestEndpointService", retStr);
+ }
+}
Property changes on:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/JBWS1909TestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/TestEndpoint.java
===================================================================
--- stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/TestEndpoint.java
(rev 0)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/TestEndpoint.java 2008-02-25
14:53:32 UTC (rev 5800)
@@ -0,0 +1,32 @@
+/*
+ * 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.jbws1909;
+
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+
+@WebService(name = "TestEndpoint", targetNamespace =
"http://org.jboss.ws/jbws1909")
+@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
+public interface TestEndpoint
+{
+ String echo(String input);
+}
Property changes on:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/TestEndpoint.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/TestEndpointImpl.java
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/TestEndpointImpl.java
(rev 0)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/TestEndpointImpl.java 2008-02-25
14:53:32 UTC (rev 5800)
@@ -0,0 +1,98 @@
+/*
+ * 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.jbws1909;
+
+// $Id$
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import javax.annotation.Resource;
+import javax.ejb.Stateless;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.management.ObjectName;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
+import org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory;
+import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.common.ObjectNameFactory;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.invocation.RequestHandler;
+import org.jboss.wsf.spi.management.EndpointRegistry;
+import org.jboss.wsf.spi.management.EndpointRegistryFactory;
+import org.w3c.dom.Element;
+
+@WebService(serviceName = "TestEndpointService", name =
"TestEndpoint", targetNamespace = "http://org.jboss.ws/jbws1909")
+@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
+@Stateless
+public class TestEndpointImpl implements TestEndpoint
+{
+ // provide logging
+ private final static Logger log = Logger.getLogger(TestEndpointImpl.class);
+
+ @Resource
+ WebServiceContext context;
+
+ @WebMethod
+ public String echo(String input)
+ {
+ MessageContext msgContext = context.getMessageContext();
+ for (String key : msgContext.keySet())
+ {
+ log.info(key + "=" + msgContext.get(key));
+ }
+
+ SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ EndpointRegistry registry =
spiProvider.getSPI(EndpointRegistryFactory.class).getEndpointRegistry();
+
+ ObjectName oname =
ObjectNameFactory.create("jboss.ws:context=jaxws-jbws1909,endpoint=TestEndpointImpl");
+ Endpoint endpoint = registry.getEndpoint(oname);
+ RequestHandler reqHandler = endpoint.getRequestHandler();
+
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ reqHandler.handleWSDLRequest(endpoint, baos, null); // The context is null
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ Element root = DOMUtils.parse(bais);
+ Element serviceEl = DOMUtils.getFirstChildElement(root, new
QName("http://schemas.xmlsoap.org/wsdl/", "service"));
+ String serviceName = DOMUtils.getAttributeValue(serviceEl, "name");
+
+ input += "|" + serviceName;
+ }
+ catch (IOException ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ return input;
+ }
+}
Property changes on:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1909/TestEndpointImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF