Update of /cvsroot/openamf/openamf/src/java/org/openamf/invoker
In directory sc8-pr-cvs1:/tmp/cvs-serv7008/src/java/org/openamf/invoker
Modified Files:
WebServiceInvoker.java
Log Message:
refactored and tried to get rid of convertHashMapToBean
when ASTranslator starts using the ContextClassLoader it will be very easy to swap in
currently ASTranslator can't find the newly generated classes
Index: WebServiceInvoker.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/invoker/WebServiceInvoker.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** WebServiceInvoker.java 1 May 2003 04:15:29 -0000 1.10
--- WebServiceInvoker.java 2 May 2003 06:28:50 -0000 1.11
***************
*** 1,8 ****
package org.openamf.invoker;
- import java.beans.BeanInfo;
import java.beans.IntrospectionException;
- import java.beans.Introspector;
- import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.io.File;
--- 1,5 ----
***************
*** 10,15 ****
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
! import java.net.URL;
! import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.List;
--- 7,11 ----
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
! import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.List;
***************
*** 24,28 ****
import org.openamf.ServiceRequest;
! public class WebServiceInvoker extends JavaServiceInvoker {
private static Log log = LogFactory.getLog(WebServiceInvoker.class);
--- 20,24 ----
import org.openamf.ServiceRequest;
! public class WebServiceInvoker extends ServiceInvoker {
private static Log log = LogFactory.getLog(WebServiceInvoker.class);
***************
*** 38,62 ****
public Object invokeService() throws ServiceInvocationException {
! /*
! * TODO: Can optimize so introspection isnt necessary every time.
! *
! */
String serviceName = request.getServiceName();
log.debug("SERVICE NAME: " + serviceName);
- Object r = null;
String requestedMethodName = request.getServiceMethodName();
! String packageFolder = "amazon";
!
! packageFolder =
serviceName.substring(
serviceName.lastIndexOf('/') + 1,
serviceName.lastIndexOf('.'));
//remove -'s and .'s
packageFolder = removeChar(packageFolder, '-');
packageFolder = removeChar(packageFolder, '.');
log.debug("PACKAGE NAME:" + packageFolder);
!
//note: things go boom right now if bad method name passed
try {
--- 34,53 ----
public Object invokeService() throws ServiceInvocationException {
! Object result = null;
String serviceName = request.getServiceName();
log.debug("SERVICE NAME: " + serviceName);
String requestedMethodName = request.getServiceMethodName();
! String packageFolder =
serviceName.substring(
serviceName.lastIndexOf('/') + 1,
serviceName.lastIndexOf('.'));
+
//remove -'s and .'s
packageFolder = removeChar(packageFolder, '-');
packageFolder = removeChar(packageFolder, '.');
log.debug("PACKAGE NAME:" + packageFolder);
!
//note: things go boom right now if bad method name passed
try {
***************
*** 65,222 ****
servletContext.getRealPath("/WEB-INF/classes");
! File testDir = new File(webservicesDir + "/" + packageFolder);
! if (!testDir.exists()) {
! // ANT stuff
! Project project = new Project();
! project.init();
! //this is a ton of debug code
! //project.addBuildListener(new ServletLogger());
! File buildFile = new File(webservicesDir + "/build.xml");
! log.debug("buildfile exists: " + buildFile.exists());
! project.setProperty("endpoint", serviceName);
! project.setProperty("packagename", packageFolder);
! ProjectHelper.configureProject(project, buildFile);
! project.executeTarget(project.getDefaultTarget());
! project.executeTarget("fetch-wsdl");
! project.executeTarget("import-wsdl");
! project.executeTarget("compile");
! //end ant stuff
! }
!
! Class bindingClass = null;
! Class locatorClass = null;
! ClassLoader classLoader = null;
! if (new File(webservicesDir).exists()) {
! classLoader =
! new URLClassLoader(
! new URL[] { new File(webservicesDir).toURL()},
! Thread.currentThread().getContextClassLoader());
! } else {
! log.debug("installFolder does not exist!");
! }
! File classDir =
! new File(webservicesDir + "/" + packageFolder + "/");
! String[] fileList = classDir.list();
! String locatorFileName = "";
! String bindingFileName = "";
! for (int i = 0; i < fileList.length; ++i)
! {
!
! String temp = fileList[i];
! if (temp.indexOf(".class") == -1)
! continue;
! if (temp.indexOf("Locator") != -1)
! locatorFileName = packageFolder + "." + temp;
! if (temp.indexOf("Stub") != -1)
! bindingFileName = packageFolder + "." + temp;
! }
! locatorFileName =
! locatorFileName.substring(0, locatorFileName.lastIndexOf('.'));
! bindingFileName =
! bindingFileName.substring(0, bindingFileName.lastIndexOf('.'));
! log.debug("locatorFileName=" + locatorFileName);
! log.debug("bindingFileName=" + bindingFileName);
! locatorClass = classLoader.loadClass(locatorFileName);
! bindingClass = classLoader.loadClass(bindingFileName);
! Method[] lcMethods = locatorClass.getMethods();
! Method getPortAddress = null;
! String methodName = null;
! for (int i = 0; i < lcMethods.length; ++i) {
! methodName = lcMethods[i].getName();
! if (methodName.indexOf("Address") != -1) {
! log.debug(
! "...............got port address locator..........");
! getPortAddress = lcMethods[i];
! }
! }
! Constructor constructor = locatorClass.getConstructor(null);
! Object locatorObj = constructor.newInstance(null);
! String endpoint =
! getPortAddress.invoke(locatorObj, null).toString();
! Class[] argTypes =
! new Class[] { java.net.URL.class, javax.xml.rpc.Service.class };
! Constructor stubConstructor = bindingClass.getConstructor(argTypes);
! Service service = null;
! Object[] args =
! new Object[] { new java.net.URL(endpoint), service };
! BeanInfo bi2 = Introspector.getBeanInfo(bindingClass);
! MethodDescriptor md2[] = bi2.getMethodDescriptors();
! Method requestedMethod = null;
! //Class returnType=null;
! for (int i = 0; i < md2.length; ++i) {
! methodName = md2[i].getName();
! if (methodName.equalsIgnoreCase(requestedMethodName)) {
! System.out.println(
! "...............got "
! + requestedMethodName
! + "..........");
! requestedMethod = md2[i].getMethod();
! }
}
! Object parameterObj = null;
! Constructor pc = null;
! Class[] argTypes2 = requestedMethod.getParameterTypes();
! log.debug("Method Name:" + requestedMethod.getName());
! log.debug(
! "REQUESTED METHOD NUM PARMS:" + argTypes2.length);
! for (int j = 0; j < argTypes2.length; ++j) {
! System.out.println(argTypes2[j].getName());
! pc = argTypes2[j].getConstructor(null);
}
! parameterObj = pc.newInstance(null);
! List parms = request.getParameters();
!
!
! Object pObj=parms.get(0);
!
! if(pObj instanceof ASObject)
! {
!
! ASObject asobj = (ASObject) parms.get(0);
! parameterObj = convertHashMapToBean(asobj, parameterObj.getClass());
! }
! else if(pObj instanceof String)
! {
! parameterObj=(String)pObj;
}
! Object stubObj = stubConstructor.newInstance(args);
! Object[] p = new Object[] { parameterObj };
! //returnType=requestedMethod.getReturnType();
! r = requestedMethod.invoke(stubObj, p);
! System.out.println("here it comes!!");
! } catch (Exception e) {
! e.printStackTrace();
! }
! return r;
}
! protected Object convertHashMapToBean(HashMap data, Class beanClass)
throws
InstantiationException,
--- 56,239 ----
servletContext.getRealPath("/WEB-INF/classes");
! runAntBuild(serviceName, packageFolder, webservicesDir);
! Class bindingClass =
! loadWSClass("Stub", webservicesDir, packageFolder);
! Class locatorClass =
! loadWSClass("Locator", webservicesDir, packageFolder);
! String endpoint = getEndPoint(locatorClass);
! Method requestedMethod =
! getRequestedMethod(requestedMethodName, bindingClass);
! result =
! invokeMethod(
! bindingClass,
! endpoint,
! requestedMethod,
! request.getParameters());
! log.debug("here it comes!!");
! } catch (Exception e) {
! throw new ServiceInvocationException(request, e);
! }
! return result;
! }
! private String removeChar(String s, char c) {
! StringBuffer b = new StringBuffer(s.length());
! for (int i = 0; i < s.length(); ++i) {
! if (s.charAt(i) != c)
! b.append(s.charAt(i));
! }
! return b.toString();
! }
! private void runAntBuild(
! String serviceName,
! String packageFolder,
! String webservicesDir) {
! File testDir = new File(webservicesDir + "/" + packageFolder);
! if (!testDir.exists()) {
! Project project = new Project();
! project.init();
! //this is a ton of debug code
! //project.addBuildListener(new ServletLogger());
! File buildFile = new File(webservicesDir + "/build.xml");
! log.debug("buildfile exists: " + buildFile.exists());
! project.setProperty("endpoint", serviceName);
! project.setProperty("packagename", packageFolder);
! ProjectHelper.configureProject(project, buildFile);
! project.executeTarget(project.getDefaultTarget());
! project.executeTarget("fetch-wsdl");
! project.executeTarget("import-wsdl");
! project.executeTarget("compile");
! }
! }
! private Class loadWSClass(
! String classType,
! String webservicesDir,
! String packageFolder)
! throws ClassNotFoundException {
! Class wsClass = null;
! File classDir = new File(webservicesDir + "/" + packageFolder + "/");
! String[] fileList = classDir.list();
! String fileName = null;
! for (int i = 0; i < fileList.length; ++i) {
! String temp = fileList[i];
! if (temp.indexOf(".class") == -1) {
! continue;
}
! if (temp.indexOf(classType) != -1) {
! fileName = packageFolder + "." + temp;
! }
! }
! fileName = fileName.substring(0, fileName.lastIndexOf('.'));
!
! log.debug("fileName=" + fileName);
!
! wsClass =
! Thread.currentThread().getContextClassLoader().loadClass(fileName);
!
! return wsClass;
! }
!
! private String getEndPoint(Class locatorClass)
! throws
! NoSuchMethodException,
! InstantiationException,
! IllegalAccessException,
! InvocationTargetException {
!
! Method[] lcMethods = locatorClass.getMethods();
! Method getPortAddress = null;
! String methodName = null;
! for (int i = 0; i < lcMethods.length; ++i) {
! methodName = lcMethods[i].getName();
! if (methodName.indexOf("Address") != -1) {
! log.debug("...got port address locator...");
! getPortAddress = lcMethods[i];
}
+ }
! Constructor constructor = locatorClass.getConstructor(null);
! Object locatorObj = constructor.newInstance(null);
! String endpoint = getPortAddress.invoke(locatorObj, null).toString();
! return endpoint;
! }
!
! private Method getRequestedMethod(
! String requestedMethodName,
! Class bindingClass) {
! Method methods[] = bindingClass.getMethods();
! Method requestedMethod = null;
! String methodName = null;
!
! //TODO add more checking, what method is overloaded
! for (int i = 0; i < methods.length; ++i) {
! methodName = methods[i].getName();
! if (methodName.equalsIgnoreCase(requestedMethodName)) {
! log.debug("...got " + requestedMethodName);
! requestedMethod = methods[i];
! }
! }
! return requestedMethod;
! }
! private Object invokeMethod(
! Class bindingClass,
! String endpoint,
! Method requestedMethod,
! List parms)
! throws
! InstantiationException,
! IntrospectionException,
! IllegalAccessException,
! InvocationTargetException,
! NoSuchMethodException,
! MalformedURLException {
!
!
! Class[] paramTypes = requestedMethod.getParameterTypes();
! for (int i = 0; i < paramTypes.length; i++) {
! Class paramType = paramTypes[i];
! Object param = parms.get(i);
! if (param instanceof ASObject) {
! //TODO call ASTranslator when they start using the ContextClassLoader
! param = convertHashMapToBean((HashMap) param, paramType);
! parms.set(i, param);
}
! }
! Class[] argTypes =
! new Class[] { java.net.URL.class, javax.xml.rpc.Service.class };
! Constructor stubConstructor = bindingClass.getConstructor(argTypes);
! //TODO is service always null?
! Service service = null;
! Object[] args = new Object[] { new java.net.URL(endpoint), service };
! Object stubObj = stubConstructor.newInstance(args);
! return requestedMethod.invoke(stubObj, parms.toArray());
}
!
! private Object convertHashMapToBean(HashMap data, Class beanClass)
throws
InstantiationException,
***************
*** 268,281 ****
return bean;
}
- public String removeChar(String s, char c) {
-
- StringBuffer b = new StringBuffer(s.length());
- for (int i=0;i<s.length();++i) {
- if (s.charAt(i) != c)
- b.append(s.charAt(i));
- }
- return b.toString();
- }
public boolean supports(ServiceRequest request) {
return (
--- 285,289 ----
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.