You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/08/11 18:43:47 UTC
svn commit: r430821 - in /incubator/servicemix/trunk/servicemix-jms: ./
src/main/java/org/apache/servicemix/jms/
src/main/java/org/apache/servicemix/jms/jca/
src/main/java/org/apache/servicemix/jms/multiplexing/
src/main/java/org/apache/servicemix/jms/...
Author: gnodet
Date: Fri Aug 11 09:43:46 2006
New Revision: 430821
URL: http://svn.apache.org/viewvc?rev=430821&view=rev
Log:
SM-367: add JCA support to servicemix-jms
Added:
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaConsumerProcessor.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaProviderProcessor.java
incubator/servicemix/trunk/servicemix-jms/src/main/resources/META-INF/services/org/apache/servicemix/jms/jca
incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringJcaTest.java
incubator/servicemix/trunk/servicemix-jms/src/test/resources/org/apache/servicemix/jms/spring-jca.xml
Modified:
incubator/servicemix/trunk/servicemix-jms/pom.xml
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsBootstrap.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsConfiguration.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsWsdl1Deployer.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsXBeanDeployer.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingConsumerProcessor.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingProviderProcessor.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardConsumerProcessor.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardProviderProcessor.java
incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/wsdl/JmsAddress.java
incubator/servicemix/trunk/servicemix-jms/src/main/jbi/META-INF/NOTICE
incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringTest.java
Modified: incubator/servicemix/trunk/servicemix-jms/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/pom.xml?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/pom.xml (original)
+++ incubator/servicemix/trunk/servicemix-jms/pom.xml Fri Aug 11 09:43:46 2006
@@ -41,6 +41,24 @@
<artifactId>servicemix-shared</artifactId>
</dependency>
<dependency>
+ <groupId>org.jencks</groupId>
+ <artifactId>jencks</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>jencks</groupId>
+ <artifactId>xapool-without-pool</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>geronimo</groupId>
+ <artifactId>geronimo-connector</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>geronimo</groupId>
+ <artifactId>geronimo-transaction</artifactId>
+ </dependency>
+ <dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>servicemix-core</artifactId>
<scope>provided</scope>
@@ -66,8 +84,48 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jms_1.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-jacc_1.0_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jta_1.0.1B_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>mx4j</groupId>
+ <artifactId>mx4j</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-activation</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>incubator-activemq</groupId>
+ <artifactId>activemq-ra</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>incubator-activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java Fri Aug 11 09:43:46 2006
@@ -22,7 +22,11 @@
import javax.jms.ConnectionFactory;
import javax.naming.Context;
import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.common.BaseLifeCycle;
import org.apache.servicemix.common.ExchangeProcessor;
public abstract class AbstractJmsProcessor implements ExchangeProcessor {
@@ -30,6 +34,8 @@
public static final String STYLE_QUEUE = "queue";
public static final String STYLE_TOPIC = "topic";
+ protected final transient Log log = LogFactory.getLog(getClass());
+
protected JmsEndpoint endpoint;
protected Connection connection;
@@ -42,39 +48,7 @@
ConnectionFactory connectionFactory = null;
try {
// First check configured connectionFactory on the endpoint
- connectionFactory = endpoint.getConnectionFactory();
- // Then, check for jndi connection factory name on the endpoint
- if (connectionFactory == null && endpoint.getJndiConnectionFactoryName() != null) {
- Hashtable props = new Hashtable();
- if (endpoint.getInitialContextFactory() != null && endpoint.getJndiProviderURL() != null) {
- props.put(Context.INITIAL_CONTEXT_FACTORY, endpoint.getInitialContextFactory());
- props.put(Context.PROVIDER_URL, endpoint.getJndiProviderURL());
- } else if (endpoint.getConfiguration().getJndiInitialContextFactory() != null &&
- endpoint.getConfiguration().getJndiProviderUrl() != null) {
- props.put(Context.INITIAL_CONTEXT_FACTORY, endpoint.getConfiguration().getJndiInitialContextFactory());
- props.put(Context.PROVIDER_URL, endpoint.getConfiguration().getJndiProviderUrl());
- }
- ctx = new InitialContext(props);
- connectionFactory = (ConnectionFactory) ctx.lookup(endpoint.getJndiConnectionFactoryName());
- }
- // Check for a configured connectionFactory on the configuration
- if (connectionFactory == null && endpoint.getConfiguration().getConnectionFactory() != null) {
- connectionFactory = endpoint.getConfiguration().getConnectionFactory();
- }
- // Check for jndi connection factory name on the configuration
- if (connectionFactory == null && endpoint.getConfiguration().getJndiConnectionFactoryName() != null) {
- Hashtable props = new Hashtable();
- if (endpoint.getInitialContextFactory() != null && endpoint.getJndiProviderURL() != null) {
- props.put(Context.INITIAL_CONTEXT_FACTORY, endpoint.getInitialContextFactory());
- props.put(Context.PROVIDER_URL, endpoint.getJndiProviderURL());
- } else if (endpoint.getConfiguration().getJndiInitialContextFactory() != null &&
- endpoint.getConfiguration().getJndiProviderUrl() != null) {
- props.put(Context.INITIAL_CONTEXT_FACTORY, endpoint.getConfiguration().getJndiInitialContextFactory());
- props.put(Context.PROVIDER_URL, endpoint.getConfiguration().getJndiProviderUrl());
- }
- ctx = new InitialContext(props);
- connectionFactory = (ConnectionFactory) ctx.lookup(endpoint.getConfiguration().getJndiConnectionFactoryName());
- }
+ connectionFactory = getConnectionFactory();
connection = connectionFactory.createConnection();
connection.start();
doStart(ctx);
@@ -91,7 +65,44 @@
}
}
}
+
+ protected ConnectionFactory getConnectionFactory() throws NamingException {
+ InitialContext ctx = null;
+ // First check configured connectionFactory on the endpoint
+ ConnectionFactory connectionFactory = endpoint.getConnectionFactory();
+ // Then, check for jndi connection factory name on the endpoint
+ if (connectionFactory == null && endpoint.getJndiConnectionFactoryName() != null) {
+ ctx = getInitialContext();
+ connectionFactory = (ConnectionFactory) ctx.lookup(endpoint.getJndiConnectionFactoryName());
+ }
+ // Check for a configured connectionFactory on the configuration
+ if (connectionFactory == null && endpoint.getConfiguration().getConnectionFactory() != null) {
+ connectionFactory = endpoint.getConfiguration().getConnectionFactory();
+ }
+ // Check for jndi connection factory name on the configuration
+ if (connectionFactory == null && endpoint.getConfiguration().getJndiConnectionFactoryName() != null) {
+ ctx = getInitialContext();
+ connectionFactory = (ConnectionFactory) ctx.lookup(endpoint.getConfiguration().getJndiConnectionFactoryName());
+ }
+ return connectionFactory;
+ }
+ protected InitialContext getInitialContext() throws NamingException {
+ Hashtable props = new Hashtable();
+ if (endpoint.getInitialContextFactory() != null && endpoint.getJndiProviderURL() != null) {
+ props.put(Context.INITIAL_CONTEXT_FACTORY, endpoint.getInitialContextFactory());
+ props.put(Context.PROVIDER_URL, endpoint.getJndiProviderURL());
+ return new InitialContext(props);
+ } else if (endpoint.getConfiguration().getJndiInitialContextFactory() != null &&
+ endpoint.getConfiguration().getJndiProviderUrl() != null) {
+ props.put(Context.INITIAL_CONTEXT_FACTORY, endpoint.getConfiguration().getJndiInitialContextFactory());
+ props.put(Context.PROVIDER_URL, endpoint.getConfiguration().getJndiProviderUrl());
+ return new InitialContext(props);
+ } else {
+ BaseLifeCycle lf = (BaseLifeCycle) endpoint.getServiceUnit().getComponent().getLifeCycle();
+ return lf.getContext().getNamingContext();
+ }
+ }
protected void doStart(InitialContext ctx) throws Exception {
}
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsBootstrap.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsBootstrap.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsBootstrap.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsBootstrap.java Fri Aug 11 09:43:46 2006
@@ -16,14 +16,14 @@
*/
package org.apache.servicemix.jms;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import javax.jbi.JBIException;
import javax.jbi.component.Bootstrap;
import javax.jbi.component.InstallationContext;
import javax.management.MBeanServer;
import javax.management.ObjectName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
public class JmsBootstrap implements Bootstrap {
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsConfiguration.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsConfiguration.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsConfiguration.java Fri Aug 11 09:43:46 2006
@@ -24,7 +24,6 @@
import javax.jms.ConnectionFactory;
-import org.apache.servicemix.common.PersistentConfiguration;
import org.apache.servicemix.jbi.security.auth.AuthenticationService;
import org.apache.servicemix.jbi.security.keystore.KeystoreManager;
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java Fri Aug 11 09:43:46 2006
@@ -25,6 +25,9 @@
import javax.jbi.servicedesc.ServiceEndpoint;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapter;
import javax.wsdl.Definition;
import javax.wsdl.Port;
import javax.wsdl.Service;
@@ -32,7 +35,6 @@
import org.apache.servicemix.common.ExchangeProcessor;
import org.apache.servicemix.jbi.security.auth.AuthenticationService;
import org.apache.servicemix.jbi.security.keystore.KeystoreManager;
-import org.apache.servicemix.jms.wsdl.JmsBinding;
import org.apache.servicemix.soap.SoapEndpoint;
/**
@@ -45,36 +47,98 @@
*/
public class JmsEndpoint extends SoapEndpoint {
- protected JmsBinding binding;
+ //
// Jms informations
+ //
protected String initialContextFactory;
protected String jndiProviderURL;
protected String destinationStyle;
protected String jndiConnectionFactoryName;
protected String jndiDestinationName;
protected String jmsProviderDestinationName;
+ //
// Spring configuration
+ //
protected ConnectionFactory connectionFactory;
protected Destination destination;
protected String processorName;
+ //
+ // JCA config
+ //
+ protected ResourceAdapter resourceAdapter;
+ protected ActivationSpec activationSpec;
+ protected BootstrapContext bootstrapContext;
+ protected boolean synchronous;
- public JmsEndpoint() {
+ /**
+ * The BootstrapContext to use for a JCA consumer endpoint.
+ *
+ * @return the bootstrapContext
+ */
+ public BootstrapContext getBootstrapContext() {
+ return bootstrapContext;
}
-
+
/**
- * @return Returns the binding.
+ * @param bootstrapContext the bootstrapContext to set
*/
- public JmsBinding getBinding() {
- return binding;
+ public void setBootstrapContext(BootstrapContext bootstrapContext) {
+ this.bootstrapContext = bootstrapContext;
}
+
+ /**
+ * For a JCA consumer endpoint, indicates if the JBI exchange
+ * should be sent synchronously or asynchronously.
+ * This changes the transaction boundary.
+ *
+ * @return the synchronous
+ */
+ public boolean isSynchronous() {
+ return synchronous;
+ }
+
+ /**
+ * @param synchronous the synchronous to set
+ */
+ public void setSynchronous(boolean synchronous) {
+ this.synchronous = synchronous;
+ }
+
+ /**
+ * The ActivatioSpec to use on this JCA consumer endpoint.
+ *
+ * @return the activationSpec
+ */
+ public ActivationSpec getActivationSpec() {
+ return activationSpec;
+ }
+
+ /**
+ * @param activationSpec the activationSpec to set
+ */
+ public void setActivationSpec(ActivationSpec activationSpec) {
+ this.activationSpec = activationSpec;
+ }
+
+ /**
+ * The ResourceAdapter to use on this JCA consumer endpoint.
+ *
+ * @return the resourceAdapter
+ */
+ public ResourceAdapter getResourceAdapter() {
+ return resourceAdapter;
+ }
+
/**
- * @param binding The binding to set.
+ * @param resourceAdapter the resourceAdapter to set
*/
- public void setBinding(JmsBinding binding) {
- this.binding = binding;
+ public void setResourceAdapter(ResourceAdapter resourceAdapter) {
+ this.resourceAdapter = resourceAdapter;
}
/**
+ * The class name of the JNDI InitialContextFactory to use.
+ *
* @return Returns the initialContextFactory.
*/
public String getInitialContextFactory() {
@@ -89,6 +153,12 @@
}
/**
+ * The name of the destination create by a call to
+ * <code>Session.createQueue</code> or <code>Session.createTopic</code>.
+ * This property is used when <code>destination</code> and
+ * <code>jndiDestinationName</code> are
+ * both <code>null</code>.
+ *
* @return Returns the jmsProviderDestinationName.
*/
public String getJmsProviderDestinationName() {
@@ -103,6 +173,9 @@
}
/**
+ * The name of the JMS ConnectionFactory to lookup in JNDI.
+ * Used if <code>connectionFactory</code> is <code>null</code>
+ *
* @return Returns the jndiConnectionFactoryName.
*/
public String getJndiConnectionFactoryName() {
@@ -117,6 +190,9 @@
}
/**
+ * The name of the JMS Destination to lookup in JNDI.
+ * Used if <code>destination</code> is <code>null</code>.
+ *
* @return Returns the jndiDestinationName.
*/
public String getJndiDestinationName() {
@@ -131,6 +207,8 @@
}
/**
+ * The provider URL used to create the JNDI context.
+ *
* @return Returns the jndiProviderURL.
*/
public String getJndiProviderURL() {
@@ -145,6 +223,9 @@
}
/**
+ * Used to select the destination type used with the jmsProviderDestinationName.
+ * Can be <code>queue</code> or <code>topic</code>.
+ *
* @return Returns the destinationStyle.
*/
public String getDestinationStyle() {
@@ -159,6 +240,8 @@
}
/**
+ * A configured ConnectionFactory to use on this endpoint.
+ *
* @return Returns the connectionFactory.
*/
public ConnectionFactory getConnectionFactory() {
@@ -173,6 +256,8 @@
}
/**
+ * A configured Destination to use on this endpoint.
+ *
* @return Returns the destination.
*/
public Destination getDestination() {
@@ -187,6 +272,9 @@
}
/**
+ * The role of this endpoint.
+ * Must be <code>consumer</code> or <code>provider</code>.
+ *
* @org.apache.xbean.Property alias="role"
* @param role
*/
@@ -310,6 +398,14 @@
}
/**
+ * Specifies the processor family to use for this endpoint.
+ * Can be:
+ * <ul>
+ * <li><code>multiplexing</code> (default)</li>
+ * <li><code>standard</code></li>
+ * <li><code>jca</code></li>
+ * </ul>
+ *
* @return Returns the processorName.
*/
public String getProcessorName() {
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsWsdl1Deployer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsWsdl1Deployer.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsWsdl1Deployer.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsWsdl1Deployer.java Fri Aug 11 09:43:46 2006
@@ -53,7 +53,6 @@
endpoint.setJndiConnectionFactoryName(((JmsAddress) portElement).getJndiConnectionFactoryName());
endpoint.setJndiDestinationName(((JmsAddress) portElement).getJndiDestinationName());
endpoint.setJndiProviderURL(((JmsAddress) portElement).getJndiProviderURL());
- endpoint.setBinding((JmsBinding) bindingElement);
return endpoint;
}
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsXBeanDeployer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsXBeanDeployer.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsXBeanDeployer.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsXBeanDeployer.java Fri Aug 11 09:43:46 2006
@@ -16,11 +16,11 @@
*/
package org.apache.servicemix.jms;
+import javax.jbi.management.DeploymentException;
+
import org.apache.servicemix.common.BaseComponent;
import org.apache.servicemix.common.Endpoint;
import org.apache.servicemix.common.xbean.AbstractXBeanDeployer;
-
-import javax.jbi.management.DeploymentException;
public class JmsXBeanDeployer extends AbstractXBeanDeployer {
Added: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaConsumerProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaConsumerProcessor.java?rev=430821&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaConsumerProcessor.java (added)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaConsumerProcessor.java Fri Aug 11 09:43:46 2006
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jms.jca;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.Map;
+
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jms.BytesMessage;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.transaction.TransactionManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.common.AsyncBaseLifeCycle;
+import org.apache.servicemix.common.BaseLifeCycle;
+import org.apache.servicemix.jms.AbstractJmsProcessor;
+import org.apache.servicemix.jms.JmsEndpoint;
+import org.apache.servicemix.soap.Context;
+import org.apache.servicemix.soap.SoapFault;
+import org.apache.servicemix.soap.SoapHelper;
+import org.apache.servicemix.soap.marshalers.SoapMessage;
+import org.apache.servicemix.soap.marshalers.SoapWriter;
+import org.jencks.SingletonEndpointFactory;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
+/**
+ *
+ * @author <a href="mailto:gnodet [at] gmail.com">Guillaume Nodet</a>
+ */
+public class JcaConsumerProcessor extends AbstractJmsProcessor implements MessageListener {
+
+ private static final Log log = LogFactory.getLog(JcaConsumerProcessor.class);
+
+ protected Map pendingMessages = new ConcurrentHashMap();
+ protected DeliveryChannel channel;
+ protected SoapHelper soapHelper;
+ protected ResourceAdapter resourceAdapter;
+ protected MessageEndpointFactory endpointFactory;
+ protected ActivationSpec activationSpec;
+ protected BootstrapContext bootstrapContext;
+ protected TransactionManager transactionManager;
+ protected ConnectionFactory connectionFactory;
+
+ public JcaConsumerProcessor(JmsEndpoint endpoint) {
+ super(endpoint);
+ this.soapHelper = new SoapHelper(endpoint);
+ }
+
+ public void start() throws Exception {
+ AsyncBaseLifeCycle lf = (AsyncBaseLifeCycle) endpoint.getServiceUnit().getComponent().getLifeCycle();
+ channel = lf.getContext().getDeliveryChannel();
+ transactionManager = (TransactionManager) lf.getContext().getTransactionManager();
+ endpointFactory = new SingletonEndpointFactory(this, transactionManager);
+ bootstrapContext = endpoint.getBootstrapContext();
+ if (bootstrapContext == null) {
+ throw new IllegalArgumentException("bootstrapContext not set");
+ }
+ connectionFactory = endpoint.getConnectionFactory();
+ if (connectionFactory == null) {
+ throw new IllegalArgumentException("connectionFactory not set");
+ }
+ activationSpec = endpoint.getActivationSpec();
+ if (activationSpec == null) {
+ throw new IllegalArgumentException("activationSpec not set");
+ }
+ resourceAdapter = endpoint.getResourceAdapter();
+ if (resourceAdapter == null) {
+ resourceAdapter = activationSpec.getResourceAdapter();
+ } else if (activationSpec.getResourceAdapter() == null) {
+ activationSpec.setResourceAdapter(resourceAdapter);
+ } else {
+ throw new IllegalArgumentException("resourceAdapter not set");
+ }
+ resourceAdapter.start(bootstrapContext);
+ resourceAdapter.endpointActivation(endpointFactory, activationSpec);
+ }
+
+ public void stop() throws Exception {
+ resourceAdapter.endpointDeactivation(endpointFactory, activationSpec);
+ pendingMessages.clear();
+ }
+
+ public void onMessage(final Message message) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Received jms message " + message);
+ }
+ InputStream is = null;
+ if (message instanceof TextMessage) {
+ is = new ByteArrayInputStream(((TextMessage) message).getText().getBytes());
+ } else if (message instanceof BytesMessage) {
+ int length = (int) ((BytesMessage) message).getBodyLength();
+ byte[] bytes = new byte[length];
+ ((BytesMessage) message).readBytes(bytes);
+ is = new ByteArrayInputStream(bytes);
+ } else {
+ throw new IllegalArgumentException("JMS message should be a text or bytes message");
+ }
+ String contentType = message.getStringProperty("Content-Type");
+ SoapMessage soap = soapHelper.getSoapMarshaler().createReader().read(is, contentType);
+ Context context = soapHelper.createContext(soap);
+ MessageExchange exchange = soapHelper.onReceive(context);
+ if (exchange instanceof InOnly == false) {
+ throw new UnsupportedOperationException("JCA consumer endpoints can only use InOnly MEP");
+ }
+ exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, transactionManager.getTransaction());
+ context.setProperty(Message.class.getName(), message);
+ // TODO: copy protocol messages
+ //inMessage.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(message));
+ pendingMessages.put(exchange.getExchangeId(), context);
+ if (endpoint.isSynchronous()) {
+ channel.sendSync(exchange);
+ process(exchange);
+ } else {
+ BaseLifeCycle lf = (BaseLifeCycle) endpoint.getServiceUnit().getComponent().getLifeCycle();
+ lf.sendConsumerExchange(exchange, JcaConsumerProcessor.this.endpoint);
+ }
+ } catch (Throwable e) {
+ log.error("Error while handling jms message", e);
+ }
+ }
+
+ public void process(MessageExchange exchange) throws Exception {
+ Context context = (Context) pendingMessages.remove(exchange.getExchangeId());
+ Message message = (Message) context.getProperty(Message.class.getName());
+ Message response = null;
+ Connection connection = null;
+ try {
+ if (exchange.getStatus() == ExchangeStatus.DONE) {
+ return;
+ }
+ connection = connectionFactory.createConnection();
+ Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+ if (exchange.getStatus() == ExchangeStatus.ERROR) {
+ Exception e = exchange.getError();
+ if (e == null) {
+ e = new Exception("Unkown error");
+ }
+ response = session.createObjectMessage(e);
+ } else if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+ if (exchange.getFault() != null) {
+ SoapFault fault = new SoapFault(SoapFault.RECEIVER, null, null, null, exchange.getFault().getContent());
+ SoapMessage soapFault = soapHelper.onFault(context, fault);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(soapFault);
+ writer.write(baos);
+ response = session.createTextMessage(baos.toString());
+ response.setStringProperty("Content-Type", writer.getContentType());
+ // TODO: Copy other properties from fault
+ } else {
+ NormalizedMessage outMsg = exchange.getMessage("out");
+ if (outMsg != null) {
+ SoapMessage out = soapHelper.onReply(context, outMsg);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(out);
+ writer.write(baos);
+ response = session.createTextMessage(baos.toString());
+ response.setStringProperty("Content-Type", writer.getContentType());
+ // TODO: Copy other properties from response
+ }
+ }
+ }
+ if (response != null) {
+ MessageProducer producer = session.createProducer(message.getJMSReplyTo());
+ response.setJMSCorrelationID(message.getJMSCorrelationID());
+ producer.send(response);
+ }
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+ exchange.setStatus(ExchangeStatus.DONE);
+ channel.send(exchange);
+ }
+ }
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaProviderProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaProviderProcessor.java?rev=430821&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaProviderProcessor.java (added)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaProviderProcessor.java Fri Aug 11 09:43:46 2006
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jms.jca;
+
+import java.io.ByteArrayOutputStream;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.RobustInOnly;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.naming.InitialContext;
+
+import org.apache.servicemix.JbiConstants;
+import org.apache.servicemix.jms.AbstractJmsProcessor;
+import org.apache.servicemix.jms.JmsEndpoint;
+import org.apache.servicemix.soap.SoapHelper;
+import org.apache.servicemix.soap.marshalers.SoapMessage;
+import org.apache.servicemix.soap.marshalers.SoapWriter;
+
+/**
+ *
+ * @author <a href="mailto:gnodet [at] gmail.com">Guillaume Nodet</a>
+ */
+public class JcaProviderProcessor extends AbstractJmsProcessor {
+
+ protected Destination destination;
+ protected Destination replyToDestination;
+ protected DeliveryChannel channel;
+ protected SoapHelper soapHelper;
+ protected ConnectionFactory connectionFactory;
+
+ public JcaProviderProcessor(JmsEndpoint endpoint) {
+ super(endpoint);
+ this.soapHelper = new SoapHelper(endpoint);
+ }
+
+ public void start() throws Exception {
+ connectionFactory = getConnectionFactory();
+ channel = endpoint.getServiceUnit().getComponent().getComponentContext().getDeliveryChannel();
+ destination = endpoint.getDestination();
+ if (destination == null) {
+ if (endpoint.getJndiDestinationName() != null) {
+ InitialContext ctx = getInitialContext();
+ destination = (Destination) ctx.lookup(endpoint.getJndiDestinationName());
+ } else if (endpoint.getJmsProviderDestinationName() == null) {
+ throw new IllegalStateException("No destination provided");
+ }
+ }
+ }
+
+
+ public void stop() throws Exception {
+ destination = null;
+ replyToDestination = null;
+ }
+
+ public void process(MessageExchange exchange) throws Exception {
+ if (exchange.getStatus() == ExchangeStatus.DONE) {
+ return;
+ } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
+ return;
+ }
+ if (exchange instanceof InOnly == false &&
+ exchange instanceof RobustInOnly == false) {
+ exchange.setError(new UnsupportedOperationException("Use an InOnly or RobustInOnly MEP"));
+ channel.send(exchange);
+ return;
+ }
+ Connection connection = null;
+ try {
+ connection = connectionFactory.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ if (destination == null) {
+ if (STYLE_QUEUE.equals(endpoint.getDestinationStyle())) {
+ destination = session.createQueue(endpoint.getJmsProviderDestinationName());
+ } else {
+ destination = session.createTopic(endpoint.getJmsProviderDestinationName());
+ }
+ }
+ MessageProducer producer = session.createProducer(destination);
+
+ SoapMessage soapMessage = new SoapMessage();
+ NormalizedMessage nm = exchange.getMessage("in");
+ soapHelper.getJBIMarshaler().fromNMS(soapMessage, nm);
+ SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(soapMessage);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ writer.write(baos);
+ Message msg = session.createTextMessage(baos.toString());
+ msg.setStringProperty("Content-Type", writer.getContentType());
+ Map headers = (Map) nm.getProperty(JbiConstants.PROTOCOL_HEADERS);
+ if (headers != null) {
+ for (Iterator it = headers.keySet().iterator(); it.hasNext();) {
+ String name = (String) it.next();
+ String value = (String) headers.get(name);
+ msg.setStringProperty(name, value);
+ }
+ }
+ producer.send(msg);
+ exchange.setStatus(ExchangeStatus.DONE);
+ channel.send(exchange);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+ }
+
+}
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingConsumerProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingConsumerProcessor.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingConsumerProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingConsumerProcessor.java Fri Aug 11 09:43:46 2006
@@ -37,8 +37,6 @@
import javax.resource.spi.work.Work;
import javax.resource.spi.work.WorkException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.common.BaseLifeCycle;
import org.apache.servicemix.jms.AbstractJmsProcessor;
import org.apache.servicemix.jms.JmsEndpoint;
@@ -52,15 +50,13 @@
public class MultiplexingConsumerProcessor extends AbstractJmsProcessor implements MessageListener {
- private static final Log log = LogFactory.getLog(MultiplexingConsumerProcessor.class);
-
protected Session session;
protected Destination destination;
protected MessageConsumer consumer;
protected Map pendingMessages = new ConcurrentHashMap();
protected DeliveryChannel channel;
protected SoapHelper soapHelper;
-
+
public MultiplexingConsumerProcessor(JmsEndpoint endpoint) {
super(endpoint);
this.soapHelper = new SoapHelper(endpoint);
@@ -86,7 +82,6 @@
consumer.setMessageListener(this);
channel = endpoint.getServiceUnit().getComponent().getComponentContext().getDeliveryChannel();
}
-
protected void doStop() throws Exception {
session = null;
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingProviderProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingProviderProcessor.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingProviderProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingProviderProcessor.java Fri Aug 11 09:43:46 2006
@@ -43,8 +43,6 @@
import javax.resource.spi.work.Work;
import javax.resource.spi.work.WorkException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.JbiConstants;
import org.apache.servicemix.jms.AbstractJmsProcessor;
import org.apache.servicemix.jms.JmsEndpoint;
@@ -56,8 +54,6 @@
public class MultiplexingProviderProcessor extends AbstractJmsProcessor implements MessageListener {
- private static final Log log = LogFactory.getLog(MultiplexingProviderProcessor.class);
-
protected Session session;
protected Destination destination;
protected Destination replyToDestination;
@@ -66,7 +62,7 @@
protected Map pendingExchanges = new ConcurrentHashMap();
protected DeliveryChannel channel;
protected SoapHelper soapHelper;
-
+
public MultiplexingProviderProcessor(JmsEndpoint endpoint) {
super(endpoint);
this.soapHelper = new SoapHelper(endpoint);
@@ -99,7 +95,6 @@
consumer.setMessageListener(this);
}
-
protected void doStop() throws Exception {
session = null;
destination = null;
@@ -209,5 +204,4 @@
}
}
-
}
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardConsumerProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardConsumerProcessor.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardConsumerProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardConsumerProcessor.java Fri Aug 11 09:43:46 2006
@@ -34,8 +34,6 @@
import javax.naming.InitialContext;
import javax.resource.spi.work.Work;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jms.AbstractJmsProcessor;
import org.apache.servicemix.jms.JmsEndpoint;
import org.apache.servicemix.soap.Context;
@@ -48,14 +46,12 @@
public class StandardConsumerProcessor extends AbstractJmsProcessor {
- private static final Log log = LogFactory.getLog(StandardConsumerProcessor.class);
-
protected Session session;
protected Destination destination;
protected DeliveryChannel channel;
protected SoapHelper soapHelper;
protected AtomicBoolean running = new AtomicBoolean(false);
-
+
public StandardConsumerProcessor(JmsEndpoint endpoint) {
super(endpoint);
this.soapHelper = new SoapHelper(endpoint);
@@ -83,7 +79,6 @@
}
}
-
protected void doStop() throws Exception {
if (running.get()) {
synchronized (running) {
@@ -96,7 +91,7 @@
session = null;
destination = null;
}
-
+
protected void poll() {
synchronized (running) {
running.set(true);
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardProviderProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardProviderProcessor.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardProviderProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardProviderProcessor.java Fri Aug 11 09:43:46 2006
@@ -40,8 +40,6 @@
import javax.jms.TextMessage;
import javax.naming.InitialContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.JbiConstants;
import org.apache.servicemix.jms.AbstractJmsProcessor;
import org.apache.servicemix.jms.JmsEndpoint;
@@ -51,8 +49,6 @@
public class StandardProviderProcessor extends AbstractJmsProcessor {
- private static final Log log = LogFactory.getLog(StandardProviderProcessor.class);
-
protected Session session;
protected Destination destination;
protected Destination replyToDestination;
@@ -78,7 +74,6 @@
}
}
-
protected void doStop() throws Exception {
session = null;
destination = null;
@@ -172,5 +167,4 @@
}
}
-
}
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/wsdl/JmsAddress.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/wsdl/JmsAddress.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/wsdl/JmsAddress.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/wsdl/JmsAddress.java Fri Aug 11 09:43:46 2006
@@ -22,12 +22,11 @@
import java.io.Serializable;
/**
+ * A JMS extensibily element used to specify the parameters needed
+ * to retrieve the JMS ConnectionFactory and Destination to use.
*
- * @author gnodet
+ * @author <a href="mailto:gnodet [at] gmail.com">Guillaume Nodet</a>
* @version $Revision$
- * @org.apache.xbean.XBean element="address"
- * description="A jms address"
- *
*/
public class JmsAddress implements ExtensibilityElement, Serializable {
Modified: incubator/servicemix/trunk/servicemix-jms/src/main/jbi/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/jbi/META-INF/NOTICE?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/jbi/META-INF/NOTICE (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/jbi/META-INF/NOTICE Fri Aug 11 09:43:46 2006
@@ -1,11 +1,8 @@
=========================================================================
- == NOTICE file corresponding to the section 4 d of ==
- == the Apache License, Version 2.0, ==
+ == NOTICE file for use with the Apache License, Version 2.0, ==
== in this case for the Apache ServiceMix distribution. ==
=========================================================================
- This product includes software developed by
+ This product contains software developed by
The Apache Software Foundation (http://www.apache.org/).
- Additional copyright notices and license terms applicable are
- present in the licenses directory of this distribution.
Added: incubator/servicemix/trunk/servicemix-jms/src/main/resources/META-INF/services/org/apache/servicemix/jms/jca
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/resources/META-INF/services/org/apache/servicemix/jms/jca?rev=430821&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/resources/META-INF/services/org/apache/servicemix/jms/jca (added)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/resources/META-INF/services/org/apache/servicemix/jms/jca Fri Aug 11 09:43:46 2006
@@ -0,0 +1,2 @@
+consumer=org.apache.servicemix.jms.jca.JcaConsumerProcessor
+provider=org.apache.servicemix.jms.jca.JcaProviderProcessor
\ No newline at end of file
Added: incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringJcaTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringJcaTest.java?rev=430821&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringJcaTest.java (added)
+++ incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringJcaTest.java Fri Aug 11 09:43:46 2006
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jms;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.naming.Context;
+import javax.transaction.TransactionManager;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.Destination;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.ExchangeCompletedListener;
+import org.apache.servicemix.tck.Receiver;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.apache.xbean.spring.jndi.SpringInitialContextFactory;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+public class JmsSpringJcaTest extends SpringTestSupport {
+
+ protected ExchangeCompletedListener listener;
+ protected DefaultServiceMixClient client;
+ protected Receiver receiver;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ listener = new ExchangeCompletedListener(5000);
+ jbi.addListener(listener);
+ client = new DefaultServiceMixClient(jbi);
+ receiver = (Receiver) getBean("receiver");
+ }
+
+ protected void tearDown() throws Exception {
+ listener.assertExchangeCompleted();
+ super.tearDown();
+ }
+
+ public void testInOut() throws Exception {
+ TransactionManager tm = (TransactionManager) getBean("transactionManager");
+ tm.begin();
+ InOut me = client.createInOutExchange();
+ me.setService(new QName("http://test", "MyProviderService"));
+ me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
+ client.send(me);
+ tm.commit();
+ me = (InOut) client.receive();
+ assertEquals(ExchangeStatus.ERROR, me.getStatus());
+ assertNotNull(me.getError());
+ assertTrue(me.getError() instanceof UnsupportedOperationException);
+ }
+
+ public void testInOnlyWithAsyncConsumer() throws Exception {
+ TransactionManager tm = (TransactionManager) getBean("transactionManager");
+ tm.begin();
+ Destination dest = client.createDestination("endpoint:http://test/MyProviderService/async");
+ InOnly me = dest.createInOnlyExchange();
+ me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
+ client.send(me);
+ tm.commit();
+ me = (InOnly) client.receive();
+ assertEquals(ExchangeStatus.DONE, me.getStatus());
+ receiver.getMessageList().assertMessagesReceived(1);
+ }
+
+ public void testInOnlySyncWithAsyncConsumer() throws Exception {
+ TransactionManager tm = (TransactionManager) getBean("transactionManager");
+ tm.begin();
+ Destination dest = client.createDestination("endpoint:http://test/MyProviderService/async");
+ InOnly me = dest.createInOnlyExchange();
+ me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
+ client.sendSync(me);
+ assertEquals(ExchangeStatus.DONE, me.getStatus());
+ tm.commit();
+ receiver.getMessageList().assertMessagesReceived(1);
+ }
+
+ public void testInOnlyWithSyncConsumer() throws Exception {
+ TransactionManager tm = (TransactionManager) getBean("transactionManager");
+ tm.begin();
+ Destination dest = client.createDestination("endpoint:http://test/MyProviderService/synchronous");
+ InOnly me = dest.createInOnlyExchange();
+ me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
+ client.send(me);
+ tm.commit();
+ me = (InOnly) client.receive();
+ assertEquals(ExchangeStatus.DONE, me.getStatus());
+ receiver.getMessageList().assertMessagesReceived(1);
+ }
+
+ public void testInOnlySyncWithSyncConsumer() throws Exception {
+ TransactionManager tm = (TransactionManager) getBean("transactionManager");
+ tm.begin();
+ Destination dest = client.createDestination("endpoint:http://test/MyProviderService/synchronous");
+ InOnly me = dest.createInOnlyExchange();
+ me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
+ client.sendSync(me);
+ assertEquals(ExchangeStatus.DONE, me.getStatus());
+ tm.commit();
+ receiver.getMessageList().assertMessagesReceived(1);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, SpringInitialContextFactory.class.getName());
+ System.setProperty(Context.PROVIDER_URL, "org/apache/servicemix/jms/jndi.xml");
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/jms/spring-jca.xml");
+ }
+
+}
Modified: incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringTest.java?rev=430821&r1=430820&r2=430821&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringTest.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringTest.java Fri Aug 11 09:43:46 2006
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.servicemix.jms;
import javax.jbi.messaging.ExchangeStatus;
Added: incubator/servicemix/trunk/servicemix-jms/src/test/resources/org/apache/servicemix/jms/spring-jca.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/test/resources/org/apache/servicemix/jms/spring-jca.xml?rev=430821&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/test/resources/org/apache/servicemix/jms/spring-jca.xml (added)
+++ incubator/servicemix/trunk/servicemix-jms/src/test/resources/org/apache/servicemix/jms/spring-jca.xml Fri Aug 11 09:43:46 2006
@@ -0,0 +1,178 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:jms="http://servicemix.apache.org/jms/1.0"
+ xmlns:amq="http://activemq.org/config/1.0"
+ xmlns:test="http://test">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi"
+ embedded="true"
+ depends-on="jndi,broker"
+ autoEnlistInTransaction="true"
+ transactionManager="#transactionManager">
+ <sm:flows>
+ <sm:sedaFlow />
+ <sm:jcaFlow bootstrapContext="#bootstrapContext"
+ connectionManager="#connectionManager"
+ jmsURL="tcp://localhost:61616?jms.asyncDispatch=true&jms.useAsyncSend=true" />
+ </sm:flows>
+
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: lightweight -->
+ <sm:activationSpec>
+ <sm:component>
+ <jms:component>
+ <jms:endpoints>
+ <jms:endpoint service="test:MyConsumerService"
+ endpoint="synchronous"
+ targetService="test:MyConsumerService"
+ role="consumer"
+ defaultMep="http://www.w3.org/2004/08/wsdl/in-only"
+ processorName="jca"
+ connectionFactory="#connectionFactory"
+ resourceAdapter="#resourceAdapter"
+ bootstrapContext="#bootstrapContext"
+ synchronous="true">
+ <jms:activationSpec>
+ <bean id="activationSpec" class="org.apache.activemq.ra.ActiveMQActivationSpec">
+ <property name="destination" value="queue/synchronous"/>
+ <property name="destinationType" value="javax.jms.Queue"/>
+ </bean>
+ </jms:activationSpec>
+ </jms:endpoint>
+
+ <jms:endpoint service="test:MyProviderService"
+ endpoint="synchronous"
+ role="provider"
+ processorName="jca"
+ connectionFactory="#connectionFactory"
+ destinationStyle="queue"
+ jmsProviderDestinationName="queue/synchronous" />
+
+ <jms:endpoint service="test:MyConsumerService"
+ endpoint="async"
+ targetService="test:MyConsumerService"
+ role="consumer"
+ defaultMep="http://www.w3.org/2004/08/wsdl/in-only"
+ processorName="jca"
+ connectionFactory="#connectionFactory"
+ resourceAdapter="#resourceAdapter"
+ bootstrapContext="#bootstrapContext"
+ synchronous="false">
+ <jms:activationSpec>
+ <bean id="activationSpec" class="org.apache.activemq.ra.ActiveMQActivationSpec">
+ <property name="destination" value="queue/async"/>
+ <property name="destinationType" value="javax.jms.Queue"/>
+ </bean>
+ </jms:activationSpec>
+ </jms:endpoint>
+
+ <jms:endpoint service="test:MyProviderService"
+ endpoint="async"
+ role="provider"
+ processorName="jca"
+ connectionFactory="#connectionFactory"
+ destinationStyle="queue"
+ jmsProviderDestinationName="queue/async" />
+ </jms:endpoints>
+ </jms:component>
+ </sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: lightweight -->
+
+ <sm:activationSpec id="receiver" service="test:MyConsumerService" endpoint="myConsumer">
+ <sm:component>
+ <bean class="org.apache.servicemix.tck.ReceiverComponent" />
+ </sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="jndi"
+ class="org.apache.xbean.spring.jndi.SpringInitialContextFactory"
+ factory-method="makeInitialContext"
+ singleton="true">
+ <property name="entries">
+ <map>
+ <entry key="jms/ConnectionFactory" value-ref="connectionFactory" />
+ </map>
+ </property>
+ </bean>
+
+ <!-- A managed JMS ConnectionFactory for ActiveMQ -->
+ <bean id="activemqMCF" class="org.apache.activemq.ra.ActiveMQManagedConnectionFactory">
+ <property name="resourceAdapter" ref="resourceAdapter" />
+ </bean>
+ <bean id="connectionFactory" class="org.springframework.jca.support.LocalConnectionFactoryBean">
+ <property name="managedConnectionFactory" ref="activemqMCF"/>
+ <property name="connectionManager" ref="connectionManager"/>
+ </bean>
+ <bean id="resourceAdapter" class="org.apache.activemq.ra.ActiveMQResourceAdapter">
+ <property name="serverUrl" value="tcp://localhost:61616?jms.asyncDispatch=true&jms.useAsyncSend=true"/>
+ </bean>
+
+ <amq:broker id="broker" persistent="false">
+
+ <amq:transportConnectors>
+ <amq:transportConnector uri="tcp://localhost:61616" />
+ </amq:transportConnectors>
+
+ </amq:broker>
+
+ <!-- Transaction log -->
+ <bean id="transactionLog" class="org.apache.geronimo.transaction.log.UnrecoverableLog" />
+
+ <!-- Internal transaction manager -->
+ <bean id="extendedTransactionManager" class="org.jencks.factory.TransactionManagerFactoryBean">
+ <property name="transactionLog" ref="transactionLog" />
+ <property name="defaultTransactionTimeoutSeconds" value="600"/>
+ </bean>
+
+ <!-- Transaction context manager -->
+ <bean id="transactionContextManager" class="org.jencks.factory.TransactionContextManagerFactoryBean">
+ <property name="transactionManager" ref="extendedTransactionManager"/>
+ </bean>
+
+ <!-- Public transaction manager -->
+ <bean id="transactionManager" class="org.jencks.factory.GeronimoTransactionManagerFactoryBean">
+ <property name="transactionContextManager" ref="transactionContextManager"/>
+ </bean>
+
+ <!-- Work manager -->
+ <bean id="workManager" class="org.jencks.factory.WorkManagerFactoryBean">
+ <property name="threadPoolSize" value="30"/>
+ <property name="transactionContextManager" ref="transactionContextManager"/>
+ </bean>
+
+ <!-- Bootstrap context for JCA -->
+ <bean id="bootstrapContext" class="org.jencks.factory.BootstrapContextFactoryBean">
+ <property name="workManager" ref="workManager"/>
+ </bean>
+
+ <!-- Connection manager for JCA -->
+ <bean id="connectionTracker" class="org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator"/>
+ <bean id="poolingSupport" class="org.jencks.factory.SinglePoolFactoryBean">
+ <property name="maxSize" value="16"/>
+ <property name="minSize" value="1"/>
+ <property name="blockingTimeoutMilliseconds" value="60"/>
+ <property name="idleTimeoutMinutes" value="60"/>
+ <property name="matchOne" value="true"/>
+ <property name="matchAll" value="true"/>
+ <property name="selectOneAssumeMatch" value="true"/>
+ </bean>
+ <bean id="transactionSupport" class="org.jencks.factory.XATransactionFactoryBean">
+ <property name="useTransactionCaching" value="true"/>
+ <property name="useThreadCaching" value="true"/>
+ </bean>
+ <bean id="connectionManager" class="org.jencks.factory.ConnectionManagerFactoryBean">
+ <property name="containerManagedSecurity" value="false"/>
+ <property name="transactionContextManager" ref="transactionContextManager"/>
+ <property name="poolingSupport" ref="poolingSupport"/>
+ <property name="transactionSupport" ref="transactionSupport"/>
+ <property name="connectionTracker" ref="connectionTracker"/>
+ </bean>
+
+
+</beans>