[jboss-svn-commits] JBL Code SVN: r12915 - 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
Thu Jun 28 04:54:52 EDT 2007


Author: tfennelly
Date: 2007-06-28 04:54:52 -0400 (Thu, 28 Jun 2007)
New Revision: 12915

Modified:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounter.java
   labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/README.TXT
   labs/jbossesb/trunk/product/services/soap/lib/ext/build-time/jboss-jaxws.jar
   labs/jbossesb/trunk/product/services/soap/lib/ext/build-time/jbossws-core.jar
   labs/jbossesb/trunk/product/services/soap/lib/ext/build-time/jbossws-spi.jar
   labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSAdapter.java
Log:
JBossWSAdapter updates to work against the new JBossWS SPI.

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounter.java	2007-06-28 08:54:13 UTC (rev 12914)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounter.java	2007-06-28 08:54:52 UTC (rev 12915)
@@ -99,8 +99,11 @@
 		lastMessageTime = ts.toString();
 		
 		totalProcessTime += msb.getProcessTime();
-		totalBytes += msb.getMessage().getBody().getByteArray().length;
-	}
+        byte[] byteArray = msb.getMessage().getBody().getByteArray();
+        if(byteArray != null) {
+            totalBytes += byteArray.length;
+        }
+    }
 
 	/**
 	 * Get the average time to process a message.

Modified: labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/README.TXT
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/README.TXT	2007-06-28 08:54:13 UTC (rev 12914)
+++ labs/jbossesb/trunk/product/samples/quickstarts/webservice_bpel/README.TXT	2007-06-28 08:54:52 UTC (rev 12915)
@@ -1,31 +1,61 @@
 Overview:
 =========
-   This Quickstart demonsrates how the ActiveBPEL BPEL Engine can be used to
-   orchestrate business process flow through JBoss ESB.
+    This Quickstart demonsrates how the ActiveBPEL BPEL Engine can be used to
+    orchestrate business process flow through JBoss ESB.
 
-   See docs folder.
+    It also demonstrates a number of other features of the ESB:
+    1.  Exposing a Webservice interface for a Service that doesn't have a Webservice
+        interface (using the JBossWSAdapter action).  In this example, the Service being exposed
+        is a legacy EJB based Order Management Service.
+    2.  Easily transforming a CSV based notification message into a Java object that's then used
+        to populate a SOAP request. See next.
+    3.  Making an invocation on an external Webserivce from within an Action Processing
+        Pipeline using the SOAPCleint action.
 
+    See docs folder.
 
+
 Before Running:
 ===============
-1. Update the "org.jboss.esb.server.home" property in the quickstarts.properties
-   file in "../conf".
-2. Make sure you're running the ESB on JBoss AS v4.2.0GA.
-3. Make sure the following ESB components are deployed to your JBoss AS. These
-   components can be located in the "lib" folder of the distro (build/jbossesb/lib
-   if you are working from the SVN source).
-        a) jbossesb.esb
-        b) jbossesb.sar
-        c) soap.esb
-        d) soapui-client.sar
-        e) smooks.esb
-4. Delete the jbm-queue-service.xml file from jbossesb.esb and smooks.esb.
-5. Checkout everything from the following Subversion address and run the
-   Ant script contained therein: http://anonsvn.labs.jboss.com/labs/jbossesb/workspace/jbossws2_0_0/
-6. Start the JBoss App Server.
+    Setting up JBoss App Server (v4.2.0GA):
+    1.  Update the "org.jboss.esb.server.home" property in the quickstarts.properties
+        file in "../conf".
+    2.  Make sure you're running the ESB on JBoss AS v4.2.0GA.
+    3.  Make sure the following ESB components are deployed to your JBoss AS. These
+        components can be located in the "lib" folder of the distro (build/jbossesb/lib
+        if you are working from the SVN source).
+            a) jbossesb.esb
+            b) jbossesb.sar
+            c) soap.esb
+            d) soapui-client.sar
+            e) smooks.esb
+    4.  Delete the jbm-queue-service.xml file from jbossesb.esb and smooks.esb.
+    5.  Checkout everything from the following Subversion address and run the
+        Ant script contained therein: http://anonsvn.labs.jboss.com/labs/jbossesb/workspace/jbossws2_0_0/
+    6.  Start the JBoss App Server.
 
+    Setting up ActiveBPEL:
+    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
+        'webservice_bpel/services/order-manager/order-manager.properties'.
+    2.  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'.
+    3.  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'.
+    4.  Start your Tomcat deployment at '${env.CATALINA_HOME}'.
+    5.  Goto 'Deployed Processes' on the BPEL Console (http://localhost:18080/BpelAdmin) and confirm that
+        the 'Customer' and 'OrderProcess' BPEL processes are deployed.
 
+
 To Run:
 =======
-1. Run "ant clean deploy" from this folder and follow the instructions printed to the
-   console at the end of the deploy.
+    1.  Run "ant clean deploy" from this folder and follow the instructions printed to the
+        console at the end of the deploy.
+    2.  Wait for the quickstart's .esb application to deploy on the App Server - watch the console.
+    3.  Start your favorite SOAP client (e.g. SOAPUI) and load the 'RetailerService' WSDL (http://localhost:18080/active-bpel/services/RetailerService?wsdl).
+    4.  Load the SOAP client with the sample order in 'bpel/resources/sampleData/submit-order-01.xml'.
+    5.  Submit the new order using the SOAP UI client.
+    6.  View the state of the new process in 'Active Processes' on the BPEL Console.  Will appear as 'Running'.
+    7.  Drill into the 'Running' OrderProcess process (select it).
+    8.  Drill down, you will see that the process is waiting on an acknowledgement/notification from the OrderManager service (WaitForNotificationFromOrderManager).
+    9.  Goto http://localhost:8080/order-manager/ (note, not port '18080').  From here, you can approve the order.

Modified: labs/jbossesb/trunk/product/services/soap/lib/ext/build-time/jboss-jaxws.jar
===================================================================
(Binary files differ)

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

Modified: labs/jbossesb/trunk/product/services/soap/lib/ext/build-time/jbossws-spi.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSAdapter.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSAdapter.java	2007-06-28 08:54:13 UTC (rev 12914)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSAdapter.java	2007-06-28 08:54:52 UTC (rev 12915)
@@ -26,8 +26,13 @@
 import java.util.Set;
 import java.util.Map;
 import java.util.HashMap;
+import java.security.Principal;
 
 import javax.management.ObjectName;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
 
 import org.jboss.internal.soa.esb.publish.Publish;
 import org.jboss.soa.esb.ConfigurationException;
@@ -42,20 +47,51 @@
 import org.jboss.soa.esb.message.Message;
 import org.jboss.wsf.spi.deployment.Endpoint;
 import org.jboss.wsf.spi.invocation.BasicInvocationContext;
+import org.jboss.wsf.spi.invocation.RequestHandler;
+import org.jboss.wsf.spi.invocation.AbstractWebServiceContext;
 import org.jboss.wsf.spi.invocation.InvocationContext;
-import org.jboss.wsf.spi.invocation.RequestHandler;
 import org.jboss.wsf.spi.management.EndpointRegistry;
 import org.jboss.wsf.spi.management.EndpointRegistryFactory;
-import org.jboss.ws.core.jaxws.JAXBContextCache;
+import org.jboss.wsf.spi.binding.jaxb.JAXBHandler;
 import org.apache.log4j.Logger;
 import com.sun.xml.bind.api.JAXBRIContext;
 
 /**
  * JBoss Webservices endpoint adapter.
+ * <p/>
+ * This action supports invocation of a JBossWS hosted webservice endpoint through any JBossESB hosted
+ * listener.  This means the ESB can be used to expose Webservice endpoints for Services that don't
+ * already expose a Webservice endpoint.  You can do this by writing a thin Service Wrapper Webservice
+ * (e.g. a JSR 181 implementation) that wraps calls to the target Service (that doesn't have a Webservice endpoint),
+ * exposing that Service via endpoints (listeners) running on the ESB.  This also means that these Services
+ * are invocable over any transport channel supported by the ESB (http, ftp, jms etc).
+ *
+ * <h3>Webservice Endpoint Deployment</h3>
+ * Any JBossWS Webservice endpoint can be exposed via ESB listeners using this action.  That includes endpoints that are deployed
+ * from inside (i.e. the Webservice .war is bundled inside the .esb) and outside (e.g. standalone Webservice .war deployments,
+ * Webservice .war deployments bundled inside a .ear) a .esb deployment.
+ *
+ * <h3>"ESB Message Aware" Webservice Endpoints</h3>
+ * Note that Webservice endpoints exposed via this action have direct access to the current
+ * JBossESB {@link org.jboss.soa.esb.message.Message} instance used to invoke this action's
+ * {@link #process(org.jboss.soa.esb.message.Message)} method.  It can access
+ * the current {@link org.jboss.soa.esb.message.Message} instance via the {@link #getMessage()} method
+ * and can change the {@link org.jboss.soa.esb.message.Message} instance via the
+ * {@link #setMessage(org.jboss.soa.esb.message.Message)} method.  This means that Webservice endpoints
+ * exposed via this action are "ESB Message Aware". 
+ *
+ * <h3>Action Configuration</h3>
+ *
+ *
+ * <h3>Quickstarts</h3>
+ * A number of quickstarts that demonstrate how to use this action are available in the JBossESB
+ * distribution (samples/quickstarts).  See the "webservice_jbossws_adapter_01" and "webservice_bpel"
+ * quickstarts.
+ *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
 @Publish(JBossWSAdapterContractPublisher.class)
-public class JBossWSAdapter extends AbstractActionPipelineProcessor {
+public class JBossWSAdapter extends AbstractActionPipelineProcessor implements JAXBHandler {
 
     public static final String JBOSSWS_ENDPOINT = "jbossws-endpoint";
 
@@ -64,6 +100,7 @@
     private String jbossws_endpoint;
     private ConfigTree config;
     private Map<String, Object> jaxbConfig = new HashMap<String, Object>();
+    private JAXBContext jaxbContext;
 
     /**
      * Public constructor.
@@ -105,25 +142,35 @@
      * Process the SOAP message.
      * <p/>
      * Invokes the JBossWS endpoint and writes the SOAP response back into the message payload.
-     * @param message The SOAP request message.
+     * @param message The ESB Aware (normalized) SOAP request message.
      * @return The SOAP response message.
      * @throws ActionProcessingException
      */
