openamf/src/java/org/openamf/invoker WebServiceInvoker.java,1.6,1.7

[email protected]
Newsgroups gmane.comp.java.openamf.cvs
Message-ID <[email protected]>
Update of /cvsroot/openamf/openamf/src/java/org/openamf/invoker
In directory sc8-pr-cvs1:/tmp/cvs-serv9625/src/java/org/openamf/invoker

Modified Files:
	WebServiceInvoker.java 
Log Message:


Index: WebServiceInvoker.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/invoker/WebServiceInvoker.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** WebServiceInvoker.java	30 Apr 2003 21:26:02 -0000	1.6
--- WebServiceInvoker.java	30 Apr 2003 23:53:14 -0000	1.7
***************
*** 1,248 ****
  package org.openamf.invoker;
  
- import org.apache.axis.encoding.*;
- 
- import org.openamf.ASObject;
  import java.beans.BeanInfo;
- import java.beans.IntrospectionException;
  import java.beans.Introspector;
! import java.beans.PropertyDescriptor;
! import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
! import java.util.HashMap;
  import java.util.List;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.openamf.ServiceRequest;
  
- //import org.apache.axis.client.Call;
- import org.apache.axis.client.Service;
- //import javax.xml.namespace.QName;
- 
- import org.apache.tools.ant.*;
- import java.beans.*;
- import java.io.*;
- import java.lang.reflect.*;
- import java.net.*;
- 
  public class WebServiceInvoker extends JavaServiceInvoker {
  
  	private static Log log = LogFactory.getLog(WebServiceInvoker.class);
  
! public WebServiceInvoker(ServiceRequest request, javax.servlet.ServletContext ctx) {
! 
! 			super(request, ctx);
  
! 		}
  
  
! public  Object invokeService() throws ServiceInvocationException{
  
  
! /*
!  * TODO: acquire className and requestedMethodName
!  * 
!  * look to see if mapping exists in context
!  * if not, have to do the whole whammie
!  * 
!  * if so, we should probably store the two classnames so we 
!  * dont have to do the introspection, maybe store ALL the method names?
!  * 
!  * look closer, maybe all we want to do is invoke()
!  * 
!  * actually looks like all we need is the package name,
!  * which we make up and then provide the ant task.
!  * 
!  * 
!  */
  
! String serviceName=request.getServiceName();
! log.debug("SERVICE NAME: "+serviceName);
! String x=request.getServiceMethodName();
! log.debug("SERVICE METHOD NAME: "+x);
! String y=request.getTarget();
! log.debug("TARGET: "+y);
  
  
! 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);
  
  
  
! //TODO: something to think about, we dont want to start creating stubs if there is a bad method name
  
! try{
! 		
! 	
! 	 	
! 	String webservicesDir=servletContext.getRealPath("/WEB-INF/classes");
! 	
! 	
! 	File testDir=new File(webservicesDir+"/"+packageFolder);
! 	if(!testDir.exists())
! 	{
! 	
! //		ANT stuff 
! 		Project project = new Project();
! 		project.fireBuildStarted();
! 		project.init();
! 		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)
! 			{
  				//System.out.println(fileList[i]);
! 				String temp=fileList[i];
! 				if(temp.indexOf(".class")==-1)continue;
  
! 				if(temp.indexOf("ServiceLocator")!=-1)locatorFileName=packageFolder+"."+temp;
! 				if(temp.indexOf("BindingStub")!=-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("PortAddress")!=-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();
! 		System.out.println("Method Name:"+requestedMethod.getName());
! 		System.out.println("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();
! 		
! 		//TODO: is this always valid?
! 		ASObject asobj=(ASObject)parms.get(0);
  
! 		parameterObj=convertHashMapToBean(asobj,parameterObj.getClass());
  
! 		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;
  	}
- 	public  String removeChar(String s, char c) {
- 	   String r = "";
- 	   for (int i = 0; i < s.length(); i ++) {
- 		  if (s.charAt(i) != c) r += s.charAt(i);
- 		  }
- 	   return r;
- 	   }
  	public boolean supports(ServiceRequest request) {
  		return (
  			request.getServiceName().toLowerCase().lastIndexOf("wsdl") != -1);
  	}
- 
  
  }
--- 1,240 ----
  package org.openamf.invoker;
  
  import java.beans.BeanInfo;
  import java.beans.Introspector;
! import java.beans.MethodDescriptor;
! import java.io.File;
! import java.lang.reflect.Constructor;
  import java.lang.reflect.Method;
! import java.net.URL;
! import java.net.URLClassLoader;
  import java.util.List;
  
+ import org.apache.axis.client.Service;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
+ import org.apache.tools.ant.Project;
+ import org.apache.tools.ant.ProjectHelper;
+ import org.openamf.ASObject;
  import org.openamf.ServiceRequest;
  
  public class WebServiceInvoker extends JavaServiceInvoker {
  
  	private static Log log = LogFactory.getLog(WebServiceInvoker.class);
  
! 	public WebServiceInvoker(
! 		ServiceRequest request,
! 		javax.servlet.ServletContext ctx) {
  
! 		super(request, ctx);
  
+ 	}
  
! 	public Object invokeService() throws ServiceInvocationException {
  
+ 		/*
+ 		 * TODO: acquire className and requestedMethodName
+ 		 * 
+ 		 * look to see if mapping exists in context
+ 		 * if not, have to do the whole whammie
+ 		 * 
+ 		 * if so, we should probably store the two classnames so we 
+ 		 * dont have to do the introspection, maybe store ALL the method names?
+ 		 * 
+ 		 * look closer, maybe all we want to do is invoke()
+ 		 * 
+ 		 * actually looks like all we need is the package name,
+ 		 * which we make up and then provide the ant task.
+ 		 * 
+ 		 * 
+ 		 */
  
! 		String serviceName = request.getServiceName();
! 		log.debug("SERVICE NAME: " + serviceName);
! 		String x = request.getServiceMethodName();
! 		log.debug("SERVICE METHOD NAME: " + x);
! 		String y = request.getTarget();
! 		log.debug("TARGET: " + y);
  
! 		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);
  
! 		//TODO: something to think about, we dont want to start creating stubs if there is a bad method name
  
+ 		try {
  
! 			String webservicesDir =
! 				servletContext.getRealPath("/WEB-INF/classes");
  
+ 			File testDir = new File(webservicesDir + "/" + packageFolder);
+ 			if (!testDir.exists()) {
  
+ 				//		ANT stuff 
+ 				Project project = new Project();
+ 				//project.fireBuildStarted();
+ 				project.init();
+ 				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) {
  				//System.out.println(fileList[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();
! 			System.out.println("Method Name:" + requestedMethod.getName());
! 			System.out.println(
! 				"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();
! 
! 			//TODO: is this always valid?
! 			
! 			Object pObj=parms.get(0);
! 			
! 			
! 			
! 			ASObject asobj = (ASObject) parms.get(0);
! 
! 			parameterObj = convertHashMapToBean(asobj, parameterObj.getClass());
! 
! 			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;
! 	}
! 	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 (
  			request.getServiceName().toLowerCase().lastIndexOf("wsdl") != -1);
  	}
  
  }




-------------------------------------------------------
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.