diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-11 07:45:29 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-11 07:45:29 +0000 |
commit | a3cbf8e5ffabac239cd965d8c0f9c680a83246f7 (patch) | |
tree | 03eede7de9657506784538ce0e3786a808e4ab22 /branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype | |
parent | a7a97f2875dc162750736b9611e3e8bc8c13f145 (diff) |
Add a new soap/jms transport module copied from the Apache WS Commons transports but with the code backported to work with Axis2 1.4.1
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@773489 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype')
8 files changed, 368 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeInfo.java b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeInfo.java new file mode 100644 index 0000000000..2b415df64d --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeInfo.java @@ -0,0 +1,49 @@ +/* +* Copyright 2004,2005 The Apache Software Foundation. +* +* Licensed 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.ws.axis2.jms.ctype; + +/** + * Class encapsulating the content type information for a given message. + */ +public class ContentTypeInfo { + private final String propertyName; + private final String contentType; + + public ContentTypeInfo(String propertyName, String contentType) { + this.propertyName = propertyName; + this.contentType = contentType; + } + + /** + * Get the name of the message property from which the content type + * has been extracted. + * + * @return the property name or null if the content type was not determined + * by extracting it from a message property + */ + public String getPropertyName() { + return propertyName; + } + + /** + * Get the content type of the message. + * + * @return The content type of the message. The return value is never null. + */ + public String getContentType() { + return contentType; + } +} diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeRule.java b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeRule.java new file mode 100644 index 0000000000..0dba93356f --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeRule.java @@ -0,0 +1,43 @@ +/* +* Copyright 2004,2005 The Apache Software Foundation. +* +* Licensed 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.ws.axis2.jms.ctype; + +import javax.jms.JMSException; +import javax.jms.Message; + +/** + * Interface implemented by content type rules. + */ +public interface ContentTypeRule { + /** + * Attempt to determine the content type of the given JMS message. + * + * @param message the message + * @return If the rule matches, the return value encapsulates the content type of the + * message and the message property name from which is was extracted + * (if applicable). If the rule doesn't match, the method returns null. + * @throws JMSException + */ + ContentTypeInfo getContentType(Message message) throws JMSException; + + /** + * Get the name of the message property used to extract the content type from, + * if applicable. + * + * @return the property name or null if not applicable + */ + String getExpectedContentTypeProperty(); +} diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeRuleFactory.java b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeRuleFactory.java new file mode 100644 index 0000000000..a9fd25ef1b --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeRuleFactory.java @@ -0,0 +1,74 @@ +/* +* Copyright 2004,2005 The Apache Software Foundation. +* +* Licensed 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.ws.axis2.jms.ctype; + +import java.util.Iterator; + +import javax.jms.BytesMessage; +import javax.jms.TextMessage; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.description.Parameter; + +/** + * Utility class to create content type rules and rule sets from XML. + */ +public class ContentTypeRuleFactory { + private ContentTypeRuleFactory() {} + + public static ContentTypeRule parse(OMElement element) throws AxisFault { + String name = element.getLocalName(); + String value = element.getText(); + if (name.equals("jmsProperty")) { + return new PropertyRule(value); + } else if (name.equals("textMessage")) { + return new MessageTypeRule(TextMessage.class, value); + } else if (name.equals("bytesMessage")) { + return new MessageTypeRule(BytesMessage.class, value); + } else if (name.equals("default")) { + return new DefaultRule(value); + } else { + throw new AxisFault("Unknown content rule type '" + name + "'"); + } + } + + public static ContentTypeRuleSet parse(Parameter param) throws AxisFault { + ContentTypeRuleSet ruleSet = new ContentTypeRuleSet(); + Object value = param.getValue(); + if (value instanceof OMElement) { + OMElement element = (OMElement)value; + + // DescriptionBuilder#processParameters actually sets the parameter element + // itself as the value. We need to support this case. + // TODO: seems like a bug in Axis2 and is inconsistent with Synapse's way of parsing parameter in proxy definitions + if (element == param.getParameterElement()) { + element = element.getFirstElement(); + } + + if (element.getLocalName().equals("rules")) { + for (Iterator it = element.getChildElements(); it.hasNext(); ) { + ruleSet.addRule(parse((OMElement)it.next())); + } + } else { + throw new AxisFault("Expected <rules> element"); + } + } else { + ruleSet.addRule(new DefaultRule((String)value)); + } + return ruleSet; + } +} diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeRuleSet.java b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeRuleSet.java new file mode 100644 index 0000000000..90383a42f8 --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/ContentTypeRuleSet.java @@ -0,0 +1,64 @@ +/* +* Copyright 2004,2005 The Apache Software Foundation. +* +* Licensed 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.ws.axis2.jms.ctype; + +import java.util.ArrayList; +import java.util.List; + +import javax.jms.JMSException; +import javax.jms.Message; + +/** + * A set of content type rules. + */ +public class ContentTypeRuleSet { + private final List<ContentTypeRule> rules = new ArrayList<ContentTypeRule>(); + private String defaultContentTypeProperty; + + /** + * Add a content type rule to this set. + * + * @param rule the rule to add + */ + public void addRule(ContentTypeRule rule) { + rules.add(rule); + if (defaultContentTypeProperty == null) { + defaultContentTypeProperty = rule.getExpectedContentTypeProperty(); + } + } + + /** + * Determine the content type of the given message. + * This method will try the registered rules in turn until the first rule matches. + * + * @param message the message + * @return the content type information for the message or null if none of the rules matches + * @throws JMSException + */ + public ContentTypeInfo getContentTypeInfo(Message message) throws JMSException { + for (ContentTypeRule rule : rules) { + ContentTypeInfo contentTypeInfo = rule.getContentType(message); + if (contentTypeInfo != null) { + return contentTypeInfo; + } + } + return null; + } + + public String getDefaultContentTypeProperty() { + return defaultContentTypeProperty; + } +} diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/DefaultRule.java b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/DefaultRule.java new file mode 100644 index 0000000000..a158f6ec74 --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/DefaultRule.java @@ -0,0 +1,37 @@ +/* +* Copyright 2004,2005 The Apache Software Foundation. +* +* Licensed 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.ws.axis2.jms.ctype; + +import javax.jms.Message; + +/** + * Content type rule that always matches and that returns a fixed (default) content type. + */ +public class DefaultRule implements ContentTypeRule { + private final String contentType; + + public DefaultRule(String contentType) { + this.contentType = contentType; + } + + public ContentTypeInfo getContentType(Message message) { + return new ContentTypeInfo(null, contentType); + } + + public String getExpectedContentTypeProperty() { + return null; + } +} diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/MessageTypeRule.java b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/MessageTypeRule.java new file mode 100644 index 0000000000..cb25ab93d4 --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/MessageTypeRule.java @@ -0,0 +1,39 @@ +/* +* Copyright 2004,2005 The Apache Software Foundation. +* +* Licensed 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.ws.axis2.jms.ctype; + +import javax.jms.Message; + +/** + * Content type rule that matches a given message type and returns a fixed content type. + */ +public class MessageTypeRule implements ContentTypeRule { + private final Class<? extends Message> messageType; + private final String contentType; + + public MessageTypeRule(Class<? extends Message> messageType, String contentType) { + this.messageType = messageType; + this.contentType = contentType; + } + + public ContentTypeInfo getContentType(Message message) { + return messageType.isInstance(message) ? new ContentTypeInfo(null, contentType) : null; + } + + public String getExpectedContentTypeProperty() { + return null; + } +} diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/PropertyRule.java b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/PropertyRule.java new file mode 100644 index 0000000000..c8d13ba462 --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/PropertyRule.java @@ -0,0 +1,39 @@ +/* +* Copyright 2004,2005 The Apache Software Foundation. +* +* Licensed 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.ws.axis2.jms.ctype; + +import javax.jms.JMSException; +import javax.jms.Message; + +/** + * Content type rule that attempts to extract the content type from a message property. + */ +public class PropertyRule implements ContentTypeRule { + private final String propertyName; + + public PropertyRule(String propertyName) { + this.propertyName = propertyName; + } + + public ContentTypeInfo getContentType(Message message) throws JMSException { + String value = message.getStringProperty(propertyName); + return value == null ? null : new ContentTypeInfo(propertyName, value); + } + + public String getExpectedContentTypeProperty() { + return propertyName; + } +} diff --git a/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/package-info.java b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/package-info.java new file mode 100644 index 0000000000..750170edd7 --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-ws-axis2-jms/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/jms/ctype/package-info.java @@ -0,0 +1,23 @@ +/* +* Copyright 2004,2005 The Apache Software Foundation. +* +* Licensed 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. +*/ + +/** + * Provides classes and interfaces to define content type rules. + * + * Content type rules are used to determine the content type of a + * received message based on JMS properties, message type, etc. + */ +package org.apache.tuscany.sca.binding.ws.axis2.jms.ctype;
\ No newline at end of file |