From fea84bc2dd440ae3c7d36990ad24455166455415 Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 24 Apr 2009 11:49:38 +0000 Subject: TUSCANY-2930 main part of separating wireFormat.jmsdefault out from wireFormat.jmsTextXML. I've spotted a few more things that need fixing but this basic functionality passes all of our current JMS tests and now better matched what the specification says about default format. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@768263 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/binding/jms/impl/JMSBindingConstants.java | 2 +- .../sca/binding/jms/impl/JMSBindingProcessor.java | 20 +++-- .../jmsdefault/WireFormatJMSDefault.java | 64 ++++++++++++++++ .../jmsdefault/WireFormatJMSDefaultProcessor.java | 88 ++++++++++++++++++++++ 4 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java create mode 100644 branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProcessor.java (limited to 'branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms') diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java index db02d6b53c..4886797b71 100644 --- a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java +++ b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java @@ -58,7 +58,7 @@ public interface JMSBindingConstants { String TEXT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.TextMessageProcessor"; String OBJECT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor"; String BYTES_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.BytesMessageProcessor"; - String DEFAULT_MP_CLASSNAME = XML_MP_CLASSNAME; + String DEFAULT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.DefaultMessageProcessor"; String DEFAULT_OPERATION_PROP_NAME = "scaOperationName"; String FAULT_PROPERTY = "org_apache_tuscany_sca_fault"; 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 4642a51d45..860e4c6982 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 @@ -44,6 +44,7 @@ import org.apache.tuscany.sca.assembly.xml.ConfiguredOperationProcessor; import org.apache.tuscany.sca.assembly.xml.Constants; import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; import org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefault; +import org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault; import org.apache.tuscany.sca.binding.jms.wireformat.jmsobject.WireFormatJMSObject; import org.apache.tuscany.sca.binding.jms.wireformat.jmstext.WireFormatJMSText; import org.apache.tuscany.sca.binding.jms.wireformat.jmstextxml.WireFormatJMSTextXML; @@ -240,18 +241,22 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if ("XMLTextMessage".equalsIgnoreCase(messageProcessorName)) { // may be overwritten be real wire format later jmsBinding.setRequestWireFormat(new WireFormatJMSTextXML()); - jmsBinding.setResponseWireFormat(new WireFormatJMSTextXML()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); } else if ("TextMessage".equalsIgnoreCase(messageProcessorName)) { // may be overwritten be real wire format later jmsBinding.setRequestWireFormat(new WireFormatJMSText()); - jmsBinding.setResponseWireFormat(new WireFormatJMSText()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); } else if ("ObjectMessage".equalsIgnoreCase(messageProcessorName)) { // may be overwritten be real wire format later jmsBinding.setRequestWireFormat(new WireFormatJMSObject()); - jmsBinding.setResponseWireFormat(new WireFormatJMSObject()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); } else { jmsBinding.setRequestMessageProcessorName(messageProcessorName); jmsBinding.setResponseMessageProcessorName(messageProcessorName); + // exploit the text wire format code to drive the user selected + // message processor + jmsBinding.setRequestWireFormat(new WireFormatJMSText()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); } } @@ -309,8 +314,9 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St case END_ELEMENT: QName x = reader.getName(); if (Constants.OPERATION.equals(x.getLocalPart())) break; - if (x.getLocalPart().equals("wireFormat.jmsBytes") || x.getLocalPart().equals("wireFormat.jmsText") - || x.getLocalPart().equals("wireFormat.jmsObject") || x.getLocalPart().equals("wireFormat.jmsTextXML")) { + // This assumption is not captured in schema, which isn't good, but will probably be fine for now. + // A better solution might be to require each processor to advance to its own END_ELEMENT. + if (x.getLocalPart().startsWith("wireFormat.") || x.getLocalPart().startsWith("operationSelector.")) { break; } if (x.equals(JMSBindingConstants.BINDING_JMS_QNAME)) { @@ -329,10 +335,10 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St // if no request wire format specified then assume the default if (jmsBinding.getRequestWireFormat() == null){ - jmsBinding.setRequestWireFormat(new WireFormatJMSTextXML()); + jmsBinding.setRequestWireFormat(new WireFormatJMSDefault()); } - // if no response wire format specific then assume the default + // if no response wire format specific then assume the same as the request if (jmsBinding.getResponseWireFormat() == null){ jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); } diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java new file mode 100644 index 0000000000..8cca30a8ca --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java @@ -0,0 +1,64 @@ +/* + * 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.wireformat.jmsdefault; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.WireFormat; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefault implements WireFormat { + public static final QName WIRE_FORMAT_JMS_DEFAULT_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jmsdefault"); + + public static final String WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR = "sendFormat"; + + public static final String WIRE_FORMAT_JMS_DEFAULT_TEXT_FORMAT_VAL = "text"; + public static final String WIRE_FORMAT_JMS_DEFAULT_BYTES_FORMAT_VAL = "bytes"; + + //default is to use a javax.jms.BytesMessage + private boolean useBytesMessage = true; + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_DEFAULT_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + @Override + public boolean equals(Object obj) { + return this.getClass() == obj.getClass(); + } + + public void setUseBytesMessage(boolean useBytesMessage) { + this.useBytesMessage = useBytesMessage; + } + + public boolean isUseBytesMessage() { + return useBytesMessage; + } +} diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProcessor.java b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProcessor.java new file mode 100644 index 0000000000..73c4876025 --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefaultProcessor.java @@ -0,0 +1,88 @@ +/* + * 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.wireformat.jmsdefault; + +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.binding.jms.wireformat.jmsobject.WireFormatJMSObject; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +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; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_QNAME; + } + + public WireFormatJMSDefaultProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + } + + public WireFormatJMSDefault read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + WireFormatJMSDefault wireFormat = new WireFormatJMSDefault(); + + String sendFormat = reader.getAttributeValue(null, WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR); + if (sendFormat != null && sendFormat.length() > 0) { + if (WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_TEXT_FORMAT_VAL.equalsIgnoreCase(sendFormat)) { + wireFormat.setUseBytesMessage(false); + } + } + + return wireFormat; + } + + public void write(WireFormatJMSDefault wireFormat, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, getArtifactType().getLocalPart(), getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS); + + if (wireFormat.isUseBytesMessage()) { + writer.writeAttribute(WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR, WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_BYTES_FORMAT_VAL); + } else { + writer.writeAttribute(WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR, WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_TEXT_FORMAT_VAL); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSDefault.class; + } + + public void resolve(WireFormatJMSDefault arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} -- cgit v1.2.3