[jboss-dev-forums] [Design of JBoss ESB] - WS Endpoints :: WSDL rendered dynamically

andretemple do-not-reply at jboss.com
Thu Oct 23 14:24:09 EDT 2008


Hi all,

I've checkout the jbossesb-4.4.GACP from SVN and took a look in publish_as_webservice sample. 

After some tests I realized that when I import some xsd into main xsd something goes wrong. Exploring the generated artifacts from JBossAS I saw that imported xsd was not copied into deployed services (tmp directory) and here is the problem.

So I got the source code from JBoss4ESBDeployer and did a few changes.

Below is the snippets from xsd and source code.

I think it's a good idea to include something like this in JBossESB new release, since we always have a complex xsd structure and could expose it as a service in the bus.

What do you think?

tks.

request.xsd

  | <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"
  |     xmlns:Q1="http://www.jboss.org/standard">
  | 
  |   <xs:import schemaLocation="standard.xsd" namespace="http://www.jboss.org/standard"></xs:import>
  |   <xs:include schemaLocation="standard.xsd"></xs:include>
  | 
  |   <xs:element name="sayHi" type="x1:sayHi"/>
  |   <xs:complexType name="sayHi">
  |     <xs:sequence>
  |       <xs:element name="person" type="Q1:person" minOccurs="1"></xs:element>
  |     </xs:sequence>
  |   </xs:complexType>
  | </xs:schema>
  | 

standard.xsd

  | <xs:schema version='1.0' targetNamespace="http://www.jboss.org/standard"
  |     xmlns:tns='http://www.jboss.org/standard' xmlns:xs='http://www.w3.org/2001/XMLSchema'
  |     elementFormDefault="qualified">
  | 
  |     <xs:complexType name='person'>
  |         <xs:sequence>
  |             <xs:element name='name' type='xs:string' />
  |             <xs:element name='surname' type='xs:string' />
  |         </xs:sequence>
  |     </xs:complexType>
  | 
  | </xs:schema>

org.jboss.soa.esb.listeners.config.JBoss4ESBDeployer.java

  | public class JBoss4ESBDeployer extends SubDeployerSupport
  |         implements SubDeployer, JBoss4ESBDeployerMBean
  | 
  | ...
  | 
  |    public void init(DeploymentInfo di) throws DeploymentException  {
  |       ...
  |          try
  |          {
  |              Thread.currentThread().setContextClassLoader(di.localCl) ;
  |              warFile = createWebserviceWars(di, jbossEsb, deploymentName, publishers) ;
  |          }
  |          finally
  |          {
  |              Thread.currentThread().setContextClassLoader(origCL) ;
  |          }
  | 
  |       ...    
  |    }
  | 
  |    private File createWebserviceWars(final DeploymentInfo di, final Jbossesb jbossEsb, final String deploymentName, final List<ContractReferencePublisher> publishers) throws DeploymentException   { 
  |    ...
  |    for(Service service: endpointServices)
  |    {
  |        final ESBServiceEndpointInfo serviceInfo = new ESBServiceEndpointInfo(service) ;
  |        final String wsdl = ESBContractGenerator.generateWSDL(service, serviceInfo) ;
  |        addFile(zos, serviceInfo.getWSDLFileName(), wsdl) ;
  |        
  |        ZipFile file = new ZipFile(di.url.getFile());
  |        Enumeration xsdFiles = file.entries();
  |        if (xsdFiles != null) {
  |          while (xsdFiles.hasMoreElements()) {
  |              ZipEntry xsdFile = (ZipEntry) xsdFiles.nextElement();
  |              if (xsdFile.getName().indexOf("xsd") > 0) {
  |                  String xsdFileName = "WEB-INF/wsdl/" + service.getCategory().replace('/', '_') 
  | + "/" + xsdFile.getName();
  |                  addFile(zos, xsdFileName, getBytesFromFile(
  | di.localCl.getResourceAsStream(xsdFile.getName()), xsdFile.getSize(), xsdFile.getName()));
  |              }
  |          }
  |        }
  |    ...
  |    }
  | 
  |    private byte[] getBytesFromFile(InputStream is, long length, String fileName) throws IOException {
  |        if (length > Integer.MAX_VALUE) {
  |            // File is too large
  |        }
  |        // Create the byte array to hold the data
  |        byte[] bytes = new byte[(int)length];
  |    
  |        // Read in the bytes
  |        int offset = 0;
  |        int numRead = 0;
  |        while (offset < bytes.length
  |               && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
  |            offset += numRead;
  |        }
  |    
  |        // Ensure all the bytes have been read in
  |        if (offset < bytes.length) {
  |            throw new IOException("Could not completely read file "+ fileName);
  |        }
  |    
  |        // Close the input stream and return bytes
  |        is.close();
  |        return bytes;
  |    }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4184285#4184285

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4184285



More information about the jboss-dev-forums mailing list