From 1fb1d12aa4c2b4c66e8697007c7eebda86b40886 Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 15 Sep 2009 09:25:56 +0000 Subject: Start merge of 1.x JMS policy code into 2.x JMS binding git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@815230 13f79535-47bb-0310-9956-ffa450edef68 --- .../token/JMSTokenAuthenticationPolicy.java | 55 ++++++ .../JMSTokenAuthenticationPolicyProcessor.java | 111 +++++++++++ .../binding/jms/policy/header/JMSHeaderPolicy.java | 130 +++++++++++++ .../policy/header/JMSHeaderPolicyProcessor.java | 205 +++++++++++++++++++++ ...ca.contribution.processor.StAXArtifactProcessor | 4 +- ...che.tuscany.sca.provider.SCADefinitionsProvider | 19 ++ ...nding-jms-policy-validation-messages.properties | 23 +++ .../tuscany/sca/binding/jms/policy/definitions.xml | 84 +++++++++ .../jms/policy/PolicyProcessorTestCase.java | 94 ++++++++++ 9 files changed, 724 insertions(+), 1 deletion(-) create mode 100644 java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java create mode 100644 java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java create mode 100644 java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java create mode 100644 java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java create mode 100644 java/sca/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider create mode 100644 java/sca/modules/binding-jms/src/main/resources/binding-jms-policy-validation-messages.properties create mode 100644 java/sca/modules/binding-jms/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml create mode 100644 java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java (limited to 'java') diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java new file mode 100644 index 0000000000..24f43d3027 --- /dev/null +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java @@ -0,0 +1,55 @@ +/* + * 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.authentication.token; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationPolicy { + public static final QName JMS_TOKEN_AUTHENTICATION_POLICY_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "jmsTokenAuthentication"); + public static final String JMS_TOKEN_AUTHENTICATION_TOKEN_NAME = "tokenName"; + + private QName tokenName; + + public QName getTokenName() { + return tokenName; + } + + public void setTokenName(QName tokenName) { + this.tokenName = tokenName; + } + + public QName getSchemaName() { + return JMS_TOKEN_AUTHENTICATION_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java new file mode 100644 index 0000000000..b73119efa0 --- /dev/null +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java @@ -0,0 +1,111 @@ +/* + * 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.authentication.token; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_POLICY_QNAME; + } + + public JMSTokenAuthenticationPolicyProcessor(ExtensionPointRegistry modelFactories, Monitor monitor) { + } + + + public JMSTokenAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + JMSTokenAuthenticationPolicy policy = new JMSTokenAuthenticationPolicy(); + int event = reader.getEventType(); + QName name = null; + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(getArtifactType()) ) { + policy.setTokenName(getQName(reader, JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_TOKEN_NAME)); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( getArtifactType().equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(JMSTokenAuthenticationPolicy policy, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + if ( policy.getTokenName() != null ) { + writer.writeAttribute(prefix, + getArtifactType().getNamespaceURI(), + JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_TOKEN_NAME, + policy.getTokenName().toString()); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return JMSTokenAuthenticationPolicy.class; + } + + public void resolve(JMSTokenAuthenticationPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java new file mode 100644 index 0000000000..48fef397c7 --- /dev/null +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java @@ -0,0 +1,130 @@ +/* + * 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.header; + +import java.util.Hashtable; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class JMSHeaderPolicy { + public static final QName JMS_HEADER_POLICY_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "jmsHeader"); + public static final String JMS_HEADER_JMS_TYPE = "JMSType"; + public static final String JMS_HEADER_JMS_CORRELATION_ID = "JMSCorrelationID"; + 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"; + + private String jmsType = null; + private String jmsCorrelationId = null; + private Boolean deliveryModePersistent = null; + private Long timeToLive = null; + private Integer jmsPriority = null; + private Map properties = new Hashtable(); + + 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 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 getProperties() { + return properties; + } + + public QName getSchemaName() { + return JMS_HEADER_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + 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/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java new file mode 100644 index 0000000000..bfa67efa72 --- /dev/null +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java @@ -0,0 +1,205 @@ +/* + * 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.header; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * + * @version $Rev$ $Date$ + */ +public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + private Monitor monitor; + + public QName getArtifactType() { + return JMSHeaderPolicy.JMS_HEADER_POLICY_QNAME; + } + + public JMSHeaderPolicyProcessor(ExtensionPointRegistry 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 = monitor.createProblem(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 = monitor.createProblem(this.getClass().getName(), "assembly-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + + public JMSHeaderPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + JMSHeaderPolicy policy = new JMSHeaderPolicy(); + int event = reader.getEventType(); + QName name = null; + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(getArtifactType()) ) { + + 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; + } + } + + if ( event == END_ELEMENT ) { + if ( getArtifactType().equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(JMSHeaderPolicy policy, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + 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.JMS_HEADER_JMS_PROPERTY, + getArtifactType().getNamespaceURI()); + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY_NAME, propertyName); + writer.writeCharacters(policy.getProperties().get(propertyName)); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return JMSHeaderPolicy.class; + } + + public void resolve(JMSHeaderPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/java/sca/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/java/sca/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor index 07e5a42f77..a2f226ce1a 100644 --- a/java/sca/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor +++ b/java/sca/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -24,4 +24,6 @@ org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXMLProcessor;qna org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.jmsText,model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObjectProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.jmsObject,model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSDefaultProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#operationSelector.jmsdefault,model=org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSDefault -org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSUserPropProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#operationSelector.jmsUserProp,model=org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSUserProp \ No newline at end of file +org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSUserPropProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#operationSelector.jmsUserProp,model=org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSUserProp +org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#jmsTokenAuthentication,model=org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy +org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#jmsHeader,model=org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy diff --git a/java/sca/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider b/java/sca/modules/binding-jms/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/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/src/main/resources/binding-jms-policy-validation-messages.properties b/java/sca/modules/binding-jms/src/main/resources/binding-jms-policy-validation-messages.properties new file mode 100644 index 0000000000..fd43b2c4e9 --- /dev/null +++ b/java/sca/modules/binding-jms/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/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml b/java/sca/modules/binding-jms/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml new file mode 100644 index 0000000000..7a82f95da9 --- /dev/null +++ b/java/sca/modules/binding-jms/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + Communication through this binding requires JMS + + + + + + + This intent is used to indicate the deliver mode + of the sent message + + + + + + Message are sent persistently + + + + + + Message are sent non-persistently + + + + + + + This intent is used to indicate the priority of the + sent message + + + + + + Messages are high priority + + + + + + Messages are medium priority + + + + + + Messages are low priority + + + \ No newline at end of file diff --git a/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java b/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java new file mode 100644 index 0000000000..7bfb355c8a --- /dev/null +++ b/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java @@ -0,0 +1,94 @@ +/* + * 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.junit.Ignore; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +@Ignore("TODO: 2.x migration") +public class PolicyProcessorTestCase { + private final static List SEQ = + Arrays.asList("property value", + ""); + + @Test + public void testRead() throws Exception { + List results = new ArrayList(); + Map processors = new HashMap(); + 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()); + Object xxx = processor.read(reader); +// Policy policy = (Policy)processor.read(reader); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(outputStream); + processor.write(xxx, writer); +// processor.write(policy, writer); + writer.flush(); + results.add(outputStream.toString()); + } + } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } + Assert.assertEquals(SEQ, results); + } +} -- cgit v1.2.3