00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.ext.webservices.soap;
00032
00033 import java.io.StringWriter;
00034 import java.util.Hashtable;
00035
00036 import javax.servlet.http.HttpServlet;
00037 import javax.servlet.http.HttpSession;
00038
00039 import org.apache.soap.Constants;
00040 import org.apache.soap.Envelope;
00041 import org.apache.soap.SOAPException;
00042 import org.apache.soap.rpc.Call;
00043 import org.apache.soap.rpc.Response;
00044 import org.apache.soap.rpc.SOAPContext;
00045 import org.apache.soap.server.DeploymentDescriptor;
00046 import org.apache.soap.server.RPCRouter;
00047 import org.apache.soap.util.Provider;
00048 import org.objectweb.fractal.api.Component;
00049 import org.objectweb.proactive.core.ProActiveException;
00050 import org.objectweb.proactive.core.body.http.util.HttpMarshaller;
00051 import org.objectweb.proactive.core.runtime.RuntimeFactory;
00052 import org.objectweb.proactive.ext.webservices.WSConstants;
00053
00054
00059 public class ProActiveProvider extends WSConstants implements Provider {
00060
00061 static {
00062 System.setSecurityManager(new java.rmi.RMISecurityManager());
00063 try {
00064 RuntimeFactory.getDefaultRuntime();
00065 } catch (ProActiveException e) {
00066 e.printStackTrace();
00067 }
00068 }
00069
00070 private DeploymentDescriptor dd;
00071 private Envelope envelope;
00072 private Call call;
00073 private String methodName;
00074 private String targetObjectURI;
00075 private HttpServlet servlet;
00076 private HttpSession session;
00077 private Object targetObject;
00078
00084 public void locate(DeploymentDescriptor dd, Envelope env, Call call,
00085 String methodName, String targetObjectURI, SOAPContext reqContext)
00086 throws SOAPException {
00087
00088 HttpServlet servlet = (HttpServlet) reqContext.getProperty(Constants.BAG_HTTPSERVLET);
00089 HttpSession session = (HttpSession) reqContext.getProperty(Constants.BAG_HTTPSESSION);
00090
00091 System.out.println("================================================");
00092 System.out.println("In ProActiveProvider.locate()");
00093 System.out.println("Method: " + methodName);
00094 System.out.println("URI: " + targetObjectURI);
00095 System.out.println("DD.ServiceClass: " + dd.getServiceClass());
00096 System.out.println("DD.ProviderClass: " + dd.getProviderClass());
00097 System.out.println("Call.MethodName: " + call.getMethodName());
00098
00099 Hashtable props = dd.getProps();
00100 String className = dd.getProviderClass();
00101
00102 this.dd = dd;
00103 this.envelope = env;
00104 this.call = call;
00105 this.methodName = methodName;
00106 this.targetObjectURI = targetObjectURI;
00107 this.servlet = servlet;
00108 this.session = session;
00109
00110 if (!RPCRouter.validCall(dd, call)) {
00111 System.err.println("It's not a valid call");
00112
00113 SOAPException e = new SOAPException(Constants.FAULT_CODE_CLIENT,
00114 "It's not a valid call");
00115 throw e;
00116 }
00117
00118 byte[] serObj = (byte[]) props.get("Stub");
00119
00120 boolean isInterfaceComponent = ((String) props.get(ProActiveDeployer.COMPONENT_INTERFACE)).equals(
00121 "true");
00122
00123 try {
00124 if (!isInterfaceComponent) {
00125 targetObject = HttpMarshaller.unmarshallObject(serObj);
00126 } else {
00127 Object o = HttpMarshaller.unmarshallObject(serObj);
00128 String actualName = targetObjectURI.substring(targetObjectURI.lastIndexOf(
00129 '_') + 1);
00130 Component c = (Component) o;
00131 targetObject = c.getFcInterface(actualName);
00132 }
00133 } catch (Exception e) {
00134 System.out.println("Exception : " + e.getMessage());
00135 e.printStackTrace(System.out);
00136 }
00137 }
00138
00144 public void invoke(SOAPContext reqContext, SOAPContext resContext)
00145 throws SOAPException {
00146 System.out.println("=============================================");
00147 System.out.println("In ProActiveProvider.invoke()");
00148
00149
00150 String reponse = null;
00151
00152
00153
00154 try {
00155 Response resp = RPCRouter.invoke(dd, call, targetObject,
00156 reqContext, resContext);
00157
00158
00159 Envelope env = resp.buildEnvelope();
00160 System.out.println(env);
00161 StringWriter sw = new StringWriter();
00162 env.marshall(sw, call.getSOAPMappingRegistry(), resContext);
00163 resContext.setRootPart(sw.toString(),
00164 Constants.HEADERVAL_CONTENT_TYPE_UTF8);
00165 } catch (Exception e) {
00166 System.out.println("--- >exception ! " + e.getMessage() + " -- " +
00167 e.getClass().getName());
00168 e.printStackTrace(System.out);
00169
00170 SOAPException ex = new SOAPException(Constants.FAULT_CODE_SERVER,
00171 e.getMessage());
00172 System.out.println(
00173 "An error has occured when trying to invoke the method on the object");
00174 throw ex;
00175 }
00176 }
00177 }