[jboss-svn-commits] JBL Code SVN: r26871 - in labs/jbossesb/workspace/maeste/product: services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jun 8 06:24:39 EDT 2009


Author: maeste
Date: 2009-06-08 06:24:39 -0400 (Mon, 08 Jun 2009)
New Revision: 26871

Modified:
   labs/jbossesb/workspace/maeste/product/samples/quickstarts/webservice_consumer_wise_binding/jboss-esb.xml
   labs/jbossesb/workspace/maeste/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java
Log:
supporting wsdl, binding files and catalog file inside esb package

Modified: labs/jbossesb/workspace/maeste/product/samples/quickstarts/webservice_consumer_wise_binding/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/maeste/product/samples/quickstarts/webservice_consumer_wise_binding/jboss-esb.xml	2009-06-08 09:05:04 UTC (rev 26870)
+++ labs/jbossesb/workspace/maeste/product/samples/quickstarts/webservice_consumer_wise_binding/jboss-esb.xml	2009-06-08 10:24:39 UTC (rev 26871)
@@ -55,7 +55,7 @@
 					<property name="serviceName" value="PingWSService"/>
 					<property name="userName" value=""/>
 					<property name="password" value=""/>
-					<property name="binding-files" value="./jaxws-binding.xml" />		
+					<property name="binding-files" value="jaxws-binding.xml" />		
 				</action>
 				<action name="response-mapper"
 					class="org.jboss.soa.esb.samples.quickstart.webservice_consumer_wise_binding.MyResponseAction">

Modified: labs/jbossesb/workspace/maeste/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java
===================================================================
--- labs/jbossesb/workspace/maeste/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java	2009-06-08 09:05:04 UTC (rev 26870)
+++ labs/jbossesb/workspace/maeste/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java	2009-06-08 10:24:39 UTC (rev 26871)
@@ -23,12 +23,20 @@
 package org.jboss.soa.esb.actions.soap.wise;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import javax.xml.ws.handler.Handler;
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.jboss.internal.soa.esb.publish.Publish;
@@ -194,6 +202,7 @@
     private final String securityConfigName;
     private final List<File> bindFiles = Collections.synchronizedList(new LinkedList<File>());
     private final File catalogFile;
+    private final File wsdlFile;
 
     private WSDynamicClient client = null;
     private WSMethod method = null;
@@ -201,7 +210,26 @@
     private WiseMapper smooksResponseMapper = null;
 
     public SOAPClient( final ConfigTree config ) throws ConfigurationException {
-        wsdl = config.getRequiredAttribute("wsdl");
+
+        String wsdlURL = config.getRequiredAttribute("wsdl");
+
+        serviceName = config.getAttribute("serviceName") != null ? config.getAttribute("serviceName") : wsdlURL.substring(wsdlURL.lastIndexOf("/"),
+                                                                                                                          wsdlURL.lastIndexOf("?"));
+
+        try {
+            if (Boolean.parseBoolean(config.getAttribute("wsdlInsidePackage"))) {
+                wsdlFile = createTmpFileFromJar(wsdlURL);
+                wsdl = wsdlFile.getAbsolutePath();
+            } else {
+                wsdlFile = null;
+                wsdl = wsdlURL;
+            }
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Exception thrown during client creation. WSDL inside package error", e);
+            }
+            throw new ConfigurationException("WSDL inside package error. Could not initialize wise client " + serviceName, e);
+        }
         soapAction = config.getAttribute("SOAPAction");
         endPointName = config.getRequiredAttribute("EndPointName");
         smooksRequestMapperURL = config.getAttribute("SmooksRequestMapper");
@@ -209,8 +237,6 @@
         smooksRequestReportURL = config.getAttribute("smooksRequestReportURL");
         smooksResponseReportURL = config.getAttribute("smooksResponseReportURL");
 
-        serviceName = config.getAttribute("serviceName") != null ? config.getAttribute("serviceName") : wsdl.substring(wsdl.lastIndexOf("/"),
-                                                                                                                       wsdl.lastIndexOf("?"));
         username = config.getAttribute("username");
         password = config.getAttribute("password");
         loggingEnabled = Boolean.parseBoolean(config.getAttribute("LoggingMessages", "false"));
@@ -223,7 +249,20 @@
 
         securityConfigUrl = config.getAttribute("securityConfigUrl", "META-INF/jboss-wsse-client.xml");
         securityConfigName = config.getAttribute("securityConfigName", "Standard WSSecurity Client");
-        catalogFile = config.getAttribute("catalogFile") != null ? new File(config.getAttribute("catalogFile")) : null;
+
+        try {
+            if (config.getAttribute("catalogFile") != null) {
+                catalogFile = createTmpFileFromJar(config.getAttribute("catalogFile"));
+            } else {
+                catalogFile = null;
+            }
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Exception thrown during client creation. Catalog Files error", e);
+            }
+            throw new ConfigurationException("Catalog Files error. Could not initialize wise client " + serviceName, e);
+        }
+
         if (config.getAttribute("smooks-handler-config") != null) {
             smooksHandler.add(config.getAttribute("smooks-handler-config"));
         }
@@ -233,10 +272,17 @@
                 customHandlers.add(className);
             }
         }
-        if (config.getAttribute("binding-files") != null) {
-            for (String filePath : config.getAttribute("binding-files").split(";")) {
-                bindFiles.add(new File(filePath));
+        try {
+            if (config.getAttribute("binding-files") != null) {
+                for (String filePath : config.getAttribute("binding-files").split(";")) {
+                    bindFiles.add(createTmpFileFromJar(filePath));
+                }
             }
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Exception thrown during client creation. Binding Files error", e);
+            }
+            throw new ConfigurationException("Binding Files error. Could not initialize wise client " + serviceName, e);
         }
         String opName = config.getAttribute("operationName");
 
@@ -273,6 +319,16 @@
             }
             client.close();
         }
+        if (wsdlFile != null) {
+            wsdlFile.delete();
+        }
+        if (catalogFile != null) {
+            catalogFile.delete();
+        }
+        for (File bindFile : bindFiles) {
+            bindFile.delete();
+        }
+        (new File(System.getProperty("java.io.tmpdir"), this.serviceName)).delete();
     }
 
     private synchronized WSMethod init( Object payload ) throws ActionProcessingException {
@@ -461,4 +517,34 @@
         return smooksResponseMapper;
     }
 
+    /**
+     * this method create a temporary file to be used by wsconsume. WsConsume needs in many cases (wsdl, bindings, catalog) to
+     * have really file on disk and not stream.
+     * 
+     * @param fileName
+     * @return the created temporary file
+     * @throws IOException
+     */
+    private File createTmpFileFromJar( String fileName ) throws IOException {
+        (new File(System.getProperty("java.io.tmpdir"), this.serviceName)).mkdir();
+        File tmpFile = new File(System.getProperty("java.io.tmpdir"), this.serviceName + "/" + fileName);
+        tmpFile.createNewFile();
+        tmpFile.deleteOnExit();
+        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
+        OutputStream out = new FileOutputStream(tmpFile);
+        try {
+
+            // Transfer bytes from in to out
+            byte[] buf = new byte[1024];
+            int len;
+            while ((len = in.read(buf)) > 0) {
+                out.write(buf, 0, len);
+            }
+            return tmpFile;
+        } finally {
+            in.close();
+            out.close();
+        }
+
+    }
 }




More information about the jboss-svn-commits mailing list