You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by de...@apache.org on 2007/02/23 17:19:34 UTC

svn commit: r511006 - /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java

Author: deepal
Date: Fri Feb 23 08:19:34 2007
New Revision: 511006

URL: http://svn.apache.org/viewvc?view=rev&rev=511006
Log:
-now we can deploy jar , and that can have any number of annotated class
- if it has multiple annotated class , then that will make to AxisServiceGroup

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java?view=diff&rev=511006&r1=511005&r2=511006
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/POJODeployer.java Fri Feb 23 08:19:34 2007
@@ -3,16 +3,21 @@
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.deployment.repository.util.DeploymentFileData;
 import org.apache.axis2.description.AxisService;
-import org.apache.axis2.util.Loader;
+import org.apache.axis2.description.AxisServiceGroup;
 import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.util.Loader;
 import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.ws.java2wsdl.AnnotationConstants;
 import org.codehaus.jam.*;
 
 import java.io.File;
-import java.net.URL;
+import java.io.FileInputStream;
 import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
 
 /*
 * Copyright 2004,2005 The Apache Software Foundation.
@@ -88,7 +93,7 @@
                                 Class pojoClass = Loader.loadClass(classLoader, className);
                                 AxisService axisService = new AxisService(className);
                                 axisService.setName(className);
-                                mthod.invoke(claxx,new Object[]{pojoClass, axisService});
+                                mthod.invoke(claxx, new Object[]{pojoClass, axisService});
                                 configCtx.getAxisConfiguration().addService(axisService);
                             } else {
                                 HashMap messageReciverMap = new HashMap();
@@ -115,8 +120,110 @@
                     }
                 }
 
-            } else if ("jar".equals(extension)) {
-                //TODO need to extart the zip file and find out the classes which has annotated
+            } else if (".jar".equals(extension)) {
+                ArrayList classList;
+                FileInputStream fin = null;
+                ZipInputStream zin = null;
+                try {
+                    fin = new FileInputStream(deploymentFileData.getAbsolutePath());
+                    zin = new ZipInputStream(fin);
+                    ZipEntry entry;
+                    classList = new ArrayList();
+                    while ((entry = zin.getNextEntry()) != null) {
+                        String name = entry.getName();
+                        if (name.endsWith(".class")) {
+                            classList.add(name);
+                        }
+                    }
+                    zin.close();
+                    fin.close();
+                } catch (Exception e) {
+                    throw new DeploymentException(e);
+                } finally {
+                    if (zin != null) {
+                        zin.close();
+                    }
+                    if (fin != null) {
+                        fin.close();
+                    }
+                }
+                ArrayList axisServiceList = new ArrayList();
+                for (int i = 0; i < classList.size(); i++) {
+                    String className = (String) classList.get(i);
+                    DeploymentClassLoader classLoader = new DeploymentClassLoader(new URL[]{deploymentFileData.getFile().toURL()},
+                            configCtx.getAxisConfiguration().getSystemClassLoader(), true);
+                    Thread.currentThread().setContextClassLoader(classLoader);
+                    className = className.replaceAll(".class", "");
+                    className = className.replaceAll("/", ".");
+                    JamServiceFactory factory = JamServiceFactory.getInstance();
+                    JamServiceParams jam_service_parms = factory.createServiceParams();
+                    jam_service_parms.addClassLoader(classLoader);
+                    jam_service_parms.includeClass(className);
+                    JamService service = factory.createService(jam_service_parms);
+                    JamClassIterator jClassIter = service.getClasses();
+                    while (jClassIter.hasNext()) {
+                        JClass jclass = (JClass) jClassIter.next();
+                        if (jclass.getQualifiedName().equals(className)) {
+                            /**
+                             * Schema genertaion done in two stage 1. Load all the methods and
+                             * create type for methods parameters (if the parameters are Bean
+                             * then it will create Complex types for those , and if the
+                             * parameters are simple type which decribe in SimpleTypeTable
+                             * nothing will happen) 2. In the next stage for all the methods
+                             * messages and port types will be creteated
+                             */
+                            boolean callJaxWs = false;
+                            JAnnotation annotation = jclass.getAnnotation(AnnotationConstants.WEB_SERVICE);
+                            if (annotation != null) {
+                                String wsdlLocation = annotation.getValue(AnnotationConstants.WSDL_LOCATION).asString();
+                                if (wsdlLocation != null && !"".equals(wsdlLocation)) {
+                                    callJaxWs = true;
+                                }
+                            } else {
+                                continue;
+                            }
+                            if (callJaxWs) {
+                                Class claxx = Class.forName(
+                                        "org.apache.axis2.jaxws.description.DescriptionFactory");
+                                Method mthod = claxx.getMethod(
+                                        "createServiceDescriptionFromServiceImpl",
+                                        new Class[]{Class.class, AxisService.class});
+                                Class pojoClass = Loader.loadClass(classLoader, className);
+                                AxisService axisService = new AxisService(className);
+                                axisService.setName(className);
+                                mthod.invoke(claxx, new Object[]{pojoClass, axisService});
+                                axisServiceList.add(axisService);
+                            } else {
+                                HashMap messageReciverMap = new HashMap();
+                                Class inOnlyMessageReceiver = Loader.loadClass(
+                                        "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver");
+                                MessageReceiver messageReceiver =
+                                        (MessageReceiver) inOnlyMessageReceiver.newInstance();
+                                messageReciverMap.put(
+                                        WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_ONLY,
+                                        messageReceiver);
+                                Class inoutMessageReceiver = Loader.loadClass(
+                                        "org.apache.axis2.rpc.receivers.RPCMessageReceiver");
+                                MessageReceiver inOutmessageReceiver =
+                                        (MessageReceiver) inoutMessageReceiver.newInstance();
+                                messageReciverMap.put(
+                                        WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OUT,
+                                        inOutmessageReceiver);
+                                AxisService axisService = AxisService.createService(className,
+                                        configCtx.getAxisConfiguration(),
+                                        messageReciverMap, null, null, classLoader);
+                                axisServiceList.add(axisService);
+                            }
+                        }
+                    }
+                }
+                AxisServiceGroup serviceGroup = new AxisServiceGroup();
+                serviceGroup.setServiceGroupName(deploymentFileData.getServiceName());
+                for (int i = 0; i < axisServiceList.size(); i++) {
+                    AxisService axisService = (AxisService) axisServiceList.get(i);
+                    serviceGroup.addService(axisService);
+                }
+                configCtx.getAxisConfiguration().addServiceGroup(serviceGroup);
             }
         } catch (Exception e) {
             e.printStackTrace();



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org