[jboss-svn-commits] JBL Code SVN: r24682 - in labs/jbossesb/trunk/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
Tue Jan 13 16:17:11 EST 2009


Author: maeste
Date: 2009-01-13 16:17:11 -0500 (Tue, 13 Jan 2009)
New Revision: 24682

Modified:
   labs/jbossesb/trunk/product/services/soap/lib/ext/Wise-core.jar
   labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java
Log:
JBESB-2274

Modified: labs/jbossesb/trunk/product/services/soap/lib/ext/Wise-core.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java	2009-01-13 18:58:30 UTC (rev 24681)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java	2009-01-13 21:17:11 UTC (rev 24682)
@@ -33,7 +33,6 @@
 import it.javalinux.wise.core.mapper.SmooksMapper;
 import it.javalinux.wise.core.mapper.WiseMapper;
 import it.javalinux.wise.core.utils.SmooksCache;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -50,10 +49,8 @@
 
 /**
  * SOAP Client action processor. <p/> Uses the Wise Client Service to generate JAXWS client class and call the target service.
- * This action then routes that message to that service.
- * <h2>Endpoint Operation Specification</h2>
- * Specifying the endpoint operation is a straightforward task. Simply specify the "wsdl" and "SOAPAction" properties on the
- * SOAPClient action as follows:
+ * This action then routes that message to that service. <h2>Endpoint Operation Specification</h2> Specifying the endpoint
+ * operation is a straightforward task. Simply specify the "wsdl" and "SOAPAction" properties on the SOAPClient action as follows:
  * 
  * <pre>
  * 	&lt;action name=&quot;soap-wise-client-action&quot; class=&quot;org.jboss.soa.esb.actions.soap.wise.SOAPClient&quot;&gt;
@@ -91,48 +88,45 @@
  * 
  * <pre>
  * 	&lt;property name=&quot;userName&quot; value=&quot;&quot;/&gt;
- * 	&lt;property name=&quot;password&quot; value=&quot;&quot;/&gt;	
+ * 	&lt;property name=&quot;password&quot; value=&quot;&quot;/&gt;
  * </pre>
  * 
- * User and password used if webservice is protected by BAsic Authentication HTTP user and password
- * <h2 id="request-construction">SOAP Request Message Construction</h2>
- * The SOAP operation parameters are supplied in one of 2 ways:
+ * User and password used if webservice is protected by BAsic Authentication HTTP user and password <h2
+ * id="request-construction">SOAP Request Message Construction</h2> The SOAP operation parameters are supplied in one of 2 ways:
  * <ol>
  * <li>As a {@link Map} instance set on the <i>default body location</i> (Message.getBody().add(Map))</li>
  * <li>As a {@link Map} instance set on in a <i>named body location</i> (Message.getBody().add(String, Map)), where the name of
- * that body location is specified as the value of the "paramsLocation" action property. </li>
+ * that body location is specified as the value of the "paramsLocation" action property.</li>
  * </ol>
  * The parameter {@link Map} itself can also be populated in one of 2 ways:
  * <ol>
  * <li><b>Option 1</b>: With a set of Objects of any type. In this case a smooks config have to be specified in action attribute
  * SmooksRequestMapper and smooks is used to make the java-to-java conversion
- * <li><b>Option 2</b>: With a set of String based key-value pairs(&lt;String, Object&gt;), where the key is the name of the
- * SOAP parameter as specified in wsdls (or in generated class) to be populated with the key's value. </li>
+ * <li><b>Option 2</b>: With a set of String based key-value pairs(&lt;String, Object&gt;), where the key is the name of the SOAP
+ * parameter as specified in wsdls (or in generated class) to be populated with the key's value.</li>
  * </ol>
- * <h2>SOAP Response Message Consumption</h2>
- * The SOAP response object instance can be is attached to the ESB {@link Message} instance in one of the following ways:
+ * <h2>SOAP Response Message Consumption</h2> The SOAP response object instance can be is attached to the ESB {@link Message}
+ * instance in one of the following ways:
  * <ol>
  * <li>On the <i>default body location</i> (Message.getBody().add(Map))</li>
- * <li>On in a <i>named body location</i> (Message.getBody().add(String, Map)), where the name of that body location is
- * specified as the value of the "responseLocation" action property. </li>
+ * <li>On in a <i>named body location</i> (Message.getBody().add(String, Map)), where the name of that body location is specified
+ * as the value of the "responseLocation" action property.</li>
  * </ol>
  * The response object instance can also be populated (from the SOAP response) in one of 3 ways:
  * <ol>
  * <li><b>Option 1</b>: With a set of Objects of any type. In this case a smooks config have to be specified in action attribute
  * SmooksResponseMapper and smooks is used to make the java-to-java conversion
- * <li><b>Option 2</b>: With a set of String based key-value pairs(&lt;String, Object&gt;), where the key is the name of the
- * SOAP answer as specified in wsdls (or in generated class) to be populated with the key's value. </li>
+ * <li><b>Option 2</b>: With a set of String based key-value pairs(&lt;String, Object&gt;), where the key is the name of the SOAP
+ * answer as specified in wsdls (or in generated class) to be populated with the key's value.</li>
  * </ol>
- * <h2>JAX-WS Handler for the SOAP Request/Response Message</h2>
- * It's often necessary to be able to transform the SOAP request or response, especially in header. This may be to simply add some
- * standard SOAP handlers. Wise support JAXWS Soap Handler, both custom or a predefined one based on smooks. <p/> Transformation
- * of the SOAP request (before sending) is supported by configuring the SOAPClient action with a Smooks transformation
- * configuration property as follows:
+ * <h2>JAX-WS Handler for the SOAP Request/Response Message</h2> It's often necessary to be able to transform the SOAP request or
+ * response, especially in header. This may be to simply add some standard SOAP handlers. Wise support JAXWS Soap Handler, both
+ * custom or a predefined one based on smooks. <p/> Transformation of the SOAP request (before sending) is supported by
+ * configuring the SOAPClient action with a Smooks transformation configuration property as follows:
  * 
  * <pre>
  *     &lt;property name=&quot;smooksTransform&quot; value=&quot;/transforms/order-transform.xml&quot; /&gt;
  * </pre>
- * 
  * <p>
  * The value of the "smooksTransform" property is resolved by first checking it as a filesystem based resource. Failing that, it's
  * checked as a classpath resource and failing that, as a URI based resource.
@@ -146,9 +140,8 @@
  *     &lt;property name=&quot;custom-handlers&quot; value=&quot;package.Class1;package.Class2&quot; /&gt;
  * </pre>
  * 
- * <h2>Logging the SOAP Request/Response Message</h2>
- * It's useful for debug purpose to view soap Message sent and response received. Wise achieve this goal using a JAX-WS handler
- * printing all messages exchanged on System.out You can enable as follow:
+ * <h2>Logging the SOAP Request/Response Message</h2> It's useful for debug purpose to view soap Message sent and response
+ * received. Wise achieve this goal using a JAX-WS handler printing all messages exchanged on System.out You can enable as follow:
  * 
  * <pre>
  *     &lt;property name=&quot;LoggingMessages&quot; value=&quot;true&quot; /&gt;
@@ -156,160 +149,227 @@
  * 
  * @author <a href="mailto:stefano.maestri at javalinux.it">stefano.maestri at javalinux.it</a>
  */
