[jbossws-commits] JBossWS SVN: r3713 - in branches/jbossws-2.0/integration: spi/src/main/java/org/jboss/wsf/spi and 2 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Mon Jun 25 09:58:16 EDT 2007


Author: thomas.diesler at jboss.com
Date: 2007-06-25 09:58:16 -0400 (Mon, 25 Jun 2007)
New Revision: 3713

Added:
   branches/jbossws-2.0/integration/jboss42/src/main/java/org/jboss/wsf/container/jboss42/InvocationHandlerMDB21.java
   branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/
   branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/
   branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/JMSMessageDispatcher.java
   branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/JMSTransportSupport.java
   branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/MessageDispatcher.java
Log:
Restore MDB endpoint invocations - more to come

Added: branches/jbossws-2.0/integration/jboss42/src/main/java/org/jboss/wsf/container/jboss42/InvocationHandlerMDB21.java
===================================================================
--- branches/jbossws-2.0/integration/jboss42/src/main/java/org/jboss/wsf/container/jboss42/InvocationHandlerMDB21.java	                        (rev 0)
+++ branches/jbossws-2.0/integration/jboss42/src/main/java/org/jboss/wsf/container/jboss42/InvocationHandlerMDB21.java	2007-06-25 13:58:16 UTC (rev 3713)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.container.jboss42;
+
+// $Id: InvocationHandlerEJB21.java 3524 2007-06-09 17:28:37Z thomas.diesler at jboss.com $
+
+import java.lang.reflect.Method;
+
+import org.jboss.logging.Logger;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.invocation.AbstractInvocationHandler;
+import org.jboss.wsf.spi.invocation.Invocation;
+
+/**
+ * Handles invocations on MDB EJB21 endpoints.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 25-Apr-2007
+ */
+public class InvocationHandlerMDB21 extends AbstractInvocationHandler
+{
+   // provide logging
+   private static final Logger log = Logger.getLogger(InvocationHandlerMDB21.class);
+   
+   private static ThreadLocal mdbAssociation = new ThreadLocal();
+   
+   public Object getTargetBean() 
+   {
+      Object targetBean = mdbAssociation.get();
+      return targetBean;
+   }
+   
+   public static void setTargetBean(Object targetBean)
+   {
+      mdbAssociation.set(targetBean);
+   }
+
+   public void invoke(Endpoint ep, Invocation epInv) throws Exception
+   {
+      log.debug("Invoke: " + epInv.getJavaMethod().getName());
+
+      try
+      {
+         Object targetBean = getTargetBean();
+         Class implClass = targetBean.getClass();
+         Method seiMethod = epInv.getJavaMethod();
+         Method implMethod = getImplMethod(implClass, seiMethod);
+
+         Object[] args = epInv.getArgs();
+         Object retObj = implMethod.invoke(targetBean, args);
+         epInv.setReturnValue(retObj);
+      }
+      catch (Exception e)
+      {
+         handleInvocationException(e);
+      }
+      finally
+      {
+         setTargetBean(null);
+      }
+   }
+}

