[jboss-svn-commits] JBL Code SVN: r38176 - in labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src: test/java/org/jboss/soa/esb/actions/soap and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Sep 12 22:07:25 EDT 2012


Author: tcunning
Date: 2012-09-12 22:07:25 -0400 (Wed, 12 Sep 2012)
New Revision: 38176

Added:
   labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/SchemaDeployerTest.java
Modified:
   labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java
   labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaDeployerImpl.java
   labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaLocationParser.java
   labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/SchemaLocatorUnitTest.java
Log:
JBESB-3802
Commit fix patch from Tadayoshi Sato to deal with classpath: URL format and rewriting the schema locations.  There was
an issue where two ? were being included in the rewritten schema URL.   Tadayoshi's patch fixes that.


Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java	2012-09-13 01:06:46 UTC (rev 38175)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java	2012-09-13 02:07:25 UTC (rev 38176)
@@ -59,11 +59,11 @@
    
     private static Logger logger = Logger.getLogger(AbstractWsdlContractPublisher.class);
 
-    public static final String CACHE_REMOTE_SCHEMAS = "cache-schemas";
+    public static final String CACHE_SCHEMAS = "cache-schemas";
     public static final String REWRITE_ENDPOINT_URL = "rewrite-endpoint-url";
 
     private Properties actionProperties;
-    private boolean cacheRemoteSchemas = false;	
+    private boolean cacheSchemas = false;
     private boolean rewriteEndpointUrl = true;
     private Smooks transformer;
 
