[Registry-dev] svn commit r17773 - in
trunk/registry/modules/extensions/src/org/wso2/registry:
handlers handlers/utils servlet
deepal at wso2.com
deepal at wso2.com
Mon Jun 2 02:53:37 PDT 2008
Author: deepal
Date: Mon Jun 2 02:53:37 2008
New Revision: 17773
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=17773
Log:
integrate WSDL validaor and WSI validator
Added:
trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSIValidationHandler.java
trunk/registry/modules/extensions/src/org/wso2/registry/handlers/utils/WSDLUtils.java
Removed:
trunk/registry/modules/extensions/src/org/wso2/registry/handlers/utils/WSIValidatorUtil.java
Modified:
trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSDLMediaTypeHandler.java
trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSDLValidationHandler.java
trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml
Modified: trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSDLMediaTypeHandler.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSDLMediaTypeHandler.java?rev=17773&r1=17772&r2=17773&view=diff
==============================================================================
--- trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSDLMediaTypeHandler.java (original)
+++ trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSDLMediaTypeHandler.java Mon Jun 2 02:53:37 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: trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSDLValidationHandler.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSDLValidationHandler.java?rev=17773&r1=17772&r2=17773&view=diff
==============================================================================
--- trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSDLValidationHandler.java (original)
+++ trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSDLValidationHandler.java Mon Jun 2 02:53:37 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 {
Added: trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSIValidationHandler.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSIValidationHandler.java?pathrev=17773
==============================================================================
--- (empty file)
+++ trunk/registry/modules/extensions/src/org/wso2/registry/handlers/WSIValidationHandler.java Mon Jun 2 02:53:37 2008
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.handlers;
+
+import org.wso2.registry.jdbc.handlers.Handler;
+import org.wso2.registry.jdbc.handlers.RequestContext;
+import org.wso2.registry.Resource;
+import org.wso2.registry.handlers.utils.WSDLUtils;
+import org.wso2.registry.exceptions.RegistryException;
+
+public class WSIValidationHandler extends Handler {
+
+ public Resource get(RequestContext requestContext) throws RegistryException {
+ return null;
+ }
+
+ public void put(RequestContext requestContext) throws RegistryException {
+ WSDLUtils.validateWSI(requestContext);
+ }
+
+ public void importResource(RequestContext requestContext) throws RegistryException {
+ WSDLUtils.validateWSI(requestContext);
+ }
+
+ public void delete(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void putChild(RequestContext requestContext) throws RegistryException {
+ }
+
+ public void importChild(RequestContext requestContext) throws RegistryException {
+ }
+}
Added: trunk/registry/modules/extensions/src/org/wso2/registry/handlers/utils/WSDLUtils.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/src/org/wso2/registry/handlers/utils/WSDLUtils.java?pathrev=17773
==============================================================================
--- (empty file)
+++ trunk/registry/modules/extensions/src/org/wso2/registry/handlers/utils/WSDLUtils.java Mon Jun 2 02:53:37 2008
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.handlers.utils;
+
+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.eclipse.wsdl.validate.wsi.internal.bp10.WSIValidator;
+import org.w3c.dom.Document;
+import org.wso2.registry.Resource;
+import org.wso2.registry.exceptions.RegistryException;
+import org.wso2.registry.jdbc.handlers.RequestContext;
+
+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.*;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ResourceBundle;
+
+public class WSDLUtils {
+
+ private static final String WSDL_VALIDATION_MESSAGE = "org.wso2.wsdl.validationMessage";
+ private static final String WSI_VALIDATION_MESSAGE = "org.wso2.wsi.validationMessage";
+
+ private static final String WSDL_STATUS = "org.wso2.wsdl.validationStatus ";
+ private static final String WSI_STATUS = "org.wso2.wsi.validationStatus ";
+ private static final String WSDL_VALID = "WSDL is valid";
+ private static final String WSDL_VALID_I = "WSDL is valid for WSI";
+ private static final String WSDL_INVALID = "WSDL is invalid ";
+ private static final String WSDL_INVALID_I = "WSDL is invalid for WSI ";
+
+ public static String[] validateForWSI(String uri) throws RegistryException {
+ ArrayList<String> errorMesage = new ArrayList();
+ try {
+ WSIValidator validator = new WSIValidator();
+ ResourceBundle rb = ResourceBundle.getBundle("validatewsdl");
+ MessageGenerator messagegenerator = new MessageGenerator(rb);
+
+ ValidationInfo info = new ValidationInfoImpl(uri, messagegenerator);
+ URIResolver uriResolver = new URIResolver();
+ ((ValidationInfoImpl) info).setURIResolver(uriResolver);
+ StandardParserConfiguration configuration = new StandardParserConfiguration();
+ DOMParser builder = new LineNumberDOMParser(configuration);
+ builder.parse(uri);
+
+ 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(uri);
+ validator.validate(doc, info);
+ ValidationMessage messages[] = info.getValidationMessages();
+ for (int i = 0; i < messages.length; i++) {
+ ValidationMessage message = messages[i];
+ errorMesage.add(message.getMessage());
+ }
+ } catch (Exception e) {
+ throw new RegistryException(e.getMessage());
+ }
+ return errorMesage.toArray(new String[errorMesage.size()]);
+ }
+
+ public static void validateWSI(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();
+ validateWSI(uri, resource);
+
+
+ } else if (requestContext.getSourceURL() != null) {
+ validateWSI(requestContext.getSourceURL(), resource);
+ }
+ } catch (Exception e) {
+ throw new RegistryException(e.getMessage());
+ }
+ }
+
+ private static void validateWSI(String uri, Resource resource) throws Exception {
+ String message[] = validateForWSI(uri);
+ if (message.length > 0) {
+ resource.setProperty(WSI_STATUS, WSDL_INVALID_I);
+ } else {
+ resource.setProperty(WSI_STATUS, WSDL_VALID_I);
+ }
+ for (int i = 0; i < message.length; i++) {
+ resource.addProperty(WSI_VALIDATION_MESSAGE, message[i]);
+ }
+ }
+
+ public static 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());
+ }
+ resource.setContentStream(null);
+ }
+
+ private static void validaWSDLFromURI(String uri, Resource resource) throws Exception {
+ InputStream inputStream = null;
+ try {
+ inputStream = new URL(uri).openStream();
+
+ ResourceBundle rb = ResourceBundle.getBundle("validatewsdl");
+ MessageGenerator messagegenerator = new MessageGenerator(rb);
+ 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);
+ }
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ }
+ }
+}
Deleted: trunk/registry/modules/extensions/src/org/wso2/registry/handlers/utils/WSIValidatorUtil.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=17772
Modified: trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml?rev=17773&r1=17772&r2=17773&view=diff
==============================================================================
--- trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml (original)
+++ trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml Mon Jun 2 02:53:37 2008
@@ -70,13 +70,18 @@
<property name="mediaType">application/x-xsd+xml</property>
</filter>
</handler>
-
+
<handler class="org.wso2.registry.handlers.WSDLMediaTypeHandler">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/wsdl+xml</property>
</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>
@@ -84,4 +89,4 @@
</handler>
<aspect name="Lifecycle" class="org.wso2.registry.aspects.Lifecycle"/>
-</wso2regsitry>
+</wso2regsitry>
\ No newline at end of file
More information about the Registry-dev
mailing list