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 aj...@apache.org on 2006/04/24 14:16:53 UTC
svn commit: r396529 - in
/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2:
deployment/repository/util/ArchiveReader.java deployment/resolver/
deployment/resolver/AARFileBasedURIResolver.java
description/WSDL2AxisServiceBuilder.java
Author: ajith
Date: Mon Apr 24 05:16:51 2006
New Revision: 396529
URL: http://svn.apache.org/viewcvs?rev=396529&view=rev
Log:
Adding support for zip file based xsd resolution
Still there is no test case to verify the functionality
Added:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/AARFileBasedURIResolver.java
Modified:
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/WSDL2AxisServiceBuilder.java
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=396529&r1=396528&r2=396529&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 Mon Apr 24 05:16:51 2006
@@ -20,6 +20,7 @@
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.deployment.*;
+import org.apache.axis2.deployment.resolver.AARFileBasedURIResolver;
import org.apache.axis2.description.AxisModule;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.AxisServiceGroup;
@@ -163,6 +164,9 @@
}
}
+ private AxisService processWSDLFile(InputStream in) throws DeploymentException {
+ return processWSDLFile(in,null);
+ }
/**
* Creats AxisService.
*
@@ -170,10 +174,15 @@
* @return Returns AxisService.
* @throws DeploymentException
*/
- private AxisService processWSDLFile(InputStream in) throws DeploymentException {
+ private AxisService processWSDLFile(InputStream in,File serviceArchiveFile) throws DeploymentException {
try {
WSDL2AxisServiceBuilder wsdl2AxisServiceBuilder =
new WSDL2AxisServiceBuilder(in, null, null);
+ if (serviceArchiveFile!=null){
+ wsdl2AxisServiceBuilder.setCustomResolver(
+ new AARFileBasedURIResolver(serviceArchiveFile));
+ }
+
return wsdl2AxisServiceBuilder.populateService();
} catch (AxisFault axisFault) {
throw new DeploymentException(axisFault);
@@ -243,7 +252,7 @@
}
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- AxisService service = processWSDLFile(in);
+ AxisService service = processWSDLFile(in,serviceFile);
servicesMap.put(service.getName(), service);
}
}
Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/AARFileBasedURIResolver.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/AARFileBasedURIResolver.java?rev=396529&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/AARFileBasedURIResolver.java (added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/AARFileBasedURIResolver.java Mon Apr 24 05:16:51 2006
@@ -0,0 +1,116 @@
+package org.apache.axis2.deployment.resolver;
+
+import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
+import org.apache.axis2.deployment.DeploymentConstants;
+import org.xml.sax.InputSource;
+
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipEntry;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+/**
+ * A custom URI resolver that can
+ */
+public class AARFileBasedURIResolver extends DefaultURIResolver{
+
+
+
+ private String aarFileName;
+ private File aarFile;
+
+ public AARFileBasedURIResolver(String aarFileName) {
+ this.aarFileName = aarFileName;
+ }
+
+ public AARFileBasedURIResolver(File aarFile) {
+ this.aarFile = aarFile;
+ }
+
+ public AARFileBasedURIResolver() {
+ }
+
+ public void setAarFileName(String aarFileName) {
+ this.aarFileName = aarFileName;
+ }
+
+ public void setAarFileName(File aarFile) {
+ this.aarFile = aarFile;
+ }
+ public InputSource resolveEntity(
+ String targetNamespace,
+ String schemaLocation,
+ String baseUri) {
+ //no issue with
+ if (isAbsolute(schemaLocation)){
+ return super.resolveEntity(
+ targetNamespace,schemaLocation,baseUri);
+ }else{
+ //validate
+ if (schemaLocation.startsWith("..")){
+ throw new RuntimeException(
+ "Unsupported schema location "+ schemaLocation);
+ }
+
+ ZipInputStream zin = null;
+ try {
+ if (aarFile!=null){
+ zin = new ZipInputStream(new FileInputStream(aarFile));
+ } else{
+ zin = new ZipInputStream(new FileInputStream(aarFileName));
+ }
+
+ ZipEntry entry;
+ byte[] buf = new byte[1024];
+ int read;
+ ByteArrayOutputStream out;
+ while ((entry = zin.getNextEntry()) != null) {
+ String entryName = entry.getName().toLowerCase();
+ if (entryName.startsWith(DeploymentConstants.META_INF.toLowerCase())
+ && entryName.endsWith(schemaLocation)) {
+ //read the item into a byte array to allow the
+ //stream to be closed
+ out = new ByteArrayOutputStream();
+ while ((read = zin.read(buf)) > 0) {
+ out.write(buf, 0, read);
+ }
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ return new InputSource(in);
+ }
+ }
+
+
+
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally{
+ try {
+ if (zin!=null) zin.close();
+ } catch (IOException e) {
+ //log this error
+ }
+ }
+
+ }
+
+ return null;
+ }
+}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/WSDL2AxisServiceBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/WSDL2AxisServiceBuilder.java?rev=396529&r1=396528&r2=396529&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/WSDL2AxisServiceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/WSDL2AxisServiceBuilder.java Mon Apr 24 05:16:51 2006
@@ -8,6 +8,8 @@
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.resolver.URIResolver;
+import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
import org.apache.ws.policy.Policy;
import org.apache.ws.policy.PolicyConstants;
import org.apache.ws.policy.PolicyReference;
@@ -17,6 +19,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
import javax.wsdl.*;
import javax.wsdl.extensions.ExtensibilityElement;
@@ -38,20 +41,20 @@
/*
* Copyright 2004,2005 The Apache Software Foundation.
- *
+ *
* 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.
- *
- *
+ *
+ *
*/
public class WSDL2AxisServiceBuilder {
@@ -130,6 +133,8 @@
private String style = null;
+ private URIResolver customResolver;
+
public WSDL2AxisServiceBuilder(InputStream in, QName serviceName,
String portName) {
this.in = in;
@@ -139,6 +144,7 @@
setPolicyRegistryFromService(axisService);
}
+
public WSDL2AxisServiceBuilder(Definition def, QName serviceName,
String portName) {
this.wsdl4jDefinition = def;
@@ -158,6 +164,11 @@
this(in, null, null);
}
+
+ public void setCustomResolver(URIResolver customResolver) {
+ this.customResolver = customResolver;
+ }
+
public boolean isServerSide() {
return isServerSide;
}
@@ -914,6 +925,11 @@
}
if (baseUri != null) schemaCollection.setBaseUri(baseUri);
+
+ if (customResolver!=null){
+ schemaCollection.setSchemaResolver(customResolver);
+ }
+
return schemaCollection.read(element);
}
@@ -1392,5 +1408,6 @@
}
}
}
+
}