-public class SOAPClient extends AbstractActionPipelineProcessor {
+public class SOAPClient extends AbstractActionPipelineProcessor
+{
 
-    private final Logger logger = Logger.getLogger(SOAPClient.class);
-    private final String wsdl;
-    private final String soapAction;
-    private final String endPointName;
-    private final String smooksRequestMapperURL;
-    private final String smooksResponseMapperURL;
-    private String serviceName;
-    private final String username;
-    private final String password;
-    // private WSDynamicClient client;
-    private final List<String> smooksHandler = new ArrayList<String>();
-    private final List<String> customHandlers = new ArrayList<String>();
-    private final MessagePayloadProxy payloadProxy;
-    private boolean loggingEnabled = false;
+   private final Logger logger = Logger.getLogger(SOAPClient.class);
+   private final String wsdl;
+   private final String soapAction;
+   private final String endPointName;
+   private final String smooksRequestMapperURL;
+   private final String smooksResponseMapperURL;
+   private String serviceName;
+   private final String username;
+   private final String password;
+   // private WSDynamicClient client;
+   private final List<String> smooksHandler = new ArrayList<String>();
+   private final List<String> customHandlers = new ArrayList<String>();
+   private final MessagePayloadProxy payloadProxy;
+   private boolean loggingEnabled = false;
+   private String smooksRequestReport = null;
+   private String smooksResponseReport = null;
 
-    public SOAPClient( ConfigTree config ) throws ConfigurationException {
-        wsdl = config.getRequiredAttribute("wsdl");
-        soapAction = config.getRequiredAttribute("SOAPAction");
-        endPointName = config.getRequiredAttribute("EndPointName");
-        smooksRequestMapperURL = config.getAttribute("SmooksRequestMapper");
-        smooksResponseMapperURL = config.getAttribute("SmooksResponseMapper");
-        serviceName = config.getAttribute("serviceName");
-        serviceName = serviceName != null ? serviceName : wsdl.substring(wsdl.lastIndexOf("/"), wsdl.lastIndexOf("?"));
-        username = config.getAttribute("username");
-        password = config.getAttribute("password");
-        logger.info(config.getAttribute("LoggingMessages"));
-        loggingEnabled = Boolean.parseBoolean(config.getAttribute("LoggingMessages"));
-        logger.info("loggingEnabled:" + loggingEnabled);
-        ConfigTree[] handlersConfig;
-        if (config.getAttribute("smooks-handler-config") != null) {
-            smooksHandler.add(config.getAttribute("smooks-handler-config"));
-        }
-        if (config.getAttribute("custom-handlers") != null) {
-            for (String className : config.getAttribute("custom-handlers").split(";")) {
-                customHandlers.add(className);
-            }
+   private WSMethod method = null;
+   private WSEndpoint endpoint;
 
-        }
-        handlersConfig = config.getChildren("custom-handlers");
+   public SOAPClient(ConfigTree config) throws ConfigurationException
+   {
+      wsdl = config.getRequiredAttribute("wsdl");
+      soapAction = config.getRequiredAttribute("SOAPAction");
+      endPointName = config.getRequiredAttribute("EndPointName");
+      smooksRequestMapperURL = config.getAttribute("SmooksRequestMapper");
+      smooksResponseMapperURL = config.getAttribute("SmooksResponseMapper");
+      serviceName = config.getAttribute("serviceName");
+      serviceName = serviceName != null ? serviceName : wsdl.substring(wsdl.lastIndexOf("/"), wsdl.lastIndexOf("?"));
+      username = config.getAttribute("username");
+      password = config.getAttribute("password");
+      smooksRequestReport = config.getAttribute("smooksRequestReport");
+      smooksResponseReport = config.getAttribute("smooksResponseReport");
+      logger.info(config.getAttribute("LoggingMessages"));
+      loggingEnabled = Boolean.parseBoolean(config.getAttribute("LoggingMessages"));
+      logger.info("loggingEnabled:" + loggingEnabled);
+      ConfigTree[] handlersConfig;
+      if (config.getAttribute("smooks-handler-config") != null)
+      {
+         smooksHandler.add(config.getAttribute("smooks-handler-config"));
+      }
+      if (config.getAttribute("custom-handlers") != null)
+      {
+         for (String className : config.getAttribute("custom-handlers").split(";"))
+         {
+            customHandlers.add(className);
+         }
 
-        payloadProxy = new MessagePayloadProxy(config);
+      }
+      handlersConfig = config.getChildren("custom-handlers");
 
-    }
+      payloadProxy = new MessagePayloadProxy(config);
 
-    @Override
-    public void initialise() throws ActionLifecycleException {
-        super.initialise();
-    }
+   }
 
-    @Override
-    public void destroy() throws ActionLifecycleException {
-    	try {
-            WSDynamicClientFactory.getInstace().clearCache();
-        } catch (Exception e) {
-            throw new ActionLifecycleException("Error durinfg wise client cache cleaning", e);
-        }
-        
-        try {
-            if (smooksRequestMapperURL != null) {
-              SmooksCache.getInstance().put(smooksRequestMapperURL, null);
-            }
-        } catch (Exception e) {
-            throw new ActionLifecycleException("Error while trying to clean SmooksCache", e);
-        }
-        
-        try {
-            if (smooksResponseMapperURL != null) {
-                  SmooksCache.getInstance().put(smooksResponseMapperURL, null);
-            } 
-        } catch (Exception e) {
-            throw new ActionLifecycleException("Error while trying to clean SmooksCache", e);
-        }
-    }
-
-    public Message process( final Message message ) throws ActionProcessingException {
-        Object params;
-        WSDynamicClient client = null;
-        // get client from cache
-        try {
+   @Override
+   public void initialise() throws ActionLifecycleException
+   {
+      super.initialise();
+      try
+      {
+         WSDynamicClientFactory.getInstace().clearCache();
+         SmooksCache.getInstance().clear();
+         Object params;
+         WSDynamicClient client = null;
+         // get client from cache
+         try
+         {
             client = WSDynamicClientFactory.getInstace().getClient(wsdl, serviceName, username, password);
-        } catch (Exception e) {
+         }
+         catch (Exception e)
+         {
             e.printStackTrace();
             throw new ActionProcessingException("Error durinfg wise client creation", e);
-        }
+         }
 
-        try {
-            params = payloadProxy.getPayload(message);
-        } catch (MessageDeliverException e) {
-            throw new ActionProcessingException("Could not locate SOAP message parameters from payload", e);
-        }
+         Map<String, WSEndpoint> endpointsMap = client.processEndpoints();
+         if (endPointName != null)
+         {
+            this.setEndpoint(endpointsMap.get(endPointName));
+         }
+         else
+         {
+            this.setEndpoint(endpointsMap.values().iterator().next());
+         }
 
-        // if (params.isEmpty()) {
-        // logger.warn("Params Map found in message, but the map is empty.");
-        // }
-        Map<String, WSEndpoint> endpointsMap = client.processEndpoints();
-        WSEndpoint endpoint;
-        if (endPointName != null) {
-            endpoint = endpointsMap.get(endPointName);
-        } else {
-            endpoint = endpointsMap.values().iterator().next();
-        }
-
-        for (String config : smooksHandler) {
-            logger.info("adding smooks handler:" + config);
-            if (params instanceof Map) {
-                endpoint.addHandler(new SmooksHandler(config, (Map)params));
-            } else {
-                endpoint.addHandler(new SmooksHandler(config, null));
-            }
-        }
-
-        for (String config : customHandlers) {
+         for (String config : customHandlers)
+         {
             logger.info("adding custom handler:" + config);
-            try {
-                Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(config);
-                endpoint.addHandler((Handler)clazz.newInstance());
-            } catch (Exception e) {
-                logger.info("Failed during custom handler addition:" + e.getLocalizedMessage());
+            try
+            {
+               Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(config);
+               this.getEndpoint().addHandler((Handler)clazz.newInstance());
             }
-        }
+            catch (Exception e)
+            {
+               logger.info("Failed during custom handler addition:" + e.getLocalizedMessage());
+            }
+         }
 
-        if (loggingEnabled) {
+         if (loggingEnabled)
+         {
             logger.info("adding logging handler");
-            endpoint.addHandler(new LoggingHandler());
-        }
+            this.getEndpoint().addHandler(new LoggingHandler());
+         }
+         
+         this.getEndpoint().setUsername(username);
+         this.getEndpoint().setPassword(password);
+         
 
-        Map<String, WSMethod> wsmethodsMap = endpoint.getWSMethods();
+         Map<String, WSMethod> wsmethodsMap = this.getEndpoint().getWSMethods();
+         this.setMethod(wsmethodsMap.get(this.soapAction));
 
-        InvocationResult result;
-        try {
-            WiseMapper mapper = null;
-            if (this.smooksRequestMapperURL != null) {
-                mapper = new SmooksMapper(this.smooksRequestMapperURL, "smook/report/report.html");
-            }
-            result = wsmethodsMap.get(this.soapAction).invoke(params, mapper);
-        } catch (WiseException e) {
-            throw new ActionProcessingException("Could not call method" + this.soapAction, e);
-        }
+      }
+      catch (Exception e)
+      {
+         throw new ActionLifecycleException("Error durinfg wise client cache cleaning", e);
+      }
 
-        WiseMapper mapper = null;
-        if (this.smooksResponseMapperURL != null) {
-            mapper = new SmooksMapper(this.smooksResponseMapperURL, "smook/report/report.html");
-        }
-        // And process the response into the message...
+   }
 
-        try {
-            payloadProxy.setPayload(message, result.getMappedResult(mapper));
-        } catch (Exception e) {
-            throw new ActionProcessingException("Could not set payload to SOAP message", e);
-        }
+   @Override
+   public void destroy() throws ActionLifecycleException
+   {
+      // nop
+   }
 
-        return message;
-    }
+   public Message process(final Message message) throws ActionProcessingException
+   {
+      Object params;
+      WiseMapper responseMapper = null;
+      WiseMapper requestMapper = null;
 
+      if (this.smooksRequestMapperURL != null)
+      {
+         requestMapper = new SmooksMapper(this.smooksRequestMapperURL, this.smooksRequestReport);
+      }
+
+      if (this.smooksResponseMapperURL != null)
+      {
+         responseMapper = new SmooksMapper(this.smooksResponseMapperURL, this.smooksResponseReport);
+      }
+
+      try
+      {
+         params = payloadProxy.getPayload(message);
+      }
+      catch (MessageDeliverException e)
+      {
+         throw new ActionProcessingException("Could not locate SOAP message parameters from payload", e);
+      }
+
+      for (String config : smooksHandler)
+      {
+         logger.info("adding smooks handler:" + config);
+         if (params instanceof Map)
+         {
+            this.getEndpoint().addHandler(new SmooksHandler(config, (Map)params));
+         }
+         else
+         {
+            this.getEndpoint().addHandler(new SmooksHandler(config, null));
+         }
+      }
+
+      InvocationResult result = null;
+      try
+      {
+         result = this.getMethod().invoke(params, requestMapper);
+      }
+      catch (WiseException e)
+      {
+         throw new ActionProcessingException("Could not call method" + this.soapAction, e);
+      }
+
+      try
+      {
+         Map map = result.getMappedResult(responseMapper, (Map)params);
+         payloadProxy.setPayload(message, map);
+      }
+      catch (Exception e)
+      {
+         throw new ActionProcessingException("Could not set payload to SOAP message", e);
+      }
+
+      return message;
+   }
+
+   /**
+    * @return the method
+    */
+   public synchronized WSMethod getMethod()
+   {
+      return method;
+   }
+
+   /**
+    * @param method the method to set
+    */
+   public synchronized void setMethod(WSMethod method)
+   {
+      this.method = method;
+   }
+
+   /**
+    * @return the endpoint
+    */
+   public synchronized WSEndpoint getEndpoint()
+   {
+      return endpoint;
+   }
+
+   /**
+    * @param endpoint the endpoint to set
+    */
+   public synchronized void setEndpoint(WSEndpoint endpoint)
+   {
+      this.endpoint = endpoint;
+   }
+
 }




More information about the jboss-svn-commits mailing list