Author: deepal
Date: Tue Dec 20 20:43:43 2005
New Revision: 358205

URL: http://svn.apache.org/viewcvs?rev=358205&view=rev
Log:
Integrate Java2WSDL into deployment section
  1. If the WSDL is there then using the WSDL first create an AxisService 
(thats wt Sanka did)
  2. If the wsdl is not there using JAM I generate WSDL

Finally if the WSDL is there or not when you type ?wsdl u should get the wsdl 
file for that service (which is always DOC-LIT , I will improve that to support 
any type).

Note : If the service class is not Java or if there are any error at the schema 
generation time ?wsdl will not work.

Fix Deploymengt Class Loader to support Paranet first and Child first scanario 
(I have to provide a way to configure that using axis2.xml)

Modified:
    
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/AxisServiceBuilder.java
    
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java
    
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/ServiceBuilder.java
    
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/ServiceGroupBuilder.java
    
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveFileData.java
    
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
    
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java

Modified: 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/AxisServiceBuilder.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/AxisServiceBuilder.java?rev=358205&r1=358204&r2=358205&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/AxisServiceBuilder.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/AxisServiceBuilder.java
 Tue Dec 20 20:43:43 2005
@@ -16,31 +16,6 @@
 
 package org.apache.axis2.deployment;
 
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.wsdl.Binding;
-import javax.wsdl.BindingOperation;
-import javax.wsdl.Definition;
-import javax.wsdl.Input;
-import javax.wsdl.Message;
-import javax.wsdl.Operation;
-import javax.wsdl.Output;
-import javax.wsdl.Port;
-import javax.wsdl.Service;
-import javax.wsdl.Types;
-import javax.wsdl.WSDLException;
-import javax.wsdl.extensions.ExtensibilityElement;
-import javax.wsdl.extensions.schema.Schema;
-import javax.wsdl.extensions.soap.SOAPBinding;
-import javax.wsdl.factory.WSDLFactory;
-import javax.wsdl.xml.WSDLReader;
-import javax.xml.namespace.QName;
-import javax.xml.parsers.ParserConfigurationException;
-
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.description.AxisMessage;
 import org.apache.axis2.description.AxisOperation;
