diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-26 15:19:21 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-26 15:19:21 +0000 |
commit | 66e7d985557957a708b802f14c56be4aee51fb12 (patch) | |
tree | 9685a9ed8f9888f4bc3ddd01d16f288909b747d1 /branches/sca-java-1.x/modules | |
parent | 673e578bf8f9b256f34ea283dc9f7d0eb8bc03e9 (diff) |
TUSCANY-3099 log an error if an invalid header priority is entered
TUSCANY-3098 don't throw an NPE is a property doesn't have a name
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@788735 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules')
2 files changed, 51 insertions, 11 deletions
diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java index 3d0a2d8bf9..2ed1dcf48b 100644 --- a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java +++ b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java @@ -565,11 +565,15 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St String jmsPriority = reader.getAttributeValue(null, "JMSPriority"); if (jmsPriority != null && jmsPriority.length() > 0) { - int p = Integer.parseInt(jmsPriority); - if (p >= 0 && p <= 9) { - jmsBinding.setJMSPriority(p); - } else { - warning("InvalidJMSPriority", jmsBinding, jmsPriority); + try { + int p = Integer.parseInt(jmsPriority); + if (p >= 0 && p <= 9) { + jmsBinding.setJMSPriority(p); + } else { + warning("InvalidJMSPriority", jmsBinding, jmsPriority); + } + } catch (NumberFormatException ex) { + error("InvalidJMSPriority", jmsBinding, jmsPriority); } } @@ -702,11 +706,15 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St String jmsPriority = reader.getAttributeValue(null, "JMSPriority"); if (jmsPriority != null && jmsPriority.length() > 0) { - int p = Integer.parseInt(jmsPriority); - if (p >= 0 && p <= 9) { - jmsBinding.setOperationJMSPriority(opName, p); - } else { - warning("InvalidOPJMSPriority", jmsBinding, jmsPriority); + try { + int p = Integer.parseInt(jmsPriority); + if (p >= 0 && p <= 9) { + jmsBinding.setOperationJMSPriority(opName, p); + } else { + warning("InvalidOPJMSPriority", jmsBinding, jmsPriority); + } + } catch (NumberFormatException ex) { + error("InvalidOPJMSPriority", jmsBinding, jmsPriority); } } @@ -1195,7 +1203,9 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St Object value = entry.getValue(); writer.writeStartElement(Constants.SCA10_NS, "property" ); - writer.writeAttribute("name", key.toString()); + if (key != null){ + writer.writeAttribute("name", key.toString()); + } if ( value instanceof String) { writer.writeCharacters( value.toString() ); diff --git a/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java b/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java index 7c294b645a..42a669b9ab 100644 --- a/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java +++ b/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java @@ -77,6 +77,20 @@ public class JMSBindingProcessorTestCase extends TestCase { + " </service>"
+ " </component>"
+ "</composite>";
+
+ public static final String HEADERS_INVALID_PRIORITY =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://binding-jms\" name=\"binding-jms\">"
+ + " <component name=\"HelloWorldComponent\">"
+ + " <implementation.java class=\"services.HelloWorld\"/>"
+ + " <service name=\"HelloWorldService\">"
+ + " <binding.jms uri=\"jms:testQueue\" >"
+ + " <headers JMSType=\"myType\" JMSCorrelationID=\"myCorrelId\" JMSDeliveryMode=\"PERSISTENT\" JMSTimeToLive=\"54321\" JMSPriority=\"medium\">"
+ + " </headers>"
+ + " </binding.jms>"
+ + " </service>"
+ + " </component>"
+ + "</composite>";
public static final String PROPERTIES1 =
"<?xml version=\"1.0\" encoding=\"ASCII\"?>"
@@ -476,6 +490,22 @@ public class JMSBindingProcessorTestCase extends TestCase { assertTrue( e.getClass().isAssignableFrom( JMSBindingException.class ) );
}
}
+
+ public void testParsingValidationErrors2() throws Exception {
+ // Composite with invalid priority
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(HEADERS_INVALID_PRIORITY));
+
+ try {
+ Composite composite = (Composite)staxProcessor.read(reader);
+ } catch(Exception e) {
+ // JMSBindingExceptions are expected with invalid composite.
+ if ( !e.getClass().isAssignableFrom( JMSBindingException.class ) )
+ throw e;
+ // Do assertion to make sure test registers results.
+ assertTrue( e.getClass().isAssignableFrom( JMSBindingException.class ) );
+ return;
+ }
+ }
/** Test various model validation requirements. */
public void testValidationErrors1() throws Exception {
|