[Registry-dev] svn commit r16727 - in trunk/registry/modules: core
core/src/main/java/org/wso2/registry/jdbc/handlers/builtin
core/src/main/java/org/wso2/registry/servlet
core/src/main/java/org/wso2/registry/utils webapps
svn at wso2.org
svn at wso2.org
Fri May 9 01:39:27 PDT 2008
Author: deepal
Date: Fri May 9 01:39:13 2008
New Revision: 16727
Log:
adding wsdl and schema validation handlers
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/WSDLValidationHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/XSDValidationHandler.java
Modified:
trunk/registry/modules/core/pom.xml
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml
trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/SchemaValidator.java
trunk/registry/modules/webapps/pom.xml
Modified: trunk/registry/modules/core/pom.xml
==============================================================================
--- trunk/registry/modules/core/pom.xml (original)
+++ trunk/registry/modules/core/pom.xml Fri May 9 01:39:13 2008
@@ -89,7 +89,7 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
- <scope>provided</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.abdera</groupId>
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/WSDLValidationHandler.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/WSDLValidationHandler.java Fri May 9 01:39:13 2008
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.registry.jdbc.handlers.builtin;
+
+import org.apache.xerces.parsers.DOMParser;
+import org.apache.xerces.parsers.StandardParserConfiguration;
+import org.apache.xerces.xs.XSModel;
+import org.eclipse.wsdl.validate.ValidationInfo;
+import org.eclipse.wsdl.validate.ValidationMessage;
+import org.eclipse.wsdl.validate.internal.ValidationInfoImpl;
+import org.eclipse.wsdl.validate.internal.resolver.URIResolver;
+import org.eclipse.wsdl.validate.internal.util.MessageGenerator;
+import org.eclipse.wsdl.validate.internal.xml.LineNumberDOMParser;
+import org.eclipse.wsdl.validate.wsdl11.internal.WSDL11BasicValidator;
+import org.eclipse.wsdl.validate.wsdl11.internal.WSDL11ValidationInfoImpl;
+import org.eclipse.wsdl.validate.wsdl11.internal.WSDL11ValidatorController;
+import org.eclipse.wsdl.validate.wsdl11.internal.WSDLDocument;
+import org.w3c.dom.Document;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
+import org.wso2.registry.jdbc.handlers.Handler;
+import org.wso2.registry.jdbc.handlers.RequestContext;
+import org.xml.sax.InputSource;
+
+import javax.wsdl.Definition;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ResourceBundle;
+
+public class WSDLValidationHandler extends Handler {
+
+ private static final String WSDL_VALIDATION_ERROR = "ValidationMessages";
+
+ 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();
+ if (resourceContent instanceof byte[]) {
+ try {
+ InputStream in = new ByteArrayInputStream((byte[]) resourceContent);
+ 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(in);
+ WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
+ reader.setFeature("javax.wsdl.importDocuments", true);
+ Definition wsdlDefinition = reader.readWSDL(getBaseURI(resource.getPath()), doc);
+ ValidationInfo validateInfo = new ValidationInfoImpl(resource.getPath(), 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());
+ System.out.println("=========================");
+ validator.validate(wsdlDefinition, new ArrayList(), info);
+ messages = validateInfo.getValidationMessages();
+ for (int i = 0; i < messages.length; i++) {
+ ValidationMessage message = messages[i];
+ String messageString = "[" + message.getLine() + "][" + message.getColumn() + "]"
+ + message.getMessage();
+ resource.addProperty(WSDL_VALIDATION_ERROR, messageString);
+ }
+ //adding the modififed resource back to the registry
+ requestContext.getRegistry().put(resource.getPath() , resource);
+ } catch (Exception e) {
+ new RegistryException(e.getMessage());
+ }
+ }
+ }
+
+ public void importResource(RequestContext requestContext) throws RegistryException {
+ validateWSDL(requestContext);
+ }
+
+ public void delete(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void putChild(RequestContext requestContext) throws RegistryException {
+
+ }
+
+ public void importChild(RequestContext requestContext) throws RegistryException {
+ }
+
+ private static String getBaseURI(String currentURI) {
+ try {
+ File file = new File(currentURI);
+ if (file.exists()) {
+ return file.getCanonicalFile().getParentFile().toURI()
+ .toString();
+ }
+ String uriFragment = currentURI.substring(0, currentURI
+ .lastIndexOf("/"));
+ return uriFragment + (uriFragment.endsWith("/") ? "" : "/");
+ } catch (IOException e) {
+ return null;
+ }
+ }
+}
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/XSDValidationHandler.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/XSDValidationHandler.java Fri May 9 01:39:13 2008
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.wso2.registry.jdbc.handlers.builtin;
+
+import org.wso2.registry.jdbc.handlers.Handler;
+import org.wso2.registry.jdbc.handlers.RequestContext;
+import org.wso2.registry.Resource;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.utils.SchemaValidator;
+
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+
+public class XSDValidationHandler extends Handler {
+
+ public Resource get(RequestContext requestContext) throws RegistryException {
+ return null;
+ }
+
+ public void put(RequestContext requestContext) throws RegistryException {
+ SchemaValidator validator = new SchemaValidator();
+ Resource resource = requestContext.getResource();
+ Object resourceContent = resource.getContent();
+ if (resourceContent instanceof byte[]) {
+ InputStream in = new ByteArrayInputStream((byte[]) resourceContent);
+ validator.validate(in, resource);
+ }
+ }
+
+ public void importResource(RequestContext requestContext) throws RegistryException {
+ SchemaValidator validator = new SchemaValidator();
+ Resource resource = requestContext.getResource();
+ Object resourceContent = resource.getContent();
+ if (resourceContent instanceof byte[]) {
+ InputStream in = new ByteArrayInputStream((byte[]) resourceContent);
+ validator.validate(in, resource);
+ }
+ }
+
+ public void delete(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void putChild(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void importChild(RequestContext requestContext) throws RegistryException {
+ }
+}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml Fri May 9 01:39:13 2008
@@ -55,6 +55,18 @@
</filter>
</handler>
+ <handler class="org.wso2.registry.jdbc.handlers.builtin.WSDLValidationHandler">
+ <filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
+ <property name="mediaType">application/x-xsd+xml</property>
+ </filter>
+ </handler>
+
+ <handler class="org.wso2.registry.jdbc.handlers.builtin.XSDValidationHandler">
+ <filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
+ <property name="mediaType">application/x-xsd+xml</property>
+ </filter>
+ </handler>
+
<aspect name="default" class="org.wso2.registry.aspects.DefaultLifecycle"/>
<!--<mediaTypeHandler>-->
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/SchemaValidator.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/SchemaValidator.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/SchemaValidator.java Fri May 9 01:39:13 2008
@@ -19,6 +19,7 @@
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
@@ -31,6 +32,7 @@
public class SchemaValidator {
private static final String XMLSCHEMA_XSD_LOCATION = "org/wso2/registry/utils/XMLSchema.xsd";
+ private static final String XSD_VALIDATION_ERROR = "ValidationMessages";
/**
* This will valide the given schema againts the w3c.XMLSchema.
@@ -38,7 +40,7 @@
* @param xsdContent : Input stream representing XSD content
* @throws RegistryException : If there is a problem in the XSD then that will throw as the exception
*/
- public void validate(InputStream xsdContent) throws RegistryException {
+ public void validate(InputStream xsdContent, Resource resource) throws RegistryException {
try {
XMLReader reader = XMLReaderFactory.createXMLReader();
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(XMLSCHEMA_XSD_LOCATION);
@@ -53,6 +55,7 @@
// validate the DOM tree
validator.validate(scoure);
} catch (Exception e) {
+ resource.addProperty(XSD_VALIDATION_ERROR, e.getMessage());
throw new RegistryException(e.getMessage());
}
}
Modified: trunk/registry/modules/webapps/pom.xml
==============================================================================
--- trunk/registry/modules/webapps/pom.xml (original)
+++ trunk/registry/modules/webapps/pom.xml Fri May 9 01:39:13 2008
@@ -121,8 +121,7 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
- <version>${servlet.api.version}</version>
- <scope>provided</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
@@ -145,7 +144,7 @@
</dependency>
<dependency>
<groupId>org.wso2.commons</groupId>
- <artifactId>authenticator</artifactId>
+ <artifactId>authenticator</artifactId>
</dependency>
More information about the Registry-dev
mailing list