[jboss-svn-commits] JBL Code SVN: r12072 - in labs/jbossesb/trunk/product: samples/quickstarts/webservice_bpel and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue May 22 08:21:46 EDT 2007


Author: tfennelly
Date: 2007-05-22 08:21:46 -0400 (Tue, 22 May 2007)
New Revision: 12072

Added:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/soap/SOAPClient.java
   labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/OGNLUtils.java
Removed:
   labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/soapui-client/
   labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/src/org/jboss/soa/esb/actions/soap/
Modified:
   labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/build.xml
   labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/jboss-esb.xml
   labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
Log:
soap ui mods

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/soap/SOAPClient.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/soap/SOAPClient.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/soap/SOAPClient.java	2007-05-22 12:21:46 UTC (rev 12072)
@@ -0,0 +1,121 @@
+package org.jboss.soa.esb.actions.soap;
+
+import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.apache.log4j.Logger;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.HttpClient;
+
+import javax.management.*;
+import java.util.Map;
+import java.io.IOException;
+
+/**
+ * SOAP Client action processor.
+ * <p/>
+ * Uses the SOAPUI Client Service to construct an populate a message
+ * for the target service.  This action then routes that message to the service.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class SOAPClient extends AbstractActionPipelineProcessor {
+
+    private Logger logger = Logger.getLogger(SOAPClient.class);
+    private String wsdl;
+    private String operation;
+    private String paramsLocation;
+    private String responseLocation;
+    private MBeanServer mbeanServer;
+    private ObjectName serviceName;
+    private String[] buildRequestSig = new String[] {String.class.getName(), String.class.getName(), Map.class.getName()};
+    private String[] getEndpointSig = new String[] {String.class.getName()};
+
+    public SOAPClient(ConfigTree config) throws ConfigurationException {
+        wsdl = config.getRequiredAttribute("wsdl");
+        operation = config.getRequiredAttribute("operation");
+        paramsLocation = config.getAttribute("paramsLocation");
+        responseLocation = config.getAttribute("responseLocation");
+        mbeanServer = MBeanServerLocator.locate();
+
+        try {
+            serviceName = new ObjectName("jboss.esb:service=SoapUIClientService");
+        } catch (MalformedObjectNameException e) {
+            throw new IllegalStateException("Unexpected exception.", e);
+        }
+    }
+
+    public Message process(final Message message) throws ActionProcessingException {
+        Map params;
+
+        if(paramsLocation != null) {
+            params = (Map) message.getBody().get(paramsLocation);
+        } else {
+            params = (Map) message.getBody().get();
+            if(params == null) {
+                params = (Map) ActionUtils.getTaskObject(message);
+            }
+        }
+        if(params == null) {
+            throw new ActionProcessingException("No params. SOAP message parameters must either be set as the default message body payload, or set on the body under the key defined in the 'paramsLocation' acton property.");
+        } else if(params.isEmpty()) {
+            logger.warn("Params Map found in message, but the map is empty.");
+        }
+
+        String request = buildRequestMessage(params);
+        String response = invokeEndpoint(request);
+
+        if(responseLocation != null) {
+            message.getBody().add(responseLocation, response);
+        } else {
+            message.getBody().add(response);
+            ActionUtils.setTaskObject(message, response);
+        }
+
+        return message;
+    }
+
+    private String buildRequestMessage(Map params) throws ActionProcessingException {
+        try {
+            return (String) mbeanServer.invoke(serviceName, "buildRequest", new Object[] {wsdl, operation, params}, buildRequestSig);
+        } catch (InstanceNotFoundException e) {
+            throw new ActionProcessingException("SOAP UI Client Service not found under name '" + serviceName.getCanonicalName() + "'.  This service must be deployed before this action can be used.", e);
+        } catch (MBeanException e) {
+            throw new ActionProcessingException(e);
+        } catch (ReflectionException e) {
+            throw new ActionProcessingException(e);
+        }
+    }
+
+    private String getEndpoint() throws ActionProcessingException {
+        try {
+            return (String) mbeanServer.invoke(serviceName, "getEndpoint", new Object[] {wsdl}, getEndpointSig);
+        } catch (InstanceNotFoundException e) {
+            throw new ActionProcessingException("SOAP UI Client Service not found under name '" + serviceName.getCanonicalName() + "'.  This service must be deployed before this action can be used.", e);
+        } catch (MBeanException e) {
+            throw new ActionProcessingException(e);
+        } catch (ReflectionException e) {
+            throw new ActionProcessingException(e);
+        }
+    }
+
+    private String invokeEndpoint(String request) throws ActionProcessingException {
+        PostMethod post = new PostMethod(getEndpoint());
+
+        post.setRequestHeader("SOAPAction", operation);
+        post.setRequestBody(request);
+        HttpClient httpclient = new HttpClient();
+        try {
+            int result = httpclient.executeMethod(post);
+            return post.getResponseBodyAsString();
+        } catch (IOException e) {
+            throw new ActionProcessingException("Failed to invoke SOAP Endpoint: '" + getEndpoint() + " ' - '" + operation + "'.", e);
+        } finally {
+            post.releaseConnection();
+        }
+    }
+}


Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/soap/SOAPClient.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/build.xml	2007-05-22 12:17:10 UTC (rev 12071)
+++ labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/build.xml	2007-05-22 12:21:46 UTC (rev 12072)
@@ -40,9 +40,6 @@
                 <include name="**/*"/>
             </fileset>
         </war>