@@ -134,9 +134,9 @@
     }
 
     public ContractInfo getContractInfo(EPR epr, HttpServletRequest servletRequest) {
-        final String cacheRemoteSchemasVal = actionProperties.getProperty(AbstractWsdlContractPublisher.CACHE_REMOTE_SCHEMAS);
-        if (cacheRemoteSchemasVal != null) {
-            cacheRemoteSchemas = !cacheRemoteSchemasVal.equals("false");
+        final String cacheSchemasVal = actionProperties.getProperty(AbstractWsdlContractPublisher.CACHE_SCHEMAS);
+        if (cacheSchemasVal != null) {
+            cacheSchemas = !cacheSchemasVal.equals("false");
         }        
 
     	String wsdlAddress = getWsdlAddress();
@@ -155,7 +155,7 @@
                 	throw new Exception("null Contract data");
                 }
                 
-                if (cacheRemoteSchemas) {
+                if (cacheSchemas) {
                 	SchemaDeployer sd = (SchemaDeployer) new SchemaDeployerImpl();
                 	SchemaLocationParser slp = new SchemaLocationParser(sd);
 

Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaDeployerImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaDeployerImpl.java	2012-09-13 01:06:46 UTC (rev 38175)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaDeployerImpl.java	2012-09-13 02:07:25 UTC (rev 38176)
@@ -22,40 +22,29 @@
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.net.MalformedURLException;
-import java.net.URI;
 import java.net.URL;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
 
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
-import javax.management.MBeanServer;
 import org.apache.log4j.Logger;
 import org.jboss.mx.util.MBeanServerLocator;
 
 public class SchemaDeployerImpl implements SchemaDeployer {
-	private static final String XSD_PATTERN = "\\w*(.xsd)";
+	private static final String XSD_PATTERN = "\\w+[.]xsd";
 	private Logger logger = Logger.getLogger(SchemaDeployerImpl.class);
     private Map<String,String> resources = new HashMap<String,String>();
 	
-	private final String ESB_WAR_FILES_DIR = "esbwarfiles";
 	private String esbContext;
+	private Pattern xsdPattern = Pattern.compile(XSD_PATTERN);
 
 	/* (non-Javadoc)
 	 * @see org.jboss.soa.esb.actions.soap.SchemaDeployer#getResources()
@@ -99,7 +88,7 @@
 	 * @return
 	 * @throws IOException
 	 */
-	public String getXSDFile(URL url, File tempFile) throws IOException {
+	protected String getXSDString(URL url, File tempFile) throws IOException {
 		BufferedReader bufferedIn = new BufferedReader(new InputStreamReader(url.openStream()));
 	    BufferedWriter bufferedOut = new BufferedWriter(new FileWriter(tempFile));
 	         
@@ -115,36 +104,42 @@
 	    
 	    return buffer.toString();
 	}
-		
+
+	protected String extractXSDFile(URL url) {
+		// try external XSD first
+		Matcher pathMatcher = xsdPattern.matcher(url.getPath());
+		if (pathMatcher.find()) {
+			return pathMatcher.group();
+		}
+		// try internal XSD
+		Matcher queryMatcher = xsdPattern.matcher(url.getQuery());
+		if (queryMatcher.find()) {
+			return queryMatcher.group();
+		}
+		return null;
+	}
+
 	/* (non-Javadoc)
 	 * @see org.jboss.soa.esb.actions.soap.SchemaDeployer#deploy(java.lang.String, java.lang.String)
 	 */
 	public String deploy(String location, String soapAddress) {
-//		String tmpDir = getTempDirectory();
-//		String warLocation = tmpDir + File.separator + ESB_WAR_FILES_DIR + File.separator + esbContext + ".war";
-				
 		File tmpXSD = null;
 		URL xsdUrl = null;
-		String xsdFile = new String();
-		String xsdString = new String();
-		
+		String xsdFile = null;
+		String xsdString = null;
+
 		try {
 			xsdUrl = new URL(location);
-			URI xsdUri = new URI(location);
-			Pattern p = Pattern.compile(XSD_PATTERN);
-			Matcher m = p.matcher(location);
-			
-			if(m.find()){
-				xsdFile = m.group();
-			} else {
-				throw new IllegalStateException("Could not find match for pattern: "+ XSD_PATTERN + 
+			xsdFile = extractXSDFile(xsdUrl);
+			if (xsdFile == null) {
+				throw new IllegalArgumentException("Could not find match for pattern: " + XSD_PATTERN + 
 						", in location: " + location);
 			}
 			
 			tmpXSD = File.createTempFile(xsdFile, ".tmp");
-			xsdString = getXSDFile(xsdUrl, tmpXSD);
+			xsdString = getXSDString(xsdUrl, tmpXSD);
 		} catch (Exception ioe) {
-			logger.error(ioe);
+			logger.error("Failed to get an XSD file", ioe);
 			return location;
 		}
 
@@ -165,60 +160,4 @@
 		resources.put(xsdFile, xsdString);
 		return soapAddress + "?wsdl&resource=" + xsdFile;		
 	}
-
-	/*
-	public void writeToJar() {
-		File warFile = new File(warLocation);
-
-		ZipInputStream in = null;
-		ZipOutputStream out = null;
-		FileInputStream fileIn = null;
-		File tmpWarFile = null;
-		try {
-			tmpWarFile = File.createTempFile((esbContext + ".war"), ".tmp");
-			out = new ZipOutputStream(new FileOutputStream(tmpWarFile));
-			in = new ZipInputStream(new FileInputStream(warFile));
-			
-			fileIn = new FileInputStream(tmpXSD);
-			
-			
-			ZipEntry entry = in.getNextEntry();
-			byte[] buffer = new byte[1024];
-			int length = 0;
-
-			while (entry != null) {
-				String entryName = entry.getName();
-				if (entryName.equals(xsdFile)) {
-				} else {		
-					out.putNextEntry(new ZipEntry(entryName));
-					while ((length = in.read(buffer)) > 0) {
-						out.write(buffer, 0, length);
-					}
-				}
-				entry = in.getNextEntry();
-			}
-
-			out.putNextEntry(new ZipEntry(xsdFile));
-	
-			while ((length = fileIn.read(buffer)) > 0) {
-				out.write(buffer, 0, length);
-			}
-		} catch (IOException ioe) {
-			logger.error(ioe);
-			return location;
-		} finally {
-			try {
-				out.closeEntry();
-
-				in.close();
-				fileIn.close();
-				out.close();
-			} catch (IOException ioe) {
-				logger.error(ioe);
-			}
-		}			
-		tmpWarFile.renameTo(new File(warLocation));
-		tmpXSD.delete();
-	}
-	*/
 }

Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaLocationParser.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaLocationParser.java	2012-09-13 01:06:46 UTC (rev 38175)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaLocationParser.java	2012-09-13 02:07:25 UTC (rev 38176)
@@ -38,12 +38,9 @@
 import org.xml.sax.SAXException;
 
 import java.io.ByteArrayInputStream;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
-import java.net.URI;
-import java.net.URISyntaxException;
 
 public class SchemaLocationParser {
 
@@ -151,7 +148,6 @@
 
 			if(node instanceof Element) {
 				Element child = (Element) node;
-				String lp = getLocalPart(node);
 				if (SCHEMA_ELEM.equals(getLocalPart(node))) {
 					getImport(child);
 				}
@@ -171,7 +167,6 @@
 
 			if(node instanceof Element) {
 				Element child = (Element) node;
-				String lp = getLocalPart(node);
 				if (PORT_ELEM.equals(getLocalPart(node))) {
 					getSOAPAddress(child);
 				}
@@ -192,13 +187,12 @@
 			if(node instanceof Element){
 				Element child = (Element) node;
 				
-				String imp = getLocalPart(node);
 				if (IMPORT_ELEM.equals(getLocalPart(node))) {
 		    
 					if (child.hasAttribute(SCHEMA_LOCATION_ATTR)) {
-						String schemaLocation = child.getAttribute(SCHEMA_LOCATION_ATTR);
-						if ((schemaLocation != null)) {
-							String xsdLocation = deployXSD(schemaLocation);
+						if ((child.getAttribute(SCHEMA_LOCATION_ATTR) != null) 
+							&& (child.getAttribute(SCHEMA_LOCATION_ATTR).startsWith("http://"))) {
+							String xsdLocation = deployXSD(child.getAttribute(SCHEMA_LOCATION_ATTR));
 							child.setAttribute(SCHEMA_LOCATION_ATTR, xsdLocation);
 						}
 					}
@@ -206,6 +200,7 @@
 			}
 		}		
 	}
+
 	/**
 	 * Get the SOAP Adddress.
 	 * @param element
@@ -219,7 +214,6 @@
 			if(node instanceof Element){
 				Element child = (Element) node;
 				
-				String imp = getLocalPart(node);
 				if ("address".equals(getLocalPart(node))) {
 		    
 					if ( (child.hasAttribute(SOAP_ADDRESS_LOCATION)) && (child.getAttribute(SOAP_ADDRESS_LOCATION) != null)) {
@@ -250,7 +244,6 @@
 			QName q = QNameUtils.newQName(child);
 			return q.getLocalPart();
 		} catch (IllegalArgumentException iae){
-			Element el = (Element) child;
 			String nodeName = child.getNodeName();
 			if (nodeName.contains(":")) {
 				return nodeName.substring(nodeName.indexOf(":") + 1);

Added: labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/SchemaDeployerTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/SchemaDeployerTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/SchemaDeployerTest.java	2012-09-13 02:07:25 UTC (rev 38176)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.soa.esb.actions.soap;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class SchemaDeployerTest extends TestCase {
+
+	private SchemaDeployer deployer;
+
+	@Override
+	protected void setUp() {
+		deployer = new SchemaDeployerImpl() {
+			// mock method to eschew actual network access
+			@Override
+			public String getXSDString(URL url, File tempFile) throws IOException {
+				return "!!! Dummy XSD data !!!";
+			}
+		};
+	}
+
+	@Override
+	protected void tearDown() {
+		deployer = null;
+	}
+
+	public void testDeploy_JBossWS_Native() {
+		String rewrittenLocation = deployer.deploy("http://127.0.0.1:8080/Quickstart_HelloWorldWS/HelloWorldWS?wsdl&resource=HelloWorldService.xsd",
+				"http://www.jboss.org/HelloWorld");
+
+		assertEquals("http://www.jboss.org/HelloWorld?wsdl&resource=HelloWorldService.xsd", rewrittenLocation);
+		Map<String, String> resources = deployer.getResources();
+		assertEquals(resources.size(), 1);
+		assertEquals("!!! Dummy XSD data !!!", resources.get("HelloWorldService.xsd"));
+	}
+
+	public void testDeploy_JBossWS_CXF() {
+		String rewrittenLocation = deployer.deploy("http://127.0.0.1:8080/Quickstart_HelloWorldWS/HelloWorldWS?xsd=HelloWorldService.xsd",
+				"http://www.jboss.org/HelloWorld");
+
+		assertEquals("http://www.jboss.org/HelloWorld?wsdl&resource=HelloWorldService.xsd", rewrittenLocation);
+		Map<String, String> resources = deployer.getResources();
+		assertEquals(resources.size(), 1);
+		assertEquals("!!! Dummy XSD data !!!", resources.get("HelloWorldService.xsd"));
+	}
+
+	public void testDeploy_DuplicateNames() {
+		String rewrittenLocation1 = deployer.deploy("http://127.0.0.1:8080/Quickstart_HelloWorldWS/HelloWorldWS?wsdl&resource=HelloWorldService.xsd",
+				"http://www.jboss.org/HelloWorld");
+		String rewrittenLocation2 = deployer.deploy("http://127.0.0.1:8080/Quickstart_HelloWorldWS/HelloWorldWS?wsdl&resource=HelloWorldService.xsd",
+				"http://www.jboss.org/HelloWorld");
+		String rewrittenLocation3 = deployer.deploy("http://127.0.0.1:8080/Quickstart_HelloWorldWS/HelloWorldWS?wsdl&resource=HelloWorldService.xsd",
+				"http://www.jboss.org/HelloWorld");
+
+		assertEquals("http://www.jboss.org/HelloWorld?wsdl&resource=HelloWorldService.xsd", rewrittenLocation1);
+		assertEquals("http://www.jboss.org/HelloWorld?wsdl&resource=1HelloWorldService.xsd", rewrittenLocation2);
+		assertEquals("http://www.jboss.org/HelloWorld?wsdl&resource=2HelloWorldService.xsd", rewrittenLocation3);
+		Map<String, String> resources = deployer.getResources();
+		assertEquals(resources.size(), 3);
+		assertEquals("!!! Dummy XSD data !!!", resources.get("HelloWorldService.xsd"));
+		assertEquals("!!! Dummy XSD data !!!", resources.get("1HelloWorldService.xsd"));
+		assertEquals("!!! Dummy XSD data !!!", resources.get("2HelloWorldService.xsd"));
+	}
+}

Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/SchemaLocatorUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/SchemaLocatorUnitTest.java	2012-09-13 01:06:46 UTC (rev 38175)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/SchemaLocatorUnitTest.java	2012-09-13 02:07:25 UTC (rev 38176)
@@ -55,7 +55,7 @@
     	assertEquals(slp.getSoapAddress(), "http://localhost:8080/jaxws-jbws2526");
     	
     	Map<String, String> resources = sd.getResources();
-    	assertEquals(resources.size(), 1);
+    	assertEquals(1, resources.size());
     	
 		for (String key : resources.keySet()) {
 			assertEquals(key, "jbws2526.xsd");
@@ -65,18 +65,21 @@
 	
 	public void testSchemaLocationInternal() throws Exception{
 		StringBuffer fileData = getFileData("/test-schema-int.wsdl");
-		SchemaDeployer sd = new SchemaDeployerImpl();
+		SchemaDeployer sd = new SchemaDeployerImpl() {
+			// mock method to eschew actual network access
+			@Override
+			public String getXSDString(URL url, File tempFile) throws IOException {
+				return "!!! Dummy XSD data !!!";
+			}
+		};
 		SchemaLocationParser slp = new SchemaLocationParser(sd);
 		String data = slp.parse(fileData.toString());
 		
 		assertEquals(slp.getSoapAddress(), "http://127.0.0.1:8080/Quickstart_HelloWorldWS/HelloWorldWS");
 		
 		Map<String, String> resources = sd.getResources();
-		assertEquals(resources.size(), 0);
-		
-		for (String key : resources.keySet()) {
-			assertEquals(key, "jbws2526.xsd");
-		}
+		assertEquals(1, resources.size());
+		assertEquals("!!! Dummy XSD data !!!", resources.get("HelloWorldService.xsd"));
 	}
 
 	private StringBuffer getFileData(String filePath) throws FileNotFoundException,



More information about the jboss-svn-commits mailing list