djencks 2005/02/23 13:13:27
Modified: modules/core/src/java/org/openejb/server/xfire
SoapHttpListener.java SoapHttpListenerGBean.java
WSContainer.java WSContainerGBean.java
Removed: modules/core/src/java/org/openejb/server/xfire
WSContainerIndex.java WSContainerIndexGBean.java
Log:
refactor ws to use WebServiceContainer rather than WSContainerIndex. Openejb
uses its SoapHttpListener, geronimo uses Jetty for invoking ws
Revision Changes Path
1.2 +31 -57
openejb/modules/core/src/java/org/openejb/server/xfire/SoapHttpListener.java
Index: SoapHttpListener.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/xfire/SoapHttpListener.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SoapHttpListener.java 18 Feb 2005 23:22:00 -0000 1.1
+++ SoapHttpListener.java 23 Feb 2005 18:13:27 -0000 1.2
@@ -46,33 +46,27 @@
import java.io.IOException;
-import java.io.OutputStream;
-import java.io.InputStream;
-import java.net.URL;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamException;
+import java.util.HashMap;
+import java.util.Map;
-import org.codehaus.xfire.MessageContext;
-import org.codehaus.xfire.java.DefaultJavaService;
+import org.apache.geronimo.webservices.WebServiceContainer;
+import org.apache.geronimo.webservices.WebServiceInvoker;
import org.openejb.server.httpd.HttpListener;
import org.openejb.server.httpd.HttpRequest;
import org.openejb.server.httpd.HttpResponse;
-public class SoapHttpListener implements HttpListener {
+public class SoapHttpListener implements HttpListener, WebServiceContainer {
- private final WSContainerIndex containerIndex;
+ private final Map contextPathToWSMap = new HashMap();
- public SoapHttpListener(WSContainerIndex containerIndex) {
- this.containerIndex = containerIndex;
- }
public void onMessage(HttpRequest req, HttpResponse res) throws
IOException {
-
+ //TODO previous behavior of closing streams was inconsistent.
+ //Following servlet model, neither in or out is beinc closed.
+ //TODO probably returning 500 internal server error would be more
appropriate than translating to IOException.
String path = req.getURI().getPath();
- WSContainer container = containerIndex.getContainer(path);
+ WebServiceInvoker container = (WebServiceInvoker)
contextPathToWSMap.get(path);
if (container == null) {
res.setCode(404);
@@ -82,51 +76,31 @@
res.setContentType("text/xml");
- if (req.getQueryParameter("wsdl") != null){
- doWSDLRequest(container, res);
+ if (req.getQueryParameter("wsdl") != null) {
+ try {
+ container.getWsdl(res.getOutputStream());
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw (IOException) new IOException("Could not fetch
wsdl!").initCause(e);
+ }
} else {
- doInvoke(res, req, container);
+ try {
+ container.invoke(req.getInputStream(),
res.getOutputStream(), req.getURI().toString());
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw (IOException) new IOException("Could not process
message!").initCause(e);
+ }
}
-
}
- private void doInvoke(HttpResponse res, HttpRequest req, WSContainer
container) throws IOException {
- // We have to set the context classloader or the StAX API
- // won't be able to find it's implementation.
- Thread thread = Thread.currentThread();
- ClassLoader originalClassLoader = thread.getContextClassLoader();
-
- try {
-
thread.setContextClassLoader(container.getClass().getClassLoader());
- MessageContext context = new MessageContext("not-used", null,
res.getOutputStream(), null, req.getURI().toString());
- context.setRequestStream(req.getInputStream());
- container.invoke(context);
- } finally {
- thread.setContextClassLoader(originalClassLoader);
- }
- }
- private void doWSDLRequest(WSContainer container, HttpResponse res)
throws IOException {
- URL wsdlURL = container.getWsdlURL();
- InputStream in = null;
- OutputStream out = null;
- try {
- in = wsdlURL.openStream();
- out = res.getOutputStream();
- byte[] buffer = new byte[1024];
- for (int read = in.read(buffer); read > 0; read =
in.read(buffer) ) {
- System.out.write(buffer, 0, read);
- out.write(buffer, 0 ,read);
- }
- } finally {
- if (in != null) {
- in.close();
- }
- if (out != null) {
- out.flush();
- out.close();
- }
- }
+ public void addWebService(String contextPath, WebServiceInvoker
webServiceInvoker) throws Exception {
+ contextPathToWSMap.put(contextPath, webServiceInvoker);
}
+ public void removeWebService(String contextPath) {
+ contextPathToWSMap.remove(contextPath);
+ }
}
1.2 +9 -11
openejb/modules/core/src/java/org/openejb/server/xfire/SoapHttpListenerGBean.java
Index: SoapHttpListenerGBean.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/xfire/SoapHttpListenerGBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SoapHttpListenerGBean.java 18 Feb 2005 23:22:00 -0000 1.1
+++ SoapHttpListenerGBean.java 23 Feb 2005 18:13:27 -0000 1.2
@@ -53,6 +53,7 @@
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.jmx.JMXUtil;
+import org.apache.geronimo.webservices.WebServiceContainer;
import org.openejb.server.httpd.HttpRequest;
import org.openejb.server.httpd.HttpResponse;
@@ -61,32 +62,29 @@
public static final GBeanInfo GBEAN_INFO;
static {
- GBeanInfoBuilder infoFactory = new
GBeanInfoBuilder(SoapHttpListener.class);
+ GBeanInfoBuilder infoBuilder = new
GBeanInfoBuilder(SoapHttpListener.class);
- infoFactory.addOperation("onMessage", new Class[]{HttpRequest.class,
HttpResponse.class});
- infoFactory.addReference("WSContainerIndex", WSContainerIndex.class);
+ infoBuilder.addOperation("onMessage", new Class[]{HttpRequest.class,
HttpResponse.class});
+ infoBuilder.addInterface(WebServiceContainer.class);
- infoFactory.setConstructor(new String[]{"WSContainerIndex"});
-
- GBEAN_INFO = infoFactory.getBeanInfo();
+ GBEAN_INFO = infoBuilder.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
- public static ObjectName addGBean(Kernel kernel, String name, ObjectName
containerIndex) throws GBeanAlreadyExistsException, GBeanNotFoundException {
- GBeanData gbean = createGBean(name, containerIndex);
+ public static ObjectName addGBean(Kernel kernel, String name) throws
GBeanAlreadyExistsException, GBeanNotFoundException {
+ GBeanData gbean = createGBean(name);
kernel.loadGBean(gbean, SoapHttpListener.class.getClassLoader());
kernel.startGBean(gbean.getName());
return gbean.getName();
}
- public static GBeanData createGBean(String name, ObjectName
containerIndex) {
+ public static GBeanData createGBean(String name) {
ObjectName gbeanName =
JMXUtil.getObjectName("openejb:type=SoapHttpListener,name=" + name);
GBeanData gbean = new GBeanData(gbeanName,
SoapHttpListenerGBean.GBEAN_INFO);
- gbean.setReferencePattern("WSContainerIndex", containerIndex);
return gbean;
}
1.3 +64 -3
openejb/modules/core/src/java/org/openejb/server/xfire/WSContainer.java
Index: WSContainer.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/xfire/WSContainer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WSContainer.java 19 Feb 2005 09:46:39 -0000 1.2
+++ WSContainer.java 23 Feb 2005 18:13:27 -0000 1.3
@@ -44,6 +44,8 @@
*/
package org.openejb.server.xfire;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
@@ -54,6 +56,9 @@
import org.apache.geronimo.core.service.InvocationResult;
import org.apache.geronimo.webservices.MessageContextInvocationKey;
+import org.apache.geronimo.webservices.WebServiceInvoker;
+import org.apache.geronimo.webservices.WebServiceContainer;
+import org.apache.geronimo.gbean.GBeanLifecycle;
import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.XFireRuntimeException;
import org.codehaus.xfire.fault.Soap11FaultHandler;
@@ -69,21 +74,23 @@
import org.openejb.EJBInvocationImpl;
import org.openejb.proxy.ProxyInfo;
-public class WSContainer implements Invoker {
+public class WSContainer implements Invoker, WebServiceInvoker,
GBeanLifecycle {
private final EJBContainer ejbContainer;
private final URI location;
private final URL wsdlURL;
private final DefaultJavaService service;
+ private final WebServiceContainer webServiceContainer;
protected WSContainer() {
this.ejbContainer = null;
this.location = null;
this.wsdlURL = null;
this.service = null;
+ this.webServiceContainer = null;
}
- public WSContainer(EJBContainer ejbContainer, Definition definition, URI
location, URL wsdlURL, String namespace, String encoding, String style) {
+ public WSContainer(EJBContainer ejbContainer, Definition definition, URI
location, URL wsdlURL, String namespace, String encoding, String style,
WebServiceContainer webServiceContainer) throws Exception {
this.ejbContainer = ejbContainer;
this.location = location;
this.wsdlURL = wsdlURL;
@@ -104,6 +111,44 @@
LightWeightServiceConfigurator configurator = new
LightWeightServiceConfigurator(definition, service);
configurator.configure();
+ this.webServiceContainer = webServiceContainer;
+ if (webServiceContainer != null) {
+ webServiceContainer.addWebService(location.getPath(), this);
+ }
+ }
+
+ public void invoke(InputStream in, OutputStream out, String uri) throws
Exception {
+ // We have to set the context classloader or the StAX API
+ // won't be able to find it's implementation.
+ Thread thread = Thread.currentThread();
+ ClassLoader originalClassLoader = thread.getContextClassLoader();
+
+ try {
+ thread.setContextClassLoader(getClass().getClassLoader());
+ MessageContext context = new MessageContext("not-used", null,
out, null, uri);
+ context.setRequestStream(in);
+ invoke(context);
+ } finally {
+ thread.setContextClassLoader(originalClassLoader);
+ }
+
+ }
+
+ public void getWsdl(OutputStream out) throws Exception {
+ InputStream in = null;
+ try {
+ in = wsdlURL.openStream();
+ byte[] buffer = new byte[1024];
+ for (int read = in.read(buffer); read > 0; read =
in.read(buffer) ) {
+ System.out.write(buffer, 0, read);
+ out.write(buffer, 0 ,read);
+ }
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+
}
public void invoke(MessageContext context) {
@@ -149,6 +194,22 @@
public URL getWsdlURL() {
return wsdlURL;
+ }
+
+ public void doStart() throws Exception {
+
+ }
+
+ public void doStop() throws Exception {
+ if (webServiceContainer != null) {
+ webServiceContainer.removeWebService(location.getPath());
+ }
+ }
+
+ public void doFail() {
+ if (webServiceContainer != null) {
+ webServiceContainer.removeWebService(location.getPath());
+ }
}
private static class SimpleMessageContext implements
javax.xml.rpc.handler.MessageContext {
1.2 +11 -5
openejb/modules/core/src/java/org/openejb/server/xfire/WSContainerGBean.java
Index: WSContainerGBean.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/xfire/WSContainerGBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WSContainerGBean.java 18 Feb 2005 23:22:00 -0000 1.1
+++ WSContainerGBean.java 23 Feb 2005 18:13:27 -0000 1.2
@@ -56,6 +56,7 @@
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.jmx.JMXUtil;
+import org.apache.geronimo.webservices.WebServiceContainer;
import org.codehaus.xfire.MessageContext;
import org.openejb.EJBContainer;
@@ -75,6 +76,7 @@
infoFactory.addAttribute("namespace", String.class, true);
infoFactory.addAttribute("encoding", String.class, true);
infoFactory.addAttribute("style", String.class, true);
+ infoFactory.addReference("WebServiceContainer",
WebServiceContainer.class);
infoFactory.setConstructor(new String[]{
"EJBContainer",
@@ -83,7 +85,9 @@
"wsdlURL",
"namespace",
"encoding",
- "style"});
+ "style",
+ "WebServiceContainer"
+ });
GBEAN_INFO = infoFactory.getBeanInfo();
}
@@ -92,14 +96,14 @@
return GBEAN_INFO;
}
- public static ObjectName addGBean(Kernel kernel, String name, ObjectName
ejbContainer, Definition definition, URI location, URL wsdlURL, String
namespace, String encoding, String style) throws GBeanAlreadyExistsException,
GBeanNotFoundException {
- GBeanData gbean = createGBean(name, ejbContainer, definition,
location, wsdlURL, namespace, encoding, style);
+ public static ObjectName addGBean(Kernel kernel, String name, ObjectName
ejbContainer, ObjectName listener, Definition definition, URI location, URL
wsdlURL, String namespace, String encoding, String style) throws
GBeanAlreadyExistsException, GBeanNotFoundException {
+ GBeanData gbean = createGBean(name, ejbContainer, listener,
definition, location, wsdlURL, namespace, encoding, style);
kernel.loadGBean(gbean, WSContainer.class.getClassLoader());
kernel.startGBean(gbean.getName());
return gbean.getName();
}
- public static GBeanData createGBean(String name, ObjectName
ejbContainer, Definition definition, URI location, URL wsdlURL, String
namespace, String encoding, String style) {
+ public static GBeanData createGBean(String name, ObjectName
ejbContainer, ObjectName listener, Definition definition, URI location, URL
wsdlURL, String namespace, String encoding, String style) {
assert ejbContainer != null : "EJBContainer objectname is null";
ObjectName gbeanName =
JMXUtil.getObjectName("openejb:type=WSContainer,name=" + name);
@@ -112,6 +116,8 @@
gbean.setAttribute("namespace", namespace);
gbean.setAttribute("encoding", encoding);
gbean.setAttribute("style", style);
+
+ gbean.setReferencePattern("WebServiceContainer", listener);
return gbean;
}