You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by sa...@locus.apache.org on 2000/09/01 04:44:35 UTC
cvs commit: xml-soap/java/src/org/apache/soap/server MessageRouter.java
sanjiva 00/08/31 19:44:35
Added: java/src/org/apache/soap/server MessageRouter.java
Log:
transport independent message routing support
Revision Changes Path
1.1 xml-soap/java/src/org/apache/soap/server/MessageRouter.java
Index: MessageRouter.java
===================================================================
package org.apache.soap.server;
import java.io.*;
import java.util.*;
import java.lang.reflect.*;
import org.w3c.dom.*;
import org.apache.soap.util.Bean;
import org.apache.soap.util.MethodUtils;
import org.apache.soap.util.IOUtils;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
/**
* This class is a transport independent SOAP message router. However you
* do it, if you get a SOAP envelope to me, I will deliver that to the
* right method of the object you give me to work on.
*
* @author Sanjiva Weerawarana <sa...@watson.ibm.com>
*/
public class MessageRouter {
/**
* Check whether the message is valid - does the service publish it?
*/
public static boolean validMessage (DeploymentDescriptor dd,
String messageName) {
String[] pubMessages = dd.getMethods ();
for (int i = 0; i < pubMessages.length; i++) {
if (messageName.equals (pubMessages[i])) {
return true;
}
}
return false;
}
/**
* Deliver the message to the appropriate method on the given target
* object.
*/
public static void invoke (DeploymentDescriptor dd, Envelope env,
Object targetObject, String messageName,
PrintWriter out)
throws SOAPException {
byte providerType = dd.getProviderType ();
try {
Class[] argTypes = new Class[] { Envelope.class, PrintWriter.class };
Object[] args = new Object[] { env, out };
if (providerType == DeploymentDescriptor.PROVIDER_JAVA) {
Method m = MethodUtils.getMethod (targetObject, messageName,
argTypes);
m.invoke (targetObject, args);
} else {
// find the class that provides the BSF services (done
// this way via reflection to avoid a compile-time dependency on BSF)
Class bc = Class.forName ("org.apache.soap.server.InvokeBSF");
// now invoke the service
Class[] sig = {DeploymentDescriptor.class,
Object.class,
String.class,
Object[].class};
Method m = MethodUtils.getMethod (bc, "service", sig, true);
m.invoke (null, new Object[] {dd, targetObject, messageName, args});
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException ();
throw new SOAPException (Constants.FAULT_CODE_SERVER, t.getMessage(), t);
} catch (ClassNotFoundException e) {
throw new SOAPException (Constants.FAULT_CODE_SERVER,
"Unable to load BSF: script services " +
"unsupported with BSF", e);
} catch (Throwable t) {
throw new SOAPException (Constants.FAULT_CODE_SERVER, t.getMessage(), t);
}
}
}