Author: heiko.braun(a)jboss.com
Date: 2008-03-07 15:31:54 -0500 (Fri, 07 Mar 2008)
New Revision: 5892
Added:
framework/branches/hbraun/framework-3.0.iml
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/TestSampleServlet.java
Modified:
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/DefaultSPIProvider.java
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/deployment/DefaultEndpoint.java
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpDeamon.java
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpSpec.java
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpTransportManager.java
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/HttpDeamonTestCase.java
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/TransportManagerTestCase.java
Log:
HttpTransportManager prototype
Added: framework/branches/hbraun/framework-3.0.iml
===================================================================
--- framework/branches/hbraun/framework-3.0.iml (rev 0)
+++ framework/branches/hbraun/framework-3.0.iml 2008-03-07 20:31:54 UTC (rev 5892)
@@ -0,0 +1,198 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module version="4" relativePaths="true"
type="JAVA_MODULE">
+ <component name="ModuleRootManager" />
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5"
inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/output/classes" />
+ <exclude-output />
+ <output-test url="file://$MODULE_DIR$/output/test/classes" />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java"
isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java"
isTestSource="false" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module" module-name="spi-3.0" />
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jbossws-common-src.zip!/"
/>
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jboss-common-core.jar!/"
/>
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jetty-util.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jbossws-spi.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jsr181-api.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jaxb-api.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jboss-xml-binding.jar!/"
/>
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jbossws-common.jar!/"
/>
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jboss-javaee.jar!/"
/>
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/dom4j.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/activation.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/junit.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jbossws-spi-src.zip!/"
/>
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jaxws-api.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root
url="jar://$MODULE_DIR$/thirdparty/jboss-common-core-sources.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jaxrpc-api.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jboss-logging-spi.jar!/"
/>
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/jetty.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root
url="jar://$MODULE_DIR$/thirdparty/jboss-xml-binding-sources.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/thirdparty/saaj-api.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntryProperties />
+ </component>
+</module>
+
Modified:
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/DefaultSPIProvider.java
===================================================================
---
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/DefaultSPIProvider.java 2008-03-07
19:17:00 UTC (rev 5891)
+++
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/DefaultSPIProvider.java 2008-03-07
20:31:54 UTC (rev 5892)
@@ -108,7 +108,11 @@
else if (ServiceRefMetaDataParserFactory.class.equals(spiType))
{
returnType = (T)loadService(spiType,
DefaultServiceRefMetaDataParserFactory.class.getName());
- }
+ }
+ else if (TransportManagerFactory.class.equals(spiType))
+ {
+ returnType = (T)loadService(spiType,
DefaultTransportManagerFactory.class.getName());
+ }
// SPI provided by either container or stack integration
@@ -139,11 +143,7 @@
else if (WebServiceContextFactory.class.equals(spiType))
{
returnType = (T)loadService(spiType, null);
- }
- else if (TransportManagerFactory.class.equals(spiType))
- {
- returnType = (T)loadService(spiType, null);
- }
+ }
if (returnType == null)
throw new WSFException("Failed to provide SPI '" + spiType +
"'");
Modified:
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/deployment/DefaultEndpoint.java
===================================================================
---
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/deployment/DefaultEndpoint.java 2008-03-07
19:17:00 UTC (rev 5891)
+++
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/deployment/DefaultEndpoint.java 2008-03-07
20:31:54 UTC (rev 5892)
@@ -26,6 +26,7 @@
import java.util.Vector;
import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
import org.jboss.wsf.spi.deployment.AbstractExtensible;
import org.jboss.wsf.spi.deployment.Endpoint;
@@ -62,6 +63,9 @@
DefaultEndpoint(String targetBean)
{
+ if(null==targetBean)
+ throw new IllegalArgumentException("targetBean name cannot be null");
+
this.targetBean = targetBean;
this.state = EndpointState.UNDEFINED;
}
@@ -128,6 +132,21 @@
public ObjectName getName()
{
+ if(null==name)
+ {
+ // build implicit name
+ try
+ {
+ String domain = "org.jboss.ws";
+ String nameAtt = getShortName()!=null ? getShortName() : targetBean;
+
+ name = new ObjectName(domain, "name", nameAtt);
+ } catch (MalformedObjectNameException e)
+ {
+ //
+ }
+ }
+
return name;
}
Modified:
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpDeamon.java
===================================================================
---
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpDeamon.java 2008-03-07
19:17:00 UTC (rev 5891)
+++
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpDeamon.java 2008-03-07
20:31:54 UTC (rev 5892)
@@ -93,16 +93,16 @@
/**
* Add a servlet for a contextand url pattern.
*
- * @param name
+ * @param contextPath
* @param urlPattern
* @param servletClass
*/
- public void addServletContext(String name, String urlPattern, Servlet servletClass)
+ public void addServletContext(String contextPath, String urlPattern, Servlet
servletClass)
{
try
{
Context context = new Context();
- context.setContextPath(name);
+ context.setContextPath(contextPath);
ServletHolder holder = new ServletHolder(servletClass);
context.addServlet(holder, urlPattern);
context.start();
@@ -110,7 +110,7 @@
} catch (Exception e)
{
- throw new RuntimeException("Failed to start webcontext: " +name, e );
+ throw new RuntimeException("Failed to start webcontext: "
+contextPath, e );
}
}
Modified:
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpSpec.java
===================================================================
---
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpSpec.java 2008-03-07
19:17:00 UTC (rev 5891)
+++
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpSpec.java 2008-03-07
20:31:54 UTC (rev 5892)
@@ -33,6 +33,15 @@
private String webContext;
private String urlPattern;
+ public HttpSpec(String webContext, String urlPattern)
+ {
+ if(!webContext.startsWith("/"))
+ throw new IllegalArgumentException("webContext needs to start with
'/'");
+
+ this.webContext = webContext;
+ this.urlPattern = urlPattern;
+ }
+
public Protocol getProtocol()
{
return Protocol.HTTP;
@@ -43,18 +52,8 @@
return webContext;
}
- public void setWebContext(String webContext)
- {
- this.webContext = webContext;
- }
-
public String getUrlPattern()
{
return urlPattern;
}
-
- public void setUrlPattern(String urlPattern)
- {
- this.urlPattern = urlPattern;
- }
}
Modified:
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpTransportManager.java
===================================================================
---
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpTransportManager.java 2008-03-07
19:17:00 UTC (rev 5891)
+++
framework/branches/hbraun/src/main/java/org/jboss/wsf/framework/transport/HttpTransportManager.java 2008-03-07
20:31:54 UTC (rev 5892)
@@ -25,8 +25,13 @@
import org.jboss.wsf.spi.transport.ListenerRef;
import org.jboss.wsf.spi.transport.TransportManager;
-import java.util.HashMap;
-import java.util.Map;
+import javax.management.ObjectName;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -35,22 +40,49 @@
*/
public class HttpTransportManager implements TransportManager<HttpSpec>
{
- private Map<String, Object> contexts = new HashMap<String, Object>();
-
- public ListenerRef createListener(Endpoint endpoint, HttpSpec transportProperties)
+ private HttpDeamon httpDeamon;
+
+ private static final int DEFAULT_PORT = 20000;
+ private static final String DEFAULT_HOST = "localhost";
+
+ private int port;
+ private String host;
+
+ public HttpTransportManager(String host, int port)
{
- contexts.put(transportProperties.getWebContext(), new Object());
- System.out.println( "Created webcontext: /" +
transportProperties.getWebContext());
+ this.host = host;
+ this.port = port;
+ this.httpDeamon = HttpDeamon.getInstance(DEFAULT_PORT);
+ this.httpDeamon.start();
+ }
+
+ public HttpTransportManager()
+ {
+ this(DEFAULT_HOST, DEFAULT_PORT);
+ }
+
+ public ListenerRef createListener(Endpoint endpoint, HttpSpec transportProperties)
+ {
+ Servlet listener = new EndpointServlet(endpoint);
+ this.httpDeamon.addServletContext(
+ transportProperties.getWebContext(),
+ transportProperties.getUrlPattern(),
+ listener
+ );
+
return createListenerRef(transportProperties);
}
private ListenerRef createListenerRef(HttpSpec transportProperties)
{
+
+ assert transportProperties.getWebContext().startsWith("/");
+
try
{
String ctx = transportProperties.getWebContext();
- URI address = new URI("http://localhost/" + ctx);
+ URI address = new URI("http://"+host+":"+port + ctx);
return new HttpListenerRef(ctx, address);
} catch (URISyntaxException e)
{
@@ -60,14 +92,34 @@
public void destroyListener(ListenerRef ref)
{
- Object result = contexts.remove(ref.getUUID());
- if(result==null)
+
+ }
+
+ public class EndpointServlet extends HttpServlet
+ {
+ ObjectName endpointName;
+
+ public EndpointServlet(Endpoint endpoint)
{
- throw new IllegalArgumentException("No such webcontext: " +
ref.getUUID());
+ if(null==endpoint.getName())
+ throw new IllegalArgumentException("Endpoint objectName is null");
+
+ this.endpointName = endpoint.getName();
}
- System.out.println("Removed webcontext: /" + ref.getUUID());
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ response.setContentType("text/plain");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().println(endpointName);
+ }
+
+
+ protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse
httpServletResponse)
+ throws ServletException, IOException
+ {
+ throw new ServletException("POST not yet implemented");
+ }
}
-
-
}
Modified:
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/HttpDeamonTestCase.java
===================================================================
---
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/HttpDeamonTestCase.java 2008-03-07
19:17:00 UTC (rev 5891)
+++
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/HttpDeamonTestCase.java 2008-03-07
20:31:54 UTC (rev 5892)
@@ -24,10 +24,6 @@
import junit.framework.TestCase;
import org.jboss.wsf.framework.transport.HttpDeamon;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -49,13 +45,16 @@
public void testContextCreation() throws Exception
{
- SERVER.addServletContext("/endpoint", "/*", new
EndpointServlet());
+ SERVER.addServletContext("/endpoint", "/*", new
TestSampleServlet());
assertEquals("I'm a web service endpoint",
GETRequest("endpoint"));
}
- private static String GETRequest(String context)
+ public static String GETRequest(String context)
throws IOException
{
+ if(context.startsWith("/"))
+ context = context.substring(1);
+
URLConnection con = new
URL("http://localhost:20000/"+context).openConnection();
con.connect();
@@ -71,17 +70,6 @@
sb.append(inputLine);
in.close();
return sb.toString();
- }
-
- private class EndpointServlet extends HttpServlet
- {
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException
- {
- response.setContentType("text/html");
- response.setStatus(HttpServletResponse.SC_OK);
- response.getWriter().println("I'm a web service endpoint");
- }
- }
+ }
}
Added:
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/TestSampleServlet.java
===================================================================
---
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/TestSampleServlet.java
(rev 0)
+++
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/TestSampleServlet.java 2008-03-07
20:31:54 UTC (rev 5892)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.framework.transport;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class TestSampleServlet extends HttpServlet
+{
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ response.setContentType("text/html");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().println("I'm a web service endpoint");
+ }
+}
\ No newline at end of file
Property changes on:
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/TestSampleServlet.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/TransportManagerTestCase.java
===================================================================
---
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/TransportManagerTestCase.java 2008-03-07
19:17:00 UTC (rev 5891)
+++
framework/branches/hbraun/src/test/java/org/jboss/test/ws/framework/transport/TransportManagerTestCase.java 2008-03-07
20:31:54 UTC (rev 5892)
@@ -32,33 +32,41 @@
import org.jboss.wsf.spi.transport.TransportManager;
import org.jboss.wsf.spi.transport.TransportManagerFactory;
+import javax.management.ObjectName;
+
/**
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
public class TransportManagerTestCase extends TestCase
{
- private Endpoint EP;
- private TransportManagerFactory TM_FACTORY;
+ private TransportManagerFactory transportManagerFactory;
+ private DeploymentModelFactory deploymentModelFactory;
protected void setUp() throws Exception
{
SPIProvider framework = DefaultSPIProviderResolver.getInstance().getProvider();
- DeploymentModelFactory fac = framework.getSPI(DeploymentModelFactory.class);
- EP = fac.newEndpoint("MyEndpointBean.class");
- TM_FACTORY = framework.getSPI(TransportManagerFactory.class);
+ deploymentModelFactory = framework.getSPI(DeploymentModelFactory.class);
+ transportManagerFactory= framework.getSPI(TransportManagerFactory.class);
}
public void testHttpTransportManager() throws Exception
{
- TransportManager transportManager =
TM_FACTORY.createTransportManager(Protocol.HTTP);
- HttpSpec spec = new HttpSpec();
- spec.setWebContext("myWebContext");
- ListenerRef ref = transportManager.createListener(EP, spec);
+ // Create a Endpoint
+ Endpoint endpoint =
deploymentModelFactory.newEndpoint("foo.bar.EndpointImpl.class");
+
+ // Create a listener
+ TransportManager transportManager =
transportManagerFactory.createTransportManager(Protocol.HTTP);
+ HttpSpec spec = new HttpSpec("/myWebContext", "/*");
+ ListenerRef ref = transportManager.createListener(endpoint, spec);
assertEquals(spec.getProtocol(), ref.getProtocol());
- System.out.println(ref.getProtocol() +": "+ref.getAddress());
- transportManager.destroyListener(ref);
+ System.out.println(ref.getProtocol() +": "+ref.getAddress());
+ // Invoke the sample endpoint
+ String response = HttpDeamonTestCase.GETRequest("/myWebContext");
+ System.out.println(response);
+ // Destroy the Listener
+ transportManager.destroyListener(ref);
}
}