-    public Message process(final Message message) throws ActionProcessingException {
+    public Message process(Message message) throws ActionProcessingException {
         Endpoint endpoint = getServiceEndpoint(jbossws_endpoint);
         byte[] soapMessage;
 
         if(endpoint == null) {
             throw new ActionProcessingException("Unknown Service Endpoint '" + jbossws_endpoint + "'.");
         }
+        final JAXBHandler installedJaxbHandler = endpoint.getJAXBHandler();
+        JBossESBJBossWSJAXBHandler jaxbHandler;
 
+        // Set up the endpoint JAXBHandler for JBossWS...
+        if(installedJaxbHandler instanceof JBossESBJBossWSJAXBHandler) {
+            jaxbHandler = (JBossESBJBossWSJAXBHandler) installedJaxbHandler;
+        } else {
+            jaxbHandler = new JBossESBJBossWSJAXBHandler(installedJaxbHandler, this);
+            endpoint.setJAXBHandler(jaxbHandler);
+        }
+
         soapMessage = getSOAPMessagePayload(message);
         try {
+            jaxbHandler.useAdapterAsHandler();
             messageTL.set(message);
-            JAXBContextCache.setJaxbContextProperties(jaxbConfig);
 
             RequestHandler requestHandler = endpoint.getRequestHandler();
-            BasicInvocationContext invocationContext = new BasicInvocationContext();
+            InvocationContext invocationContext = new JBossESBJBossWSInvocationContext();
             ByteArrayOutputStream os = new ByteArrayOutputStream();
 
             requestHandler.handleRequest(endpoint, new ByteArrayInputStream(soapMessage), os, invocationContext);
@@ -133,7 +180,10 @@
         catch (Exception ex) {
             throw new ActionProcessingException("Cannot process SOAP request", ex);
         } finally {
-            JAXBContextCache.setJaxbContextProperties(null);
+            jaxbHandler.useInstalledHandler();
+            // Get the message instance set on the Threadlocal before removing it.  The Webservice endpoint
+            // may have reset it with a new Message instance.
+            message = messageTL.get();
             messageTL.remove();
         }
 
@@ -157,10 +207,23 @@
         return soapMessage;
     }
 
+    /**
+     * Set the {@link org.jboss.soa.esb.message.Message} instance for this invocation context.
+     * <p/>
+     * This allows message aware Webservice endpoints modify the {@link org.jboss.soa.esb.message.Message}
+     * instance for the current Action Processing Pipeline.
+     *
+     * @param message The new message instance.
+     */
     public static void setMessage(final Message message) {
         messageTL.set(message);
     }
 
+    /**
+     * Get the {@link org.jboss.soa.esb.message.Message} instance for this invocation context.
+     *  
+     * @return The message instance.
+     */
     public static Message getMessage() {
         return messageTL.get();
     }
@@ -184,4 +247,70 @@
 
         return null;
     }
+
+    public JAXBContext getJAXBContext(Class[] classes) throws JAXBException {
+        if(jaxbContext == null) {
+            jaxbContext = JAXBContext.newInstance(classes, jaxbConfig);
+        }
+
+        return jaxbContext;
+    }
+
+    private static class JBossESBJBossWSJAXBHandler implements JAXBHandler {
+        private static ThreadLocal<JAXBHandler> handlerTL =
+                new ThreadLocal<JAXBHandler>();
+        private JAXBHandler installedJaxbHandler;
+        private JBossWSAdapter adapter;
+
+        private JBossESBJBossWSJAXBHandler(JAXBHandler installedJaxbHandler, JBossWSAdapter adapter) {
+            this.installedJaxbHandler = installedJaxbHandler;
+            this.adapter = adapter;
+            handlerTL.set(installedJaxbHandler);
+        }
+
+        public JAXBContext getJAXBContext(Class[] classes) throws JAXBException {
+            return handlerTL.get().getJAXBContext(classes);
+        }
+
+        /**
+         * This method helps ensure that only threads executing out of the
+         * JBossWSAdapter are supplied with JAXBContext instances from the
+         * JBossWSAdapter.  We don't like the idea of not using the installed
+         * JAXBHandler for non ESB initiated JBossWS requests after the
+         * JBossWSAdapter has changed the JAXBHandler for the endpoint.
+         */
+        private void useAdapterAsHandler() {
+            handlerTL.set(adapter);
+        }
+        
+        private void useInstalledHandler() {
+            handlerTL.set(installedJaxbHandler);
+        }
+    }
+
+    private class JBossESBJBossWSInvocationContext extends BasicInvocationContext {
+
+        public <T> T addAttachment(Class<T> aClass, Object object) {
+            if(aClass == WebServiceContext.class) {
+                MessageContext messageContext = ((AbstractWebServiceContext)object).getMessageContext();
+                return super.addAttachment(aClass, new JBossESBJBossWSWebServiceContextJSE(messageContext));
+            } else {
+                return super.addAttachment(aClass, object);
+            }
+        }
+
+        public class JBossESBJBossWSWebServiceContextJSE extends AbstractWebServiceContext {
+            public JBossESBJBossWSWebServiceContextJSE(MessageContext messageContext) {
+                super(messageContext);
+            }
+
+            public Principal getUserPrincipal() {
+                throw new IllegalStateException("Unexpected call to 'getUserPrincipal' on " + getClass().getName());
+            }
+
+            public boolean isUserInRole(String targetProfile) {
+                throw new IllegalStateException("Unexpected call to 'isUserInRole' on " + getClass().getName());
+            }
+        }
+    }
 }
\ No newline at end of file




More information about the jboss-svn-commits mailing list