Added: branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/JMSMessageDispatcher.java
===================================================================
--- branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/JMSMessageDispatcher.java	                        (rev 0)
+++ branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/JMSMessageDispatcher.java	2007-06-25 13:58:16 UTC (rev 3713)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.spi.transport.jms;
+
+// $Id:JMSMessageDispatcher.java 915 2006-09-08 08:40:45Z thomas.diesler at jboss.com $
+
+import java.io.InputStream;
+import java.rmi.RemoteException;
+
+import javax.management.ObjectName;
+import javax.xml.rpc.handler.soap.SOAPMessageContext;
+import javax.xml.soap.SOAPMessage;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.NotImplementedException;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.invocation.BasicInvocationContext;
+import org.jboss.wsf.spi.invocation.InvocationContext;
+import org.jboss.wsf.spi.invocation.InvocationHandler;
+import org.jboss.wsf.spi.invocation.RequestHandler;
+import org.jboss.wsf.spi.management.EndpointRegistry;
+import org.jboss.wsf.spi.management.EndpointRegistryFactory;
+
+/**
+ * A dispatcher for SOAPMessages
+ *  
+ * @author Thomas.Diesler at jboss.org
+ */
+public class JMSMessageDispatcher implements MessageDispatcher
+{
+   // logging support
+   protected Logger log = Logger.getLogger(JMSMessageDispatcher.class);
+
+   /** Dispatch the message to the underlying SOAP engine
+    */
+   public SOAPMessage dipatchMessage(String fromName, Object targetBean, InputStream inputStream) throws RemoteException
+   {
+      EndpointRegistry epRegistry = EndpointRegistryFactory.getEndpointRegistry();
+      Endpoint endpoint = getEndpointForDestination(epRegistry, fromName);
+
+      if (endpoint == null)
+         throw new IllegalStateException("Cannot find endpoint for: " + fromName);
+
+      log.debug("dipatchMessage: " + endpoint.getName());
+
+      RequestHandler reqHandler = endpoint.getRequestHandler();
+      InvocationHandler invHandler = endpoint.getInvocationHandler();
+      
+      try
+      {
+         BasicInvocationContext context = new BasicInvocationContext();
+         reqHandler.handleRequest(endpoint, inputStream, null, context);
+         SOAPMessage resMessage = getResponseMessage(context);
+         return resMessage;
+      }
+      catch (Exception ex)
+      {
+         throw new RemoteException("Cannot process SOAP request", ex);
+      }
+   }
+
+   private SOAPMessage getResponseMessage(InvocationContext context)
+   {
+      SOAPMessage resMessage = null;
+      if (context.getAttachment(javax.xml.rpc.handler.MessageContext.class) != null)
+      {
+         javax.xml.rpc.handler.MessageContext msgContext = context.getAttachment(javax.xml.rpc.handler.MessageContext.class);
+         SOAPMessageContext soapContext = (SOAPMessageContext)msgContext;
+         resMessage = soapContext.getMessage();
+      }
+      return resMessage;
+   }
+
+   /** Dispatch the message to the underlying SOAP engine
+    */
+   public SOAPMessage delegateMessage(String serviceID, InputStream soapMessage) throws RemoteException
+   {
+      throw new NotImplementedException();
+   }
+
+   // The destination jndiName is encoded in the service object name under key 'jms'
+   private Endpoint getEndpointForDestination(EndpointRegistry epRegistry, String fromName)
+   {
+      Endpoint endpoint = null;
+      for (ObjectName oname : epRegistry.getEndpoints())
+      {
+         Endpoint aux = epRegistry.getEndpoint(oname);
+         String jmsProp = aux.getName().getKeyProperty("jms");
+         if (jmsProp != null && jmsProp.equals(fromName))
+         {
+            endpoint = aux;
+            break;
+         }
+      }
+      return endpoint;
+   }
+}

