User: jung
Date: 00/12/04 04:35:59
Modified: src/org/jboss/ejb/plugins/zoap ComponentURNResolver.java
SoapComponent.java SoapContainerInvoker.java
SoapInvocationHandler.java zoap.dfPackage
Removed: src/org/jboss/ejb/plugins/zoap ContractBinding.java
Log:
adopted to latest jboss container,
added decimal and date
removed some problems due to forward-referencing in meta-data
added serialisation policy
Revision Changes Path
1.3 +26 -69 zoap/src/org/jboss/ejb/plugins/zoap/ComponentURNResolver.java
Index: ComponentURNResolver.java
===================================================================
RCS file:
/products/cvs/ejboss/zoap/src/org/jboss/ejb/plugins/zoap/ComponentURNResolver.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ComponentURNResolver.java 2000/09/04 16:44:23 1.2
+++ ComponentURNResolver.java 2000/12/04 12:35:57 1.3
@@ -1,22 +1,22 @@
/*
- * $Id: ComponentURNResolver.java,v 1.2 2000/09/04 16:44:23 jung Exp $
- * Copyright (c) 2000 infor:business solutions AG, Hauerstrasse 12,
- * D-66299 Friedrichsthal, Germany. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
+ * $Id: ComponentURNResolver.java,v 1.3 2000/12/04 12:35:57 jung Exp $
+ * Copyright (c) 2000 infor:business solutions AG, Hauerstrasse 12,
+ * D-66299 Friedrichsthal, Germany. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
package org.jboss.ejb.plugins.zoap;
@@ -32,9 +32,7 @@
import org.zoap.xml.URNResolver;
import org.zoap.xml.XmlObjectReader;
-/**
- * this urnresolver uses the context classpath to find meta-data resources
- */
+/** this urnresolver uses the context classpath to find meta-data resources */
public class ComponentURNResolver implements URNResolver {
@@ -42,64 +40,29 @@
throws IOException {
- if(Environment.DEBUG_ZOAP)
-
Environment.out.println(toString()+".resolveURN("+theUrn+","+visitedURNs+")");
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".resolveURN(" + theUrn +
"," + visitedURNs + ")");
- return new XmlObjectReader(new java.io.InputStreamReader(Thread.
- currentThread().getContextClassLoader().
- getResourceAsStream(theUrn.toString())), theUrn, this,
- visitedURNs);
+ return new XmlObjectReader(
+ new java.io.InputStreamReader(Thread.
+ currentThread().getContextClassLoader().
+ getResourceAsStream(theUrn.toString())), theUrn, this,
+ visitedURNs);
}
-
-
}
-
-
/*
-
* $Log: ComponentURNResolver.java,v $
- * Revision 1.2 2000/09/04 16:44:23 jung
- * Class should be public to be extensible.
- *
- * Revision 1.1 2000/08/11 14:43:49 jung
- * added comments how to run the testsuite with jboss.
- * an scl file was wrongly named and had to be moved.
- * added a special urn resolver that uses the bean-context
- * classloader to find the meta-data.
+ * Revision 1.3 2000/12/04 12:35:57 jung
+ * adopted to latest jboss container,
*
- * Revision 1.1.1.1 2000/08/10 21:07:34 jung
- * Initial import.
+ * added decimal and date
*
+ * removed some problems due to forward-referencing in meta-data
*
-
- * Revision 1.1.2.1 2000/08/04 17:20:19 jung
-
- * close to beta stadium. Meta-Data import now works.
-
+ * added serialisation policy
*
-
- * Revision 1.2 2000/07/06 16:55:05 jung
-
- * moved the default binding caches in order to make apartments
-
- * with different versions of the same class possible.
-
- *
-
- * Revision 1.1.1.1 2000/07/06 14:11:25 jung
-
- * Import of a pre beta version of ZOAP source with a new directory structure,
-
- * ant-based make, apache-kind of license, etc.
-
- *
-
- * jars are coming later because of cvs-history reasons.
-
- *
-
*/
1.2 +93 -69 zoap/src/org/jboss/ejb/plugins/zoap/SoapComponent.java
Index: SoapComponent.java
===================================================================
RCS file:
/products/cvs/ejboss/zoap/src/org/jboss/ejb/plugins/zoap/SoapComponent.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SoapComponent.java 2000/08/10 21:06:50 1.1
+++ SoapComponent.java 2000/12/04 12:35:58 1.2
@@ -1,69 +1,93 @@
-/*
- * $Id: SoapComponent.java,v 1.1 2000/08/10 21:06:50 jung Exp $
- * Copyright (c) 2000 infor:business solutions AG, Hauerstrasse 12,
- * D-66299 Friedrichsthal, Germany. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-package org.jboss.ejb.plugins.zoap;
-
-import org.jboss.zoap.Environment;
-
-import org.zoap.soap.meta.SoapBinding;
-import org.zoap.soap.meta.builtin.DefaultMetaBinding;
-
-import org.zoap.xml.XmlObjectReader;
-
-import de.infor.ce.util.Component;
-import de.infor.ce.util.URN;
-
-import java.net.URL;
-
-/**
- * SoapComponent is an extension to the de.infor.ce.util.Component concept that
stores meta-data used for SOAP services.
- * @author $Author: jung $
- * @version $Revision: 1.1 $
- */
-
-public class SoapComponent extends Component {
-
- /** cant change the binding once set */
- final private SoapBinding binding;
-
- /** construct a new component for the given classloader */
-
- public SoapComponent(ClassLoader classLoader)
- throws Component.DoubleComponentException, ClassCastException,
InstantiationException, IllegalAccessException {
-
- super(classLoader);
-
- if (Environment.DEBUG_ZOAP)
- Environment.out.print(toString() + "(" + classLoader + ")\n");
-
- enter();
-
- binding = (SoapBinding)Environment.defaultBindingClass.newInstance();
-
- leave();
- }
-
- /** returns the binding associated to this component */
-
- public SoapBinding getBinding() {
- return binding;
- }
-
-} // SoapComponent
+/*
+ * $Id: SoapComponent.java,v 1.2 2000/12/04 12:35:58 jung Exp $
+ * Copyright (c) 2000 infor:business solutions AG, Hauerstrasse 12,
+ * D-66299 Friedrichsthal, Germany. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package org.jboss.ejb.plugins.zoap;
+
+import org.jboss.zoap.Environment;
+
+import org.zoap.soap.meta.SoapBinding;
+import org.zoap.soap.meta.builtin.DefaultMetaBinding;
+
+import org.zoap.xml.XmlObjectReader;
+
+import de.infor.ce.util.Component;
+import de.infor.ce.util.URN;
+
+import java.net.URL;
+
+import java.util.ArrayList;
+
+import java.io.IOException;
+
+
+/**
+ * SoapComponent is an extension to the de.infor.ce.util.Component concept that
stores meta-data used for SOAP services.
+ * @author $Author: jung $
+ * @version $Revision: 1.2 $
+ */
+
+public class SoapComponent extends Component {
+
+ /** cant change the binding once set */
+ final private SoapBinding binding;
+
+ /** construct a new component for the given classloader */
+
+ public SoapComponent(ClassLoader classLoader, String bindingClassName, boolean
readMetaData, String fileName)
+ throws Component.DoubleComponentException, ClassNotFoundException,
IOException, InstantiationException, IllegalAccessException {
+
+ super(classLoader);
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.print(toString() + "(" + classLoader + "," +
bindingClassName + "," + readMetaData + "," + fileName + ")\n");
+
+ enter();
+
+ binding = (SoapBinding)Class.forName(bindingClassName, true,
+ classLoader).newInstance();
+
+
+ if (readMetaData) {
+
+ ComponentURNResolver resolver = new ComponentURNResolver();
+
+ XmlObjectReader xmlObjectReader =
+ resolver.resolveURN(
+ new URN(fileName),
+ new ArrayList(0));
+
+ xmlObjectReader.setBinding(binding);
+ xmlObjectReader.readObject();
+ }
+
+ leave();
+ }
+
+ /** returns the binding associated to this component */
+
+ public SoapBinding getBinding() {
+
+ if(Environment.DEBUG_LEVEL>0)
+ Environment.out.println(toString()+".getBinding()");
+
+ return binding;
+ }
+
+} // SoapComponent
1.2 +521 -394 zoap/src/org/jboss/ejb/plugins/zoap/SoapContainerInvoker.java
Index: SoapContainerInvoker.java
===================================================================
RCS file:
/products/cvs/ejboss/zoap/src/org/jboss/ejb/plugins/zoap/SoapContainerInvoker.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SoapContainerInvoker.java 2000/08/10 21:06:51 1.1
+++ SoapContainerInvoker.java 2000/12/04 12:35:58 1.2
@@ -1,394 +1,521 @@
-/*
- * $Id: SoapContainerInvoker.java,v 1.1 2000/08/10 21:06:51 jung Exp $
- * Copyright (c) 2000 infor:business solutions AG, Hauerstrasse 12,
- * D-66299 Friedrichsthal, Germany. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-package org.jboss.ejb.plugins.zoap;
-
-import org.jboss.zoap.Environment;
-
-import org.zoap.soap.SoapRouter;
-import org.zoap.soap.SoapObject;
-import org.zoap.soap.SoapServer;
-import org.zoap.soap.SoapMessage;
-import org.zoap.soap.SoapMessageException;
-import org.zoap.soap.meta.SoapBinding;
-import org.zoap.soap.Envelope;
-import org.zoap.soap.SoapException;
-import org.zoap.soap.MethodRequest;
-import org.zoap.soap.MethodResponse;
-
-import org.jboss.ejb.ContainerInvoker;
-import org.jboss.ejb.ContainerInvokerContainer;
-import org.jboss.ejb.Container;
-import org.jboss.ejb.Interceptor;
-import org.jboss.util.MBeanProxy;
-import org.jboss.ejb.StatelessSessionEnterpriseContext;
-import org.jboss.ejb.MethodInvocation;
-
-import de.infor.ce.util.Component;
-
-import javax.ejb.EJBObject;
-import javax.ejb.EJBMetaData;
-import javax.ejb.EJBHome;
-
-import java.util.Collection;
-import java.util.Properties;
-
-
-/**
- * SoapContainerInvoker is a container-invoker plugin for jboss that is able
- * to provide beans as Soap objects over the network. The idea is that the
- * invoker registers in a soap server as a router under a url directory that
- * corresponds to the JNDI name of the bean. Requests dedicated to the directory
will create new beans that are invoked.
- * Requests dedicated to a particular handle will invoke dedicated beans that have
been taken out of the pool, hopefully.
- * SoapContainerInvoker (de-)serialises incoming SOAP messages before giving them
- * to processing inside the beans. For that purpose, the deployed component
- * needs to have extended meta-data in the form of a data-binding that is used for
- * (de-)serialisation.
- *
- * Some of the EJB-responsibilities of a container invoker are not yet
- * resolved sufficiently. For example the creation of invocation handlers
- * to the home and to the bean is yet implemented only prototypically.
- *
- * @author $Author: jung $
- * @version $Revision: 1.1 $
- */
-
-public class SoapContainerInvoker implements ContainerInvoker, SoapRouter {
-
- /** reference to my container should also implement the
containerinvokercontainer interface since yesterday ... */
- private Container con;
-
- /** the soap server that we can bind to */
- private SoapServer server;
-
- /** the component we are sitting inside */
- private Component component;
-
- /** accessor to container, sets the right databinding and contructs the home
and remote class references */
-
- public void setContainer(Container theContainer) {
-
- if (Environment.DEBUG_ZOAP)
- Environment.out.println("SoapContainerInvoker.setContainer(" +
theContainer + ")");
-
- con = theContainer;
-
- component = Component.getComponentFor(con.getClassLoader());
-
- if (component == null) {
- try {
- component = new SoapComponent(con.getClassLoader());
- } catch (Component.DoubleComponentException e) {
-
- if(Environment.DEBUG_ZOAP || Environment.LOG_ZOAP>0)
-
Environment.err.print(toString()+".setContainer("+theContainer+"): encountered
component error "+e+".\n");
-
- } catch (InstantiationException e) {
-
- if(Environment.DEBUG_ZOAP || Environment.LOG_ZOAP>0)
-
Environment.err.print(toString()+".setContainer("+theContainer+"): encountered
component error "+e+".\n");
-
- } catch(IllegalAccessException e) {
-
- if(Environment.DEBUG_ZOAP || Environment.LOG_ZOAP>0)
-
Environment.err.print(toString()+".setContainer("+theContainer+"): encountered
component error "+e+".\n");
-
- }
-
-
- }
-
- } // setContainer
-
- /** the constructor is empty */
-
- public SoapContainerInvoker() {
- }
-
- /** the init method, prepare to operation by finding out the server */
-
- public void init() throws Exception {
- server =
- (SoapServer)MBeanProxy.create(SoapServer.class, Environment.PROPERTY +
":server=HTTP");
- }
-
- /** start method to register at the server as a soap router */
-
- public void start() throws Exception {
- server.registerSoapRouter(con.getMetaData().getJndiName(), this);
- }
-
- /** this method is called from the server when an EJB object should be invoked
through SOAP */
-
- public void receiveRequest(String handle, SoapMessage message,
- SoapMessage response) throws SoapMessageException {
-
- if (Environment.DEBUG_ZOAP)
- Environment.out.println("SoapContainerInvoker.receiveRequest("
+ handle + "," +
- message + "," + response + ")");
-
- // fiddle with the class loader to run into protected component code
- component.enter();
-
- // this is the envelope what we return
- Envelope returnValue = null;
-
- // this should be the envelope that we receive
- Envelope envelope = null;
-
- try {
-
- // extract the envelope that they have sent us
- envelope =
message.getEnvelope(((SoapComponent)component).getBinding());
-
- } catch (SoapException e) {
-
- // SoapException means a generic error while getting the
envelope
- // this is preinvocation, so we return a message exception
-
- if (Environment.DEBUG_ZOAP)
-
Environment.err.println("SoapContainerInvoker.receiveMessage(" + handle + "," +
- message + "," + response + "): encountered soap
exception " + e);
-
- component.leave();
-
- throw new SoapMessageException();
-
- }
-
- // if it does not contain a method call, we are pissed
- if (envelope == null || !(envelope.getBody() instanceof
MethodRequest)) {
- component.leave();
- throw new SoapMessageException();
- }
-
- // isolate the embedded method call that is inside
- MethodRequest methodRequest = (MethodRequest)envelope.getBody();
-
- try {
-
- // now thats a longie, use reflection to determine and invoke
- // the envisaged method using the detected classes and the
- // proper arguments through the container, produce a return
object and put it
- // into a fresh envelope
- MethodResponse methodResponse = new
MethodResponse(methodRequest.getMethod());
-
- methodResponse.setValue(con.invoke(new MethodInvocation(handle,
- methodRequest.getMethod(), methodRequest.getArguments(), null,
null)));
-
- returnValue = new Envelope(null, methodResponse);
-
- // what could have crashed?
- } catch (IllegalAccessException e) {
-
- // illegal access is deep, no application error
- if (Environment.DEBUG_ZOAP)
-
Environment.err.println("SoapContainerInvoker.receiveMessage(" + message + "," +
response +
- "): encountered security problem " + e);
-
- component.leave();
- throw new SoapMessageException();
-
- } catch (NoSuchMethodException e) {
-
- // no such method exception is not quite that deep, but
- // for the moment, we dont treat it as application-close error
-
- if (Environment.DEBUG_ZOAP)
-
Environment.err.println("SoapContainerInvoker.receiveMessage(" + message + "," +
response +
- "): no such method " + e);
-
- component.leave();
- throw new SoapMessageException();
-
- } catch (Throwable t) {
-
- // ahh, this is the indicator for some application error that
we
- // put into the message back to the sender
-
- if (Environment.DEBUG_ZOAP)
-
Environment.err.println("SoapContainerInvoker.receiveMessage(" + message + "," +
response +
- "): application exception encountered " + t);
-
- t.printStackTrace();
-
- returnValue = new Envelope(null, t);
-
- } // try
-
-
- // at this place, the call went through and could only have
- // produced shippable application errors. Hence, we register
- // the result in the reponse
-
- try {
-
- response.setEnvelope(returnValue,
((SoapComponent)component).getBinding());
-
-
- } catch (SoapException e) {
-
- // where still, some exception could occur
- if (Environment.DEBUG_ZOAP)
- Environment.err.println("Interceptor.receiveMessage("
+ message + "," + response +
- "): soap exception while setting return envelope " +
e);
-
- throw new SoapMessageException();
-
- } finally {
- component.leave();
- } // try
-
- } // receiveRequest
-
-
- /** stop this invoker temporarily */
-
- public void stop() {
- try {
- server.unRegisterSoapRouter(con.getMetaData().getJndiName());
- } catch (SoapException e) { }
- }
-
- /** destroy it */
-
- public void destroy() {
- server = null;
- }
-
- /**
- * stuff that we IMHO do not necessarily need, but come from the
ContainerInvoker superclass
- * this is a really silly design where the container and the invoker are
recursively
- * coupled. I do not fully understand why you would like to do it like this ...
- */
-
- public EJBMetaData getEJBMetaData() {
- return null;
- }
-
-
-
- /**
- * this is not to be taken for serious right now. We must find a way to
- * connect to the other�s side server when deserialising the proxy (if
asynchronous, anyway, but thats a thing for later)
- */
-
- public EJBHome getEJBHome() {
-
- if (Environment.DEBUG_ZOAP)
- Environment.out.println("SoapContainerInvoker.getEJBHome()");
-
- // fiddle with the class loader to run into protected component code
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(con.getClassLoader());
-
- // currently a total fake!
-
- EJBHome home = (EJBHome)java.lang.reflect.Proxy.
- newProxyInstance(Thread.currentThread().getContextClassLoader(),
- new Class[] { ((ContainerInvokerContainer)con).getHomeClass() },
- new
SoapInvocationHandler(getURL(),getURL(),((ContainerInvokerContainer)con).getHomeClass(),
- ((ContainerInvokerContainer)con).getRemoteClass(),((SoapComponent)
component)));
-
- Thread.currentThread().setContextClassLoader(oldCl);
-
- return home;
- }
-
- public EJBObject getStatelessSessionEJBObject() {
-
- if (Environment.DEBUG_ZOAP)
-
Environment.out.println("SoapContainerInvoker.getStatelessSessionEJBObject()");
-
- // fiddle with the class loader to run into protected component code
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(con.getClassLoader());
-
- EJBObject object = (EJBObject)java.lang.reflect.Proxy.
- newProxyInstance(con.getClassLoader(),
- new Class[] { ((ContainerInvokerContainer)con).getRemoteClass() },
- new
SoapInvocationHandler(getURL(),getURL(),((ContainerInvokerContainer)con).getHomeClass(),
- ((ContainerInvokerContainer)con).getRemoteClass(),((SoapComponent)
component)));
-
- Thread.currentThread().setContextClassLoader(oldCl);
-
- if (Environment.DEBUG_ZOAP)
-
Environment.out.println("SoapContainerInvoker.getStatelessSessionEJBObject():
returning " +
- object);
-
- return object;
-
- }
-
- public EJBObject getStatefulSessionEJBObject(Object id) {
-
- if (Environment.DEBUG_ZOAP)
-
Environment.out.println("SoapContainerInvoker.getStatefulSessionEJBObject()");
-
- // fiddle with the class loader to run into protected component code
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(con.getClassLoader());
-
- EJBObject object = (EJBObject)java.lang.reflect.Proxy.
- newProxyInstance(con.getClassLoader(),
- new Class[] { ((ContainerInvokerContainer)con).getRemoteClass() },
- new
SoapInvocationHandler(getURL(),getURL(),((ContainerInvokerContainer)con).getHomeClass(),
- ((ContainerInvokerContainer)con).getRemoteClass(), ((SoapComponent)
component)));
-
- Thread.currentThread().setContextClassLoader(oldCl);
-
- return object;
- }
-
- public EJBObject getEntityEJBObject(Object id) {
- return null;
- }
-
- public Collection getEntityCollection(Collection ids) {
- return null;
- }
-
- /** unregistration is not necessary */
-
- public void unRegisterSoapObject(String handle) {
- }
-
- /** registration is not necessary */
-
- public String registerSoapObject(SoapObject object) {
- return null;
- }
-
- /** gets the url pointing to this invoker */
-
- public java.net.URL getURL() {
- try{
- return new java.net.URL(server.getURL(),
con.getMetaData().getJndiName());
- } catch (java.net.MalformedURLException e) {
- return null;
- } catch(java.net.UnknownHostException e) {
- return null;
- }
-
- }
-
-
-
-}
+/*
+ * $Id: SoapContainerInvoker.java,v 1.2 2000/12/04 12:35:58 jung Exp $
+ * Copyright (c) 2000 infor:business solutions AG, Hauerstrasse 12,
+ * D-66299 Friedrichsthal, Germany. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package org.jboss.ejb.plugins.zoap;
+
+import org.jboss.zoap.Environment;
+
+import org.zoap.xml.SerialisationPolicy;
+
+import org.zoap.soap.SoapRouter;
+import org.zoap.soap.SoapObject;
+import org.zoap.soap.SoapServer;
+import org.zoap.soap.SoapMessage;
+import org.zoap.soap.SoapMessageException;
+import org.zoap.soap.meta.SoapBinding;
+import org.zoap.soap.Envelope;
+import org.zoap.soap.SoapException;
+import org.zoap.soap.MethodRequest;
+import org.zoap.soap.MethodResponse;
+
+import org.jboss.ejb.ContainerInvoker;
+import org.jboss.ejb.ContainerInvokerContainer;
+import org.jboss.ejb.Container;
+import org.jboss.ejb.Interceptor;
+import org.jboss.util.MBeanProxy;
+import org.jboss.ejb.StatelessSessionEnterpriseContext;
+import org.jboss.ejb.MethodInvocation;
+
+import org.jboss.metadata.XmlLoadable;
+import org.jboss.metadata.MetaData;
+
+import org.jboss.ejb.DeploymentException;
+
+import de.infor.ce.util.Component;
+
+import javax.ejb.EJBObject;
+import javax.ejb.EJBMetaData;
+import javax.ejb.EJBHome;
+
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.w3c.dom.Element;
+
+/**
+ * SoapContainerInvoker is a container-invoker plugin for jboss that is able
+ * to provide beans as Soap objects over the network. The idea is that the
+ * invoker registers in a soap server as a router under a url directory that
+ * corresponds to the JNDI name of the bean. Requests dedicated to the directory
will create new beans that are invoked.
+ * Requests dedicated to a particular handle will invoke dedicated beans that have
been taken out of the pool, hopefully.
+ * SoapContainerInvoker (de-)serialises incoming SOAP messages before giving them
+ * to processing inside the beans. For that purpose, the deployed component
+ * needs to have extended meta-data in the form of a data-binding that is used for
(de-)serialisation.
+ * Some of the EJB-responsibilities of a container invoker are not yet
+ * resolved sufficiently. For example the creation of invocation handlers
+ * to the home and to the bean is yet implemented only prototypically.
+ * @author $Author: jung $
+ * @version $Revision: 1.2 $
+ */
+
+public class SoapContainerInvoker implements ContainerInvoker, SoapRouter,
XmlLoadable {
+
+ /** reference to my container should also implement the
containerinvokercontainer interface since yesterday ... */
+ private Container con;
+
+ /** the soap server that we can bind to */
+ private SoapServer server;
+
+ /** the component we are sitting inside */
+ private Component component;
+
+ /** whether or not to read meta-data */
+ private boolean readMetaData = true;
+
+ /** default filename to read meta-data from */
+ private String metaDataFileName = "META-INF/contract.scl";
+
+ /** default binding class */
+ private String bindingClassName =
"org.zoap.soap.meta.builtin.DefaultMetaBinding";
+
+ /** which serialisation policy we apply */
+ private SerialisationPolicy serialisationPolicy =
org.zoap.xml.SerialisationPolicy.
+ defaultSerialisationPolicy;
+
+ /** accessor to container, initialises the component information for the whole
EJB application */
+ public void setContainer(Container theContainer) {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".setContainer(" +
theContainer + ")");
+
+ con = theContainer;
+
+ component = Component.getComponentFor(con.getClassLoader());
+
+ } // setContainer
+
+ // XmlLoadable implementation
+ public void importXml(Element element) throws DeploymentException {
+
+ try {
+ readMetaData = Boolean.
+ valueOf(MetaData.getElementContent(MetaData.
+ getUniqueChild(element, "ReadMetaData"))).booleanValue();
+ } catch (Exception e) {
+ }
+
+ try {
+ metaDataFileName = MetaData.getElementContent(MetaData.
+ getUniqueChild(element, "MetaDataFileName"));
+ } catch (Exception e) {
+ }
+
+
+ try {
+ bindingClassName = MetaData.getElementContent(MetaData.
+ getUniqueChild(element, "BindingClass"));
+ } catch (Exception e) {
+ }
+
+ try {
+ serialisationPolicy = (SerialisationPolicy)
Class.forName(MetaData.getElementContent(MetaData.
+ getUniqueChild(element, "SerialisationPolicyClass")),true,
con.getClassLoader()).newInstance();
+ } catch (Exception e) {
+ }
+ }
+
+ /** the constructor is empty */
+
+ public SoapContainerInvoker() {
+
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + "()");
+
+
+ }
+
+ /** the init method, prepare to operation by finding out the server */
+
+ public void init() throws Exception {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".init()");
+
+
+ server =
+ (SoapServer)MBeanProxy.create(SoapServer.class, Environment.moduleName
+ ":server=HTTP");
+ }
+
+ /** start method to register at the server as a soap router */
+
+ public void start() throws Exception {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".start()");
+
+ server.registerSoapRouter(con.getBeanMetaData().getJndiName(), this);
+ }
+
+ /** if we were already stateful, we could allow for seperate handles */
+ public SoapObject lookupSoapObject(String handle) {
+ return null;
+ }
+
+ /** return the associated server */
+ public SoapServer getServer() {
+ return server;
+ }
+
+ /** this method is called from the SOAP-server when an EJB object should be
invoked through SOAP */
+
+ public void receiveRequest(String handle, SoapMessage message,
+ SoapMessage response) throws SoapMessageException {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".receiveRequest(" +
handle + "," +
+ message + "," + response + ")");
+
+ if (component == null) {
+ synchronized(this) {
+ if (component == null) {
+ try {
+ component = new
SoapComponent(con.getClassLoader(),
+ bindingClassName,
readMetaData, metaDataFileName);
+ } catch (Component.DoubleComponentException e)
{
+
+ if (Environment.DEBUG_LEVEL > 0 ||
Environment.LOG_LEVEL > 0)
+
Environment.err.print(toString() + ".receiveRequest(" + handle + "," +
+ message + "," + response + "):
encountered component error " + e + ".\n");
+
+ } catch (java.io.IOException e) {
+
+ if (Environment.DEBUG_LEVEL > 0 ||
Environment.LOG_LEVEL > 0)
+
Environment.err.print(toString() + ".receiveRequest(" + handle + "," +
+ message + "," + response + "):
encountered component error " + e + ".\n");
+
+ } catch (ClassNotFoundException e) {
+
+ if (Environment.DEBUG_LEVEL > 0 ||
Environment.LOG_LEVEL > 0)
+
Environment.err.print(toString() + ".receiveRequest(" + handle + "," +
+ message + "," + response + "):
encountered component error " + e + ".\n");
+
+ } catch (InstantiationException e) {
+
+ if (Environment.DEBUG_LEVEL > 0 ||
Environment.LOG_LEVEL > 0)
+
Environment.err.print(toString() + ".receiveRequest(" + handle + "," +
+ message + "," + response + "):
encountered component error " + e + ".\n");
+
+ } catch (IllegalAccessException e) {
+
+ if (Environment.DEBUG_LEVEL > 0 ||
Environment.LOG_LEVEL > 0)
+
Environment.err.print(toString() + ".receiveRequest(" + handle + "," +
+ message + "," + response + "):
encountered component error " + e + ".\n");
+
+ }
+ } // if
+ } // synchronized
+ } // if
+
+ // fiddle with the class loader to run into protected component code
+ component.enter();
+
+ // this is the envelope what we return
+ Envelope returnValue = null;
+
+ // this should be the envelope that we receive
+ Envelope envelope = null;
+
+ if (Environment.LOG_LEVEL > 1)
+ Environment.out.println(((org.zoap.soap.HttpRequest)
message).getBody());
+
+ try {
+
+ // extract the envelope that they have sent us
+ envelope =
message.getEnvelope(((SoapComponent)component).getBinding());
+
+ } catch (SoapException e) {
+
+ // SoapException means a generic error while getting the
envelope
+ // this is preinvocation, so we return a message exception
+
+ if (Environment.DEBUG_LEVEL > 0)
+
Environment.err.println("SoapContainerInvoker.receiveMessage(" + handle + "," +
+ message + "," + response + "): encountered soap
exception " + e);
+
+ component.leave();
+
+ throw new SoapMessageException();
+
+ }
+
+ // if it does not contain a method call, we are pissed
+ if (envelope == null || !(envelope.getBody() instanceof
MethodRequest)) {
+ component.leave();
+ throw new SoapMessageException();
+ }
+
+ // isolate the embedded method call that is inside
+ MethodRequest methodRequest = (MethodRequest)envelope.getBody();
+
+ try {
+
+ // now thats a longie, use reflection to determine and invoke
+ // the envisaged method using the detected classes and the
+ // proper arguments through the container, produce a return
object and put it
+ // into a fresh envelope
+ MethodResponse methodResponse = new
MethodResponse(methodRequest.getMethod());
+
+ methodResponse.setValue(con.invoke(
+ new MethodInvocation(handle,
+ methodRequest.getMethod(), methodRequest.getArguments(),
null, null,null)));
+
+ returnValue = new Envelope(null, methodResponse);
+
+ // what could have crashed?
+ } catch (IllegalAccessException e) {
+
+ // illegal access is deep, no application error
+ if (Environment.DEBUG_LEVEL > 0)
+
Environment.err.println("SoapContainerInvoker.receiveMessage(" + message + "," +
response +
+ "): encountered security problem " + e);
+
+ component.leave();
+ throw new SoapMessageException();
+
+ } catch (NoSuchMethodException e) {
+
+ // no such method exception is not quite that deep, but
+ // for the moment, we dont treat it as application-close error
+
+ if (Environment.DEBUG_LEVEL > 0)
+
Environment.err.println("SoapContainerInvoker.receiveMessage(" + message + "," +
response +
+ "): no such method " + e);
+
+ component.leave();
+ throw new SoapMessageException();
+
+ } catch (Throwable t) {
+
+ // ahh, this is the indicator for some application error that
we
+ // put into the message back to the sender
+
+ if (Environment.DEBUG_LEVEL > 0)
+
Environment.err.println("SoapContainerInvoker.receiveMessage(" + message + "," +
response +
+ "): application exception encountered " + t);
+
+ t.printStackTrace();
+
+ returnValue = new Envelope(null, t);
+
+ } // try
+
+
+ // at this place, the call went through and could only have
+ // produced shippable application errors. Hence, we register
+ // the result in the reponse
+
+ try {
+
+ response.setEnvelope(returnValue,
((SoapComponent)component).getBinding(),
+ serialisationPolicy);
+
+ } catch (SoapException e) {
+
+ // where still, some exception could occur
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.err.println("Interceptor.receiveMessage("
+ message + "," + response +
+ "): soap exception while setting return envelope " +
e);
+
+ throw new SoapMessageException();
+
+ } finally {
+ component.leave();
+ } // try
+
+ if (Environment.LOG_LEVEL > 1)
+ Environment.out.println(((org.zoap.soap.HttpResponse)
response).
+ getBody());
+
+ } // receiveRequest
+
+
+ /** stop this invoker temporarily */
+
+ public void stop() {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".stop()");
+
+ try {
+
server.unRegisterSoapRouter(con.getBeanMetaData().getJndiName());
+ } catch (SoapException e) { }
+ }
+
+ /** destroy it */
+
+ public void destroy() {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".destroy()");
+
+ server = null;
+ }
+
+ /**
+ * stuff that we IMHO do not necessarily need, but come from the
ContainerInvoker superclass
+ * this is a really silly design where the container and the invoker are
recursively
+ * coupled. I do not fully understand why you would like to do it like this ...
+ */
+
+ public EJBMetaData getEJBMetaData() {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".getEJBMetaData()");
+
+ return null;
+ }
+
+
+
+ /**
+ * this is not to be taken for serious right now. We must find a way to
+ * connect to the other�s side server when deserialising the proxy (if
asynchronous, anyway, but thats a thing for later)
+ */
+
+ public EJBHome getEJBHome() {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".getEJBHome()");
+
+ // fiddle with the class loader to run into protected component code
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(con.getClassLoader());
+
+ // currently a total fake!
+
+ EJBHome home = (EJBHome)java.lang.reflect.Proxy.
+ newProxyInstance(Thread.currentThread().getContextClassLoader(),
+ new Class[] { ((ContainerInvokerContainer)con).getHomeClass() },
+ new SoapInvocationHandler(getURL(), getURL(),
((ContainerInvokerContainer)con).getHomeClass(),
+ ((ContainerInvokerContainer)con).getRemoteClass(),
((SoapComponent)component)));
+
+ Thread.currentThread().setContextClassLoader(oldCl);
+
+ return home;
+ }
+
+ public EJBObject getStatelessSessionEJBObject() {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() +
".getStatelessSessionEJBObject()");
+
+ // fiddle with the class loader to run into protected component code
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(con.getClassLoader());
+
+ EJBObject object = (EJBObject)java.lang.reflect.Proxy.
+ newProxyInstance(con.getClassLoader(),
+ new Class[] { ((ContainerInvokerContainer)con).getRemoteClass() },
+ new SoapInvocationHandler(getURL(), getURL(),
((ContainerInvokerContainer)con).getHomeClass(),
+ ((ContainerInvokerContainer)con).getRemoteClass(),
((SoapComponent)component)));
+
+ Thread.currentThread().setContextClassLoader(oldCl);
+
+ return object;
+
+ }
+
+ public EJBObject getStatefulSessionEJBObject(Object id) {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() +
".getStatefulSessionEJBObject()");
+
+ // fiddle with the class loader to run into protected component code
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(con.getClassLoader());
+
+ EJBObject object = (EJBObject)java.lang.reflect.Proxy.
+ newProxyInstance(con.getClassLoader(),
+ new Class[] { ((ContainerInvokerContainer)con).getRemoteClass() },
+ new SoapInvocationHandler(getURL(), getURL(),
((ContainerInvokerContainer)con).getHomeClass(),
+ ((ContainerInvokerContainer)con).getRemoteClass(),
((SoapComponent)component)));
+
+ Thread.currentThread().setContextClassLoader(oldCl);
+
+ return object;
+ }
+
+ public EJBObject getEntityEJBObject(Object id) {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".getEntityEJBObject(" +
id + ")");
+
+ return null;
+ }
+
+ public Collection getEntityCollection(Collection ids) {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".getEntityCollection(" +
ids + ")");
+
+ return null;
+ }
+
+ /** unregistration is not necessary */
+
+ public void unRegisterSoapObject(String handle) {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".unregisterSoapObject("
+ handle + ")");
+
+ }
+
+ /** registration is not necessary */
+
+ public String registerSoapObject(SoapObject object) {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".registerSoapObject(" +
object + ")");
+
+ return null;
+ }
+
+ /** gets the url pointing to this invoker */
+
+ public java.net.URL getURL() {
+
+ if (Environment.DEBUG_LEVEL > 0)
+ Environment.out.println(toString() + ".getURL()");
+
+ try {
+ return new java.net.URL(server.getURL(),
con.getBeanMetaData().getJndiName());
+ } catch (java.net.MalformedURLException e) {
+ return null;
+ } catch (java.net.UnknownHostException e) {
+ return null;
+ }
+
+ }
+
+
+
+}
1.2 +213 -204 zoap/src/org/jboss/ejb/plugins/zoap/SoapInvocationHandler.java
Index: SoapInvocationHandler.java
===================================================================
RCS file:
/products/cvs/ejboss/zoap/src/org/jboss/ejb/plugins/zoap/SoapInvocationHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SoapInvocationHandler.java 2000/08/10 21:06:52 1.1
+++ SoapInvocationHandler.java 2000/12/04 12:35:58 1.2
@@ -1,207 +1,222 @@
-/*
- * $Id: SoapInvocationHandler.java,v 1.1 2000/08/10 21:06:52 jung Exp $
- * Copyright (c) 2000 infor:business solutions AG, Hauerstrasse 12,
- * D-66299 Friedrichsthal, Germany. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-package org.jboss.ejb.plugins.zoap;
-
-import org.jboss.ejb.Container;
-import org.jboss.ejb.ContainerInvokerContainer;
-import org.jboss.ejb.MethodInvocation;
-
-import org.jboss.zoap.Environment;
-
-import org.zoap.soap.SoapServer;
-import org.zoap.soap.SoapObject;
-import org.zoap.soap.SoapException;
-import org.zoap.soap.SoapMessage;
-import org.zoap.soap.SoapMessageException;
-import org.zoap.soap.MethodRequest;
-import org.zoap.soap.MethodResponse;
-import org.zoap.soap.Envelope;
-import org.zoap.soap.MessageFactory;
-import org.zoap.soap.SoapTargetNotSupportedException;
-
-import org.zoap.soap.meta.SoapBinding;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-import java.io.Serializable;
-import java.net.URL;
-
-import de.infor.ce.util.Component;
-
-/**
- * A lightweight in-VM invocation-handler that provides an immediate access to
the interceptor-chain of jBoss.
- * @see <related>
- * @author $Author: jung $
- * @version $Revision: 1.1 $
- */
-
-public class SoapInvocationHandler implements InvocationHandler, SoapObject,
Serializable {
-
- /** the target url of the server behind that SoapInvocationHandler */
- URL url;
-
- /** the SoapInvocationHandler url of the SoapInvocationHandler server through
which we tunnel */
- URL SoapInvocationHandler;
-
- /** the interface that we are standing for */
- Class remoteInterface;
-
- /** the home that we are standing for */
- Class homeInterface;
-
- /** the component that this handler has been created in */
- transient SoapComponent component;
-
- /** the requests associated to different threads */
- transient ThreadLocal requests = new ThreadLocal();
-
- /** the soap server that we are bound to */
- transient SoapServer server;
-
- /** the handle that we got from our server */
- transient String handle;
-
-
- /** initialise the component you are living in */
- public SoapInvocationHandler() {
- }
-
- /** Constructor: establish a server, a target URL and a corresponding
databinding */
- public SoapInvocationHandler(URL theSoapInvocationHandler, URL theURL,
- Class remoteInterface, Class homeInterface, SoapComponent component) {
-
- url = theURL;
- SoapInvocationHandler = theSoapInvocationHandler;
- this.remoteInterface = remoteInterface;
- this.homeInterface = homeInterface;
- this.component=component;
-
- }
-
- /**
- * this is called whenever an interface that this invocationhandler pretends
to belong to is invoked
- * we do it purely synchronous for the moment
- */
-
- public Object invoke(Object target, Method method, Object[] args) throws
Throwable {
-
- if (Environment.DEBUG_ZOAP)
- Environment.out.print(toString() + ".invoke(" + method + "," +
args + ")\n");
-
- if (homeInterface.equals(method.getDeclaringClass()) &&
- method.getName().equals("create")) {
- return
java.lang.reflect.Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
- new Class[] { remoteInterface },
- new SoapInvocationHandler(SoapInvocationHandler, url,
- remoteInterface, homeInterface,component));
- } else {
- try {
-
- SoapMessage request = (SoapMessage)requests.get();
-
- if (request == null) {
- // construct a new message to your target
- request = MessageFactory.getMessageFactory().
- createMessage(SoapInvocationHandler, url);
- requests.set(request);
- }
-
- // construct a new method call structure out of the
method
- // and the arguments
- MethodRequest methodRequest = new
MethodRequest(method);
-
- methodRequest.setArguments(args);
-
- // construct a new envelope with an empty header
- // and the call as its body
- Envelope envelope = new Envelope(null, methodRequest);
-
- // put the envelope into the message given your
databinding
- request.setEnvelope(envelope,
((SoapComponent)component).getBinding());
-
- // send it and receive a synchronous reponse for the
message
- SoapMessage response = request.sendMessage();
-
- // unpack the envelope from the message using your
databinding
- Envelope responseEnvelope =
response.getEnvelope(((SoapComponent)component)
- .getBinding());
-
- // there are two cases
- if (responseEnvelope.getBody() instanceof Throwable)
-
- // one in which the response really carries a
fault, hence exception in it
- // we try to get around the serialisation
exceptions in the outer try
- throw(Throwable)responseEnvelope.getBody();
-
- else if (responseEnvelope.getBody() instanceof
MethodResponse)
-
- return
((MethodResponse)responseEnvelope.getBody()).getValue();
-
- else
- throw new SoapException();
-
- } catch (SoapTargetNotSupportedException e) {
-
- // this happens, if the given url is not supported, so
we throw a
- // severe runtime exception
-
- if (Environment.DEBUG_ZOAP)
-
Environment.err.println("SoapInvocationHandler.invoke(" + method + "," + args +
- "): encountered url exception " + e);
-
- throw e;
-
- } catch (SoapException e) {
-
- // this happens if something with the serialisation
has been broken
- // so we throw a severe runtime exception
-
- if (Environment.DEBUG_ZOAP)
-
Environment.err.println("SoapInvocationHandler.invoke(" + method + "," + args +
- "): encountered soap exception " + e);
-
- throw e;
-
- }
- }
-
- } // invoke
-
- /** receiveRequest is used for the asynchronouse mode, we do not need it
hopefully at the moment */
-
- public void receiveRequest(SoapMessage message, SoapMessage response)
- throws SoapMessageException {
-
- if (Environment.DEBUG_ZOAP)
-
Environment.out.println("SoapInvocationHandler.receiveRequest(" + message + "," +
response + ")");
-
- }
-
-} // SoapInvocationHandler
-
-/*
+/*
+ * $Id: SoapInvocationHandler.java,v 1.2 2000/12/04 12:35:58 jung Exp $
+ * Copyright (c) 2000 infor:business solutions AG, Hauerstrasse 12,
+ * D-66299 Friedrichsthal, Germany. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package org.jboss.ejb.plugins.zoap;
+
+import org.jboss.ejb.Container;
+import org.jboss.ejb.ContainerInvokerContainer;
+import org.jboss.ejb.MethodInvocation;
+
+import org.jboss.zoap.Environment;
+
+import org.zoap.soap.SoapServer;
+import org.zoap.soap.SoapRouter;
+import org.zoap.soap.SoapObject;
+import org.zoap.soap.SoapException;
+import org.zoap.soap.SoapMessage;
+import org.zoap.soap.SoapMessageException;
+import org.zoap.soap.MethodRequest;
+import org.zoap.soap.MethodResponse;
+import org.zoap.soap.Envelope;
+import org.zoap.soap.MessageFactory;
+import org.zoap.soap.SoapTargetNotSupportedException;
+
+import org.zoap.soap.meta.SoapBinding;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import java.io.Serializable;
+import java.net.URL;
+
+import de.infor.ce.util.Component;
+
+/**
+ * A lightweight in-VM invocation-handler that provides an immediate access to
the interceptor-chain of jBoss.
+ * @see <related>
+ * @author $Author: jung $
+ * @version $Revision: 1.2 $
+ */
+
+public class SoapInvocationHandler implements InvocationHandler, SoapObject,
Serializable {
+
+ /** the target url of the server behind that SoapInvocationHandler */
+ URL url;
+
+ /** the SoapInvocationHandler url of the SoapInvocationHandler server through
which we tunnel */
+ URL SoapInvocationHandler;
+
+ /** the interface that we are standing for */
+ Class remoteInterface;
+
+ /** the home that we are standing for */
+ Class homeInterface;
+
+ /** the component that this handler has been created in */
+ transient SoapComponent component;
+
+ /** the requests associated to different threads */
+ transient ThreadLocal requests = new ThreadLocal();
+
+ /** the soap server that we are bound to */
+ transient SoapServer server;
+
+ /** the handle that we got from our server */
+ transient String handle;
+
+
+ /** initialise the component you are living in */
+ public SoapInvocationHandler() {
+ }
+
+ /** Constructor: establish a server, a target URL and a corresponding
databinding */
+ public SoapInvocationHandler(URL theSoapInvocationHandler, URL theURL,
+ Class remoteInterface, Class homeInterface, SoapComponent component) {
+
+ url = theURL;
+ SoapInvocationHandler = theSoapInvocationHandler;
+ this.remoteInterface = remoteInterface;
+ this.homeInterface = homeInterface;
+ this.component=component;
+
+ }
+
+ /**
+ * this is called whenever an interface that this invocationhandler pretends
to belong to is invoked
+ * we do it purely synchronous for the moment
+ */
+
+ public Object invoke(Object target, Method method, Object[] args) throws
Throwable {
+
+ if (Environment.DEBUG_LEVEL>0)
+ Environment.out.print(toString() + ".invoke(" + method + "," +
args + ")\n");
+
+ if (homeInterface.equals(method.getDeclaringClass()) &&
+ method.getName().equals("create")) {
+ return
java.lang.reflect.Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
+ new Class[] { remoteInterface },
+ new SoapInvocationHandler(SoapInvocationHandler, url,
+ remoteInterface, homeInterface,component));
+ } else {
+ try {
+
+ SoapMessage request = (SoapMessage)requests.get();
+
+ if (request == null) {
+ // construct a new message to your target
+ request = MessageFactory.getMessageFactory().
+ createMessage(SoapInvocationHandler, url);
+ requests.set(request);
+ }
+
+ // construct a new method call structure out of the
method
+ // and the arguments
+ MethodRequest methodRequest = new
MethodRequest(method);
+
+ methodRequest.setArguments(args);
+
+ // construct a new envelope with an empty header
+ // and the call as its body
+ Envelope envelope = new Envelope(null, methodRequest);
+
+ // put the envelope into the message given your
databinding
+ request.setEnvelope(envelope,
((SoapComponent)component).getBinding());
+
+ // send it and receive a synchronous reponse for the
message
+ SoapMessage response = request.sendMessage();
+
+ // unpack the envelope from the message using your
databinding
+ Envelope responseEnvelope =
response.getEnvelope(((SoapComponent)component)
+ .getBinding());
+
+ // there are two cases
+ if (responseEnvelope.getBody() instanceof Throwable)
+
+ // one in which the response really carries a
fault, hence exception in it
+ // we try to get around the serialisation
exceptions in the outer try
+ throw(Throwable)responseEnvelope.getBody();
+
+ else if (responseEnvelope.getBody() instanceof
MethodResponse)
+
+ return
((MethodResponse)responseEnvelope.getBody()).getValue();
+
+ else
+ throw new SoapException();
+
+ } catch (SoapTargetNotSupportedException e) {
+
+ // this happens, if the given url is not supported, so
we throw a
+ // severe runtime exception
+
+ if (Environment.DEBUG_LEVEL>0)
+
Environment.err.println("SoapInvocationHandler.invoke(" + method + "," + args +
+ "): encountered url exception " + e);
+
+ throw e;
+
+ } catch (SoapException e) {
+
+ // this happens if something with the serialisation
has been broken
+ // so we throw a severe runtime exception
+
+ if (Environment.DEBUG_LEVEL>0)
+
Environment.err.println("SoapInvocationHandler.invoke(" + method + "," + args +
+ "): encountered soap exception " + e);
+
+ throw e;
+
+ }
+ }
+
+ } // invoke
+
+ /** receiveRequest is used for the asynchronouse mode, we do not need it
hopefully at the moment */
+
+ public void receiveRequest(SoapMessage message, SoapMessage response)
+ throws SoapMessageException {
+
+ if (Environment.DEBUG_LEVEL>0)
+
Environment.out.println("SoapInvocationHandler.receiveRequest(" + message + "," +
response + ")");
+
+ }
+
+ public SoapRouter getRouter() {
+ return null;
+ }
+
+} // SoapInvocationHandler
+
+/*
* $Log: SoapInvocationHandler.java,v $
- * Revision 1.1 2000/08/10 21:06:52 jung
- * Initial revision
- *
- */
-
+ * Revision 1.2 2000/12/04 12:35:58 jung
+ * adopted to latest jboss container,
+ *
+ * added decimal and date
+ *
+ * removed some problems due to forward-referencing in meta-data
+ *
+ * added serialisation policy
+ *
+ * Revision 1.1.1.1 2000/08/10 21:06:52 jung
+ * Initial import.
+ *
+ *
+ */
+
1.3 +50 -54 zoap/src/org/jboss/ejb/plugins/zoap/zoap.dfPackage
Index: zoap.dfPackage
===================================================================
RCS file: /products/cvs/ejboss/zoap/src/org/jboss/ejb/plugins/zoap/zoap.dfPackage,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- zoap.dfPackage 2000/08/11 14:43:49 1.2
+++ zoap.dfPackage 2000/12/04 12:35:58 1.3
@@ -1,60 +1,56 @@
-package id1atnbca8544noca855nay;
-
-/**
-@version 2.0
-@physicalPackage
-@__modelType diagram
-*/
-class diagram {
-/**
-@__ref
<oiref:java#Class#org.jboss.ejb.plugins.zoap.SoapContainerInvoker:oiref><oihard>
-@__modelType reference
-*/
-class reference7 {
-}/**
-@shapeType DependencyLink
-@__modelType link
-@__ref <oiref:design#Class#id3lximc9pgodo2c9pqksa8.diagram:oiref><oihard>
-@label builds on
-*/
-class link {
-}/**
-@shapeType NoteLink
-@__modelType link
-@__ref <oiref:design#Class#id2e2vrc9pgodo2c9pgqtl6.node23:oiref><oihard>
-*/
-class link25 {
-}/**
-@__ref <oiref:java#Class#org.jboss.ejb.plugins.zoap.SoapComponent:oiref><oihard>
-@__modelType reference
-*/
-class reference8 {
-}/**
-@__ref <oiref:java#Class#org.jboss.ejb.plugins.zoap.ContractBinding:oiref><oihard>
-@__modelType reference
-*/
-class reference9 {
-}/**
-@__ref
<oiref:java#Class#org.jboss.ejb.plugins.zoap.SoapInvocationHandler:oiref><oihard>
-@__modelType reference
-*/
-class reference10 {
+package id1atnbca8544noca855nay;
+
+/**
+@version 2.0
+@physicalPackage
+@__modelType diagram
+*/
+class diagram {
+/**
+@__ref
<oiref:java#Class#org.jboss.ejb.plugins.zoap.SoapContainerInvoker:oiref><oihard>
+@__modelType reference
+*/
+class reference7 {
+}/**
+@shapeType DependencyLink
+@__modelType link
+@__ref <oiref:design#Class#id3lximc9pgodo2c9pqksa8.diagram:oiref><oihard>
+@label builds on
+*/
+class link {
+}/**
+@shapeType NoteLink
+@__modelType link
+@__ref <oiref:design#Class#id2e2vrc9pgodo2c9pgqtl6.node23:oiref><oihard>
+*/
+class link25 {
+}/**
+@__ref <oiref:java#Class#org.jboss.ejb.plugins.zoap.SoapComponent:oiref><oihard>
+@__modelType reference
+*/
+class reference8 {
}/**
+@__ref
<oiref:java#Class#org.jboss.ejb.plugins.zoap.SoapInvocationHandler:oiref><oihard>
+@__modelType reference
+*/
+class reference10 {
+}/**
@__ref
<oiref:java#Class#org.jboss.ejb.plugins.zoap.ComponentURNResolver:oiref><oihard>
@__modelType reference
*/
class reference {
-}}/**
-@__tags
-@shapeType ClassDiagram
-*/
-class __tags {
-}/**
-@__options
-*/
-class __options {
-}/**
-@__positions
-*/
-class __positions {
+}}/**
+@__tags
+@shapeType ClassDiagram
+@number txmiid8
+*/
+class __tags {
+}/**
+@__options
+*/
+class __options {
+}/**
+@__positions
+*/
+class __positions {
}