dblevins 2005/02/18 18:22:00
Added: modules/core/src/java/org/openejb/server/xfire
LightWeightServiceConfigurator.java
SoapHttpListener.java SoapHttpListenerGBean.java
WSContainer.java WSContainerGBean.java
WSContainerIndex.java WSContainerIndexGBean.java
Log:
Moved soap package into xfire to easily make room for Axis code
Revision Changes Path
1.1
openejb/modules/core/src/java/org/openejb/server/xfire/LightWeightServiceConfigurator.java
Index: LightWeightServiceConfigurator.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: LightWeightServiceConfigurator.java,v 1.1 2005/02/18 23:22:00
dblevins Exp $
*/
package org.openejb.server.xfire;
import java.lang.reflect.Method;
import java.util.*;
import javax.wsdl.Definition;
import javax.wsdl.Input;
import javax.wsdl.Operation;
import javax.wsdl.Part;
import javax.xml.namespace.QName;
import org.codehaus.xfire.java.DefaultJavaService;
import org.codehaus.xfire.java.Parameter;
import org.codehaus.xfire.java.mapping.DefaultTypeMappingRegistry;
import org.codehaus.xfire.java.mapping.TypeMapping;
import org.codehaus.xfire.java.type.Type;
/**
* TODO: I would be great to be able to configure XFire during deployment and
write it to the configuration
*/
public class LightWeightServiceConfigurator extends
org.apache.geronimo.webservices.WSDLVisitor {
private DefaultJavaService service;
private TypeMapping typeMappings;
private Map parameterMap;
private Map typeMap;
public LightWeightServiceConfigurator(Definition definition,
DefaultJavaService service) {
super(definition);
this.service = service;
// Setup Type Mapping
service.setAutoTyped(true);
DefaultTypeMappingRegistry registry = new
DefaultTypeMappingRegistry();
typeMappings = registry.createDefaultMappings();
registry.registerDefault(typeMappings);
service.setTypeMappingRegistry(registry);
service.initializeTypeMapping();
parameterMap = new HashMap();
typeMap = new HashMap();
}
public void configure() {
this.walkTree();
}
protected void visit(Part part) {
Type type = typeMappings.getType(part.getTypeName());
Parameter parameter = new Parameter(new QName(part.getName()), type);
parameterMap.put(part, parameter);
typeMap.put(part, type.getTypeClass());
}
protected void visit(Operation wsdlOperation) {
Method method = getMethod(wsdlOperation);
org.codehaus.xfire.java.Operation xfireOperation = new
org.codehaus.xfire.java.Operation(method);
// setup input params
Collection inParts =
wsdlOperation.getInput().getMessage().getParts().values();
for (Iterator iterator = inParts.iterator(); iterator.hasNext();) {
Part part = (Part) iterator.next();
Parameter inParameter = (Parameter) parameterMap.get(part);
xfireOperation.addInParameter(inParameter);
}
// setup output param
Iterator outParts =
wsdlOperation.getOutput().getMessage().getParts().values().iterator();
if (outParts.hasNext()) {
Part part = (Part) outParts.next();
Parameter outParameter = (Parameter) parameterMap.get(part);
xfireOperation.addOutParameter(outParameter);
}
service.addOperation(xfireOperation);
}
private Method getMethod(Operation wsdlOperation) {
Input input = wsdlOperation.getInput();
List parts =
input.getMessage().getOrderedParts(wsdlOperation.getParameterOrdering());
Class[] types = new Class[parts.size()];
for (int i = 0; i < parts.size(); i++) {
types[i] = (Class) typeMap.get((Part) parts.get(i));
}
try {
return
service.getServiceClass().getMethod(wsdlOperation.getName(), types);
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("There is no method matching
the operation named " + wsdlOperation.getName());
}
}
}
1.1
openejb/modules/core/src/java/org/openejb/server/xfire/SoapHttpListener.java
Index: SoapHttpListener.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: SoapHttpListener.java,v 1.1 2005/02/18 23:22:00 dblevins Exp $
*/
package org.openejb.server.xfire;
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 org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.java.DefaultJavaService;
import org.openejb.server.httpd.HttpListener;
import org.openejb.server.httpd.HttpRequest;
import org.openejb.server.httpd.HttpResponse;
public class SoapHttpListener implements HttpListener {
private final WSContainerIndex containerIndex;
public SoapHttpListener(WSContainerIndex containerIndex) {
this.containerIndex = containerIndex;
}
public void onMessage(HttpRequest req, HttpResponse res) throws
IOException {
String path = req.getURI().getPath();
WSContainer container = containerIndex.getContainer(path);
if (container == null) {
res.setCode(404);
res.setResponseString("No such web service");
return;
}
res.setContentType("text/xml");
if (req.getQueryParameter("wsdl") != null){
doWSDLRequest(container, res);
} else {
doInvoke(res, req, container);
}
}
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();
}
}
}
}
1.1
openejb/modules/core/src/java/org/openejb/server/xfire/SoapHttpListenerGBean.java
Index: SoapHttpListenerGBean.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: SoapHttpListenerGBean.java,v 1.1 2005/02/18 23:22:00 dblevins Exp $
*/
package org.openejb.server.xfire;
import javax.management.ObjectName;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.openejb.server.httpd.HttpRequest;
import org.openejb.server.httpd.HttpResponse;
public class SoapHttpListenerGBean {
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoBuilder infoFactory = new
GBeanInfoBuilder(SoapHttpListener.class);
infoFactory.addOperation("onMessage", new Class[]{HttpRequest.class,
HttpResponse.class});
infoFactory.addReference("WSContainerIndex", WSContainerIndex.class);
infoFactory.setConstructor(new String[]{"WSContainerIndex"});
GBEAN_INFO = infoFactory.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);
kernel.loadGBean(gbean, SoapHttpListener.class.getClassLoader());
kernel.startGBean(gbean.getName());
return gbean.getName();
}
public static GBeanData createGBean(String name, ObjectName
containerIndex) {
ObjectName gbeanName =
JMXUtil.getObjectName("openejb:type=SoapHttpListener,name=" + name);
GBeanData gbean = new GBeanData(gbeanName,
SoapHttpListenerGBean.GBEAN_INFO);
gbean.setReferencePattern("WSContainerIndex", containerIndex);
return gbean;
}
}
1.1
openejb/modules/core/src/java/org/openejb/server/xfire/WSContainer.java
Index: WSContainer.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: WSContainer.java,v 1.1 2005/02/18 23:22:00 dblevins Exp $
*/
package org.openejb.server.xfire;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import javax.wsdl.Definition;
import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.XFireRuntimeException;
import org.codehaus.xfire.fault.Soap11FaultHandler;
import org.codehaus.xfire.fault.XFireFault;
import org.codehaus.xfire.handler.SoapHandler;
import org.codehaus.xfire.java.DefaultJavaService;
import org.codehaus.xfire.java.Invoker;
import org.codehaus.xfire.java.JavaServiceHandler;
import org.codehaus.xfire.soap.Soap11;
import org.openejb.EJBContainer;
import org.openejb.EJBInterfaceType;
import org.openejb.EJBInvocation;
import org.openejb.EJBInvocationImpl;
import org.openejb.proxy.ProxyInfo;
import org.apache.geronimo.core.service.InvocationKey;
import org.apache.geronimo.webservices.MessageContextInvocationKey;
public class WSContainer implements Invoker {
private final EJBContainer ejbContainer;
private final URI location;
private final URL wsdlURL;
private final DefaultJavaService service;
protected WSContainer() {
this.ejbContainer = null;
this.location = null;
this.wsdlURL = null;
this.service = null;
}
public WSContainer(EJBContainer ejbContainer, Definition definition, URI
location, URL wsdlURL, String namespace, String encoding, String style) {
this.ejbContainer = ejbContainer;
this.location = location;
this.wsdlURL = wsdlURL;
ProxyInfo proxyInfo = ejbContainer.getProxyInfo();
Class serviceEndpointInterface =
proxyInfo.getServiceEndpointInterface();
service = new DefaultJavaService();
service.setName(ejbContainer.getEJBName());
service.setDefaultNamespace(namespace);
service.setServiceClass(serviceEndpointInterface);
service.setSoapVersion(Soap11.getInstance());
service.setStyle(style);
service.setUse(encoding);
service.setWSDLURL(wsdlURL);
service.setServiceHandler(new SoapHandler(new
JavaServiceHandler(this)));
service.setFaultHandler(new Soap11FaultHandler());
LightWeightServiceConfigurator configurator = new
LightWeightServiceConfigurator(definition, service);
configurator.configure();
}
public void invoke(MessageContext context) {
SoapHandler handler = null;
try {
context.setService(service);
handler = (SoapHandler) service.getServiceHandler();
handler.invoke(context);
} catch (Exception e) {
e.printStackTrace();
if (e instanceof XFireRuntimeException) {
throw (XFireRuntimeException) e;
} else if (handler != null) {
XFireFault fault = XFireFault.createFault(e);
handler.handleFault(fault, context);
} else {
throw new XFireRuntimeException("Couldn't process message.",
e);
}
}
}
public Object invoke(Method m, Object[] params, MessageContext context)
throws XFireFault {
try {
int index = ejbContainer.getProxyFactory().getMethodIndex(m);
EJBInvocation invocation = new
EJBInvocationImpl(EJBInterfaceType.WEB_SERVICE, null, index, params);
//I give up, why would you use xfire?
Map properties = new HashMap();
javax.xml.rpc.handler.MessageContext messageContext = new
SimpleMessageContext(properties);
invocation.put(MessageContextInvocationKey.INSTANCE,
messageContext);
return ejbContainer.invoke(invocation);
} catch (Throwable throwable) {
throwable.printStackTrace();
throw new XFireFault("Error invoking EJB", throwable,
XFireFault.RECEIVER);
}
}
public URI getLocation() {
return location;
}
public URL getWsdlURL() {
return wsdlURL;
}
private static class SimpleMessageContext implements
javax.xml.rpc.handler.MessageContext {
private final Map properties;
public SimpleMessageContext(Map properties) {
this.properties = new HashMap(properties);
}
public boolean containsProperty(String name) {
return properties.containsKey(name);
}
public Object getProperty(String name) {
return properties.get(name);
}
public Iterator getPropertyNames() {
return properties.keySet().iterator();
}
public void removeProperty(String name) {
properties.remove(name);
}
public void setProperty(String name, Object value) {
properties.put(name, value);
}
}
}
1.1
openejb/modules/core/src/java/org/openejb/server/xfire/WSContainerGBean.java
Index: WSContainerGBean.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: WSContainerGBean.java,v 1.1 2005/02/18 23:22:00 dblevins Exp $
*/
package org.openejb.server.xfire;
import java.net.URI;
import java.net.URL;
import javax.management.ObjectName;
import javax.wsdl.Definition;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.codehaus.xfire.MessageContext;
import org.openejb.EJBContainer;
public class WSContainerGBean {
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoBuilder infoFactory = new
GBeanInfoBuilder(WSContainer.class);
infoFactory.addOperation("invoke", new Class[]{MessageContext.class});
infoFactory.addReference("EJBContainer", EJBContainer.class);
infoFactory.addAttribute("definition", Definition.class, true);
infoFactory.addAttribute("location", URI.class, true);
infoFactory.addAttribute("wsdlURL", URL.class, true);
infoFactory.addAttribute("namespace", String.class, true);
infoFactory.addAttribute("encoding", String.class, true);
infoFactory.addAttribute("style", String.class, true);
infoFactory.setConstructor(new String[]{
"EJBContainer",
"definition",
"location",
"wsdlURL",
"namespace",
"encoding",
"style"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
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);
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) {
assert ejbContainer != null : "EJBContainer objectname is null";
ObjectName gbeanName =
JMXUtil.getObjectName("openejb:type=WSContainer,name=" + name);
GBeanData gbean = new GBeanData(gbeanName,
WSContainerGBean.GBEAN_INFO);
gbean.setReferencePattern("EJBContainer", ejbContainer);
gbean.setAttribute("definition", definition);
gbean.setAttribute("location", location);
gbean.setAttribute("wsdlURL", wsdlURL);
gbean.setAttribute("namespace", namespace);
gbean.setAttribute("encoding", encoding);
gbean.setAttribute("style", style);
return gbean;
}
}
1.1
openejb/modules/core/src/java/org/openejb/server/xfire/WSContainerIndex.java
Index: WSContainerIndex.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: WSContainerIndex.java,v 1.1 2005/02/18 23:22:00 dblevins Exp $
*/
package org.openejb.server.xfire;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.gbean.ReferenceCollection;
import org.apache.geronimo.gbean.ReferenceCollectionEvent;
import org.apache.geronimo.gbean.ReferenceCollectionListener;
/**
* This class is a bit crufty. Need something like this, but not static
* and more along the lines of a collection of containers registered as gbeans
*/
public class WSContainerIndex implements ReferenceCollectionListener,
GBeanLifecycle {
// todo delete me
private static WSContainerIndex containerIndex = new WSContainerIndex();
public static WSContainerIndex getInstance() {
return containerIndex;
}
/**
* Index from jndi name to the index (Integer) number in the containers
lookup table
*/
private final HashMap urlToContainerMap = new HashMap();
/**
* GBean reference collection that we watch for new containers to register
*/
private ReferenceCollection wsContainers;
protected WSContainerIndex() {
}
public WSContainerIndex(Collection wsContainers) {
WSContainerIndex.containerIndex = this;
this.wsContainers = (ReferenceCollection) wsContainers;
this.wsContainers.addReferenceCollectionListener(this);
}
public void doStart() throws Exception {
for (Iterator iterator = wsContainers.iterator();
iterator.hasNext();) {
WSContainer container = (WSContainer) iterator.next();
urlToContainerMap.put(container.getLocation().getPath(),
container);
}
}
public void doStop() throws Exception {
urlToContainerMap.clear();
}
public void doFail() {
urlToContainerMap.clear();
}
public synchronized void addContainer(WSContainer container) {
urlToContainerMap.put(container.getLocation().getPath(), container);
}
public synchronized void removeContainer(WSContainer container) {
urlToContainerMap.remove(container.getLocation().getPath());
}
public void memberAdded(ReferenceCollectionEvent event) {
addContainer((WSContainer) event.getMember());
}
public void memberRemoved(ReferenceCollectionEvent event) {
removeContainer((WSContainer) event.getMember());
}
public synchronized WSContainer getContainer(String urlPath) {
return (WSContainer) urlToContainerMap.get(urlPath);
}
}
1.1
openejb/modules/core/src/java/org/openejb/server/xfire/WSContainerIndexGBean.java
Index: WSContainerIndexGBean.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: WSContainerIndexGBean.java,v 1.1 2005/02/18 23:22:00 dblevins Exp $
*/
package org.openejb.server.xfire;
import javax.management.ObjectName;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.jmx.JMXUtil;
public class WSContainerIndexGBean {
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoBuilder infoFactory = new
GBeanInfoBuilder(WSContainerIndex.class);
infoFactory.addOperation("getContainer", new Class[]{String.class});
infoFactory.addReference("WSContainers", WSContainer.class);
infoFactory.setConstructor(new String[]{"WSContainers"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
public static ObjectName addGBean(Kernel kernel, String name, ObjectName
wsContainers) throws GBeanAlreadyExistsException, GBeanNotFoundException {
GBeanData gbean = createGBean(name, wsContainers);
kernel.loadGBean(gbean, WSContainerIndex.class.getClassLoader());
kernel.startGBean(gbean.getName());
return gbean.getName();
}
public static GBeanData createGBean(String name, ObjectName wsContainers)
{
ObjectName gbeanName =
JMXUtil.getObjectName("openejb:type=WSContainerIndex,name=" + name);
GBeanData gbean = new GBeanData(gbeanName,
WSContainerIndexGBean.GBEAN_INFO);
gbean.setReferencePattern("WSContainers", wsContainers);
return gbean;
}
}