Author: thomas.diesler(a)jboss.com
Date: 2007-08-03 05:18:27 -0400 (Fri, 03 Aug 2007)
New Revision: 4140
Added:
common/trunk/src/main/java/org/jboss/wsf/common/transport/
common/trunk/src/main/java/org/jboss/wsf/common/transport/jms/
common/trunk/src/main/java/org/jboss/wsf/common/transport/jms/JMSTransportSupport.java
Modified:
common/trunk/ant-import/build-thirdparty.xml
common/trunk/version.properties
Log:
Add JMSTransportSupport
Modified: common/trunk/ant-import/build-thirdparty.xml
===================================================================
--- common/trunk/ant-import/build-thirdparty.xml 2007-08-03 08:58:16 UTC (rev 4139)
+++ common/trunk/ant-import/build-thirdparty.xml 2007-08-03 09:18:27 UTC (rev 4140)
@@ -38,18 +38,21 @@
<target name="thirdparty-get" depends="thirdparty-init"
if="force.thirdparty" description="Gets the thirdparty libraries">
<mkdir dir="${thirdparty.dir}"/>
- <get src="${jboss.repository}/junit/${junit}/lib/junit.jar"
dest="${thirdparty.dir}/junit.jar" usetimestamp="true"
verbose="true"/>
+ <get
src="${jboss.repository}/jboss/jbossws-spi/${jbossws-spi}/lib/jbossws-spi.jar"
dest="${thirdparty.dir}/jbossws-spi.jar" usetimestamp="true"
verbose="true"/>
+
<get
src="${jboss.repository}/jboss/common-core/${jboss-common-core}/lib/jboss-common-core.jar"
dest="${thirdparty.dir}/jboss-common-core.jar" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/jboss/common-core/${jboss-common-core}/lib/jboss-common-core-sources.jar"
dest="${thirdparty.dir}/jboss-common-core-sources.jar"
usetimestamp="true" verbose="true"/>
<get
src="${jboss.repository}/jboss/common-logging-spi/${jboss-common-logging-spi}/lib/jboss-logging-spi.jar"
dest="${thirdparty.dir}/jboss-logging-spi.jar" usetimestamp="true"
verbose="true"/>
- <get
src="${jboss.repository}/jboss/jbossws-spi/${jbossws-spi}/lib/jbossws-spi.jar"
dest="${thirdparty.dir}/jbossws-spi.jar" usetimestamp="true"
verbose="true"/>
+ <get
src="${jboss.repository}/jboss/jboss-javaee/${jboss-javaee}/lib/jboss-javaee.jar"
dest="${thirdparty.dir}/jboss-javaee.jar" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/jboss/microcontainer/${jboss-microcontainer}/lib/jboss-dependency.jar"
dest="${thirdparty.dir}/jboss-dependency.jar" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/jboss/microcontainer/${jboss-microcontainer}/lib/jboss-dependency-src.zip"
dest="${thirdparty.dir}/jboss-dependency-src.zip" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/jboss/microcontainer/${jboss-microcontainer}/lib/jboss-microcontainer.jar"
dest="${thirdparty.dir}/jboss-microcontainer.jar" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/jboss/microcontainer/${jboss-microcontainer}/lib/jboss-microcontainer-src.zip"
dest="${thirdparty.dir}/jboss-microcontainer-src.zip"
usetimestamp="true" verbose="true"/>
+ <get src="${jboss.repository}/junit/${junit}/lib/junit.jar"
dest="${thirdparty.dir}/junit.jar" usetimestamp="true"
verbose="true"/>
<get src="${jboss.repository}/sun-jaf/${sun-jaf}/lib/activation.jar"
dest="${thirdparty.dir}/activation.jar" usetimestamp="true"
verbose="true"/>
<get src="${jboss.repository}/sun-jaxb/${sun-jaxb}/lib/jaxb-api.jar"
dest="${thirdparty.dir}/jaxb-api.jar" usetimestamp="true"
verbose="true"/>
<get src="${jboss.repository}/sun-jaxws/${sun-jaxws}/lib/jaxws-api.jar"
dest="${thirdparty.dir}/jaxws-api.jar" usetimestamp="true"
verbose="true"/>
+ <get src="${jboss.repository}/sun-jaxws/${sun-jaxws}/lib/saaj-api.jar"
dest="${thirdparty.dir}/saaj-api.jar" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/sun-jaxrpc/${sun-jaxrpc}/lib/jaxrpc-api.jar"
dest="${thirdparty.dir}/jaxrpc-api.jar" usetimestamp="true"
verbose="true"/>
<checksum file="${common.dir}/version.properties"
fileext=".md5"/>
</target>
@@ -58,16 +61,19 @@
<!-- The compile classpath for jbossws common -->
<path id="common.thirdparty.classpath">
+ <pathelement location="${thirdparty.dir}/jaxws-api.jar"/>
+
<pathelement location="${thirdparty.dir}/activation.jar"/>
<pathelement location="${thirdparty.dir}/jaxb-api.jar"/>
<pathelement location="${thirdparty.dir}/jaxrpc-api.jar"/>
- <pathelement location="${thirdparty.dir}/jaxws-api.jar"/>
<pathelement location="${thirdparty.dir}/jboss-common-core.jar"/>
<pathelement location="${thirdparty.dir}/jboss-dependency.jar"/>
<pathelement location="${thirdparty.dir}/jboss-logging-spi.jar"/>
+ <pathelement location="${thirdparty.dir}/jboss-javaee.jar"/>
<pathelement
location="${thirdparty.dir}/jboss-microcontainer.jar"/>
<pathelement location="${thirdparty.dir}/jbossws-spi.jar"/>
<pathelement location="${thirdparty.dir}/junit.jar"/>
+ <pathelement location="${thirdparty.dir}/saaj-api.jar"/>
</path>
</target>
Copied:
common/trunk/src/main/java/org/jboss/wsf/common/transport/jms/JMSTransportSupport.java
(from rev 4136,
framework/trunk/src/main/java/org/jboss/wsf/framework/transport/jms/JMSTransportSupport.java)
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/transport/jms/JMSTransportSupport.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/transport/jms/JMSTransportSupport.java 2007-08-03
09:18:27 UTC (rev 4140)
@@ -0,0 +1,284 @@
+/*
+ * 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.common.transport.jms;
+
+// $Id:JMSTransportSupport.java 915 2006-09-08 08:40:45Z thomas.diesler(a)jboss.com $
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+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.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.xml.soap.SOAPException;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.NestedRuntimeException;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.deployment.Endpoint;
+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;
+
+/**
+ * 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(a)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 inputStream = new ByteArrayInputStream(msgStr.getBytes());
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
+ processSOAPMessage(fromName, inputStream, outputStream);
+
+ msgStr = new String(outputStream.toByteArray());
+ log.debug("Outgoing SOAP message: " + msgStr);
+
+ if (msgStr.length() > 0)
+ {
+ 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 void processSOAPMessage(String fromName, InputStream inputStream,
OutputStream outStream) throws SOAPException, IOException, RemoteException
+ {
+ SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ EndpointRegistry epRegistry =
spiProvider.getSPI(EndpointRegistryFactory.class).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();
+
+ try
+ {
+ InvocationContext invContext = new InvocationContext();
+ invContext.setTargetBean(this);
+
+ reqHandler.handleRequest(endpoint, inputStream, outStream, invContext);
+ }
+ catch (Exception ex)
+ {
+ throw new RemoteException("Cannot process SOAP request", ex);
+ }
+ }
+
+ // 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;
+ }
+
+ 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;
+ }
+}
Modified: common/trunk/version.properties
===================================================================
--- common/trunk/version.properties 2007-08-03 08:58:16 UTC (rev 4139)
+++ common/trunk/version.properties 2007-08-03 09:18:27 UTC (rev 4140)
@@ -18,9 +18,10 @@
jboss-common-core=2.0.2.GA
jboss-common-logging-spi=2.0.2.GA
+jboss-javaee=5.0.0-SNAPSHOT
jboss-microcontainer=2.0.0.Beta3
+junit=3.8.1
sun-jaf=1.1
sun-jaxb=2.1.4
sun-jaxrpc=1.1
sun-jaxws=2.1.1
-junit=3.8.1