-
-        <!-- Build the SOAPUI Client Service. -->
-        <ant dir="${basedir}/soapui-client" />
     </target>
 
     <target name="quickstart-specific-deploys">
@@ -50,7 +47,6 @@
         <copy overwrite="true" todir="${org.jboss.esb.server.deploy.dir}">
             <fileset dir="${build.dir}/order-manager" includes="order-manager-service.jar,order-manager.war" />
             <fileset dir="${build.dir}/shipping" includes="shipping-service.jar" />
-            <fileset dir="${basedir}/soapui-client/target" includes="soapui-client.sar" />
         </copy>
 
         <!-- Deploy the ActiveBPEL components. -->
@@ -69,18 +65,19 @@
         <echo message='${line.separator}******************' />
         <echo>Quickstart deployed to target JBoss ESB/App Server at '${org.jboss.esb.server.deploy.dir}'.</echo>
         <echo>1.   Ensure that the value of the 'directory' attribute on the 'notificationChannel' (jboss-esb.xml) matches the value of the 'order.approval.drop.location' property in 'services/order-manager/order-manager.properties'.</echo>
-        <echo>2.   Check your ESB Server console to make sure the deployment was executed without errors.</echo>
-        <echo>3.   Make sure your Tomcat deployment at '${env.CATALINA_HOME}' is configured such that it's ports do not clash with those of your running JBoss AS. See '${env.CATALINA_HOME}/conf/server.xml'.</echo>
-        <echo>4.   Make sure your Tomcat deployment at '${env.CATALINA_HOME}' is configured to listen for HTTP traffic on port 18080. See '${env.CATALINA_HOME}/conf/server.xml'.</echo>
-        <echo>5.   Start your Tomcat deployment at '${env.CATALINA_HOME}'.</echo>
-        <echo>6.   Goto 'Deployed Processes' on the BPEL Console (http://localhost:18080/BpelAdmin) and confirm that the 'Customer' and 'OrderProcess' BPEL processes are deployed.</echo>
-        <echo>7.   Start your favorite SOAP client (e.g. SOAPUI) and load the 'RetailerService' WSDL (http://localhost:18080/active-bpel/services/RetailerService?wsdl).</echo>
-        <echo>8.   Load the SOAP client with the sample order in 'bpel/resources/sampleData/submit-order-01.xml'.</echo>
-        <echo>9.   Submit the new order using the SOAP UI client.</echo>
-        <echo>10.  View the state of the new process in 'Active Processes' on the BPEL Console.  Will appear as 'Running'.</echo>
-        <echo>11.  Drill into the 'Running' OrderProcess process (select it).</echo>
-        <echo>12.  Drill down, you will see that the process is waiting on an acknowledgement/notification from the OrderManager service (WaitForNotificationFromOrderManager).</echo>
-        <echo>13.  Goto http://localhost:8080/order-manager/ (note, not port '18080').  From here, you can approve the order.</echo>        
+        <echo>2.   Check your JBoss App Server deployment folder to make sure the "soapui-client.sar" service is deployed.  This .sar can be found in the "services" folder of the distribution.</echo>
+        <echo>3.   Check your JBoss App Server console to make sure the deployment was executed without errors.</echo>
+        <echo>4.   Make sure your Tomcat deployment at '${env.CATALINA_HOME}' is configured such that it's ports do not clash with those of your running JBoss AS. See '${env.CATALINA_HOME}/conf/server.xml'.</echo>
+        <echo>5.   Make sure your Tomcat deployment at '${env.CATALINA_HOME}' is configured to listen for HTTP traffic on port 18080. See '${env.CATALINA_HOME}/conf/server.xml'.</echo>
+        <echo>6.   Start your Tomcat deployment at '${env.CATALINA_HOME}'.</echo>
+        <echo>7.   Goto 'Deployed Processes' on the BPEL Console (http://localhost:18080/BpelAdmin) and confirm that the 'Customer' and 'OrderProcess' BPEL processes are deployed.</echo>
+        <echo>8.   Start your favorite SOAP client (e.g. SOAPUI) and load the 'RetailerService' WSDL (http://localhost:18080/active-bpel/services/RetailerService?wsdl).</echo>
+        <echo>9.   Load the SOAP client with the sample order in 'bpel/resources/sampleData/submit-order-01.xml'.</echo>
+        <echo>10.   Submit the new order using the SOAP UI client.</echo>
+        <echo>11.  View the state of the new process in 'Active Processes' on the BPEL Console.  Will appear as 'Running'.</echo>
+        <echo>12.  Drill into the 'Running' OrderProcess process (select it).</echo>
+        <echo>13.  Drill down, you will see that the process is waiting on an acknowledgement/notification from the OrderManager service (WaitForNotificationFromOrderManager).</echo>
+        <echo>14.  Goto http://localhost:8080/order-manager/ (note, not port '18080').  From here, you can approve the order.</echo>        
         <echo message='******************' />
     </target>
 
@@ -111,8 +108,4 @@
         </jar>
     </target>
 
-    <target name="quickstart-specific-clean">
-        <ant dir="${basedir}/soapui-client" target="clean" />
-    </target>
-
 </project>
\ No newline at end of file

Modified: labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/jboss-esb.xml	2007-05-22 12:17:10 UTC (rev 12071)
+++ labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/jboss-esb.xml	2007-05-22 12:21:46 UTC (rev 12072)
@@ -120,13 +120,13 @@
                     <property name="to-type" value="text/xml:SendSalesOrderNotification"/>
                 </action>
                 <action name="print-after-transform" class="org.jboss.soa.esb.actions.SystemPrintln">
-                    <property name="message" value="[Quickstart_webservice_bpel] Message after transform and before SOAPUI"/>
+                    <property name="message" value="[Quickstart_webservice_bpel] Message after transform and before SOAPClient"/>
                 </action>
                 <!-- Inject the com.activebpel.ordermanagement.SalesOrderNotification instance
-                     into the SOAPUIClient. SOAPUIClient will use SOAPUI to construct a soap request
+                     into the SOAPClient. SOAPClient will use SOAPUI to construct a soap request
                      template and will then use OGNL to populate the values (from the Smooks 
                      EXTRACTED_BEANS_HASH) into the soap message. -->
-                <action name="soapui-client" class="org.jboss.soa.esb.actions.soap.SOAPUIClient">
+                <action name="soapui-client" class="org.jboss.soa.esb.actions.soap.SOAPClient">
                     <property name="wsdl" value="http://localhost:18080/active-bpel/services/RetailerCallback?wsdl"/>
                     <property name="operation" value="SendSalesOrderNotification"/>
                     <property name="paramsLocation" value="EXTRACTED_BEANS_HASH"/>

Added: labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/OGNLUtils.java
===================================================================
--- labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/OGNLUtils.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/OGNLUtils.java	2007-05-22 12:21:46 UTC (rev 12072)
@@ -0,0 +1,98 @@
+/*
+	Milyn - Copyright (C) 2006
+
+	This library is free software; you can redistribute it and/or
+	modify it under the terms of the GNU Lesser General Public
+	License (version 2.1) as published by the Free Software
+	Foundation.
+
+	This library is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+	See the GNU Lesser General Public License for more details:
+	http://www.gnu.org/licenses/lgpl.txt
+*/
+package org.jboss.soa.esb.services.soapui;
+
+import ognl.Ognl;
+import ognl.OgnlException;
+
+import java.util.Map;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.apache.log4j.Logger;
+
+/**
+ * OGNL Utilities for the SOAP UI Client service.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class OGNLUtils {
+
+    private static Logger logger = Logger.getLogger(OGNLUtils.class);
+
+    public static Object getParameter(String ognl, Map params) {
+        Object param;
+
+        // Try getting the parameter from the params Map using the
+        // raw OGNL expression as the key...
+        param = params.get(ognl);
+        if(param == null) {
+            // And if that didn't work, try using the OGNL expression to extract the param
+            // from an Object Graph using the OGNL toolkit...
+            try {
+                param = Ognl.getValue(ognl, params);
+            } catch (OgnlException ex) {
+                if(logger.isDebugEnabled()) {
+                    logger.debug("OGNL Error.", ex);
+                }
+            }
+        }
+
+        return (param != null?param:"");
+    }
+
+    public static String getOGNLExpression(Element element) {
+        StringBuffer xpath = new StringBuffer();
+        Node parent = element.getParentNode();
+
+        xpath.append(getOGNLToken(element));
+
+        while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
+            if (parent.getLocalName().equalsIgnoreCase("body") &&
+                    parent.getNamespaceURI().equalsIgnoreCase("http://schemas.xmlsoap.org/soap/envelope/")) {
+                break;
+            }
+
+            Element parentElement = (Element) parent;
+            String preassignedOgnl = parentElement.getAttributeNS(SoapUIClientService.SOAPUICL_NS, SoapUIClientService.OGNL_ATTRIB);
+            if(preassignedOgnl != null && !preassignedOgnl.equals("")) {
+                xpath.insert(0, "." + preassignedOgnl);
+                break;
+            } else {
+                xpath.insert(0, getOGNLToken(parentElement));
+            }
+            parent = parent.getParentNode();
+        }
+
+        // Remove the leading '.'
+        xpath.deleteCharAt(0);
+
+        return xpath.toString();
+    }
+
+    public static String getOGNLToken(Element element) {
+        String localName = element.getLocalName();
+        int count = DomUtils.countElementsBefore(element, element.getTagName());
+        String xpathToken;
+
+        if (count > 0) {
+            xpathToken = "." + localName + "[" + (count + 1) + "]";
+        } else {
+            xpathToken = "." + localName;
+        }
+
+        return xpathToken;
+    }
+}


Property changes on: labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/OGNLUtils.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
===================================================================
--- labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java	2007-05-22 12:17:10 UTC (rev 12071)
+++ labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java	2007-05-22 12:21:46 UTC (rev 12072)
@@ -36,11 +36,7 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerFactory;
 
-import ognl.OgnlException;
-import ognl.Ognl;
-
 /**
  * Soap UI Soap Client Service MBean.
  *
@@ -48,10 +44,10 @@
  */
 public class SoapUIClientService extends ServiceMBeanSupport implements SoapUIClientServiceMBean {
 
-    private static final String SOAPUICL_NS = "http://jbossesb.jboss.org/soapui-client";
-    private static final String SOAPUICL_NS_PREFIX = "soapui:";
-    private static final String IS_CLONE_ATTRIB = "is-clone";
-    private static final String OGNL_ATTRIB = "ognl";
+    protected static final String SOAPUICL_NS = "http://jbossesb.jboss.org/soapui-client";
+    protected static final String SOAPUICL_NS_PREFIX = "soapui:";
+    protected static final String IS_CLONE_ATTRIB = "is-clone";
+    protected static final String OGNL_ATTRIB = "ognl";
     private static Logger logger = Logger.getLogger(SoapUIClientService.class);
     private Map<String, WsdlInterface[]> wsdls = new HashMap<String, WsdlInterface[]>();
     private DocumentBuilder docBuilder;
@@ -166,29 +162,23 @@
 
         // If this element is not a cloned element, check does it need to be cloned...
         if(!element.hasAttributeNS(SOAPUICL_NS, IS_CLONE_ATTRIB)) {
-            String ognl = getOGNLExpression(element);
+            String ognl = OGNLUtils.getOGNLExpression(element);
             Object param;
-            try {
-                param = Ognl.getValue(ognl, params);
-                if(param != null) {
-                    Class paramRuntime = param.getClass();
+            param = OGNLUtils.getParameter(ognl, params);
+            if(param != null) {
+                Class paramRuntime = param.getClass();
 
-                    if(paramRuntime.isArray()) {
-                        Element item = getCollectionItemElement(element);
-                        // It's an "array" containing node.  Grab the first/only
-                        // Element in it and clone it the required number of times.
-                        cloneCollectionTemplateElement(item, ((Object[])param).length - 1, ognl);
-                    } else if(Collection.class.isAssignableFrom(paramRuntime)) {
-                        Element item = getCollectionItemElement(element);
-                        // It's a "collection" containing node.  Grab the first/only
-                        // Element in it and clone it the required number of times.
-                        cloneCollectionTemplateElement(item, ((Collection)param).size() - 1, ognl);
-                    }
+                if(paramRuntime.isArray()) {
+                    Element item = getCollectionItemElement(element);
+                    // It's an "array" containing node.  Grab the first/only
+                    // Element in it and clone it the required number of times.
+                    cloneCollectionTemplateElement(item, ((Object[])param).length - 1, ognl);
+                } else if(Collection.class.isAssignableFrom(paramRuntime)) {
+                    Element item = getCollectionItemElement(element);
+                    // It's a "collection" containing node.  Grab the first/only
+                    // Element in it and clone it the required number of times.
+                    cloneCollectionTemplateElement(item, ((Collection)param).size() - 1, ognl);
                 }
-            } catch (OgnlException ex) {
-                if(logger.isDebugEnabled()) {
-                    logger.debug("OGNL Error.", ex);
-                }
             }
         }
 
@@ -266,14 +256,10 @@
 
             if (childCount == 1 && node.getNodeType() == Node.TEXT_NODE) {
                 if (node.getTextContent().equals("?")) {
-                    String ognl = getOGNLExpression(element);
+                    String ognl = OGNLUtils.getOGNLExpression(element);
                     Object param;
 
-                    try {
-                        param = Ognl.getValue(ognl, params);
-                    } catch (OgnlException ex) {
-                        param = "";
-                    }
+                    param = OGNLUtils.getParameter(ognl, params);
 
                     element.removeChild(node);
                     element.appendChild(element.getOwnerDocument().createTextNode(param.toString()));
@@ -287,47 +273,4 @@
         element.removeAttributeNS(SOAPUICL_NS, OGNL_ATTRIB);
     }
 
-    private String getOGNLExpression(Element element) {
-        StringBuffer xpath = new StringBuffer();
-        Node parent = element.getParentNode();
-
-        xpath.append(getOGNLToken(element));
-
-        while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
-            if (parent.getLocalName().equalsIgnoreCase("body") &&
-                    parent.getNamespaceURI().equalsIgnoreCase("http://schemas.xmlsoap.org/soap/envelope/")) {
-                break;
-            }
-
-            Element parentElement = (Element) parent;
-            String preassignedOgnl = parentElement.getAttributeNS(SOAPUICL_NS, OGNL_ATTRIB);
-            if(preassignedOgnl != null && !preassignedOgnl.equals("")) {
-                xpath.insert(0, "." + preassignedOgnl);
-                break;
-            } else {
-                xpath.insert(0, getOGNLToken(parentElement));
-            }
-            parent = parent.getParentNode();
-        }
-
-        // Remove the leading '.'
-        xpath.deleteCharAt(0);
-
-        return xpath.toString();
-    }
-
-    private String getOGNLToken(Element element) {
-        String localName = element.getLocalName();
-        int count = DomUtils.countElementsBefore(element, element.getTagName());
-        String xpathToken;
-
-        if (count > 0) {
-            xpathToken = "." + localName + "[" + (count + 1) + "]";
-        } else {
-            xpathToken = "." + localName;
-        }
-
-        return xpathToken;
-    }
-
 }




More information about the jboss-svn-commits mailing list