diff options
Diffstat (limited to 'java/sca/modules/binding-jms-policy/src')
10 files changed, 491 insertions, 57 deletions
diff --git a/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/JMSBindingDefinitionsProvider.java b/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/JMSBindingDefinitionsProvider.java new file mode 100644 index 0000000000..de54545f7e --- /dev/null +++ b/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/JMSBindingDefinitionsProvider.java @@ -0,0 +1,66 @@ +/* + * 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.tuscany.sca.binding.jms.policy; + +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; + +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.provider.SCADefinitionsProvider; +import org.apache.tuscany.sca.provider.SCADefinitionsProviderException; + +/** + * Provider for Policy Intents and PolicySet definitions for the JMS binding + * + * @version $Rev$ $Date$ + */ +public class JMSBindingDefinitionsProvider implements SCADefinitionsProvider { + private String definitionsFile = "org/apache/tuscany/sca/binding/jms/policy/definitions.xml"; + URLArtifactProcessor urlArtifactProcessor = null; + + public JMSBindingDefinitionsProvider(ExtensionPointRegistry registry) { + URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + urlArtifactProcessor = (URLArtifactProcessor)documentProcessors.getProcessor(SCADefinitions.class); + } + + public SCADefinitions getSCADefinition() throws SCADefinitionsProviderException { + final URL definitionsFileUrl = getClass().getClassLoader().getResource(definitionsFile); + SCADefinitions scaDefn = null; + try { + final URI uri = new URI(definitionsFile); + // Allow bindings to read properties. Requires PropertyPermission read in security policy. + scaDefn = AccessController.doPrivileged(new PrivilegedExceptionAction<SCADefinitions>() { + public SCADefinitions run() throws ContributionReadException { + return (SCADefinitions)urlArtifactProcessor.read(null, uri, definitionsFileUrl); + } + }); + } catch (Exception e) { + throw new SCADefinitionsProviderException(e); + } + return scaDefn; + } + +} diff --git a/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java b/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java index 2d63fd5a16..11747914da 100644 --- a/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java +++ b/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java @@ -27,6 +27,7 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; @@ -91,11 +92,10 @@ public class JMSTokenAuthenticationPolicyProcessor extends BaseStAXArtifactProce writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); if ( policy.getTokenName() != null ) { - writer.writeStartElement(prefix, - JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_TOKEN_NAME, - getArtifactType().getNamespaceURI()); - writer.writeCharacters(policy.getTokenName().toString()); - writer.writeEndElement(); + writer.writeAttribute(prefix, + getArtifactType().getNamespaceURI(), + JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_TOKEN_NAME, + policy.getTokenName().toString()); } writer.writeEndElement(); diff --git a/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java b/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java index c51e33fb53..e109c52fba 100644 --- a/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java +++ b/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java @@ -18,6 +18,9 @@ */ package org.apache.tuscany.sca.binding.jms.policy.header; +import java.util.Hashtable; +import java.util.Map; + import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.xml.Constants; @@ -30,21 +33,68 @@ import org.apache.tuscany.sca.policy.Policy; * @version $Rev$ $Date$ */ public class JMSHeaderPolicy implements Policy { - public static final QName AXIS2_HEADER_POLICY_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "axis2Header"); - public static final String AXIS2_HEADER_NAME = "headerName"; - - private QName headerName; + public static final QName JMS_HEADER_POLICY_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "jmsHeader"); + public static final String JMS_HEADER_JMS_TYPE = "JMSType"; + public static final String JMS_HEADER_JMS_CORRELATION_ID = "JMSDeliveryMode"; + public static final String JMS_HEADER_JMS_DELIVERY_MODE = "JMSDeliveryMode"; + public static final String JMS_HEADER_JMS_TIME_TO_LIVE = "JMSTimeToLive"; + public static final String JMS_HEADER_JMS_PRIORITY = "JMSPriority"; + public static final String JMS_HEADER_JMS_PROPERTY = "property"; + public static final String JMS_HEADER_JMS_PROPERTY_NAME = "name"; - public QName getHeaderName() { - return headerName; + private String jmsType = null; + private String jmsCorrelationId = null; + private Boolean deliveryModePersistent = null; + private Long timeToLive = null; + private Integer jmsPriority = null; + private Map<String, String> properties = new Hashtable<String, String>(); + + public String getJmsType() { + return jmsType; + } + + public void setJmsType(String jmsType) { + this.jmsType = jmsType; + } + + public String getJmsCorrelationId() { + return jmsCorrelationId; + } + + public void setJmsCorrelationId(String jmsCorrelationId) { + this.jmsCorrelationId = jmsCorrelationId; + } + + public Boolean getDeliveryModePersistent() { + return deliveryModePersistent; } - public void setHeaderName(QName headerName) { - this.headerName = headerName; + public void setDeliveryModePersistent(Boolean deliveryModePersistent) { + this.deliveryModePersistent = deliveryModePersistent; } + public Long getTimeToLive() { + return timeToLive; + } + + public void setTimeToLive(Long timeToLive) { + this.timeToLive = timeToLive; + } + + public Integer getJmsPriority() { + return jmsPriority; + } + + public void setJmsPriority(Integer jmsPriority) { + this.jmsPriority = jmsPriority; + } + + public Map<String, String> getProperties() { + return properties; + } + public QName getSchemaName() { - return AXIS2_HEADER_POLICY_QNAME; + return JMS_HEADER_POLICY_QNAME; } public boolean isUnresolved() { @@ -53,4 +103,29 @@ public class JMSHeaderPolicy implements Policy { public void setUnresolved(boolean unresolved) { } + + @Override + public String toString() { + String result = "jmsHeader"; + + result += " JMSType "; + result += getJmsType(); + result += " JMSDeliveryMode "; + result += getJmsCorrelationId(); + result += " JMSDeliveryMode "; + result += getDeliveryModePersistent(); + result += " JMSTimeToLive "; + result += getTimeToLive(); + result += " JMSPriority "; + result += getJmsPriority(); + + for (String propertyName : properties.keySet()){ + result += " property "; + result += propertyName; + result += " "; + result += properties.get(propertyName); + } + + return result; + } } diff --git a/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java b/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java index f8186470c8..d6167b4895 100644 --- a/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java +++ b/java/sca/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java @@ -21,6 +21,8 @@ package org.apache.tuscany.sca.binding.jms.policy.header; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; +import java.util.Hashtable; +import java.util.Map; import java.util.logging.Level; import javax.xml.namespace.QName; @@ -28,6 +30,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; import org.apache.tuscany.sca.assembly.xml.Constants; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; @@ -37,6 +40,8 @@ import org.apache.tuscany.sca.contribution.service.ContributionReadException; import org.apache.tuscany.sca.contribution.service.ContributionResolveException; import org.apache.tuscany.sca.contribution.service.ContributionWriteException; import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; /** * @@ -44,12 +49,43 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<JMSHeaderPolicy> { + private Monitor monitor; + public QName getArtifactType() { - return JMSHeaderPolicy.AXIS2_HEADER_POLICY_QNAME; + return JMSHeaderPolicy.JMS_HEADER_POLICY_QNAME; } public JMSHeaderPolicyProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + this.monitor = monitor; + } + + /** + * Marshals warnings into the monitor + * + * @param message + * @param model + * @param messageParameters + */ + protected void warning(String message, Object model, String... messageParameters) { + if (monitor != null){ + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-xml-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } } + + /** + * Marshals errors into the monitor + * + * @param problems + * @param message + * @param model + */ + protected void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } public JMSHeaderPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { @@ -63,7 +99,44 @@ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implemen case START_ELEMENT : { name = reader.getName(); if ( name.equals(getArtifactType()) ) { - policy.setHeaderName(getQName(reader, JMSHeaderPolicy.AXIS2_HEADER_NAME)); + + policy.setJmsType(getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_TYPE)); + policy.setJmsCorrelationId(getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_CORRELATION_ID)); + + String deliveryMode = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_DELIVERY_MODE); + if (deliveryMode != null){ + if (deliveryMode.equals("PERSISTENT")) { + policy.setDeliveryModePersistent(true); + } else if (deliveryMode.equals("NON_PERSISTENT")){ + policy.setDeliveryModePersistent(false); + } else { + error("InvalidDeliveryMode", policy, deliveryMode); + } + } + + String timeToLive = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_TIME_TO_LIVE); + + if ( timeToLive != null){ + try { + policy.setTimeToLive(Long.valueOf(timeToLive)); + } catch (NumberFormatException ex){ + error("InvalidTimeToLive", policy, timeToLive); + } + } + + String priority = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_PRIORITY); + + if ( priority != null){ + try { + policy.setJmsPriority(Integer.valueOf(priority)); + } catch (NumberFormatException ex){ + error("InvalidPriority", policy, priority); + } + } + } else if (name.getLocalPart().equals(JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY)) { + String propertyName = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY_NAME); + String propertyValue = reader.getElementText(); + policy.getProperties().put(propertyName, propertyValue); } break; } @@ -91,14 +164,37 @@ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implemen getArtifactType().getLocalPart(), getArtifactType().getNamespaceURI()); writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); - - if ( policy.getHeaderName() != null ) { + + if (policy.getJmsType() != null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_TYPE, policy.getJmsType()); + } + + if (policy.getJmsCorrelationId() != null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_CORRELATION_ID, policy.getJmsCorrelationId()); + } + + if (policy.getDeliveryModePersistent() == true){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_DELIVERY_MODE, "PERSISTENT"); + } else { + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_DELIVERY_MODE, "NON_PERSISTENT"); + } + + if (policy.getTimeToLive()!= null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_TIME_TO_LIVE, policy.getTimeToLive().toString()); + } + + if (policy.getJmsPriority()!= null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_PRIORITY, policy.getJmsPriority().toString()); + } + + for (String propertyName : policy.getProperties().keySet()){ writer.writeStartElement(prefix, - JMSHeaderPolicy.AXIS2_HEADER_NAME, + JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY, getArtifactType().getNamespaceURI()); - writer.writeCharacters(policy.getHeaderName().toString()); + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY_NAME, propertyName); + writer.writeCharacters(policy.getProperties().get(propertyName)); writer.writeEndElement(); - } + } writer.writeEndElement(); } diff --git a/java/sca/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider b/java/sca/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider new file mode 100644 index 0000000000..0598cdc368 --- /dev/null +++ b/java/sca/modules/binding-jms-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider @@ -0,0 +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.
+
+# Implementation class for SCA Definitions Providers
+org.apache.tuscany.sca.binding.jms.policy.JMSBindingDefinitionsProvider
\ No newline at end of file diff --git a/java/sca/modules/binding-jms-policy/src/main/resources/binding-jms-policy-validation-messages.properties b/java/sca/modules/binding-jms-policy/src/main/resources/binding-jms-policy-validation-messages.properties new file mode 100644 index 0000000000..fd43b2c4e9 --- /dev/null +++ b/java/sca/modules/binding-jms-policy/src/main/resources/binding-jms-policy-validation-messages.properties @@ -0,0 +1,23 @@ +# +# +# 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. +# +# +InvalidDeliveryMode = JMSDeliveryMode must be either PERSISTENT or NON_PERSISTENT but found {0} +InvalidTimeToLive = JMSTimeToLive must be a long integer but found {0} +InvalidPriority = JMSPriority must be a integer but found {0} diff --git a/java/sca/modules/binding-jms-policy/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml b/java/sca/modules/binding-jms-policy/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml new file mode 100644 index 0000000000..044ed834e6 --- /dev/null +++ b/java/sca/modules/binding-jms-policy/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + * 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. +--> +<definitions xmlns="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"> + + <!-- intents not yet enabled --> + <!--sca:bindingType type="sca:binding.jms" + alwaysProvides="JMS" + mayProvide="atLeastOnce atMostOnce ordered conversation" /--> + + <!-- PolicyIntents defined by the SCA Runtime Extension for JMS Binding --> + <sca:intent name="JMS" constrains="sca:binding.jms"> + <sca:description> + Communication through this binding requires JMS + </sca:description> + </sca:intent> + + <intent name="priority" + constrains="sca:binding"> + <description> + This intent is used to indicate the priority of the + sent message + </description> + </intent> + + <intent name="priority.high"> + <description> + Messages are high priority + </description> + </intent> + + <intent name="priority.medium"> + <description> + Messages are meduim priority + </description> + </intent> + + <intent name="priority.low"> + <description> + Messages are low priority + </description> + </intent> +</definitions>
\ No newline at end of file diff --git a/java/sca/modules/binding-jms-policy/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java b/java/sca/modules/binding-jms-policy/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java new file mode 100644 index 0000000000..4c0e3d2e11 --- /dev/null +++ b/java/sca/modules/binding-jms-policy/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java @@ -0,0 +1,91 @@ +/* + * 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.tuscany.sca.binding.jms.policy; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy; +import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicyProcessor; +import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy; +import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicyProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.policy.Policy; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class PolicyProcessorTestCase { + private final static List<String> SEQ = + Arrays.asList("<tuscany:jmsHeader xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\" JMSType=\"ABC\" JMSDeliveryMode=\"PERSISTENT\" JMSDeliveryMode=\"PERSISTENT\" JMSTimeToLive=\"123\" JMSPriority=\"4\"><tuscany:property name=\"aProperty\">property value</tuscany:property></tuscany:jmsHeader>", + "<tuscany:jmsTokenAuthentication xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\" tuscany:tokenName=\"{http://tuscany.apache.org/foo}myname\" />"); + + @Test + public void testRead() throws Exception { + List<String> results = new ArrayList<String>(); + Map<QName, StAXArtifactProcessor> processors = new HashMap<QName, StAXArtifactProcessor>(); + processors.put(JMSHeaderPolicy.JMS_HEADER_POLICY_QNAME, new JMSHeaderPolicyProcessor(null, null)); + processors.put(JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_POLICY_QNAME, new JMSTokenAuthenticationPolicyProcessor(null, null)); + + InputStream is = getClass().getResourceAsStream("mock_policy_definitions.xml"); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + + XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + + while (true) { + int event = reader.getEventType(); + if (event == XMLStreamConstants.START_ELEMENT) { + if ("policySet".equals(reader.getName().getLocalPart())) { + reader.nextTag(); + StAXArtifactProcessor processor = processors.get(reader.getName()); + Policy policy = (Policy)processor.read(reader); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(outputStream); + processor.write(policy, writer); + writer.flush(); + results.add(outputStream.toString()); + } + } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } + Assert.assertEquals(SEQ, results); + } +} diff --git a/java/sca/modules/binding-jms-policy/src/test/resources/org/apache/tuscany/sca/binding/jms/policy/mock_policy_definitions.xml b/java/sca/modules/binding-jms-policy/src/test/resources/org/apache/tuscany/sca/binding/jms/policy/mock_policy_definitions.xml new file mode 100644 index 0000000000..3631c682aa --- /dev/null +++ b/java/sca/modules/binding-jms-policy/src/test/resources/org/apache/tuscany/sca/binding/jms/policy/mock_policy_definitions.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + * 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. +--> +<definitions xmlns="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"> + + <!-- POLICY SETS --> + <policySet name="ps1" provides="authorization" appliesTo="sca:implementation"> + <tuscany:jmsHeader JMSType="ABC" + JMSCorrelattionID="DEF" + JMSDeliveryMode="PERSISTENT" + JMSTimeToLive="123" + JMSPriority="4"> + <property name="aProperty">property value</property> + </tuscany:jmsHeader> + </policySet> + + <policySet name="ps2" provides="authorization" appliesTo="sca:implementation"> + <tuscany:jmsTokenAuthentication xmlns:foo="http://tuscany.apache.org/foo" tokenName="foo:myname"/> + </policySet> +</definitions>
\ No newline at end of file diff --git a/java/sca/modules/binding-jms-policy/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/mock_policies.xml b/java/sca/modules/binding-jms-policy/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/mock_policies.xml deleted file mode 100644 index 77f750cd0d..0000000000 --- a/java/sca/modules/binding-jms-policy/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/mock_policies.xml +++ /dev/null @@ -1,36 +0,0 @@ -<?xml version="1.0" encoding="ASCII"?> -<!-- - * 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. ---> -<tuscany:wsConfigParam xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"> - <parameter name="InflowSecurity"> - <action> - <items>Timestamp Signature</items> - <signaturePropFile>org/apache/tuscany/sca/binding/ws/axis2/itests/policy/security.properties</signaturePropFile> - </action> - </parameter> - <parameter name="OutflowSecurity"> - <action> - <items>Timestamp Signature</items> - <user>TuscanyWsUser</user> - <signaturePropFile>org/apache/tuscany/sca/binding/ws/axis2/itests/policy/security.properties</signaturePropFile> - <passwordCallbackClass>org.apache.tuscany.sca.binding.ws.axis2.itests.policy.IntegrityPWCBHandler</passwordCallbackClass>" + - <signatureKeyIdentifier>DirectReference</signatureKeyIdentifier> - </action> - </parameter> -</tuscany:wsConfigParam>
\ No newline at end of file |