From a6261ada0a56abe83378e9f2d1200539fd2ca34a Mon Sep 17 00:00:00 2001 From: bdaniel Date: Mon, 30 Aug 2010 21:29:10 +0000 Subject: Add support for ActivationSpec error conditions git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@990951 13f79535-47bb-0310-9956-ffa450edef68 --- .../binding-jms-runtime/META-INF/MANIFEST.MF | 1 + .../trunk/modules/binding-jms-runtime/pom.xml | 6 ++++ .../jms/host/DefaultJMSServiceListener.java | 42 ++++++++++++++++++---- .../binding/jms/provider/JMSResourceFactory.java | 4 +++ .../jms/provider/JMSResourceFactoryImpl.java | 11 ++++++ 5 files changed, 58 insertions(+), 6 deletions(-) (limited to 'sca-java-2.x/trunk/modules') diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/binding-jms-runtime/META-INF/MANIFEST.MF index a25cc85adb..a16f0c48ca 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/META-INF/MANIFEST.MF @@ -8,6 +8,7 @@ Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt Bundle-Description: Apache Tuscany SCA JMS Binding Runtime Import-Package: javax.jms, javax.naming, + javax.resource.spi, javax.security.auth, javax.xml.namespace, javax.xml.stream, diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/pom.xml b/sca-java-2.x/trunk/modules/binding-jms-runtime/pom.xml index 27dd79ff46..21fd859398 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/pom.xml +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/pom.xml @@ -91,6 +91,12 @@ provided + + org.apache.geronimo.specs + geronimo-j2ee-connector_1.5_spec + 2.0.0 + + org.apache.tuscany.sca tuscany-implementation-java-runtime diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListener.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListener.java index aca0d58697..94728699a2 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListener.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultJMSServiceListener.java @@ -31,6 +31,7 @@ import javax.jms.Queue; import javax.jms.Session; import javax.jms.Topic; import javax.naming.NamingException; +import javax.resource.spi.ActivationSpec; import org.apache.tuscany.sca.binding.jms.JMSBinding; import org.apache.tuscany.sca.binding.jms.JMSBindingConstants; @@ -71,7 +72,7 @@ public class DefaultJMSServiceListener implements JMSServiceListener { this.running = true; try { - registerListerner(); + registerListener(); } catch (Exception e) { if (e instanceof JMSBindingException) throw (JMSBindingException)e; throw new JMSBindingException("Error starting JMSServiceBinding", e); @@ -94,9 +95,10 @@ public class DefaultJMSServiceListener implements JMSServiceListener { } } - private void registerListerner() throws NamingException, JMSException { + private void registerListener() throws NamingException, JMSException { Session session = jmsResourceFactory.createSession(); + lookupActivationSpec(); destination = lookupDestinationQueue(); if (destination == null) { destination = session.createTemporaryQueue(); @@ -146,7 +148,33 @@ public class DefaultJMSServiceListener implements JMSServiceListener { + ((destination instanceof Queue) ? ((Queue)destination).getQueueName() : ((Topic)destination).getTopicName())); } - /** + // Stub code for ActivationSpec support that throws appropriate errors + private void lookupActivationSpec() { + if ( jmsBinding.getActivationSpecName() != null ) { + String createMode = jmsBinding.getActivationSpecCreate(); + if ( JMSBindingConstants.CREATE_ALWAYS.equals(createMode) ) { + ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName()); + if ( spec != null ) { + throw new JMSBindingException("ActivationSpec specifies create mode of \"always\" but resource already exists."); + } + throw new JMSBindingException("Can not create ActivationSpec"); + } else if ( JMSBindingConstants.CREATE_IF_NOT_EXIST.equals(createMode)) { + ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName()); + if ( spec == null ) { + throw new JMSBindingException("Can not create ActivationSpec"); + } + } else if ( JMSBindingConstants.CREATE_NEVER.equals(createMode)) { + ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName()); + if ( spec == null ) + throw new JMSBindingException("ActivationSpec specifies create mode of \"never\" but resource does not exist at jndiName " + jmsBinding.getActivationSpecName()); + + } + + + } + } + + /** * Looks up the Destination Queue for the JMS Binding. *

* What happens in the look up will depend on the create mode specified for the JMS Binding: @@ -168,8 +196,8 @@ public class DefaultJMSServiceListener implements JMSServiceListener { if (isCallbackService && (jmsBinding.getDestinationName() == null)) { // if its a callback service returning null indicates to use a temporary queue return null; - } - + } + Destination destination = jmsResourceFactory.lookupDestination(jmsBinding.getDestinationName()); String qCreateMode = jmsBinding.getDestinationCreate(); @@ -236,7 +264,9 @@ public class DefaultJMSServiceListener implements JMSServiceListener { return destination; } - public String getDestinationName() { + + + public String getDestinationName() { try { if (destination instanceof Queue) { return ((Queue)destination).getQueueName(); diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java index cd53857ed8..5aaeca4ebc 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java @@ -24,6 +24,7 @@ import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Session; import javax.naming.NamingException; +import javax.resource.spi.ActivationSpec; public interface JMSResourceFactory { @@ -92,4 +93,7 @@ public interface JMSResourceFactory { * shared with other users, or where connections cannot be held across transaction boundaries. */ public abstract boolean isConnectionClosedAfterUse(); + + public abstract ActivationSpec lookupActivationSpec( + String activationSpecName); } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java index c4c5f8c7af..9c1a384c7a 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java @@ -28,6 +28,7 @@ import javax.jms.Session; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import javax.resource.spi.ActivationSpec; import org.apache.tuscany.sca.binding.jms.JMSBindingException; @@ -286,4 +287,14 @@ public class JMSResourceFactoryImpl implements JMSResourceFactory { return false; } + public ActivationSpec lookupActivationSpec(String activationSpecName) { + Object o = jndiLookUp(activationSpecName); + if ( o == null ) + return null; + else if (o instanceof ActivationSpec) + return (ActivationSpec) o; + + throw new JMSBindingException("Incorrect resource type for ActivationSpec: " + o.getClass().getName()); + } + } -- cgit v1.2.3