[jboss-svn-commits] JBL Code SVN: r38166 - in labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src: test/java/org/jboss/soa/esb/actions/soap and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Aug 22 11:41:32 EDT 2012
Author: tcunning
Date: 2012-08-22 11:41:32 -0400 (Wed, 22 Aug 2012)
New Revision: 38166
Added:
labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaDeployer.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
labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/resources/test-schema.wsdl
Modified:
labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java
Log:
JBESB-3802
Add a cache-remote-schemas property, and if it is set, cache any external schemas locally within the ContractInfo.
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-08-17 16:17:41 UTC (rev 38165)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java 2012-08-22 15:41:32 UTC (rev 38166)
@@ -27,6 +27,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.URI;
+import java.util.Map;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
@@ -58,9 +59,11 @@
private static Logger logger = Logger.getLogger(AbstractWsdlContractPublisher.class);
+ public static final String CACHE_REMOTE_SCHEMAS = "cache-remote-schemas";
public static final String REWRITE_ENDPOINT_URL = "rewrite-endpoint-url";
private Properties actionProperties;
+ private boolean cacheRemoteSchemas = false;
private boolean rewriteEndpointUrl = true;
private Smooks transformer;
@@ -131,7 +134,12 @@
}
public ContractInfo getContractInfo(EPR epr, HttpServletRequest servletRequest) {
- String wsdlAddress = getWsdlAddress();
+ final String cacheRemoteSchemasVal = actionProperties.getProperty(AbstractWsdlContractPublisher.CACHE_REMOTE_SCHEMAS);
+ if (cacheRemoteSchemasVal != null) {
+ cacheRemoteSchemas = !cacheRemoteSchemasVal.equals("false");
+ }
+
+ String wsdlAddress = getWsdlAddress();
if (wsdlAddress != null) {
String targetServiceCat = servletRequest.getParameter("serviceCat");
String targetServiceName = servletRequest.getParameter("serviceName");
@@ -142,10 +150,24 @@
contract = getContractInfo(Service.getService(targetServiceCat, targetServiceName), wsdlAddress);
String data = contract.getData();
if (data != null) {
- contract.setData( updateWsdl(data, epr, targetServiceCat, targetServiceName, targetProtocol) );
+ data = updateWsdl(data, epr, targetServiceCat, targetServiceName, targetProtocol);
} else {
throw new Exception("null Contract data");
}
+
+ if (cacheRemoteSchemas) {
+ SchemaDeployer sd = (SchemaDeployer) new SchemaDeployerImpl();
+ SchemaLocationParser slp = new SchemaLocationParser(sd);
+
+ data = slp.parse(data);
+
+ Map<String, String> resources = sd.getResources();
+ for (String key : resources.keySet()) {
+ contract.putResource(key, resources.get(key));
+ }
+
+ }
+ contract.setData(data);
} catch (Exception e) {
String e_msg = "Failed to load WSDL contract information from address '" + wsdlAddress + "': " + e.getMessage();
logger.error(e_msg, e);
Added: labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaDeployer.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaDeployer.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaDeployer.java 2012-08-22 15:41:32 UTC (rev 38166)
@@ -0,0 +1,29 @@
+/*
+ * 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.util.Map;
+
+public interface SchemaDeployer {
+ public Map<String,String> getResources();
+ public void setEsbContext(String context);
+ public String getEsbContext();
+ public String deploy(String location, String soapAddress);
+}
Added: 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 (rev 0)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaDeployerImpl.java 2012-08-22 15:41:32 UTC (rev 38166)
@@ -0,0 +1,213 @@
+/*
+ * 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.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.URL;
+import java.util.HashMap;
+import java.util.Map;
+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 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;
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.soap.SchemaDeployer#getResources()
+ */
+ public Map<String,String> getResources() {
+ return resources;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.soap.SchemaDeployer#getEsbContext()
+ */
+ public String getEsbContext() {
+ return esbContext;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.soap.SchemaDeployer#setEsbContext(java.lang.String)
+ */
+ public void setEsbContext(String esbContext) {
+ this.esbContext = esbContext;
+ }
+
+ /**
+ * Find the temp directory from the ServerConfig bean
+ * @return
+ */
+ public String getTempDirectory() {
+ File tempDir = null;
+ MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
+ try {
+ tempDir = (File) mbeanServer.getAttribute(new ObjectName("jboss.system:type=ServerConfig"), "ServerTempDir");
+ } catch (JMException ignored) {
+ }
+ return tempDir.getAbsolutePath();
+ }
+
+ /**
+ * Get the XSD content from an URL and store it in a String.
+ * @param url
+ * @param tempFile
+ * @return
+ * @throws IOException
+ */
+ public String getXSDFile(URL url, File tempFile) throws IOException {
+ BufferedReader bufferedIn = new BufferedReader(new InputStreamReader(url.openStream()));
+ BufferedWriter bufferedOut = new BufferedWriter(new FileWriter(tempFile));
+
+ StringBuffer buffer = new StringBuffer(100);
+ String inputLine;
+ while ((inputLine = bufferedIn.readLine()) != null) {
+ bufferedOut.write(inputLine);
+ buffer.append(inputLine);
+ }
+
+ bufferedIn.close();
+ bufferedOut.close();
+
+ return buffer.toString();
+ }
+
+ /* (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();
+
+ try {
+ xsdUrl = new URL(location);
+
+ if (xsdUrl.getFile().startsWith(File.separator)) {
+ xsdFile = xsdUrl.getFile().substring(1);
+ }
+
+ tmpXSD = File.createTempFile(xsdFile, ".tmp");
+ xsdString = getXSDFile(xsdUrl, tmpXSD);
+ } catch (IOException ioe) {
+ logger.error(ioe);
+ return location;
+ }
+
+ // If by chance we have a name collision and the duplicate names of xsd files
+ // prepend an integer on front of the XSD file name until we find a unique name
+ if (resources.containsKey(xsdFile)) {
+ int i = 0;
+ String tempXsdFileName = xsdFile;
+
+ while (resources.containsKey(tempXsdFileName)) {
+ i++;
+ tempXsdFileName = i + xsdFile;
+ }
+
+ xsdFile = tempXsdFileName;
+ }
+
+ 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();
+ }
+ */
+}
Added: 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 (rev 0)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SchemaLocationParser.java 2012-08-22 15:41:32 UTC (rev 38166)
@@ -0,0 +1,261 @@
+/*
+ * 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 com.ibm.wsdl.Constants;
+import com.ibm.wsdl.util.xml.QNameUtils;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Result;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+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;
+
+public class SchemaLocationParser {
+
+ private static final String IMPORT_ELEM = "import";
+ private static final String SCHEMA_ELEM = "schema";
+ private static final String PORT_ELEM = "port";
+ private static final String SCHEMA_LOCATION_ATTR = "schemaLocation";
+ private static final String SOAP_ADDRESS_LOCATION = "location";
+
+ private String soapAddress;
+
+ DocumentBuilderFactory dbFactory;
+ DocumentBuilder dBuilder;
+ SchemaDeployer deployer;
+
+
+ /**
+ * The constructor for this class takes a deployer which is used deploy the XSD file given a filename.
+ * @param deployer
+ * @throws ParserConfigurationException
+ */
+ public SchemaLocationParser(SchemaDeployer deployer) throws ParserConfigurationException {
+ this.deployer = deployer;
+
+ dbFactory = DocumentBuilderFactory.newInstance();
+ dBuilder = dbFactory.newDocumentBuilder();
+ }
+
+ public String getSoapAddress() {
+ return soapAddress;
+ }
+
+ /**
+ * Get the SOAP Address attribute from the WSDL.
+ * @param wsdl
+ * @throws SAXException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ public void getSOAPAddress(String wsdl) throws SAXException, IOException, TransformerException {
+ InputStream is = new ByteArrayInputStream(wsdl.getBytes());
+ Document doc = dBuilder.parse(is);
+
+ doc.getDocumentElement().normalize();
+
+ NodeList nList = doc.getElementsByTagName("service");
+ for (int i = 0; i < nList.getLength(); i++) {
+ Node nNode = nList.item(i);
+
+ if (nNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element eElement = (Element) nNode;
+ getPort(eElement);
+ }
+ }
+ is.close();
+ }
+
+ /**
+ * Parse the wsdl for any specified schemaLocations.
+ * @param wsdl
+ * @return
+ * @throws SAXException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ public String parse(String wsdl) throws SAXException, IOException, TransformerException {
+ getSOAPAddress(wsdl);
+ InputStream is = new ByteArrayInputStream(wsdl.getBytes());
+ Document doc = dBuilder.parse(is);
+
+ doc.getDocumentElement().normalize();
+
+ NodeList nList = doc.getElementsByTagName(Constants.ELEM_TYPES);
+ for (int i = 0; i < nList.getLength(); i++) {
+ Node nNode = nList.item(i);
+
+ if (nNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element eElement = (Element) nNode;
+ getSchema(eElement);
+ }
+ }
+
+ // Transform to string
+ javax.xml.transform.TransformerFactory tfactory = TransformerFactory.newInstance();
+ javax.xml.transform.Transformer xform = tfactory.newTransformer();
+
+ javax.xml.transform.Source src = new DOMSource(doc);
+ java.io.StringWriter writer = new StringWriter();
+ Result result = new javax.xml.transform.stream.StreamResult(writer);
+ xform.transform(src, result);
+
+ return writer.toString();
+ }
+
+
+ /**
+ * Extract the schema from an element.
+ * @param element
+ */
+ public void getSchema(Element element) {
+ NodeList nodes = element.getChildNodes();
+
+ for(int i=0; i<nodes.getLength(); i++){
+ Node node = nodes.item(i);
+
+ if(node instanceof Element) {
+ Element child = (Element) node;
+ String lp = getLocalPart(node);
+ if (SCHEMA_ELEM.equals(getLocalPart(node))) {
+ getImport(child);
+ }
+ }
+ }
+ }
+
+ /**
+ * Extract the port.
+ * @param element
+ */
+ public void getPort(Element element) {
+ NodeList nodes = element.getChildNodes();
+
+ for(int i=0; i<nodes.getLength(); i++){
+ Node node = nodes.item(i);
+
+ if(node instanceof Element) {
+ Element child = (Element) node;
+ String lp = getLocalPart(node);
+ if (PORT_ELEM.equals(getLocalPart(node))) {
+ getSOAPAddress(child);
+ }
+ }
+ }
+ }
+
+ /**
+ * Extract an import element.
+ * @param element
+ */
+ public void getImport(Element element) {
+ NodeList nodes = element.getChildNodes();
+
+ for(int i=0; i<nodes.getLength(); i++){
+ Node node = nodes.item(i);
+
+ if(node instanceof Element){
+ Element child = (Element) node;
+
+ String imp = getLocalPart(node);
+ if (IMPORT_ELEM.equals(getLocalPart(node))) {
+
+ if (child.hasAttribute(SCHEMA_LOCATION_ATTR)) {
+ 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);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Get the SOAP Adddress.
+ * @param element
+ */
+ public void getSOAPAddress(Element element) {
+ NodeList nodes = element.getChildNodes();
+
+ for(int i=0; i<nodes.getLength(); i++){
+ Node node = nodes.item(i);
+
+ 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)) {
+ soapAddress = child.getAttribute(SOAP_ADDRESS_LOCATION);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Call the deployer to deploy the XSD.
+ * @param location
+ * @return
+ */
+ public String deployXSD(String location) {
+ String xsdLocation = deployer.deploy(location, soapAddress);
+ return xsdLocation;
+ }
+
+ /**
+ * Utility method for parsing local part of a QName.
+ * @param child
+ * @return
+ */
+ public static String getLocalPart(Node child) {
+ try {
+ 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);
+ } else {
+ return nodeName;
+ }
+ }
+ }
+}
Added: 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 (rev 0)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/SchemaLocatorUnitTest.java 2012-08-22 15:41:32 UTC (rev 38166)
@@ -0,0 +1,73 @@
+/*
+ * 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.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.actions.soap.SchemaDeployer;
+import org.jboss.soa.esb.actions.soap.SchemaDeployerImpl;
+import org.jboss.soa.esb.actions.soap.SchemaLocationParser;
+import org.xml.sax.SAXException;
+
+public class SchemaLocatorUnitTest extends TestCase {
+ public SchemaLocatorUnitTest() {
+
+ }
+
+ public void testSchemaLocation()
+ throws ParserConfigurationException, SAXException, IOException, TransformerException {
+
+ StringBuffer fileData = new StringBuffer(1000);
+ URL testSchema = getClass().getResource("/test-schema.wsdl");
+
+ BufferedReader reader = new BufferedReader(new FileReader(testSchema.getPath()));
+ char[] buffer = new char[1024];
+ int length=0;
+ while ((length=reader.read(buffer)) != -1) {
+ String readData = String.valueOf(buffer, 0, length);
+ fileData.append(readData);
+ buffer = new char[1024];
+ }
+ reader.close();
+
+ SchemaDeployer sd = (SchemaDeployer) new SchemaDeployerImpl();
+ SchemaLocationParser slp = new SchemaLocationParser(sd);
+
+ String data = slp.parse(fileData.toString());
+
+ assertEquals(slp.getSoapAddress(), "http://localhost:8080/jaxws-jbws2526");
+
+ Map<String, String> resources = sd.getResources();
+ assertEquals(resources.size(), 1);
+ for (String key : resources.keySet()) {
+ assertEquals(key, "jbws2526.xsd");
+ }
+ }
+}
Added: labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/resources/test-schema.wsdl
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/resources/test-schema.wsdl (rev 0)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/services/soap/src/test/resources/test-schema.wsdl 2012-08-22 15:41:32 UTC (rev 38166)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<definitions name="JBWS-2526"
+ targetNamespace="urn:JBWS-2526-Service"
+ xmlns:service="urn:JBWS-2526-Service"
+ xmlns:schema="urn:JBWS-2526-Schema"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns="http://schemas.xmlsoap.org/wsdl/">
+ <types>
+ <xs:schema>
+ <xs:import namespace="urn:JBWS-2526-Schema"
+ schemaLocation="http://www.rotowatch.com/jbws2526.xsd"/>
+ </xs:schema>
+ </types>
+
+ <message name="Request">
+ <part name="request" element="schema:Request"/>
+ </message>
+ <message name="Response">
+ <part name="response" element="schema:Response"/>
+ </message>
+
+ <portType name="Port">
+ <operation name="evaluate">
+ <input message="service:Request"/>
+ <output message="service:Response"/>
+ </operation>
+ </portType>
+
+ <binding name="Binding" type="service:Port">
+ <soap:binding style="document"
+ transport="http://schemas.xmlsoap.org/soap/http"/>
+ <operation name="evaluate">
+ <soap:operation/>
+ <input>
+ <soap:body use="literal"/>
+ </input>
+ <output>
+ <soap:body use="literal"/>
+ </output>
+ </operation>
+ </binding>
+
+ <service name="Service">
+ <port binding="service:Binding" name="Port">
+ <soap:address location="http://localhost:8080/jaxws-jbws2526"/>
+ </port>
+ </service>
+</definitions>
More information about the jboss-svn-commits
mailing list