[jboss-svn-commits] JBossWS SVN: r1010 - in branches/jbossws-1.0.3.GA_JBWS-1210/src: main/java/org/jboss/ws main/java/org/jboss/ws/integration/jboss main/java/org/jboss/ws/integration/jboss/jms test test/java/org/jboss/test/ws/samples/jmstransport
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Sep 19 10:03:32 EDT 2006
Author: darran.lofthouse at jboss.com
Date: 2006-09-19 10:03:26 -0400 (Tue, 19 Sep 2006)
New Revision: 1010
Added:
branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/
branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/JMSMessageDispatcher.java
branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/JMSTransportSupport.java
branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/MessageDispatcher.java
Removed:
branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/transport/
Modified:
branches/jbossws-1.0.3.GA_JBWS-1210/src/test/build.xml
branches/jbossws-1.0.3.GA_JBWS-1210/src/test/java/org/jboss/test/ws/samples/jmstransport/OrganizationJMSEndpoint.java
Log:
JBWS-1210 - Fork JMSTransportSupport so SOAPMessageContextImpl can be set before the call and removed after the call.
Copied: branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/JMSMessageDispatcher.java (from rev 990, tags/jbossws-1.0.3.GA/src/main/java/org/jboss/ws/transport/jms/JMSMessageDispatcher.java)
===================================================================
--- tags/jbossws-1.0.3.GA/src/main/java/org/jboss/ws/transport/jms/JMSMessageDispatcher.java 2006-09-19 08:34:11 UTC (rev 990)
+++ branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/JMSMessageDispatcher.java 2006-09-19 14:03:26 UTC (rev 1010)
@@ -0,0 +1,106 @@
+/*
+ * 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.ws.integration.jboss.jms;
+
+// $Id: JMSMessageDispatcher.java 356 2006-05-16 17:26:40Z 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.logging.Logger;
+import org.jboss.util.NotImplementedException;
+import org.jboss.ws.WSException;
+import org.jboss.ws.binding.BindingException;
+import org.jboss.ws.integration.jboss.ServiceEndpointInvokerMDB;
+import org.jboss.ws.server.ServiceEndpoint;
+import org.jboss.ws.server.ServiceEndpointInvoker;
+import org.jboss.ws.server.ServiceEndpointManager;
+import org.jboss.ws.server.ServiceEndpointManagerFactory;
+
+/**
+ * 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 reqMessage) throws RemoteException
+ {
+ try
+ {
+ ServiceEndpointManagerFactory factory = ServiceEndpointManagerFactory.getInstance();
+ ServiceEndpointManager epManager = factory.getServiceEndpointManager();
+ ObjectName sepID = getServiceEndpointForDestination(epManager, fromName);
+
+ if (sepID == null)
+ throw new WSException("Cannot find serviceID for: " + fromName);
+
+ log.debug("dipatchMessage: " + sepID);
+
+ // Setup the MDB invoker
+ ServiceEndpoint sep = epManager.getServiceEndpointByID(sepID);
+ ServiceEndpointInvoker invoker = sep.getServiceEndpointInfo().getInvoker();
+ if (invoker instanceof ServiceEndpointInvokerMDB)
+ {
+ ServiceEndpointInvokerMDB mdbInvoker = (ServiceEndpointInvokerMDB)invoker;
+ mdbInvoker.setTargetBeanObject(targetBean);
+ }
+
+ return sep.handleRequest(null, null, reqMessage);
+ }
+ catch (BindingException ex)
+ {
+ throw new WSException("Cannot bind incomming soap message", ex);
+ }
+ }
+
+ /** 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 ObjectName getServiceEndpointForDestination(ServiceEndpointManager epManager, String fromName)
+ {
+ ObjectName sepID = null;
+ for (ObjectName aux : epManager.getServiceEndpoints())
+ {
+ String jmsProp = aux.getKeyProperty("jms");
+ if (jmsProp != null && jmsProp.equals(fromName))
+ {
+ sepID = aux;
+ break;
+ }
+ }
+ return sepID;
+ }
+}
Added: branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/JMSTransportSupport.java
===================================================================
--- branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/JMSTransportSupport.java 2006-09-19 13:55:01 UTC (rev 1009)
+++ branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/JMSTransportSupport.java 2006-09-19 14:03:26 UTC (rev 1010)
@@ -0,0 +1,245 @@
+/*
+ * 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.ws.integration.jboss.jms;
+
+// $Id$
+
+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;
+import org.jboss.ws.soap.MessageContextAssociation;
+import org.jboss.ws.soap.SOAPMessageContextImpl;
+
+/**
+ * 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();
+
+ SOAPMessageContextImpl messageContext = new SOAPMessageContextImpl();
+ MessageContextAssociation.pushMessageContext(messageContext);
+
+ try
+ {
+ 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");
+ }
+ }
+ finally
+ {
+ MessageContextAssociation.popMessageContext();
+ }
+ }
+ 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 (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;
+ }
+}
Property changes on: branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/JMSTransportSupport.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/MessageDispatcher.java
===================================================================
--- branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/MessageDispatcher.java 2006-09-19 13:55:01 UTC (rev 1009)
+++ branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/MessageDispatcher.java 2006-09-19 14:03:26 UTC (rev 1010)
@@ -0,0 +1,44 @@
+/*
+ * 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.ws.integration.jboss.jms;
+
+import java.io.InputStream;
+import java.rmi.RemoteException;
+
+import javax.xml.soap.SOAPMessage;
+
+/**
+ * A dispatcher for SOAPMessages
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 19-Feb-2006
+ */
+public interface MessageDispatcher
+{
+ /** 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
Property changes on: branches/jbossws-1.0.3.GA_JBWS-1210/src/main/java/org/jboss/ws/integration/jboss/jms/MessageDispatcher.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: branches/jbossws-1.0.3.GA_JBWS-1210/src/test/build.xml
===================================================================
--- branches/jbossws-1.0.3.GA_JBWS-1210/src/test/build.xml 2006-09-19 13:55:01 UTC (rev 1009)
+++ branches/jbossws-1.0.3.GA_JBWS-1210/src/test/build.xml 2006-09-19 14:03:26 UTC (rev 1010)
@@ -143,6 +143,7 @@
<pathelement location="${jboss.server.lib}/jboss.jar"/>
<pathelement location="${jboss.server.deploy}/ejb3.deployer/jboss-annotations-ejb3.jar"/>
<pathelement location="${jboss.server.deploy}/ejb3.deployer/jboss-ejb3x.jar"/>
+ <pathelement location="${build.lib.dir}/jbossws-jboss-integration.jar"/>
</path>
<!-- The test client classpath -->
Modified: branches/jbossws-1.0.3.GA_JBWS-1210/src/test/java/org/jboss/test/ws/samples/jmstransport/OrganizationJMSEndpoint.java
===================================================================
--- branches/jbossws-1.0.3.GA_JBWS-1210/src/test/java/org/jboss/test/ws/samples/jmstransport/OrganizationJMSEndpoint.java 2006-09-19 13:55:01 UTC (rev 1009)
+++ branches/jbossws-1.0.3.GA_JBWS-1210/src/test/java/org/jboss/test/ws/samples/jmstransport/OrganizationJMSEndpoint.java 2006-09-19 14:03:26 UTC (rev 1010)
@@ -9,7 +9,7 @@
// $Id$
import org.jboss.logging.Logger;
-import org.jboss.webservice.transport.jms.JMSTransportSupport;
+import org.jboss.ws.integration.jboss.jms.JMSTransportSupport;
import java.rmi.RemoteException;
More information about the jboss-svn-commits
mailing list