[jboss-svn-commits] JBL Code SVN: r33329 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/soa/esb/listeners/deployers/mc and 14 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jun 3 08:18:36 EDT 2010
Author: beve
Date: 2010-06-03 08:18:34 -0400 (Thu, 03 Jun 2010)
New Revision: 33329
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/JarUtil.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/JarUtilUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/jar-util-test.jar
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/schemasDir/schema.jar
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/schemasExploded.esb/lib/
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/schemasExploded.esb/lib/schema.jar
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/test_esb_archives/exploded-esb-archive-subdeployment.esb/jars/
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/test_esb_archives/exploded-esb-archive-subdeployment.esb/jars/schema.jar
labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/lib/schemas.jar
Removed:
labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/fault.xsd
labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/request.xsd
labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/response.xsd
labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/types/
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/deployers/mc/EsbWsdlDeployer.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/deployers/mc/util/VfsUtil.java
labs/jbossesb/trunk/product/rosetta/tests/build.xml
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployerUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/schemasDir.esb
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/EsbWsdlDeployerUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/util/VfsUtilUnitTest.java
labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/build.xml
labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/readme.txt
Log:
Work for https://jira.jboss.org/browse/JBESB-3281 "EBWS: Add support for schemas that exist in jar inside of .esb archives"
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java 2010-06-03 12:18:34 UTC (rev 33329)
@@ -21,7 +21,9 @@
*/
package org.jboss.soa.esb.listeners.config;
+import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -29,7 +31,6 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -38,9 +39,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
-import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
import javax.management.JMException;
import javax.management.MalformedObjectNameException;
@@ -56,7 +55,6 @@
import org.jboss.internal.soa.esb.listeners.war.WebModel;
import org.jboss.internal.soa.esb.publish.ContractReferencePublisher;
import org.jboss.internal.soa.esb.util.JBossDeployerUtil;
-import org.jboss.internal.soa.esb.util.StreamUtils;
import org.jboss.internal.soa.esb.webservice.ESBContractGenerator;
import org.jboss.internal.soa.esb.webservice.ESBResponseFilter;
import org.jboss.internal.soa.esb.webservice.ESBServiceContractReferencePublisher;
@@ -74,6 +72,7 @@
import org.jboss.soa.esb.listeners.config.model.ModelAdapter;
import org.jboss.soa.esb.util.DeploymentArchive;
import org.jboss.soa.esb.util.FileUtil;
+import org.jboss.soa.esb.util.JarUtil;
import org.jboss.system.ServiceControllerMBean;
import org.jboss.web.AbstractWebContainer;
import org.w3c.dom.Element;
@@ -427,8 +426,8 @@
}
}
}
-
- private void createWebserviceWars(final DeploymentInfo di, final ModelAdapter model, final String deploymentName,
+
+ private void createWebserviceWars(final DeploymentInfo di, final ModelAdapter model, final String deploymentName,
final List<ContractReferencePublisher> publishers, WebDeploymentArchive webDeployment)
throws DeploymentException
{
@@ -451,12 +450,12 @@
final String wsdlDir = "WEB-INF/wsdl/" + service.getCategory().replace('/', '_') + "/";
for (Entry<String, String> schemaEntry : schemasMap.entrySet())
{
- webDeployment.addEntry(wsdlDir + schemaEntry.getKey(), schemaEntry.getValue().getBytes("UTF-8"));
+ webDeployment.addEntry(wsdlDir + schemaEntry.getKey(), schemaEntry.getValue().getBytes());
log.debug("Added schema " + wsdlDir + schemaEntry.getKey());
}
final ESBServiceEndpointInfo serviceInfo = new ESBServiceEndpointInfo(webserviceInfo) ;
- final String wsdl = ESBContractGenerator.generateWSDL(webserviceInfo, serviceInfo, di.localCl) ;
+ final String wsdl = ESBContractGenerator.generateWSDL(webserviceInfo, serviceInfo, new WebDeploymentClassLoader(di.localCl, schemasMap)) ;
webDeployment.addEntry(serviceInfo.getWSDLFileName(), wsdl.getBytes("UTF-8"));
final String handlers = JBossDeployerUtil.getHandlers(serviceInfo) ;
@@ -756,6 +755,11 @@
throw new DeploymentException("IOException while trying to read xsd '" + file.getName() + "'", e);
}
}
+ else if (file.getName().endsWith(".jar"))
+ {
+ Map<String, String> schemasFromArchive = getSchemasFromArchive(file);
+ schemasMap.putAll(schemasFromArchive);
+ }
}
}
return schemasMap;
@@ -781,57 +785,71 @@
{
return fileName.endsWith(".xsd");
}
-
+
static Map<String, String> getSchemasFromArchive(final File archive) throws DeploymentException
{
- if (archive == null || !archive.isFile() || !archive.getName().endsWith(".esb"))
+ if (archive == null)
{
return Collections.emptyMap();
}
- final HashMap<String, String> schemas = new HashMap<String, String>();
- final ZipFile zip = getZipFile(archive);
-
- final Enumeration<? extends ZipEntry> entries = zip.entries();
- while (entries.hasMoreElements())
+ ZipInputStream zipInputStream = null;
+ try
{
- ZipEntry entry = entries.nextElement();
-
- final String fileName = entry.getName();
- if (isXsd(fileName))
- {
- InputStream in = null;
- try
- {
- in = zip.getInputStream(entry);
- schemas.put(fileName, StreamUtils.readStreamString(in, "UTF-8"));
- }
- catch (final IOException e)
- {
- throw new DeploymentException("IOException while trying to read from file '" + fileName + "' from archive '" + archive + "'", e);
- }
- finally
- {
- try { in.close(); } catch (IOException ignore) { log.error("Error while trying to close in stream for file '" + fileName + "'", ignore); }
- }
- }
+ zipInputStream = new ZipInputStream(new FileInputStream(archive));
+ return JarUtil.extractStringContents(".xsd", zipInputStream);
}
- return schemas;
- }
-
- private static ZipFile getZipFile(final File archive) throws DeploymentException
- {
- try
+ catch (FileNotFoundException e)
{
- return new ZipFile(archive);
- }
- catch (ZipException e)
- {
throw new DeploymentException(e.getMessage(), e);
- }
+ }
catch (IOException e)
{
throw new DeploymentException(e.getMessage(), e);
}
+ finally
+ {
+ closeStream(zipInputStream);
+ }
}
+
+ private static void closeStream (InputStream in)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (final IOException e)
+ {
+ log.warn(e.getMessage(), e);
+ }
+
+ }
+
+ private class WebDeploymentClassLoader extends ClassLoader
+ {
+
+ private Map<String, String> schemas;
+
+ WebDeploymentClassLoader(final ClassLoader parent, final Map<String, String> schemas)
+ {
+ super(parent);
+ this.schemas = schemas;
+ }
+
+ @Override
+ public InputStream getResourceAsStream (final String name)
+ {
+ if (schemas != null)
+ {
+ String schema = schemas.get(name);
+ if (schema != null)
+ return new ByteArrayInputStream(schema.getBytes());
+ }
+
+ return super.getResourceAsStream(name);
+ }
+
+ }
+
}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/deployers/mc/EsbWsdlDeployer.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/deployers/mc/EsbWsdlDeployer.java 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/deployers/mc/EsbWsdlDeployer.java 2010-06-03 12:18:34 UTC (rev 33329)
@@ -25,7 +25,9 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.log4j.Logger;
import org.jboss.deployers.spi.DeploymentException;
@@ -58,6 +60,8 @@
*/
public class EsbWsdlDeployer extends AbstractSimpleVFSRealDeployer<EsbMetaData>
{
+ public static final String WSDL_DIR = "WEB-INF/wsdl/";
+
private Logger log = Logger.getLogger(EsbWsdlDeployer.class);
/**
@@ -126,18 +130,22 @@
{
for (WebserviceInfo wsInfo : webServices)
{
+ final ESBServiceEndpointInfo serviceInfo = new ESBServiceEndpointInfo(wsInfo);
+
// Generate the wsdl for the web service.
- final ESBServiceEndpointInfo serviceInfo = new ESBServiceEndpointInfo(wsInfo);
+ final URL wsdlUrl = VfsUtil.createInMemUrl(inMemRootUrl, serviceInfo.getWSDLFileName());
+ VirtualFile wsdlFile = VfsUtil.addFile(inMemRootUrl, serviceInfo.getWSDLFileName(), "".getBytes());
+
+ // Add any schemas in the deployment unit to the in-memory vfs.
+ List<VirtualFile> schemas = getSchemas(unit.getRoot());
+ addSchemasToVfs(schemas, wsdlFile.getParent(), esbMetaData.getArchiveName());
+
final String wsdl = ESBContractGenerator.generateWSDL(wsInfo, serviceInfo, unit.getClassLoader());
- final URL wsdlUrl = VfsUtil.createInMemUrl(inMemRootUrl, serviceInfo.getWSDLFileName());
log.info("Generating wsdl url : " + wsdlUrl);
// Add the wsdl in the virtual file system
- VirtualFile wsdlFile = VfsUtil.addFile(inMemRootUrl, serviceInfo.getWSDLFileName(), wsdl.getBytes());
+ VfsUtil.addFile(inMemRootUrl, serviceInfo.getWSDLFileName(), wsdl.getBytes());
wsdls.add(wsdlUrl);
-
- // Add any additional schemas in the deployment unit to the in-memory vfs.
- addSchemasToVfs(getSchemas(unit.getRoot()), wsdlFile.getParent(), esbMetaData.getArchiveName());
}
// Add the root of the virtual file system as a meta data location.
@@ -165,7 +173,7 @@
{
return root.getChildrenRecursively(schemaFileFilter);
}
-
+
/**
* Will add all the schemas to the virtual file system specified by toVfs.
* <p/>
@@ -185,9 +193,21 @@
*/
void addSchemasToVfs(final List<VirtualFile> schemas, VirtualFile toVfs, String archiveName) throws MalformedURLException, IOException, URISyntaxException
{
- VfsUtil.addFiles(schemas, toVfs.toURL(), archiveName, "WEB-INF/wsdl/" + toVfs.getName());
+ Map<VirtualFile, String> schemaJars = getSchmeaJarPaths(schemas, toVfs);
+ if (schemaJars.size() > 0)
+ {
+ log.info("Adding schemas from jars: " + schemaJars.values());
+ VfsUtil.addFiles(schemaJars, toVfs.toURL(), WSDL_DIR + toVfs.getName());
+ // The schemas in jars will have a path containing the '.jar' suffix in it.
+ // The above addFiles method will remove the 'suffix' and we don't want the
+ // incorrect paths to be added.
+ schemas.removeAll(schemaJars.keySet());
+ }
+
+ log.info("Adding schemas: " + schemas);
+ VfsUtil.addFiles(schemas, toVfs.toURL(), archiveName, WSDL_DIR + toVfs.getName());
}
-
+
/**
* Undeploy will inspect the deployment unit to see if the deploy method attached a
* {@link VirtualFile} representing an in-memory file system. If one exists it will
@@ -244,4 +264,37 @@
return file.getName().endsWith(".xsd");
}
}
+
+ /**
+ * Returns a map of the original {@link VirtualFile} to the schemas and a new path
+ * to the schema.
+ * </p>
+ * The Microcontainer is able to recursively find all files in nested archives, for
+ * example all '.xsd' files. If the schema in question is in a nested jar then the
+ * name of the jar will be included in the VFS path name. This is not desired in our
+ * case and this method will remove the jar name from the path.
+ *
+ * @param schemas The schema from which jar paths should be extracted.
+ *
+ * @return Map containing the orginal paths as keys and a pruned paths as
+ * its value.
+ *
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ public Map<VirtualFile, String> getSchmeaJarPaths (final List<VirtualFile> schemas, final VirtualFile toVfs) throws IOException, URISyntaxException
+ {
+ final Map<VirtualFile, String> schemaJarPaths = new HashMap<VirtualFile, String>();
+ for (VirtualFile virtualFile : schemas)
+ {
+ final String pathName = virtualFile.getPathName();
+ final int indexOf = pathName.indexOf(".jar");
+ if (indexOf != -1)
+ {
+ schemaJarPaths.put(virtualFile, pathName.substring(indexOf+4));
+ }
+ }
+ return schemaJarPaths;
+ }
+
}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/deployers/mc/util/VfsUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/deployers/mc/util/VfsUtil.java 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/deployers/mc/util/VfsUtil.java 2010-06-03 12:18:34 UTC (rev 33329)
@@ -26,6 +26,9 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
import org.jboss.internal.soa.esb.util.StreamUtils;
import org.jboss.virtual.MemoryFileFactory;
@@ -106,20 +109,37 @@
{
for (final VirtualFile file : files)
{
- InputStream in = null;
- try
- {
- in = file.openStream();
- final URL newUrl = createInMemUrl(destUrl.getHost(), subpath(file.getPathName(), subPath, pathPrefix));
- MemoryFileFactory.putFile(newUrl, StreamUtils.readStream(in));
- }
- finally
- {
- in.close();
- }
+ String path = subpath(file.getPathName(), subPath, pathPrefix);
+ addFile(file, destUrl, path);
}
}
+ public static void addFiles(final Map<VirtualFile, String> filesToNamesMap, final URL destUrl, final String pathPrefix) throws IOException, URISyntaxException
+ {
+ Set<Entry<VirtualFile, String>> entrySet = filesToNamesMap.entrySet();
+ for (Entry<VirtualFile, String> entry : entrySet)
+ {
+ VirtualFile file = entry.getKey();
+ String path = entry.getValue();
+ addFile(file, destUrl, pathPrefix + path);
+ }
+ }
+
+ private static void addFile(final VirtualFile file, final URL destUrl, final String path) throws IOException
+ {
+ InputStream in = null;
+ try
+ {
+ in = file.openStream();
+ final URL newUrl = createInMemUrl(destUrl.getHost(), path);
+ MemoryFileFactory.putFile(newUrl, StreamUtils.readStream(in));
+ }
+ finally
+ {
+ in.close();
+ }
+ }
+
static String subpath(final String path, final String pathName, final String pathPrefix)
{
if (path == null || pathName == null)
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/JarUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/JarUtil.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/JarUtil.java 2010-06-03 12:18:34 UTC (rev 33329)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2009, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.internal.soa.esb.util.StreamUtils;
+
+/**
+ * Util class for dealing with zip archives.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class JarUtil
+{
+ private JarUtil()
+ {
+ }
+
+ /**
+ * Extracts all the files ending with the fileSuffix and adds the file name as the key in
+ * the returned map. The contents of the file is the value of the map entry.
+ * </p>
+ *
+ * @param fileSuffix the suffix of files that should be returned.
+ * @param charSet the character set that files should be read with.
+ * @param inStream the ZipInputStream that is to be processed.
+ * @return Map<String, String> A Map containg the file name as its key and the file contents as its value.
+ * @throws IOException
+ */
+ public static Map<String, String> extractStringContents(final String fileSuffix, final String charSet, final ZipInputStream inStream) throws IOException
+ {
+ AssertArgument.isNotNullAndNotEmpty(fileSuffix, "fileSuffix");
+ AssertArgument.isNotNullAndNotEmpty(charSet, "charSet");
+ AssertArgument.isNotNull(inStream, "inStream");
+
+ final Map<String, String> filesMap = new HashMap<String, String>();
+ ZipEntry entry = null;
+ while ((entry = inStream.getNextEntry()) != null)
+ {
+ final String entryName = entry.getName();
+ if (entryName.endsWith(fileSuffix))
+ {
+ filesMap.put(entryName, StreamUtils.readStreamString(inStream, charSet));
+ }
+ else if (isJar(entryName))
+ {
+ final ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ byte[] byteReadBuffer = new byte[512];
+ int byteReadCount;
+
+ while((byteReadCount = inStream.read(byteReadBuffer)) != -1)
+ {
+ bout.write(byteReadBuffer, 0, byteReadCount);
+ }
+ final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bout.toByteArray());
+ final ZipInputStream zipInputStream = new ZipInputStream(byteArrayInputStream);
+ final Map<String, String> schemasFromNestedZip = extractStringContents(fileSuffix, zipInputStream);
+ filesMap.putAll(schemasFromNestedZip);
+ }
+ }
+ return filesMap;
+ }
+
+ /**
+ * Extracts all the files ending with the fileSuffix and adds the file name as the key in
+ * the returned map. The contents of the file is the value of the map entry.
+ * </p>
+ * Calling this method is equivalent to calling:
+ * extractStringContents(suffix, Charset.defaultCharset().name(), inStream).
+ *
+ * @param fileSuffix the suffix of files that should be returned.
+ * @param inStream the ZipInputStream that is to be processed.
+ * @return Map<String, String> A Map containg the file name as its key and the file contents as its value.
+ * @throws IOException
+ */
+ public static Map<String, String> extractStringContents(final String fileSuffix, final ZipInputStream inStream) throws IOException
+ {
+ return extractStringContents(fileSuffix, Charset.defaultCharset().name(), inStream);
+ }
+
+ private static boolean isJar(final String fileName)
+ {
+ return fileName.endsWith(".jar");
+ }
+
+}
Modified: labs/jbossesb/trunk/product/rosetta/tests/build.xml
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/build.xml 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/rosetta/tests/build.xml 2010-06-03 12:18:34 UTC (rev 33329)
@@ -125,6 +125,7 @@
<fileset dir="${org.jboss.esb.module.tests.src.dir}" includes="**/*.xml" />
<fileset dir="${org.jboss.esb.module.tests.src.dir}" includes="**/*.war" />
<fileset dir="${org.jboss.esb.module.tests.src.dir}" includes="**/*.xsd" />
+ <fileset dir="${org.jboss.esb.module.tests.src.dir}" includes="**/*.jar" />
<fileset dir="${org.jboss.esb.module.tests.src.dir}" includes="**/*.xslt" />
<fileset dir="${org.jboss.esb.module.tests.src.dir}" includes="**/*.properties" />
</copy>
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/JarUtilUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/JarUtilUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/JarUtilUnitTest.java 2010-06-03 12:18:34 UTC (rev 33329)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2009, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.zip.ZipInputStream;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.soa.esb.util.JarUtil;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link JarUtil}
+ * </p>
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ */
+public class JarUtilUnitTest
+{
+ @Test
+ public void test() throws IOException
+ {
+ ZipInputStream zipInputStream = new ZipInputStream(getClass().getResourceAsStream("jar-util-test.jar"));
+ Map<String, String> filesMap = JarUtil.extractStringContents(".txt", zipInputStream);
+ assertEquals(2, filesMap.size());
+ assertEquals("Some text in textfile 1.", filesMap.get("testfile1.txt").trim());
+ assertEquals("Some text in textfile 2.", filesMap.get("subdir/testfile2.txt").trim());
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(JarUtilUnitTest.class);
+ }
+
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/jar-util-test.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/jar-util-test.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployerUnitTest.java 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployerUnitTest.java 2010-06-03 12:18:34 UTC (rev 33329)
@@ -25,6 +25,7 @@
import java.io.File;
import java.net.URL;
import java.util.Map;
+import java.util.zip.ZipInputStream;
import junit.framework.JUnit4TestAdapter;
@@ -60,7 +61,7 @@
URL resource = getClass().getResource("schemasDir.esb");
File archive = new File(resource.getFile());
Map<String, String> schemas = JBoss4ESBDeployer.getSchemasFromArchive(archive);
- assertTrue(schemas.containsKey("mock.xsd"));
+ assertAddedSchemas(schemas);
}
@Test
@@ -84,6 +85,8 @@
assertTrue(schemas.containsKey("mock.xsd"));
assertTrue(schemas.containsKey("subdir" + File.separator + "type.xsd"));
assertTrue(schemas.containsKey("subdir" + File.separator + "subdir2" + File.separator + "type.xsd"));
+ assertTrue(schemas.containsKey("jarsubdir" + File.separator + "jarsubdir.xsd"));
+ assertTrue(schemas.containsKey("mockFromjar.xsd"));
}
public static junit.framework.Test suite()
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/schemasDir/schema.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/schemasDir/schema.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/schemasDir.esb
===================================================================
(Binary files differ)
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/schemasExploded.esb/lib/schema.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/schemasExploded.esb/lib/schema.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/EsbWsdlDeployerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/EsbWsdlDeployerUnitTest.java 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/EsbWsdlDeployerUnitTest.java 2010-06-03 12:18:34 UTC (rev 33329)
@@ -25,6 +25,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
+import java.util.Map;
import org.jboss.deployers.plugins.main.MainDeployerImpl;
import org.jboss.deployers.spi.DeploymentException;
@@ -65,48 +66,61 @@
mainDeployer.deploy(deployment);
}
- public void _testGetAllSchemas() throws Throwable
+ public void testGetAllSchemas() throws Throwable
{
final VirtualFile virtualFile = VFS.getVirtualFile(dir, "exploded-esb-archive.esb");
final EsbWsdlDeployer esbWsdlDeployer = new EsbWsdlDeployer();
final List<VirtualFile> schemas = esbWsdlDeployer.getSchemas(virtualFile);
assertNotNull(schemas);
- assertEquals(2, schemas.size());
+ assertEquals(1, schemas.size());
}
- public void _testAddSchemasToVFS() throws IOException, URISyntaxException
+ public void testAddSchemasToVFS() throws IOException, URISyntaxException
{
- final String archiveName = "exploded-esb-archive.esb";
- final VirtualFile virtualFile = VFS.getVirtualFile(dir, archiveName);
- final EsbWsdlDeployer esbWsdlDeployer = new EsbWsdlDeployer();
- final List<VirtualFile> schemas = esbWsdlDeployer.getSchemas(virtualFile);
-
- final URL dynamicClassRootUrl = new URL("vfsmemory", "junit", "");
- final VirtualFile dynamicClasspathDir = MemoryFileFactory.createRoot(dynamicClassRootUrl).getRoot();
- final URL wsdlUrl = new URL(dynamicClassRootUrl + "/somefile");
- VirtualFile putFile = MemoryFileFactory.putFile(wsdlUrl, "dummy".getBytes());
-
- esbWsdlDeployer.addSchemasToVfs(schemas, putFile.getParent(), archiveName);
-
- final List<VirtualFile> addedSchemas = esbWsdlDeployer.getSchemas(dynamicClasspathDir);
+ final List<VirtualFile> addedSchemas = getSchemasFromExplodedEsbArchive();
assertNotNull(addedSchemas);
- assertEquals(2, addedSchemas.size());
-
- for (final VirtualFile schemaFile : addedSchemas)
+ assertEquals(3, addedSchemas.size());
+ assertSchemaPaths(addedSchemas);
+ }
+
+ private void assertSchemaPaths(final List<VirtualFile> schemaPaths) throws MalformedURLException, URISyntaxException
+ {
+ for (final VirtualFile schemaFile : schemaPaths)
{
final String fileName = schemaFile.getName();
if (fileName.equals("request.xsd"))
{
assertEquals("vfsmemory://junit/WEB-INF/wsdl/request.xsd", schemaFile.toURL().toString());
}
- else
+ if (fileName.equals("custom-request-type.xsd"))
{
assertEquals("vfsmemory://junit/WEB-INF/wsdl/types/custom-request-type.xsd", schemaFile.toURL().toString());
}
+ if (fileName.equals("jarsubdir.xsd"))
+ {
+ assertEquals("vfsmemory://junit/WEB-INF/wsdl/jarsubdir/jarsubdir.xsd", schemaFile.toURL().toString());
+ }
}
}
+ private List<VirtualFile> getSchemasFromExplodedEsbArchive() throws IOException, URISyntaxException
+ {
+ final String archiveName = "exploded-esb-archive-subdeployment.esb";
+ final VirtualFile virtualFile = VFS.getVirtualFile(dir, archiveName);
+ final EsbWsdlDeployer esbWsdlDeployer = new EsbWsdlDeployer();
+ final List<VirtualFile> schemas = esbWsdlDeployer.getSchemas(virtualFile);
+
+ final URL dynamicClassRootUrl = new URL("vfsmemory", "junit", "");
+ final VirtualFile dynamicClasspathDir = MemoryFileFactory.createRoot(dynamicClassRootUrl).getRoot();
+ final URL wsdlUrl = new URL(dynamicClassRootUrl + "/somefile");
+ VirtualFile putFile = MemoryFileFactory.putFile(wsdlUrl, "dummy".getBytes());
+
+ esbWsdlDeployer.addSchemasToVfs(schemas, putFile.getParent(), archiveName);
+
+ return esbWsdlDeployer.getSchemas(dynamicClasspathDir);
+ }
+
public void testUndeployCleanup() throws DeploymentException, MalformedURLException, IOException
{
final String wsdl = "WEB-INF/wsdl/FirstServiceESB/SimpleListener.wsdl";
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/test_esb_archives/exploded-esb-archive-subdeployment.esb/jars/schema.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/test_esb_archives/exploded-esb-archive-subdeployment.esb/jars/schema.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/util/VfsUtilUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/util/VfsUtilUnitTest.java 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/util/VfsUtilUnitTest.java 2010-06-03 12:18:34 UTC (rev 33329)
@@ -29,6 +29,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import org.jboss.virtual.VFS;
@@ -127,8 +128,29 @@
assertNotNull(destDir.getChild("WEB-INF/wsdl/types/test.xsd"));
assertNotNull(destDir.getChild("WEB-INF/wsdl/types/test2.xsd"));
}
-
+
@Test
+ public void addSchemas() throws IOException, URISyntaxException
+ {
+ URL sourceUrl = VfsUtil.createInMemUrl("vsftest");
+ VirtualFile file1 = VfsUtil.addFile(sourceUrl, "/rootPath/schema.jar/types/test.xsd", "dummy".getBytes());
+ VirtualFile file2 = VfsUtil.addFile(sourceUrl, "/rootPath/schema.jar/types/test2.xsd", "dummy".getBytes());
+ HashMap<VirtualFile, String> map = new HashMap<VirtualFile, String>();
+
+ // specify that file1 should be given a different path
+ map.put(file1, "newpath/test1.xsd");
+ // specify that file2 should be given a different path
+ map.put(file2, "newpath/test2.xsd");
+
+ URL destUrl = VfsUtil.createInMemUrl("vsftest3");
+ VirtualFile destDir = VfsUtil.createInMemoryFs(destUrl);
+ VfsUtil.addFiles(map, destUrl, "WEB-INF/wsdl/" + destDir.getName());
+
+ assertNotNull(destDir.getChild("WEB-INF/wsdl/newpath/test1.xsd"));
+ assertNotNull(destDir.getChild("WEB-INF/wsdl/newpath/test2.xsd"));
+ }
+
+ @Test
public void addFilesInFromFileFs() throws IOException, URISyntaxException
{
File workDir = null;
Modified: labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/build.xml 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/build.xml 2010-06-03 12:18:34 UTC (rev 33329)
@@ -4,12 +4,25 @@
${ant.project.name}
${line.separator}
</description>
-
+
<!-- additional deploys -->
- <property name="additional.deploys" value="*.xsd types/**/*.xsd"/>
+ <property name="additional.deploys" value="lib/schemas.jar"/>
+ <target name="package-deployment" description="Quickstart specific target that does not put the jars in lib into the root of the .esb archive">
+ <mkdir dir="lib"/>
+ <jar destfile="${build.dir}/${ant.project.name}.esb">
+ <fileset dir="${build.dir}/classes" excludes="${quickstart.classes.excludes}" includes="${quickstart.classes.includes}"/>
+ <fileset dir="${build.dir}" includes="*.jar,*.war"/>
+ <fileset dir="${build.dir}" includes="deployment.xml"/>
+ <fileset dir="${build.dir}" includes="META-INF/**" />
+ <fileset dir="${basedir}/src" excludes="**/*.java" /> <!-- Please leave the src dir in here! -->
+ <fileset dir="${basedir}" includes="${jms.service.file} ${additional.deploys}" excludes="build/**" />
+ </jar>
+ </target>
+
<!-- Import the base Ant build script... -->
<import file="../conf/base-build.xml"/>
+
<target name="runtest" depends="compile" description="sends soap message to published web service">
<echo>Send soap message to published web service and receive reponse</echo>
<java fork="yes" classname="org.jboss.soa.esb.samples.quickstart.publishAsWebservice.test.SOAPTest" failonerror="true">
Deleted: labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/fault.xsd
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/fault.xsd 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/fault.xsd 2010-06-03 12:18:34 UTC (rev 33329)
@@ -1,9 +0,0 @@
-<xs:schema version="1.0" targetNamespace="http://www.jboss.org/sayHi" xmlns:x1="http://www.jboss.org/sayHi" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
- <xs:element name="sayFault" type="x1:fault"/>
- <xs:complexType name="fault">
- <xs:sequence>
- <xs:element name="code" type="xs:string"/>
- <xs:element name="faultString" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
-</xs:schema>
\ No newline at end of file
Added: labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/lib/schemas.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/lib/schemas.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/readme.txt 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/readme.txt 2010-06-03 12:18:34 UTC (rev 33329)
@@ -46,12 +46,13 @@
2. Schema imports
Schema import elements are used to add multiple schemas with different target namespaces to a document.
+ All schemas are packaged in a lib/schemas.jar.
a) Take a look the import element in request.xsd:
<xs:import namespace="http://www.jboss.org/custom-request" schemaLocation="custom-request-type.xsd"/>
- This custom-request-type.xsd should in this case be packaged in the root of the .esb archive.
+ This custom-request-type.xsd should in this case be packaged in the root of the schemas.jar
b) Another example can be found in response.xsd:
<xs:import namespace="http://www.jboss.org/custom-response" schemaLocation="imports/custom-response-type.xsd"/>
- In this case the xsd has is located in a directory named 'imports' in the .esb archive.
+ In this case the xsd has is located in a directory named 'imports' in the schemas.jar
Deleted: labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/request.xsd
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/request.xsd 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/request.xsd 2010-06-03 12:18:34 UTC (rev 33329)
@@ -1,19 +0,0 @@
-<xs:schema version="1.0"
- targetNamespace="http://www.jboss.org/sayHi"
- xmlns:x1="http://www.jboss.org/sayHi"
- xmlns:cust="http://www.jboss.org/custom-request"
- xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
-
- <xs:import namespace="http://www.jboss.org/custom-request" schemaLocation="./types/custom-request-type.xsd"/>
-
- <xs:element name="sayHi" type="x1:sayHi"/>
-
- <xs:complexType name="sayHi">
- <xs:sequence>
- <xs:element name="arg0" type="xs:string" minOccurs="1"/>
- <xs:element ref="cust:customType" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
-
-</xs:schema>
-
Deleted: labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/response.xsd
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/response.xsd 2010-06-03 09:52:12 UTC (rev 33328)
+++ labs/jbossesb/trunk/product/samples/quickstarts/publish_as_webservice/response.xsd 2010-06-03 12:18:34 UTC (rev 33329)
@@ -1,17 +0,0 @@
-<xs:schema version="1.0"
- targetNamespace="http://www.jboss.org/sayHi"
- xmlns:x1="http://www.jboss.org/sayHi"
- xmlns:cust="http://www.jboss.org/custom-response"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- elementFormDefault="qualified">
-
- <xs:import namespace="http://www.jboss.org/custom-response" schemaLocation="types/custom-response-type.xsd"/>
-
- <xs:element name="sayHiResponse" type="x1:sayHiResponse"/>
- <xs:complexType name="sayHiResponse">
- <xs:sequence>
- <xs:element name="arg0" type="xs:string" minOccurs="0"/>
- <xs:element name="importedElement" type="cust:customType" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
-</xs:schema>
More information about the jboss-svn-commits
mailing list