@@ -55,11 +30,23 @@
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
+import javax.wsdl.*;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.Map;
+
 /**
  * AxisServiceBuilder builds an AxisService using a WSDL document which is feed
  * as a javax.wsdl.Definition or as an InputStream. If there are multiple
  * javax.wsdl.Service elements in the WSDL, the first is picked.
- * 
+ *
  * @author Sanka Samaranayake ([EMAIL PROTECTED])
  */
 public class AxisServiceBuilder {
@@ -68,16 +55,16 @@
             throws WSDLException {
         WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
         reader.setFeature("javax.wsdl.importDocuments", true);
-        
+
         Document doc;
 
         try {
             doc = XMLUtils.newDocument(wsdlInputStream);
-        
+
         } catch (ParserConfigurationException e) {
             throw new WSDLException(WSDLException.PARSER_ERROR,
                     "Parser Configuration Error", e);
-        
+
         } catch (SAXException e) {
             throw new WSDLException(WSDLException.PARSER_ERROR,
                     "Parser SAX Error", e);
@@ -172,7 +159,7 @@
         Iterator ports = service.getPorts().values().iterator();
         Port port;
         Binding binding;
-        
+
         while (ports.hasNext()) {
             port = (Port) ports.next();
             binding = port.getBinding();

Modified: 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java?rev=358205&r1=358204&r2=358205&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentClassLoader.java
 Tue Dec 20 20:43:43 2005
@@ -19,12 +19,7 @@
 
 import org.apache.axis2.i18n.Messages;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
@@ -37,6 +32,8 @@
     // To keep jar files inside /lib directory in the main jar
     private ArrayList lib_jars_list;
     private HashMap loadedClass;
+    //to set the loading ordere parent first or child first : default is child 
first
+    private boolean parentFirst = false;
 
     // urls which gives to create the classLoader
     private URL[] urls;
@@ -74,32 +71,26 @@
      */
     protected Class findClass(final String name) throws ClassNotFoundException 
{
         Class cla;
-
-        try {
-            cla = (Class) loadedClass.get(name);
-
-            if (cla != null) {
-                return cla;
-            }
-
+        cla = (Class) loadedClass.get(name);
+        if (cla != null) {
+            //the class is already in the loaded class list so no need to load 
it again
+            return cla;
+        }
+        if (parentFirst) {
+            //if parent first is true then first it is require to check in the 
parent
             boolean foundClass;
-
             try {
                 cla = super.findClass(name);
                 loadedClass.put(name, cla);
-
                 return cla;
             } catch (ClassNotFoundException e) {
                 foundClass = false;
             }
-
             if (!foundClass) {
                 try {
                     byte raw[] = getClassByteCodes(name);
-
                     cla = defineClass(name, raw, 0, raw.length);
                     loadedClass.put(name, cla);
-
                     return cla;
                 } catch (Exception e) {
                     foundClass = false;
@@ -107,16 +98,26 @@
                     foundClass = false;
                 }
             }
-
             if (!foundClass) {
                 throw new ClassNotFoundException(
                         
Messages.getMessage(DeploymentErrorMsgs.CLASS_NOT_FOUND, name));
             }
-        } catch (Exception e) {
-            throw new ClassNotFoundException(
-                    Messages.getMessage(DeploymentErrorMsgs.CLASS_NOT_FOUND, 
name));
+        } else {
+            try {
+                byte raw[] = getClassByteCodes(name);
+                cla = defineClass(name, raw, 0, raw.length);
+                loadedClass.put(name, cla);
+                return cla;
+            } catch (ClassFormatError e) {
+                throw e;
+            } catch (Exception e) {
+                // no need to do any thing
+            }
+            // finding in parent
+            cla = super.findClass(name);
+            loadedClass.put(name, cla);
+            return cla;
         }
-
         return null;
     }
 
@@ -125,7 +126,6 @@
      * will be added to the arraylit (only the name of the jar file)
      */
     private void findLibJars() {
-
         /**
          * though the URL array can contains one or more urls , I have only 
consider the
          * first one , that is this classLoader is only for Axis2 stuff and 
the classloader
@@ -138,10 +138,8 @@
             ZipInputStream zin = new ZipInputStream(new FileInputStream(file));
             ZipEntry entry;
             String entryName;
-
             while ((entry = zin.getNextEntry()) != null) {
                 entryName = entry.getName();
-
                 /**
                  * id the entry name start with /lib and end with .jar
                  * then those entry name will be added to the arraylist
@@ -151,7 +149,6 @@
                     lib_jars_list.add(entryName);
                 }
             }
-
             zin.close();
         } catch (Exception e) {
             throw new RuntimeException(e);
@@ -169,32 +166,26 @@
     private byte[] getBytes(String resourceName) {
         byte raw[];
         ZipInputStream zin = null;
-
         for (int i = 0; i < lib_jars_list.size(); i++) {
             String libjar_name = (String) lib_jars_list.get(i);
-            InputStream in = getResourceAsStream(libjar_name);
-
+            // seince we are trying to get jar file , we need for sure that 
all the
+            // libs are in parent class loader not in child class loader
+            InputStream in = super.getResourceAsStream(libjar_name);
             try {
                 zin = new ZipInputStream(in);
-
                 ZipEntry entry;
                 String entryName;
-
                 while ((entry = zin.getNextEntry()) != null) {
                     entryName = entry.getName();
-
                     if ((entryName != null) && 
entryName.endsWith(resourceName)) {
                         byte data[] = new byte[2048];
                         ByteArrayOutputStream out = new 
ByteArrayOutputStream();
                         int count;
-
                         while ((count = zin.read(data, 0, 2048)) != -1) {
                             out.write(data, 0, count);
                         }
-
                         raw = out.toByteArray();
                         out.close();
-
                         return raw;
                     }
                 }
@@ -232,9 +223,7 @@
          * Replacing org.apache. -> org/apache/...
          */
         completeFileName = completeFileName.replace('.', '/').concat(".class");
-
         byte[] byteCodes = getBytes(completeFileName);
-
         if (byteCodes != null) {
             return byteCodes;
         } else {
@@ -255,20 +244,29 @@
         if (name == null) {
             return null;
         }
-
-        InputStream is = super.getResourceAsStream(name);
-
-        // ohh , input stream is null , so need to check whether thats there 
in lib/*.jar
-        if (is == null) {
-            byte data[] = getBytes(name);
-
-            if (data == null) {
-                return null;
+        if (parentFirst) {
+            InputStream is = super.getResourceAsStream(name);
+            // ohh , input stream is null , so need to check whether thats 
there in lib/*.jar
+            if (is == null) {
+                byte data[] = getBytes(name);
+                if (data == null) {
+                    return null;
+                } else {
+                    return new ByteArrayInputStream(data);
+                }
             } else {
-                return new ByteArrayInputStream(data);
+                return is;
             }
         } else {
-            return is;
+            byte data[] = getBytes(name);
+            if (data != null) {
+                return new ByteArrayInputStream(data);
+            }
+            return super.getResourceAsStream(name);
         }
+    }
+
+    public void setParentFirst(boolean parentFirst) {
+        this.parentFirst = parentFirst;
     }
 }

Modified: 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/ServiceBuilder.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/ServiceBuilder.java?rev=358205&r1=358204&r2=358205&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/ServiceBuilder.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/ServiceBuilder.java
 Tue Dec 20 20:43:43 2005
@@ -19,7 +19,6 @@
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.deployment.util.PhasesInfo;
-import org.apache.axis2.deployment.util.Utils;
 import org.apache.axis2.description.*;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.MessageReceiver;
@@ -123,13 +122,6 @@
                     Messages.getMessage(
                             DeploymentErrorMsgs.OPERATION_PROCESS_ERROR, 
axisFault.getMessage()));
         }
-
-        //todo this is not the right way pls improve this : Deepal
-        try {
-            Utils.fillAxisService(service);
-        } catch (Exception e) {
-            log.info("Error in generating scheam:" + e.getMessage());
-        }
         return service;
     }
 
@@ -223,21 +215,20 @@
 
             if (op_mep_att != null) {
                 mepurl = op_mep_att.getAttributeValue();
-                // todo value has to be validated
             }
 
             String opname = op_name_att.getAttributeValue();
             AxisOperation op_descrip;
-
-            if (mepurl == null) {
-
-                // assumed MEP is in-out
-                op_descrip = new InOutAxisOperation();
-            } else {
-                op_descrip = 
AxisOperationFactory.getOperationDescription(mepurl);
+            op_descrip = service.getOperation(new QName(opname));
+            if (op_descrip == null) {
+                if (mepurl == null) {
+                    // assumed MEP is in-out
+                    op_descrip = new InOutAxisOperation();
+                } else {
+                    op_descrip = 
AxisOperationFactory.getOperationDescription(mepurl);
+                }
+                op_descrip.setName(new QName(opname));
             }
-
-            op_descrip.setName(new QName(opname));
 
             // Operation Parameters
             Iterator parameters = operation.getChildrenWithName(new 
QName(TAG_PARAMETER));

Modified: 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/ServiceGroupBuilder.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/ServiceGroupBuilder.java?rev=358205&r1=358204&r2=358205&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/ServiceGroupBuilder.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/ServiceGroupBuilder.java
 Tue Dec 20 20:43:43 2005
@@ -18,6 +18,7 @@
 package org.apache.axis2.deployment;
 
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.deployment.util.Utils;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisServiceGroup;
 import org.apache.axis2.description.ModuleConfiguration;
@@ -81,6 +82,8 @@
 
                     if (axisService == null) {
                         axisService = new AxisService(serviceName);
+                    } else {
+                        axisService.setWsdlfound(true);
                     }
 
                     // the service that has to be deployed
@@ -89,7 +92,14 @@
 
                     ServiceBuilder serviceBuilder = new 
ServiceBuilder(axisConfig, axisService);
                     AxisService as = serviceBuilder.populateService(service);
-
+                    if (!as.isWsdlfound()) {
+                        //trying to generate WSDL for the service using JAM  
and Java refelection
+                        try {
+                            Utils.fillAxisService(as);
+                        } catch (Exception e) {
+                            log.info("Error in scheam generating :" + 
e.getMessage());
+                        }
+                    }
                     serviceList.add(as);
                 }
             }

Modified: 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveFileData.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveFileData.java?rev=358205&r1=358204&r2=358205&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveFileData.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveFileData.java
 Tue Dec 20 20:43:43 2005
@@ -109,13 +109,11 @@
 
             if (file != null) {
                 URL[] urlsToLoadFrom;
-
                 try {
                     if (!file.exists()) {
                         throw new 
AxisFault(Messages.getMessage(DeploymentErrorMsgs.FILE_NOT_FOUND,
                                 file.getAbsolutePath()));
                     }
-
                     urlsToLoadFrom = new URL[]{file.toURL()};
                     classLoader = new DeploymentClassLoader(urlsToLoadFrom, 
parent);
                 } catch (Exception e) {

Modified: 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java?rev=358205&r1=358204&r2=358205&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
 Tue Dec 20 20:43:43 2005
@@ -17,44 +17,23 @@
 
 package org.apache.axis2.deployment.repository.util;
 
-import org.apache.axis2.deployment.DeploymentConstants;
-import org.apache.axis2.deployment.DeploymentEngine;
-import org.apache.axis2.deployment.DeploymentErrorMsgs;
-import org.apache.axis2.deployment.DeploymentException;
-import org.apache.axis2.deployment.DescriptionBuilder;
-import org.apache.axis2.deployment.ModuleBuilder;
-import org.apache.axis2.deployment.ServiceBuilder;
-import org.apache.axis2.deployment.ServiceGroupBuilder;
-import org.apache.axis2.description.AxisDescWSDLComponentFactory;
+import org.apache.axis2.deployment.*;
+import org.apache.axis2.deployment.util.Utils;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisServiceGroup;
 import org.apache.axis2.description.ModuleDescription;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.om.OMElement;
-import org.apache.axis2.wsdl.WSDLVersionWrapper;
-import org.apache.axis2.wsdl.builder.WOMBuilder;
-import org.apache.axis2.wsdl.builder.WOMBuilderFactory;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.wsdl.WSDLDescription;
-import org.apache.wsdl.impl.WSDLServiceImpl;
 
 import javax.wsdl.WSDLException;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
@@ -79,10 +58,11 @@
             AxisService axisService = (AxisService) wsdlServices.get(
                     DescriptionBuilder.getShortFileName(
                             engine.getCurrentFileItem().getName()));
-
             if (axisService == null) {
                 axisService = new AxisService(
                         
DescriptionBuilder.getShortFileName(engine.getCurrentFileItem().getName()));
+            } else {
+                axisService.setWsdlfound(true);
             }
 
             axisService.setParent(axisServiceGroup);
@@ -93,8 +73,15 @@
 
             ArrayList serviceList = new ArrayList();
 
+            if (!axisService.isWsdlfound()) {
+                //trying to generate WSDL for the service using JAM  and Java 
refelection
+                try {
+                    Utils.fillAxisService(service);
+                } catch (Exception e) {
+                    log.info("Error in scheam generating :" + e.getMessage());
+                }
+            }
             serviceList.add(service);
-
             return serviceList;
         } else if (TAG_SERVICE_GROUP.equals(rootelementName)) {
             ServiceGroupBuilder groupBuilder = new 
ServiceGroupBuilder(services, wsdlServices,
@@ -196,7 +183,9 @@
      * @param engine
      */
     public ArrayList processServiceGroup(String filename, DeploymentEngine 
engine,
-                                         AxisServiceGroup axisServiceGroup, 
boolean extractService, HashMap wsdls,
+                                         AxisServiceGroup axisServiceGroup,
+                                         boolean extractService,
+                                         HashMap wsdls,
                                          AxisConfiguration axisConfig)
             throws DeploymentException {
 
@@ -248,34 +237,20 @@
         }
     }
 
+    /**
+     * Craeting AxisService using
+     *
+     * @param in
+     * @return
+     * @throws DeploymentException
+     */
     private AxisService processWSDLFile(InputStream in) throws 
DeploymentException {
         try {
-            WOMBuilder builder =
-                    
WOMBuilderFactory.getBuilder(org.apache.wsdl.WSDLConstants.WSDL_1_1);
-            WSDLVersionWrapper wsdlVersionWrapper = builder.build(in,
-                    new AxisDescWSDLComponentFactory());
-            WSDLDescription womDescription = 
wsdlVersionWrapper.getDescription();
-
-            Iterator iterator = 
womDescription.getServices().keySet().iterator();
-
-            if (iterator.hasNext()) {
-
-                // remove <wsdl:service> and <wsdl:binding> elements from the 
service
-                // description we read in as we will be replacing them anyway.
-                WSDLServiceImpl serviceimpl =
-                        (WSDLServiceImpl) 
womDescription.getServices().get(iterator.next());
-                AxisService service = new AxisService();
-
-                service.setName(serviceimpl.getName().getLocalPart());
-                service.setWSDLDefinition(wsdlVersionWrapper.getDefinition());
-
-                return service;
-            }
+            AxisServiceBuilder axisServiceBuilder = new AxisServiceBuilder();
+            return axisServiceBuilder.getAxisService(in);
         } catch (WSDLException e) {
             throw new DeploymentException(e);
         }
-
-        return null;
     }
 
     /**
@@ -339,7 +314,7 @@
                 while ((entry = zin.getNextEntry()) != null) {
                     String entryName = entry.getName().toLowerCase();
 
-                    if (entryName.startsWith(META_INF.toLowerCase()) 
+                    if (entryName.startsWith(META_INF.toLowerCase())
                             && entryName.endsWith(SUFFIX_WSDL)) {
                         out = new ByteArrayOutputStream();
 

Modified: 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java
URL: 
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java?rev=358205&r1=358204&r2=358205&view=diff
==============================================================================
--- 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java
 (original)
+++ 
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService.java
 Tue Dec 20 20:43:43 2005
@@ -72,6 +72,9 @@
     //to keep the XMLScheam getting either from WSDL or java2wsdl
     private XmlSchema schema;
 
+    //wsdl is there for this service or not (in side META-INF)
+    private boolean wsdlfound = false;
+
     /**
      * Constructor AxisService
      */
@@ -588,5 +591,13 @@
 
     public void setSchema(XmlSchema schema) {
         this.schema = schema;
+    }
+
+    public boolean isWsdlfound() {
+        return wsdlfound;
+    }
+
+    public void setWsdlfound(boolean wsdlfound) {
+        this.wsdlfound = wsdlfound;
     }
 }


Reply via email to