[Registry-dev] svn commit r17759 - in branches/registry/1_1/modules/extensions/src/org/wso2/registry: handlers handlers/utils servlet

deepal at wso2.com deepal at wso2.com
Mon Jun 2 01:58:30 PDT 2008


Author: deepal
Date: Mon Jun  2 01:58:29 2008
New Revision: 17759
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=17759

Log:
integrate WSDL validaor and WSI validator 

Removed:
   branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/utils/WSIValidatorUtil.java
Modified:
   branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/WSDLMediaTypeHandler.java
   branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/WSDLValidationHandler.java
   branches/registry/1_1/modules/extensions/src/org/wso2/registry/servlet/registry.xml

Modified: branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/WSDLMediaTypeHandler.java
URL: http://wso2.org/svn/browse/wso2/branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/WSDLMediaTypeHandler.java?rev=17759&r1=17758&r2=17759&view=diff
==============================================================================
--- branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/WSDLMediaTypeHandler.java	(original)
+++ branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/WSDLMediaTypeHandler.java	Mon Jun  2 01:58:29 2008
@@ -47,7 +47,7 @@
             requestContext.setActualPath(parentPath + RegistryConstants.PATH_SEPARATOR + savedName);
         }
 
-        requestContext.setProcessingComplete(true);
+//        requestContext.setProcessingComplete(true);
     }
 
     public void delete(RequestContext requestContext) throws RegistryException {

Modified: branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/WSDLValidationHandler.java
URL: http://wso2.org/svn/browse/wso2/branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/WSDLValidationHandler.java?rev=17759&r1=17758&r2=17759&view=diff
==============================================================================
--- branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/WSDLValidationHandler.java	(original)
+++ branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/WSDLValidationHandler.java	Mon Jun  2 01:58:29 2008
@@ -28,6 +28,7 @@
 import org.eclipse.wsdl.validate.wsdl11.internal.WSDLDocument;
 import org.w3c.dom.Document;
 import org.wso2.registry.Resource;
+import org.wso2.registry.handlers.utils.WSDLUtils;
 import org.wso2.registry.exceptions.RegistryException;
 import org.wso2.registry.jdbc.handlers.Handler;
 import org.wso2.registry.jdbc.handlers.RequestContext;
@@ -45,124 +46,16 @@
 import java.util.ResourceBundle;
 
 public class WSDLValidationHandler extends Handler {
-
-    private static final String WSDL_VALIDATION_MESSAGE = "org.wso2.wsdl.validationMessage";
-
-    private static final String WSDL_STATUS = "org.wso2.wsdl.validationStatus ";
-    private static final String WSDL_VALID = "WSDL is valid";
-    private static final String WSDL_INVALID = "WSDL is invalid ";
-
     public Resource get(RequestContext requestContext) throws RegistryException {
         return null;
     }
 
     public void put(RequestContext requestContext) throws RegistryException {
-        validateWSDL(requestContext);
-    }
-
-    private void validateWSDL(RequestContext requestContext) throws RegistryException {
-        Resource resource = requestContext.getResource();
-        Object resourceContent = resource.getContent();
-        try {
-            if (resourceContent instanceof byte[]) {
-
-                InputStream in = new ByteArrayInputStream((byte[])resourceContent);
-
-                File tempFile = File.createTempFile("reg", ".bin");
-                tempFile.deleteOnExit();
-
-                BufferedOutputStream   out = new BufferedOutputStream(new FileOutputStream(tempFile));
-                byte[] contentChunk = new byte[1024];
-                int byteCount;
-                while ((byteCount = in.read(contentChunk)) != -1) {
-                    out.write(contentChunk, 0, byteCount);
-                }
-                out.flush();
-
-                String uri = tempFile.toURI().toString();
-                validaWSDLFromURI(uri, resource);
-
-
-            }  else if(requestContext.getSourceURL() != null) {
-                validaWSDLFromURI(requestContext.getSourceURL(), resource);
-            }
-        } catch (Exception e) {
-            throw new RegistryException(e.getMessage());
-        }
-    }
-
-    private void validaWSDLFromURI(String uri, Resource resource) throws Exception
-    {
-        InputStream inputStream = new URL(uri).openStream();
-
-        ResourceBundle rb = ResourceBundle.getBundle("validatewsdl");
-        MessageGenerator messagegenerator = new MessageGenerator(rb);
-
-//                StandardParserConfiguration configuration = new StandardParserConfiguration();
-//                DOMParser builder = new LineNumberDOMParser(configuration);
-//                builder.parse(new InputSource(in));
-
-        DocumentBuilder db;
-        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-        dbf.setNamespaceAware(true);
-
-        try {
-            db = dbf.newDocumentBuilder();
-        } catch (Exception e) {
-            dbf = DocumentBuilderFactory.newInstance();
-            db = dbf.newDocumentBuilder();
-        }
-
-        Document doc = db.parse(inputStream);
-        WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
-        reader.setFeature("javax.wsdl.importDocuments", true);
-        Definition wsdlDefinition = reader.readWSDL(uri);
-        ValidationInfo validateInfo = new ValidationInfoImpl(uri, messagegenerator);
-
-        URIResolver uriResolver = new URIResolver();
-        ((ValidationInfoImpl)validateInfo).setURIResolver(uriResolver);
-        java.util.Hashtable attributes = new java.util.Hashtable();
-        ((ValidationInfoImpl)validateInfo).setAttributes(attributes);
-
-        WSDL11ValidationInfoImpl info = new WSDL11ValidationInfoImpl(validateInfo);
-        info.setElementLocations(new java.util.Hashtable());
-        WSDL11BasicValidator validator = new WSDL11BasicValidator();
-        validator.setResourceBundle(rb);
-        ValidationMessage[] messages;
-
-        WSDL11ValidatorController wsdl11ValidatorController =
-                new WSDL11ValidatorController();
-        WSDLDocument[] wsdlDocs = wsdl11ValidatorController.readWSDLDocument(doc,
-                validateInfo.getFileURI(),
-                messagegenerator,
-                info);
-        WSDLDocument document = wsdlDocs[0];
-        List schema = document.getSchemas();
-        Iterator xsdIter = schema.iterator();
-        while (xsdIter.hasNext()) {
-            info.addSchema((XSModel)xsdIter.next());
-        }
-        // Set the element locations table.
-        info.setElementLocations(document.getElementLocations());
-        validator.validate(wsdlDefinition, new ArrayList(), info);
-        messages = validateInfo.getValidationMessages();
-        if (messages.length > 0) {
-            resource.setProperty(WSDL_STATUS, WSDL_INVALID);
-        } else {
-            resource.setProperty(WSDL_STATUS, WSDL_VALID);
-        }
-        for (ValidationMessage message : messages) {
-            String messageString =
-                    "[" + message.getLine() + "][" + message.getColumn() + "]"
-                            + message.getMessage();
-            resource.addProperty(WSDL_VALIDATION_MESSAGE, messageString);
-        }
-        resource.setContentStream(null);
-        //adding the modififed resource back to the registry
+        WSDLUtils.validateWSDL(requestContext);
     }
 
     public void importResource(RequestContext requestContext) throws RegistryException {
-        validateWSDL(requestContext);
+        WSDLUtils.validateWSDL(requestContext);
     }
 
     public void delete(RequestContext requestContext) throws RegistryException {

Deleted: branches/registry/1_1/modules/extensions/src/org/wso2/registry/handlers/utils/WSIValidatorUtil.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=17758

Modified: branches/registry/1_1/modules/extensions/src/org/wso2/registry/servlet/registry.xml
URL: http://wso2.org/svn/browse/wso2/branches/registry/1_1/modules/extensions/src/org/wso2/registry/servlet/registry.xml?rev=17759&r1=17758&r2=17759&view=diff
==============================================================================
--- branches/registry/1_1/modules/extensions/src/org/wso2/registry/servlet/registry.xml	(original)
+++ branches/registry/1_1/modules/extensions/src/org/wso2/registry/servlet/registry.xml	Mon Jun  2 01:58:29 2008
@@ -77,6 +77,11 @@
         </filter>
     </handler>
 
+     <handler class="org.wso2.registry.handlers.WSIValidationHandler">
+        <filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
+            <property name="mediaType">application/wsdl+xml</property>
+        </filter>
+    </handler>
     <handler class="org.wso2.registry.handlers.XSDMediaTypeHandler">
         <filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
             <property name="mediaType">application/x-xsd+xml</property>



More information about the Registry-dev mailing list