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/06/22 09:09:28 UTC
cvs commit: xml-soap/java/webapps/rpcrouter rpcrouter.jsp
sanjiva 00/06/22 00:09:28
Added: java/src/org/apache/soap/server RPCRouter.java
java/webapps/admin blankpage.html deploy.gif deploy.jsp
header.html index.html list.gif list.jsp
showdetails.jsp soapadmin.gif toc.html undeploy.gif
undeploy.jsp
java/webapps/rpcrouter rpcrouter.jsp
Removed: java/src/org/apache/soap/server blankpage.html deploy.gif
deploy.jsp header.html index.html list.gif list.jsp
rpcrouter.jsp showdetails.jsp soapadmin.gif
toc.html undeploy.gif undeploy.jsp
Log:
Moved most of the core logic of rpcrouter.jsp into a regular class
called RPCRouter.java. Also restructured the code so that only real
code is in the org/apache/soap/server directory/package. Added a new
directory under the xml-soap/java directory called "webapps" which has
two subdirs - rpcrouter and admin. The first contains the JSP that
received HTTP requests and uses the org.apache.soap.server.RPCRouter
class to do the real work. The second is the SOAP admin tool which
can be used to deploy and manage services. More detailed posting will
be made to the soap-dev list.
Revision Changes Path
1.1 xml-soap/java/src/org/apache/soap/server/RPCRouter.java
Index: RPCRouter.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 RPC router. However you
* do it, if you get a SOAP envelope to me, I will build a Call object
* out of it, check whether its valid and finally do it for you (on
* an object you give me).
*
* @author Sanjiva Weerawarana <sa...@watson.ibm.com>
*/
public class RPCRouter {
ServiceManager serviceManager;
public void setServiceManager (ServiceManager serviceManager) {
this.serviceManager = serviceManager;
}
public Call extractCallFromEnvelope (Envelope callEnv) throws SOAPException {
// determine target object URI by looking in the envelope
Vector bodyEntries = callEnv.getBody ().getBodyEntries ();
Element mainEntry = (Element) bodyEntries.elementAt (0);
String targetObjectURI = mainEntry.getNamespaceURI ();
// call on known entity?
DeploymentDescriptor dd = serviceManager.query (targetObjectURI);
if (dd == null) {
throw new SOAPException (
RPCConstants.FAULT_CODE_SERVER_BAD_TARGET_OBJECT_URI,
"Unable to determine object id from call: is the method element " +
"namespaced?");
}
// now extract the call from the call envelope with the given
// deployment information about the object. Note that I still
// pass in the service manager because I don't want to mess
// with that code right now. I should actually be passing in
// the soap mapping registry for this service.
return Call.extractFromEnvelope (callEnv, serviceManager);
}
/**
* Check whether the call is valid w.r.t. being on a method that's
* published by the service. The call is assumed to have been built
* by the above method; hence the call is on a known service.
*/
public boolean validCall (Call call) {
DeploymentDescriptor dd = null;
try {
dd = serviceManager.query (call.getTargetObjectURI ());
} catch (SOAPException e) {
// cannot happen
}
String callMethodName = call.getMethodName ();
String[] pubMethods = dd.getMethods ();
for (int i = 0; i < pubMethods.length; i++) {
if (callMethodName.equals (pubMethods[i])) {
return true;
}
}
return false;
}
/**
* Do the call on the given target object.
*/
public Response invoke (Call call, Object targetObject)
throws SOAPException {
DeploymentDescriptor dd =
serviceManager.query (call.getTargetObjectURI ());
byte providerType = dd.getProviderType ();
// build the args and determine response encoding style
Vector params = call.getParams ();
String respEncStyle = call.getEncodingStyleURI ();
Object[] args = null;
Class[] argTypes = null;
if (params != null) {
int paramsCount = params.size ();
args = new Object[paramsCount];
argTypes = new Class[paramsCount];
for (int i = 0; i < paramsCount; i++) {
Parameter param = (Parameter) params.elementAt (i);
args[i] = param.getValue ();
argTypes[i] = param.getType ();
if (respEncStyle == null) {
respEncStyle = param.getEncodingStyleURI ();
}
}
}
if (respEncStyle == null) {
// need to set a default encoding to be used for the response
respEncStyle = Constants.NS_URI_SOAP_ENC;
}
// invoke the method (directly for Java and via InvokeBSF for script
// methods)
Bean result = null;
try {
if (providerType == DeploymentDescriptor.PROVIDER_JAVA) {
Method m = MethodUtils.getMethod (targetObject, call.getMethodName (),
argTypes);
result = new Bean (m.getReturnType (), 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);
result = (Bean) m.invoke (null, new Object[] {dd, targetObject,
call.getMethodName (),
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);
}
// build the response object
Parameter ret = null;
if (result.type != void.class) {
ret = new Parameter (RPCConstants.ELEM_RETURN, result.type,
result.value, null);
}
return new Response (call.getTargetObjectURI (), call.getMethodName (),
ret, null, null, respEncStyle);
}
}
1.1 xml-soap/java/webapps/admin/blankpage.html
Index: blankpage.html
===================================================================
<b>What do you want to do today?</b>
1.1 xml-soap/java/webapps/admin/deploy.gif
<<Binary file>>
1.1 xml-soap/java/webapps/admin/deploy.jsp
Index: deploy.jsp
===================================================================
<%@ page import="java.io.*, java.util.*, org.w3c.dom.*" %>
<%@ page import="org.apache.soap.util.*, org.apache.soap.util.xml.*, org.apache.soap.server.*" %>
<!-- get the serviceManager object -->
<jsp:useBean id="serviceManager"
class="org.apache.soap.server.ServiceManager"
scope="application">
</jsp:useBean>
<h1>Deploy a Service</h1>
<%
if (!request.getMethod().equals ("POST")) {
%>
<form action="deploy.jsp" method="POST">
<table border="1" width="100%">
<tr>
<th colspan="2"><h2>Service Deployment Descriptor
Template</h2>
</th>
</tr>
<tr>
<th>Property</th>
<th>Details</th>
</tr>
<tr>
<td>ID</td>
<td><input type="text" size="60" name="id"></td>
</tr>
<tr>
<td>Scope</td>
<td><select name="scope" size="1">
<option selected value="0">Page</option>
<option value="1">Request</option>
<option value="2">Session</option>
<option value="3">Application</option>
</select></td>
</tr>
<tr>
<td>Methods</td>
<td><input type="text" size="60" name="methods"><br>
(Whitespace separated list of method names) </td>
</tr>
<tr>
<td>Provider Type</td>
<td><select name="providerType" size="1">
<option selected value="0">Java</option>
<option value="1">Script</option>
</select></td>
</tr>
<tr>
<td>Java Provider</td>
<td><div align="left"><table border="0">
<tr>
<td>Provider Class</td>
<td><input type="text" size="40"
name="providerClass"></td>
</tr>
<tr>
<td width="150">Static?</td>
<td><select name="isStatic" size="1">
<option value="true">Yes</option>
<option selected value="no">No</option>
</select></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td>Script Provider</td>
<td><div align="left"><table border="0">
<tr>
<td>Script Language</td>
<td><select name="scriptLanguage" size="1">
<option value="bml">BML</option>
<option value="jacl">Jacl</option>
<option value="javascript">JavaScript (Rhino)</option>
<option value="jpython">JPython</option>
<option value="jscript">JScript</option>
<option value="perlscript">PerlScript</option>
<option value="vbscript">VBScript</option>
<option value="other">Other .. (type in)</option>
</select><input type="text" size="20"
name="scriptLanguageTypein"></td>
</tr>
<tr>
<td width="150">Script Filename, or</td>
<td><input type="text" size="40"
name="scriptFilename"></td>
</tr>
<tr>
<td>Script</td>
<td><textarea name="script" rows="10"
cols="40"></textarea></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td>Type Mappings</td>
<td>Number of mappings: <input type="text" size="10"
name="nmaps" /><br>
<div align="center"><center><table border="0">
<tr>
<td align="center" rowspan="2">Encoding Style</td>
<td align="center" colspan="2">Element Type </td>
<td align="center" rowspan="2">Java Type</td>
<td align="center" rowspan="2">Java to XML
Serializer </td>
<td align="center" rowspan="2">XML to Java
Deserializer </td>
</tr>
<tr>
<td align="center">Namespace URI</td>
<td align="center">Local Part</td>
</tr>
<tr>
<td><select name="encstyle1" size="1">
<option selected value="0">SOAP</option>
<option value="1">XMI</option>
</select></td>
<td><input type="text" size="15"
name="nsuri1"></td>
<td><input type="text" size="10"
name="localpart1"></td>
<td><input type="text" size="15"
name="classname1"></td>
<td><input type="text" size="15"
name="java2xml1"></td>
<td><input type="text" size="15"
name="xml2java1"></td>
</tr>
<tr>
<td><select name="encstyle2" size="1">
<option selected value="0">SOAP</option>
<option value="1">XMI</option>
</select></td>
<td><input type="text" size="15"
name="nsuri2"></td>
<td><input type="text" size="10"
name="localpart2"></td>
<td><input type="text" size="15"
name="classname2"></td>
<td><input type="text" size="15"
name="java2xml2"></td>
<td><input type="text" size="15"
name="xml2java2"></td>
</tr>
<tr>
<td><select name="encstyle3" size="1">
<option selected value="0">SOAP</option>
<option value="1">XMI</option>
</select></td>
<td><input type="text" size="15"
name="nsuri3"></td>
<td><input type="text" size="10"
name="localpart3"></td>
<td><input type="text" size="15"
name="classname3"></td>
<td><input type="text" size="15"
name="java2xml3"></td>
<td><input type="text" size="15"
name="xml2java3"></td>
</tr>
<tr>
<td><select name="encstyle4" size="1">
<option selected value="0">SOAP</option>
<option value="1">XMI</option>
</select></td>
<td><input type="text" size="15"
name="nsuri4"></td>
<td><input type="text" size="10"
name="localpart4"></td>
<td><input type="text" size="15"
name="classname4"></td>
<td><input type="text" size="15"
name="java2xml4"></td>
<td><input type="text" size="15"
name="xml2java4"></td>
</tr>
<tr>
<td><select name="encstyle5" size="1">
<option selected value="0">SOAP</option>
<option value="1">XMI</option>
</select></td>
<td><input type="text" size="15"
name="nsuri5"></td>
<td><input type="text" size="10"
name="localpart5"></td>
<td><input type="text" size="15"
name="classname5"></td>
<td><input type="text" size="15"
name="java2xml5"></td>
<td><input type="text" size="15"
name="xml2java5"></td>
</tr>
<tr>
<td><select name="encstyle6" size="1">
<option selected value="0">SOAP</option>
<option value="1">XMI</option>
</select></td>
<td><input type="text" size="15"
name="nsuri6"></td>
<td><input type="text" size="10"
name="localpart6"></td>
<td><input type="text" size="15"
name="classname6"></td>
<td><input type="text" size="15"
name="java2xml6"></td>
<td><input type="text" size="15"
name="xml2java6"></td>
</tr>
<tr>
<td><select name="encstyle7" size="1">
<option selected value="0">SOAP</option>
<option value="1">XMI</option>
</select></td>
<td><input type="text" size="15"
name="nsuri7"></td>
<td><input type="text" size="10"
name="localpart7"></td>
<td><input type="text" size="15"
name="classname7"></td>
<td><input type="text" size="15"
name="java2xml7"></td>
<td><input type="text" size="15"
name="xml2java7"></td>
</tr>
<tr>
<td><select name="encstyle8" size="1">
<option selected value="0">SOAP</option>
<option value="1">XMI</option>
</select></td>
<td><input type="text" size="15"
name="nsuri8"></td>
<td><input type="text" size="10"
name="localpart8"></td>
<td><input type="text" size="15"
name="classname8"></td>
<td><input type="text" size="15"
name="java2xml8"></td>
<td><input type="text" size="15"
name="xml2java8"></td>
</tr>
<tr>
<td><select name="encstyle9" size="1">
<option selected value="0">SOAP</option>
<option value="1">XMI</option>
</select></td>
<td><input type="text" size="15"
name="nsuri9"></td>
<td><input type="text" size="10"
name="localpart9"></td>
<td><input type="text" size="15"
name="classname9"></td>
<td><input type="text" size="15"
name="java2xml9"></td>
<td><input type="text" size="15"
name="xml2java9"></td>
</tr>
<tr>
<td><select name="encstyle10" size="1">
<option selected value="0">SOAP</option>
<option value="1">XMI</option>
</select></td>
<td><input type="text" size="15"
name="nsuri10"></td>
<td><input type="text" size="10"
name="localpart10"></td>
<td><input type="text" size="15"
name="classname10"></td>
<td><input type="text" size="15"
name="java2xml10"></td>
<td><input type="text" size="15"
name="xml2java10"></td>
</tr>
</table>
</center></div></td>
</tr>
</table>
<p><input type="submit" value="Deploy" /></p>
</form>
<%
} else {
String id = request.getParameter ("id");
DeploymentDescriptor dd = new DeploymentDescriptor ();
dd.setID (id);
// get the provider info
int scope = Integer.parseInt (request.getParameter ("scope"));
String providerTypeStr = request.getParameter ("providerType");
String className = request.getParameter ("providerClass");
boolean isStatic = request.getParameter ("isStatic").equals ("true");
String scriptLang = request.getParameter ("scriptLanguage");
if (scriptLang.equals ("other")) {
scriptLang = request.getParameter ("scriptLanguageTypeIn");
}
String scriptFilename = request.getParameter ("scriptFilename");
String script = request.getParameter ("script");
String methodsStr = request.getParameter ("methods");
StringTokenizer st = new StringTokenizer (methodsStr);
int nTokens = st.countTokens ();
String[] methods = new String[nTokens];
for (int i = 0; i < nTokens; i++) {
methods[i] = st.nextToken ();
}
dd.setScope (scope);
dd.setMethods (methods);
if (providerTypeStr.equals ("0")) {
dd.setProviderType (DeploymentDescriptor.PROVIDER_JAVA);
dd.setProviderClass (className);
dd.setIsStatic (isStatic);
} else {
if (!scriptFilename.equals ("")) { // filename specified
dd.setProviderType (DeploymentDescriptor.PROVIDER_SCRIPT_FILE);
} else { // there better be a script to run
dd.setProviderType (DeploymentDescriptor.PROVIDER_SCRIPT_STRING);
}
dd.setScriptLanguage (scriptLang);
dd.setScriptFilenameOrString (scriptFilename);
}
String[] encs = {org.apache.soap.Constants.NS_URI_SOAP_ENC,
org.apache.soap.Constants.NS_URI_XMI_ENC};
// set up any type mappings
int nmaps = 0;
try {
nmaps = Integer.parseInt (request.getParameter ("nmaps"));
} catch (NumberFormatException e) {
}
if (nmaps != 0) {
TypeMapping[] mappings = new TypeMapping[nmaps];
for (int i = 1; i <= nmaps; i++) { // the form is hard-coded to a max of 10
int encStyle = Integer.parseInt (request.getParameter ("encstyle" + i));
String nsuri = request.getParameter ("nsuri" + i);
String localPart = request.getParameter ("localpart" + i);
String classNameStr = request.getParameter ("classname" + i);
String java2XMLClass = request.getParameter ("java2xml" + i);
String xml2JavaClass = request.getParameter ("xml2java" + i);
QName elementType = (nsuri.equals ("") || localPart.equals (""))
? null : new QName (nsuri, localPart);
// map "" to null (the unfilled params come as empty strings because
// they are infact actual parameters)
classNameStr = classNameStr.equals ("") ? null : classNameStr;
java2XMLClass = java2XMLClass.equals ("") ? null : java2XMLClass;
xml2JavaClass = xml2JavaClass.equals ("") ? null : xml2JavaClass;
mappings[i-1] = new TypeMapping (encs[encStyle], elementType,
classNameStr, java2XMLClass,
xml2JavaClass);
}
dd.setMappings (mappings);
}
// ok now deploy it
serviceManager.deploy (dd);
// show what was deployed
out.println ("<p>Service <b>" + dd.getID () + "</b> deployed.</p>");
}
%>
1.1 xml-soap/java/webapps/admin/header.html
Index: header.html
===================================================================
<center>
<img src="soapadmin.gif"/>
</center>
1.1 xml-soap/java/webapps/admin/index.html
Index: index.html
===================================================================
<html>
<head>
<title>IBM-SOAP Admin Tool</title>
<script language="JavaScript" type="text/javascript">
<!-- Hide from non-scripting browsers
function refresh()
{
toc.location.reload();
data.location.href='blankpage.html';
}
// -->
</script>
</head>
<frameset rows="90,*" border="0">
<frame name="image" src="header.html">
<frameset cols="150,*" border="0">
<frame name="toc" src="toc.html">
<frame name="data" src="blankpage.html">
</frameset>
</frameset>
</html>
1.1 xml-soap/java/webapps/admin/list.gif
<<Binary file>>
1.1 xml-soap/java/webapps/admin/list.jsp
Index: list.jsp
===================================================================
<%@ page import="java.util.*, org.apache.soap.server.*" %>
<!-- get the serviceManager object -->
<jsp:useBean id="serviceManager"
class="org.apache.soap.server.ServiceManager"
scope="application">
</jsp:useBean>
<h1>Service Listing</h1>
<%
String[] serviceNames = serviceManager.list ();
if (serviceNames.length == 0) {
out.println ("<p>Sorry, there are no services currently deployed.</p>");
} else {
out.println ("<p>Here are the deployed services (select one to see");
out.println ("details)</p>");
%>
<ul>
<%
for (int i = 0; i < serviceNames.length; i++) {
String id = serviceNames[i];
%>
<li><a href="showdetails.jsp?id=<%=id%>"><%= id%></li>
<%
}
%>
</ul>
<%
}
%>
1.1 xml-soap/java/webapps/admin/showdetails.jsp
Index: showdetails.jsp
===================================================================
<%@ page import="java.util.*, org.apache.soap.server.*, org.apache.soap.util.xml.*" %>
<!-- get the serviceManager object -->
<jsp:useBean id="serviceManager"
class="org.apache.soap.server.ServiceManager"
scope="application">
</jsp:useBean>
<h1>Deployed Service Information</h1>
<%
String id = request.getParameter ("id");
DeploymentDescriptor dd = (id != null)
? serviceManager.query (id)
: null;
String[] scopes = {"Page", "Request", "Session", "Application"};
if (id == null) {
out.println ("<p>Huh? You hafta select a service to display ..</p>");
} else if (dd == null) {
out.println ("<p>Service '" + id + "' is not known.</p>");
} else {
out.println ("<table border='1' width='100%'>");
out.println ("<tr>");
out.println ("<th colspan='2'><h2>'" + id +
"' Service Deployment Descriptor</h2></th>");
out.println ("</tr>");
out.println ("<tr>");
out.println ("<th>Property</th>");
out.println ("<th>Details</th>");
out.println ("</tr>");
out.println ("<tr>");
out.println ("<td>ID</td>");
out.println ("<td>" + dd.getID()+ "</td>");
out.println ("</tr>");
out.println ("<tr>");
out.println ("<td>Scope</td>");
out.println ("<td>" + scopes[dd.getScope()]+ "</td>");
out.println ("</tr>");
out.println ("<tr>");
out.println ("<td>Provider Type</td>");
byte ptb = dd.getProviderType ();
String pt = (ptb==DeploymentDescriptor.PROVIDER_JAVA) ? "java" : "script";
out.println ("<td>" + pt + "</td>");
out.println ("</tr>");
out.println ("<tr>");
if (ptb == DeploymentDescriptor.PROVIDER_JAVA) {
out.println ("<td>Provider Class</td>");
out.println ("<td>" + dd.getProviderClass()+ "</td>");
out.println ("</tr>");
out.println ("<tr>");
out.println ("<td>Use Static Class</td>");
out.println ("<td>" + dd.getIsStatic()+ "</td>");
} else {
out.println ("<td>Scripting Language</td>");
out.println ("<td>" + dd.getScriptLanguage () + "</td>");
out.println ("</tr>");
out.println ("<tr>");
if (ptb == DeploymentDescriptor.PROVIDER_SCRIPT_FILE) {
out.println ("<td>Filename</td>");
out.println ("<td>" + dd.getScriptFilenameOrString () + "</td>");
} else {
out.println ("<td>Script</td>");
out.println ("<td><pre>" + dd.getScriptFilenameOrString () +
"</pre></td>");
}
}
out.println ("</tr>");
out.println ("<tr>");
out.println ("<td>Methods</td>");
out.print ("<td>");
String[] m = dd.getMethods ();
for (int i = 0; i < m.length; i++) {
out.print (m[i]);
if (i < m.length-1) {
out.print (", ");
}
}
out.println ("</td>");
out.println ("</tr>");
out.println ("<tr>");
out.println ("<td>Type Mappings</td>");
out.println ("<td>");
TypeMapping[] mappings = dd.getMappings();
if (mappings != null) {
for (int i = 0; i < mappings.length; i++) {
out.print (mappings[i]);
if (i < mappings.length-1) {
out.print ("<br>");
} else {
break;
}
}
}
out.println ("</td>");
out.println ("</tr>");
out.println ("</table>");
}
%>
1.1 xml-soap/java/webapps/admin/soapadmin.gif
<<Binary file>>
1.1 xml-soap/java/webapps/admin/toc.html
Index: toc.html
===================================================================
<body bgcolor='lightgreen'>
<a href="list.jsp" target="data"><img src="list.gif"/></a>
<p/>
<a href="deploy.jsp" target="data"><img src="deploy.gif"/></a><br/>
<p/>
<a href="undeploy.jsp" target="data"><img src="undeploy.gif"/></a><br/>
</body>
1.1 xml-soap/java/webapps/admin/undeploy.gif
<<Binary file>>
1.1 xml-soap/java/webapps/admin/undeploy.jsp
Index: undeploy.jsp
===================================================================
<%@ page import="org.apache.soap.*" %>
<%@ page import="org.apache.soap.server.*" %>
<!-- get the serviceManager object -->
<jsp:useBean id="serviceManager"
class="org.apache.soap.server.ServiceManager"
scope="application">
</jsp:useBean>
<h1>Un-Deploy a Service</h1>
<%
String id = request.getParameter ("id");
if (id == null) {
String[] serviceNames = serviceManager.list ();
if (serviceNames.length == 0) {
out.println ("<p>Sorry, there are no services currently deployed.</p>");
} else {
out.println ("<p>Select the service to be undeployed:</p>");
%>
<ul>
<%
for (int i = 0; i < serviceNames.length; i++) {
id = serviceNames[i];
%>
<li><a href="undeploy.jsp?id=<%=id%>"><%= id%></li>
<%
}
%>
</ul>
<%
}
} else {
try {
DeploymentDescriptor dd = serviceManager.undeploy (id);
out.println ("OK, service named '" + id + "' undeployed successfully!");
} catch (SOAPException e) {
out.println ("Ouch, coudn't undeploy service '" + id + "' because: ");
e.getMessage ();
}
}
%>
1.1 xml-soap/java/webapps/rpcrouter/rpcrouter.jsp
Index: rpcrouter.jsp
===================================================================
<%@ page language="java" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.reflect.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="org.apache.soap.util.Bean" %>
<%@ page import="org.apache.soap.util.MethodUtils" %>
<%@ page import="org.apache.soap.util.IOUtils" %>
<%@ page import="org.apache.soap.util.StringUtils" %>
<%@ page import="org.apache.soap.util.xml.XMLParserLiaison" %>
<%@ page import="org.apache.soap.util.xml.XercesParserLiaison" %>
<%@ page import="org.apache.soap.*" %>
<%@ page import="org.apache.soap.encoding.*" %>
<%@ page import="org.apache.soap.rpc.*" %>
<%@ page import="org.apache.soap.server.*" %>
<jsp:useBean id="serviceManager"
class="org.apache.soap.server.ServiceManager"
scope="application">
</jsp:useBean>
<jsp:useBean id="rpcRouter"
class="org.apache.soap.server.RPCRouter"
scope="application">
</jsp:useBean>
<%
// this should be done like this:
//<jsp:setProperty name="rpcRouter" property="serviceManager"
// value="serviceManager"/>
// but I get an internal servlet exception from tomcat for it ..
rpcRouter.setServiceManager (serviceManager);
Response resp = null;
String targetID = null;
// Query the relevant header fields.
String requestMethod = request.getMethod ();
String contentType = request.getContentType ();
int contentLength = request.getContentLength ();
Call call = null;
try
{
if (requestMethod == null ||
!requestMethod.equals (Constants.HEADER_POST))
{
throw new SOAPException (Constants.FAULT_CODE_PROTOCOL,
"Can only respond to '" +
Constants.HEADER_POST + "' requests.");
}
else if (contentType == null
|| !contentType.equals (Constants.HEADERVAL_CONTENT_TYPE))
{
throw new SOAPException (Constants.FAULT_CODE_PROTOCOL,
"Content type must be: '" +
Constants.HEADERVAL_CONTENT_TYPE + "'.");
}
else if (contentLength < 0)
{
throw new SOAPException (Constants.FAULT_CODE_PROTOCOL,
"Content length must be specified.");
}
else
{
System.err.println (">>(" + new Date() +
") Processing SOAP request...");
response.setContentType (Constants.HEADERVAL_CONTENT_TYPE);
Reader requestReader = request.getReader ();
char[] payload = new char[contentLength];
int offset = 0;
while (offset < contentLength) {
offset += requestReader.read (payload, offset, contentLength - offset);
}
// Parse the incoming request stream.
org.apache.soap.util.xml.XMLParserLiaison xpl = new XercesParserLiaison ();
Document callDoc = xpl.read("- SOAP HTTP RPC Call Envelope -",
new CharArrayReader (payload));
Element payloadEl = null;
if (callDoc == null) {
throw new SOAPException(Constants.FAULT_CODE_PROTOCOL,
"DOM parsing error: " + payload);
}
// get the call out
try {
payloadEl = callDoc.getDocumentElement ();
Envelope callEnv = Envelope.unmarshall (payloadEl);
call = rpcRouter.extractCallFromEnvelope (callEnv);
targetID = call.getTargetObjectURI ();
} catch (IllegalArgumentException e) {
String msg = e.getMessage ();
String faultCode = (msg != null
&& msg.equals(Constants.ERR_MSG_VERSION_MISMATCH))
? Constants.FAULT_CODE_VERSION_MISMATCH
: Constants.FAULT_CODE_CLIENT;
throw new SOAPException (faultCode, msg, e);
}
// call on a valid method name?
if (!rpcRouter.validCall (call)) {
throw new SOAPException (Constants.FAULT_CODE_SERVER,
"Method '" + call.getMethodName () +
"' is not supported.");
}
// lifecycle stuff of target object: what's the class to instantiate?
DeploymentDescriptor dd = serviceManager.query (targetID);
int scope = dd.getScope ();
byte providerType = dd.getProviderType ();
String className;
Object targetObject = null;
if (providerType == DeploymentDescriptor.PROVIDER_JAVA) {
className = dd.getProviderClass ();
} else {
// for scripts, we need a new BSF manager basically
className = "com.ibm.bsf.BSFManager";
}
// determine the scope and lock object to use to manage the lifecycle
// of the service providing object
int[] iScopes = {PageContext.PAGE_SCOPE, PageContext.REQUEST_SCOPE,
PageContext.SESSION_SCOPE,
PageContext.APPLICATION_SCOPE};
int iScope = iScopes[scope];
Object[] scopeLocks = {pageContext, request, session, application};
Object scopeLock = scopeLocks[scope];
boolean freshObject = false;
// find the target object on which the requested method should
// be invoked
if (targetID.equals (ServerConstants.SERVICE_MANAGER_SERVICE_NAME)) {
targetObject = serviceManager;
} else {
// locate (or create) the target object and invoke the method
synchronized (scopeLock) {
targetObject = pageContext.getAttribute (targetID, iScope);
if (targetObject == null) {
try {
Class c = Class.forName (className);
if (dd.getIsStatic ()) {
targetObject = c;
} else {
targetObject = c.newInstance ();
}
freshObject = true;
} catch (Exception e) {
String msg;
if (providerType == DeploymentDescriptor.PROVIDER_JAVA) {
msg = "Unable to resolve target object: " + e.getMessage ();
} else {
msg = "Unable to load BSF: script services not available " +
"without BSF: " + e.getMessage ();
}
throw new SOAPException (
RPCConstants.FAULT_CODE_SERVER_BAD_TARGET_OBJECT_URI,
msg, e);
}
}
pageContext.setAttribute (targetID, targetObject, iScope);
}
}
// if script provider type and first time to it, then load and
// exec the script
if (providerType != DeploymentDescriptor.PROVIDER_JAVA &&
freshObject) {
// find the class that provides the BSF services (done
// this way via reflection to avoid a static dependency on BSF)
Class bc = Class.forName ("org.apache.soap.server.InvokeBSF");
// get the script string to exec
String script = dd.getScriptFilenameOrString ();
if (providerType == DeploymentDescriptor.PROVIDER_SCRIPT_FILE) {
String fileName = getServletContext().getRealPath (script);
script = IOUtils.getStringFromReader (new FileReader (fileName));
}
// exec it
Class[] sig = {DeploymentDescriptor.class,
Object.class,
String.class};
Method m = MethodUtils.getMethod (bc, "init", sig, true);
m.invoke (null, new Object[] {dd, targetObject, script});
}
// invoke the method on the target object
resp = rpcRouter.invoke (call, targetObject);
}
}
catch (SOAPException e)
{
Fault fault = new Fault ();
String faultCode = e.getFaultCode ();
String faultString = e.getMessage ();
boolean returnSOAPResponse = true;
if (faultCode == null || faultCode.startsWith (Constants.FAULT_CODE_SERVER))
{
response.setStatus (ServerConstants.SC_INTERNAL_SERVER_ERROR);
}
else if (faultCode.startsWith (Constants.FAULT_CODE_CLIENT))
{
response.setStatus (ServerConstants.SC_BAD_REQUEST);
}
else if (faultCode.startsWith (Constants.FAULT_CODE_PROTOCOL))
{
response.setStatus (ServerConstants.SC_BAD_REQUEST);
returnSOAPResponse = false;
}
if (returnSOAPResponse)
{
fault.setFaultCode (faultCode);
fault.setFaultString (faultString);
fault.setFaultActorURI (request.getRequestURI ());
resp = new Response (null,
null,
fault,
null,
null,
null);
}
else
{
out.println (faultString);
}
}
catch (Throwable t)
{
t.printStackTrace ();
t.printStackTrace (new PrintWriter (out));
}
// Send it out.
if (resp != null)
{
try
{
// Build an envelope containing the response.
Envelope respEnvelope = resp.buildEnvelope ();
SOAPMappingRegistry smr = (call != null
? call.getSOAPMappingRegistry ()
: new SOAPMappingRegistry());
respEnvelope.marshall (out, smr);
out.println (StringUtils.lineSeparator);
}
catch (IllegalArgumentException e)
{
throw new SOAPException (Constants.FAULT_CODE_SERVER, e.getMessage(), e);
}
catch (IOException e)
{
throw new SOAPException (Constants.FAULT_CODE_SERVER, e.getMessage(), e);
}
}
%>