Added: branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/JMSTransportSupport.java
===================================================================
--- branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/JMSTransportSupport.java	                        (rev 0)
+++ branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/JMSTransportSupport.java	2007-06-25 13:58:16 UTC (rev 3713)
@@ -0,0 +1,241 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.spi.transport.jms;
+
+// $Id:JMSTransportSupport.java 915 2006-09-08 08:40:45Z thomas.diesler at jboss.com $
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.rmi.RemoteException;
+
+import javax.ejb.EJBException;
+import javax.ejb.MessageDrivenBean;
+import javax.ejb.MessageDrivenContext;
+import javax.jms.BytesMessage;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.NestedRuntimeException;
+
+/**
+ * The abstract base class for MDBs that want to act as web service endpoints.
+ * A subclass should only need to implement the service endpoint interface.
+ *
+ * @author Thomas.Diesler at jboss.org
+ */
+public abstract class JMSTransportSupport implements MessageDrivenBean, MessageListener
+{
+   // logging support
+   protected Logger log = Logger.getLogger(JMSTransportSupport.class);
+
+   //private MessageDrivenContext mdbCtx;
+   private QueueConnectionFactory queueFactory;
+
+   /**
+    * All messages come in here, if it is a BytesMessage we pass it on for further processing.
+    */
+   public void onMessage(Message message)
+   {
+      try
+      {
+         String msgStr = null;
+         if (message instanceof BytesMessage)
+         {
+            msgStr = getMessageStr((BytesMessage)message);
+         }
+         else if (message instanceof TextMessage)
+         {
+            msgStr = ((TextMessage)message).getText();
+         }
+         else
+         {
+            log.warn("Invalid message type: " + message);
+            return;
+         }
+
+         log.debug("Incomming SOAP message: " + msgStr);
+
+         String fromName = null;
+         Destination destination = message.getJMSDestination();
+         if (destination instanceof Queue)
+            fromName = "queue/" + ((Queue)destination).getQueueName();
+         if (destination instanceof Topic)
+            fromName = "topic/" + ((Topic)destination).getTopicName();
+
+         InputStream reqMessage = new ByteArrayInputStream(msgStr.getBytes());
+         SOAPMessage resMessage = processSOAPMessage(fromName, reqMessage);
+
+         if (resMessage != null)
+         {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            resMessage.writeTo(baos);
+
+            msgStr = new String(baos.toByteArray());
+            log.debug("Outgoing SOAP message: " + msgStr);
+
+            Queue replyQueue = getReplyQueue(message);
+            if (replyQueue != null)
+            {
+               sendResponse(replyQueue, msgStr);
+            }
+            else
+            {
+               log.warn("No reply queue, ignore response message");
+            }
+         }
+         else
+         {
+            log.debug("SOAP response message is null");
+         }
+      }
+      catch (RuntimeException rte)
+      {
+         throw rte;
+      }
+      catch (Exception e)
+      {
+         throw new EJBException(e);
+      }
+   }
+
+   protected SOAPMessage processSOAPMessage(String fromName, InputStream reqMessage) throws SOAPException, IOException, RemoteException
+   {
+      MessageDispatcher msgDispatcher = new JMSMessageDispatcher();
+      SOAPMessage resMessage = msgDispatcher.dipatchMessage(fromName, this, reqMessage);
+      return resMessage;
+   }
+
+   private String getMessageStr(BytesMessage message) throws Exception
+   {
+      byte[] buffer = new byte[8 * 1024];
+      ByteArrayOutputStream out = new ByteArrayOutputStream(buffer.length);
+      int read = message.readBytes(buffer);
+      while (read != -1)
+      {
+         out.write(buffer, 0, read);
+         read = message.readBytes(buffer);
+      }
+
+      byte[] msgBytes = out.toByteArray();
+      return new String(msgBytes);
+   }
+
+   /**
+    * Get the reply queue.
+    */
+   protected Queue getReplyQueue(Message message) throws JMSException
+   {
+      Queue replyQueue = (Queue)message.getJMSReplyTo();
+      return replyQueue;
+   }
+
+   /**
+    * Respond to the call by sending a message to the reply queue
+    */
+   protected void sendResponse(Queue replyQueue, String msgStr) throws SOAPException, IOException, JMSException
+   {
+      QueueConnection qc = queueFactory.createQueueConnection();
+      QueueSession session = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      QueueSender sender = null;
+      try
+      {
+         sender = session.createSender(replyQueue);
+         TextMessage responseMessage = session.createTextMessage(msgStr);
+         sender.send(responseMessage);
+         log.info("Sent response");
+      }
+      finally
+      {
+         try
+         {
+            sender.close();
+         }
+         catch (JMSException ignored)
+         {
+         }
+         try
+         {
+            session.close();
+         }
+         catch (JMSException ignored)
+         {
+         }
+         try
+         {
+            qc.close();
+         }
+         catch (JMSException ignored)
+         {
+         }
+      }
+   }
+
+   // MDB lifecycle methods ********************************************************************************************
+
+   public void ejbCreate()
+   {
+      try
+      {
+         InitialContext ctx = new InitialContext();
+         queueFactory = (QueueConnectionFactory)ctx.lookup("java:/ConnectionFactory");
+      }
+      catch (RuntimeException rte)
+      {
+         throw rte;
+      }
+      catch (Exception e)
+      {
+         throw new NestedRuntimeException(e);
+      }
+   }
+
+   /**
+    * A container invokes this method before it ends the life of the message-driven object.
+    */
+   public void ejbRemove() throws EJBException
+   {
+   }
+
+   /**
+    * Set the associated message-driven context.
+    */
+   public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException
+   {
+      //this.mdbCtx = ctx;
+   }
+}

Added: branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/MessageDispatcher.java
===================================================================
--- branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/MessageDispatcher.java	                        (rev 0)
+++ branches/jbossws-2.0/integration/spi/src/main/java/org/jboss/wsf/spi/transport/jms/MessageDispatcher.java	2007-06-25 13:58:16 UTC (rev 3713)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.spi.transport.jms;
+
+// $Id:MessageDispatcher.java 898 2006-09-05 08:23:03Z thomas.diesler at jboss.com $
+
+import java.io.InputStream;
+import java.rmi.RemoteException;
+
+import javax.management.ObjectName;
+import javax.xml.soap.SOAPMessage;
+
+import org.jboss.wsf.spi.utils.ObjectNameFactory;
+
+/**
+ * A dispatcher for SOAPMessages 
+ * 
+ * @author Thomas.Diesler at jboss.org
+ * @since 19-Feb-2006
+ */
+public interface MessageDispatcher
+{
+   public static final ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss.ws:service=JMSTransportSupport");
+   
+   /** Dispatch the message to the underlying SOAP engine
+    */
+   SOAPMessage dipatchMessage(String fromName, Object targetImplBean, InputStream reqMessage) throws RemoteException;
+   
+   /** Dispatch the message to the underlying SOAP engine
+    */
+   SOAPMessage delegateMessage(String serviceID, InputStream reqMessage) throws RemoteException;
+}
\ No newline at end of file




More information about the jbossws-commits mailing list