You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2006/02/20 23:26:27 UTC
svn commit: r379259 [3/7] - in /incubator/tuscany/sandbox/binding.axis2: ./
src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/binding/
src/main/java/org/apache/...
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/Axis2SDOHelper.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/Axis2SDOHelper.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/Axis2SDOHelper.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/Axis2SDOHelper.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,217 @@
+package org.apache.tuscany.binding.axis2.serialization;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.List;
+import java.util.Vector;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.SOAPException;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axis.message.MessageElement;
+import org.apache.axis.message.SOAPEnvelope;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.tuscany.binding.axis2.serialization.mediator.SOAPMediator;
+import org.apache.tuscany.binding.axis2.serialization.mediator.impl.SOAPDocumentLiteralMediatorImpl;
+import org.apache.tuscany.binding.axis2.serialization.mediator.impl.SOAPEnvelopeImpl;
+import org.apache.tuscany.binding.axis2.serialization.mediator.impl.SOAPRPCLiteralMediatorImpl;
+import org.apache.tuscany.binding.axis2.utils.WSDLOperationTypeHelper;
+import org.apache.tuscany.binding.axis2.utils.WebServiceOperationMetaData;
+import org.apache.tuscany.binding.axis2.utils.WebServicePortMetaData;
+import org.apache.tuscany.core.context.TuscanyModuleComponentContext;
+import org.apache.tuscany.core.deprecated.sdo.util.HelperProvider;
+import org.apache.tuscany.core.deprecated.sdo.util.impl.HelperProviderImpl;
+import org.apache.tuscany.core.message.Message;
+import org.apache.tuscany.core.message.impl.MessageFactoryImpl;
+import org.apache.tuscany.model.types.wsdl.WSDLOperationType;
+import org.apache.tuscany.model.util.ConfiguredResourceSet;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Type;
+
+/**
+ * Utility for converting between Tuscany Message objects and AXIOM OMElements
+ *
+ * TODO: Probably only a temporary class to clearly seperate this from the other
+ * code so multiple people can easily work on the WS binding concurrently.
+ */
+public class Axis2SDOHelper {
+
+ private TuscanyModuleComponentContext moduleContext;
+ private WebServicePortMetaData portMetaData;
+ private WSDLOperationType wsdlOperationType;
+ private WebServiceOperationMetaData operationMetaData;
+ private SOAPMediator mediator;
+ private boolean wrappedStyle;
+
+ public Axis2SDOHelper(TuscanyModuleComponentContext moduleContext, WebServicePortMetaData portMetaData, WSDLOperationType wsdlOperationType,
+ WebServiceOperationMetaData operationMetaData) {
+
+ this.moduleContext = moduleContext;
+ this.wsdlOperationType = wsdlOperationType;
+ this.operationMetaData = operationMetaData;
+ this.portMetaData = portMetaData;
+
+ this.wrappedStyle = WSDLOperationTypeHelper.isWrappedStyle(wsdlOperationType);
+ this.mediator = createSOAPMediator();
+ }
+
+ /**
+ * Get an AXIOM OMElement from a Tuscany request Message
+ * The OMElement will be the payload of the SOAP Body excluding the Body tags
+ */
+ public OMElement getRequestAsOMElement(Message message) {
+
+ Object input = message.getBody();
+ Message requestMessage = createRequestMessage(moduleContext, wsdlOperationType, input);
+
+ SOAPEnvelopeImpl requestEnvelope = new SOAPEnvelopeImpl();
+ try {
+
+ mediator.writeRequest(moduleContext, requestMessage, wsdlOperationType, requestEnvelope);
+ Vector bes = requestEnvelope.getBodyElements();
+
+ MessageElement me = (MessageElement) bes.get(0);
+ String s;
+ try {
+ s = me.getAsString();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ OMElement om = createOMElment(s);
+ return om;
+
+ } catch (IOException e1) {
+ throw new RuntimeException(e1);
+ } catch (SOAPException e1) {
+ throw new RuntimeException(e1);
+ }
+ }
+
+ /**
+ * Get a Tuscany response Message from an AXIOM OMElement
+ * The OMElement is the payload of the SOAP Body excluding the Body tags
+ */
+ public Message getResponseAsMessage(OMElement responseOM) {
+ Message responseMessage = new MessageFactoryImpl().createMessage();
+
+ try {
+ SOAPEnvelope responseEnvelope = createFakeEnvelope(responseOM);
+ mediator.readResponse(moduleContext, responseEnvelope, responseMessage, wsdlOperationType);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ Object output = getResponse(responseMessage, wsdlOperationType);
+ responseMessage.setBody(output);
+
+ return responseMessage;
+ }
+
+ private Message createRequestMessage(TuscanyModuleComponentContext context, WSDLOperationType operationType, Object input) {
+ Message message = new MessageFactoryImpl().createMessage();
+ HelperProvider provider = new HelperProviderImpl((ConfiguredResourceSet) context.getAssemblyModelContext().getAssemblyLoader());
+ Type inputType = operationType.getInputType();
+ DataObject inputBody = provider.getDataFactory().create(inputType);
+
+ DataObject inputData = null;
+ if (wrappedStyle) {
+ inputData = inputBody.createDataObject(0);
+ } else
+ inputData = inputBody;
+
+ Object[] args = (Object[]) input;
+ for (int i = 0; i < args.length; i++) {
+ inputData.set(i, args[i]);
+ }
+ message.setBody(inputBody);
+ return message;
+ }
+
+ private OMElement createOMElment(String xml) {
+ StringReader sr = new StringReader(xml);
+ XMLInputFactory xif = XMLInputFactory.newInstance();
+ XMLStreamReader reader;
+ try {
+ reader = xif.createXMLStreamReader(sr);
+ } catch (XMLStreamException e) {
+ throw new RuntimeException(e);
+ }
+ StAXOMBuilder builder = new StAXOMBuilder(reader);
+ OMElement om = builder.getDocumentElement();
+ return om;
+ }
+
+ private SOAPEnvelope createFakeEnvelope(OMElement responseOM) throws XMLStreamException, FactoryConfigurationError, SOAPException, SAXException,
+ IOException, ParserConfigurationException {
+
+ SOAPEnvelope envelope = new SOAPEnvelopeImpl();
+ javax.xml.soap.SOAPBody body = envelope.getBody();
+
+ StringWriter writer = new StringWriter();
+ responseOM.serializeAndConsume(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
+ writer.flush();
+ String s = writer.toString();
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(s)));
+ body.addDocument(d);
+
+ return envelope;
+ }
+
+ private Object getResponse(Message responseMessage, WSDLOperationType wsdlOperationType) {
+ Object result = responseMessage.getBody();
+ if (result == null)
+ return null;
+
+ List properties = wsdlOperationType.getOutputType().getProperties();
+ if (wrappedStyle) {
+ DataObject outputBody = ((DataObject) result).getDataObject(0);
+ Property property = (Property) properties.get(0); // the single part
+ List argList = property.getType().getProperties();
+ Object[] results = new Object[argList.size()];
+ for (int i = 0; i < results.length; i++) {
+ results[i] = outputBody.get(i);
+ }
+ if (results.length == 1)
+ return results[0];
+ else
+ return results;
+
+ } else {
+ // FIXME: [rfeng] How to deal with multi-parts output
+ DataObject outputBody = ((DataObject) result).getDataObject(0);
+ return outputBody;
+ }
+ }
+
+ private SOAPMediator createSOAPMediator() {
+ SOAPMediator mediator;
+ if ("rpc".equals(operationMetaData.getStyle())) {
+ if ("encoded".equals(operationMetaData.getUse())) {
+ // mediator = new SOAPRPCEncodedMediatorImpl(portMetaData);
+ // TODO: No rpc/enc mediator so try doc/lit one (works for simple service)
+ mediator = new SOAPDocumentLiteralMediatorImpl(portMetaData);
+ } else {
+ mediator = new SOAPRPCLiteralMediatorImpl(portMetaData);
+ }
+ } else {
+ mediator = new SOAPDocumentLiteralMediatorImpl(portMetaData);
+ }
+ return mediator;
+ }
+
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/Axis2SDOHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/Axis2SDOHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializer.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializer.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializer.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializer.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,59 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.encoding.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import commonj.sdo.DataObject;
+import org.apache.axis.encoding.DeserializationContext;
+import org.apache.axis.encoding.Deserializer;
+import org.apache.axis.encoding.DeserializerImpl;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
+import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ */
+public class DataObjectDeserializer extends DeserializerImpl implements Deserializer {
+ private static final URI SOAP_ELEMENT_URI = URI.createURI("sca:/soapElement.xml");
+
+ public void onStartElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException {
+ try {
+ XMLResource resource = new XMLResourceImpl(SOAP_ELEMENT_URI);
+ Element element = context.getCurElement();
+ // FIXME: [rfeng]
+ String str = element.toString();
+ InputStream inputStream = new ByteArrayInputStream(str.getBytes());
+ Map options = new HashMap();
+ options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
+ resource.load(inputStream, options);
+ DataObject root = (DataObject) resource.getContents().get(0);
+ DataObject dataObject = root.getDataObject(element.getLocalName());
+ setValue(dataObject);
+ } catch (Exception xe) {
+ throw new SAXException(xe);
+ }
+
+ }
+
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializer.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializerFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializerFactory.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializerFactory.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializerFactory.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,32 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.encoding.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.encoding.DeserializerFactory;
+import org.apache.axis.encoding.ser.BaseDeserializerFactory;
+
+/**
+ */
+
+public class DataObjectDeserializerFactory extends BaseDeserializerFactory implements DeserializerFactory {
+
+ public DataObjectDeserializerFactory(Class javaType, QName xmlType) {
+ super(DataObjectDeserializer.class, xmlType, javaType);
+ }
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectDeserializerFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializer.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializer.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializer.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializer.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,95 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.encoding.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+
+import commonj.sdo.DataObject;
+import org.apache.axis.Constants;
+import org.apache.axis.encoding.SerializationContext;
+import org.apache.axis.encoding.Serializer;
+import org.apache.axis.utils.Messages;
+import org.apache.axis.wsdl.fromJava.Types;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.util.ExtendedMetaData;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
+import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
+
+import org.apache.tuscany.common.io.util.UTF8String;
+
+/**
+ */
+
+public class DataObjectSerializer implements Serializer {
+ private static final URI SOAP_ELEMENT_URI = URI.createURI("sca:/soapElement.xml");
+
+ /**
+ * Serialize a DOM Document
+ */
+ public void serialize(QName name, Attributes attributes, Object value,
+ SerializationContext context) throws IOException {
+ if (!(value instanceof DataObject))
+ throw new IOException(Messages.getMessage("cantSerialize01"));
+
+ context.setWriteXMLType(null);
+
+ XMLResource resource = new XMLResourceImpl(SOAP_ELEMENT_URI);
+ Map options = new HashMap();
+ options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
+ options.put(XMLResource.OPTION_DECLARE_XML, Boolean.FALSE);
+
+ DataObject dataObject = (DataObject) value;
+
+ EStructuralFeature feature = ExtendedMetaData.INSTANCE.getElement(name.getNamespaceURI(), name.getLocalPart());
+ EObject root = EcoreUtil.create(feature.getEContainingClass());
+ root.eSet(feature, value);
+
+ resource.getContents().add(root);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ resource.save(bos, options);
+ context.writeString(UTF8String.toString(bos));
+ }
+
+ public String getMechanismType() {
+ return Constants.AXIS_SAX;
+ }
+
+ /**
+ * Return XML schema for the specified type, suitable for insertion into the
+ * <types> element of a WSDL document, or underneath an
+ * <element> or <attribute> declaration.
+ *
+ * @param javaType the Java Class we're writing out schema for
+ * @param types the Java2WSDL Types object which holds the context for the
+ * WSDL being generated.
+ * @return a type element containing a schema simpleType/complexType
+ * @see Types
+ */
+ public Element writeSchema(Class javaType, Types types) throws Exception {
+ return null;
+ }
+
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializer.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializerFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializerFactory.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializerFactory.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializerFactory.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,33 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.encoding.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.encoding.SerializerFactory;
+import org.apache.axis.encoding.ser.BaseSerializerFactory;
+
+/**
+ */
+
+public class DataObjectSerializerFactory extends BaseSerializerFactory implements SerializerFactory {
+
+ public DataObjectSerializerFactory(Class javaType, QName xmlType) {
+ super(DataObjectSerializer.class, xmlType, javaType);
+ }
+
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/encoding/impl/DataObjectSerializerFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/SOAPMediator.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/SOAPMediator.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/SOAPMediator.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/SOAPMediator.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,77 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.mediator;
+
+import java.io.IOException;
+import javax.xml.soap.SOAPException;
+
+import org.apache.axis.message.SOAPEnvelope;
+import org.osoa.sca.ModuleContext;
+
+import org.apache.tuscany.core.message.Message;
+import org.apache.tuscany.model.types.wsdl.WSDLOperationType;
+
+/**
+ */
+public interface SOAPMediator {
+
+ /**
+ * Write a request message to a SOAP envelope
+ *
+ * @param moduleContext
+ * @param message
+ * @param soapEnvelope
+ * @throws IOException
+ * @throws SOAPException
+ */
+ public void writeRequest(ModuleContext moduleContext, Message message, WSDLOperationType operationType, SOAPEnvelope soapEnvelope) throws IOException, SOAPException;
+
+ /**
+ * Write a response message to a SOAP envelope
+ *
+ * @param moduleContext
+ * @param message
+ * @param soapEnvelope
+ * @throws IOException
+ * @throws SOAPException
+ */
+ public void writeResponse(ModuleContext moduleContext, Message message, WSDLOperationType operationType, SOAPEnvelope soapEnvelope) throws IOException, SOAPException;
+
+ /**
+ * Read a request message from a SOAP envelope
+ *
+ * @param moduleContext
+ * @param soapEnvelope
+ * @param message
+ * @param bodyEClass
+ * @throws IOException
+ * @throws SOAPException
+ */
+ public void readRequest(ModuleContext moduleContext, SOAPEnvelope soapEnvelope, Message message, WSDLOperationType operationType) throws IOException, SOAPException;
+
+ /**
+ * Read a response message from a SOAP envelope
+ * @param moduleContext
+ * @param soapEnvelope
+ * @param message
+ * @param bodyEClass
+ * @throws IOException
+ * @throws SOAPException
+ */
+ public void readResponse(ModuleContext moduleContext, SOAPEnvelope soapEnvelope, Message message, WSDLOperationType operationType) throws IOException, SOAPException;
+
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/SOAPMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/SOAPMediator.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPBaseMediatorImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPBaseMediatorImpl.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPBaseMediatorImpl.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPBaseMediatorImpl.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,145 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.mediator.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import javax.xml.soap.SOAPException;
+
+import commonj.sdo.DataObject;
+import org.apache.axis.Constants;
+import org.apache.axis.message.MessageElement;
+import org.apache.axis.message.SOAPEnvelope;
+import org.apache.axis.utils.Mapping;
+import org.osoa.sca.ModuleContext;
+
+import org.apache.tuscany.binding.axis2.serialization.mediator.SOAPMediator;
+import org.apache.tuscany.binding.axis2.utils.WebServicePortMetaData;
+import org.apache.tuscany.common.io.util.UTF8String;
+import org.apache.tuscany.model.util.ConfiguredResourceSet;
+import org.apache.tuscany.core.context.TuscanyModuleComponentContext;
+import org.apache.tuscany.core.deprecated.sdo.util.HelperProvider;
+import org.apache.tuscany.core.deprecated.sdo.util.XMLHelper;
+import org.apache.tuscany.core.deprecated.sdo.util.impl.HelperProviderImpl;
+import org.apache.tuscany.core.message.Message;
+
+/**
+ */
+public abstract class SOAPBaseMediatorImpl
+ implements SOAPMediator {
+
+ protected WebServicePortMetaData portMetaData;
+
+ /**
+ *
+ */
+ public SOAPBaseMediatorImpl(WebServicePortMetaData portMetaData) {
+ super();
+ this.portMetaData = portMetaData;
+ }
+
+ /**
+ * Read a SOAP envelope into a Message DataObject
+ *
+ * @param moduleContext
+ * @param soapEnvelope
+ * @return
+ * @throws SOAPException
+ * @throws IOException
+ */
+ protected Message readSOAPEnvelope(ModuleContext moduleContext, SOAPEnvelope soapEnvelope)
+ throws SOAPException, IOException {
+ XMLHelper xmlHelper = getHelperProvider(moduleContext).getXMLHelper();
+
+ String xml;
+ try {
+ xml = soapEnvelope.getAsString();
+ }
+ catch (Exception e) {
+ throw new SOAPException(e);
+ }
+ InputStream is = UTF8String.getInputStream(xml);
+
+ // Fix the namespace prefix attributes
+ // fixAttributes(soapEnvelope);
+
+ // Load the SOAP envelope into a Message DataObject
+ // Message message=(Message)xmlHelper.load(soapEnvelope);
+ Message message = (Message) xmlHelper.load(is);
+ return message;
+ }
+
+ /**
+ * Fix the attributes of the given element.
+ *
+ * @param element
+ */
+ protected void fixAttributes(MessageElement element) {
+ if (element.namespaces != null) {
+ for (Iterator i = element.namespaces.iterator(); i.hasNext();) {
+ Mapping mapping = (Mapping) i.next();
+ String prefix = mapping.getPrefix();
+ String nsURI = mapping.getNamespaceURI();
+ String qname = prefix.length() != 0 ? "xmlns:" + prefix : "xmlns";
+ element.setAttributeNS(Constants.NS_URI_XMLNS, qname, nsURI);
+ }
+ }
+ for (Iterator i = element.getChildElements(); i.hasNext();) {
+ Object e = i.next();
+ if (e instanceof MessageElement) {
+ fixAttributes((MessageElement) e);
+ }
+ }
+ }
+
+ /**
+ * @param moduleContext
+ * @param message
+ * @param soapEnvelope
+ * @throws IOException
+ */
+ protected void writeSOAPEnvelope(ModuleContext moduleContext, Message message, SOAPEnvelope soapEnvelope)
+ throws IOException {
+ XMLHelper xmlHelper = getHelperProvider(moduleContext).getXMLHelper();
+ SOAPDocumentImpl document = new SOAPDocumentImpl(soapEnvelope);
+ xmlHelper.save((DataObject) message, document);
+ }
+
+ /*
+ protected static DataFactory getDataFactory( ModuleContext moduleContext )
+ {
+ HelperProvider helperProvider = getHelperProvider( moduleContext );
+ DataFactory dataFactory = helperProvider.getDataFactory();
+ return dataFactory;
+ }
+
+ protected static XSDHelper getXSDHelper( ModuleContext moduleContext )
+ {
+ HelperProvider helperProvider = getHelperProvider( moduleContext );
+ return helperProvider.getXSDHelper();
+ }
+ */
+
+ protected static HelperProvider getHelperProvider(ModuleContext moduleContext) {
+ TuscanyModuleComponentContext context = (TuscanyModuleComponentContext) moduleContext;
+ HelperProvider helperProvider = new HelperProviderImpl((ConfiguredResourceSet) context
+ .getAssemblyModelContext().getAssemblyLoader());
+ return helperProvider;
+ }
+
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPBaseMediatorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPBaseMediatorImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentImpl.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentImpl.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentImpl.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,97 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.mediator.impl;
+
+import javax.xml.soap.SOAPException;
+
+import org.apache.axis.Constants;
+import org.apache.axis.message.MessageElement;
+import org.apache.axis.message.SOAPEnvelope;
+import org.apache.axis.soap.SOAPConstants;
+import org.eclipse.emf.common.util.WrappedException;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ */
+public class SOAPDocumentImpl extends org.apache.axis.message.SOAPDocumentImpl {
+
+ private SOAPEnvelope soapEnvelope;
+ private Element documentElement;
+
+ /**
+ * Constructor
+ */
+ public SOAPDocumentImpl(SOAPEnvelope soapEnvelope) {
+ super(null);
+ this.soapEnvelope = soapEnvelope;
+ this.documentElement = soapEnvelope;
+ }
+
+ /**
+ * @see org.apache.axis.message.SOAPDocumentImpl#createElementNS(java.lang.String, java.lang.String)
+ */
+ public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException {
+ try {
+ SOAPConstants soapConstants = null;
+ if (Constants.URI_SOAP11_ENV.equals(namespaceURI)) {
+ soapConstants = SOAPConstants.SOAP11_CONSTANTS;
+ } else if (Constants.URI_SOAP12_ENV.equals(namespaceURI)) {
+ soapConstants = SOAPConstants.SOAP12_CONSTANTS;
+ }
+
+ if (soapConstants != null) {
+ // Special SOAP elements
+ String localName = qualifiedName.substring(qualifiedName.indexOf(':') + 1);
+ if (localName.equals(Constants.ELEM_ENVELOPE)) {
+ return soapEnvelope;
+ } else if (localName.equals(Constants.ELEM_HEADER)) {
+ return soapEnvelope.getHeader();
+ } else if (localName.equals(Constants.ELEM_BODY)) {
+ return soapEnvelope.getBody();
+ }
+ }
+
+ // General elements
+ return new MessageElement(namespaceURI, qualifiedName);
+
+ } catch (SOAPException e) {
+ throw new WrappedException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.axis.message.SOAPDocumentImpl#appendChild(org.w3c.dom.Node)
+ */
+ public Node appendChild(Node newChild) throws DOMException {
+ if (newChild.getParentNode() == null) {
+ MessageElement parent = new MessageElement();
+ parent.appendChild(newChild);
+ }
+ documentElement = (Element) newChild;
+ return newChild;
+ }
+
+ /**
+ * @see org.apache.axis.message.SOAPDocumentImpl#getDocumentElement()
+ */
+ public Element getDocumentElement() {
+ return documentElement;
+ }
+
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentLiteralMediatorImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentLiteralMediatorImpl.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentLiteralMediatorImpl.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentLiteralMediatorImpl.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,276 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.mediator.impl;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import javax.wsdl.Part;
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPException;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Sequence;
+import commonj.sdo.Type;
+import org.apache.axis.message.SOAPEnvelope;
+import org.eclipse.emf.ecore.sdo.EDataObject;
+import org.eclipse.emf.ecore.sdo.util.SDOUtil;
+import org.osoa.sca.ModuleContext;
+
+import org.apache.tuscany.binding.axis2.serialization.mediator.SOAPMediator;
+import org.apache.tuscany.binding.axis2.utils.WebServiceOperationMetaData;
+import org.apache.tuscany.binding.axis2.utils.WebServicePortMetaData;
+import org.apache.tuscany.core.deprecated.sdo.util.DataFactory;
+import org.apache.tuscany.core.deprecated.sdo.util.HelperProvider;
+import org.apache.tuscany.core.deprecated.sdo.util.XSDHelper;
+import org.apache.tuscany.core.message.Message;
+import org.apache.tuscany.core.message.sdo.FaultElement;
+import org.apache.tuscany.core.message.sdo.MessageElement;
+import org.apache.tuscany.core.message.sdo.MessageElementPackage;
+import org.apache.tuscany.model.types.wsdl.WSDLOperationType;
+
+/**
+ */
+public class SOAPDocumentLiteralMediatorImpl
+ extends SOAPBaseMediatorImpl
+ implements SOAPMediator {
+
+ /**
+ * Constructor
+ */
+ public SOAPDocumentLiteralMediatorImpl(WebServicePortMetaData portMetaData) {
+ super(portMetaData);
+ }
+
+ /**
+ * @see org.apache.tuscany.binding.axis2.serialization.mediator.SOAPMediator#writeRequest(ModuleContext, org.apache.tuscany.core.message.Message, org.eclipse.emf.ecore.WSDLOperationType, org.apache.axis.message.SOAPEnvelope)
+ */
+ public void writeRequest(ModuleContext moduleContext, Message message, WSDLOperationType wsdlOperationType,
+ SOAPEnvelope soapEnvelope)
+ throws IOException, SOAPException {
+
+ WebServiceOperationMetaData operationMetaData = portMetaData.getOperationMetaData(wsdlOperationType.getName());
+
+ MessageElement messageElement = (MessageElement) message;
+
+ Sequence headerElements = messageElement.getHeaderElement().getAny();
+ Set headerParts = operationMetaData.getInputHeaderParts();
+
+ DataObject body = (DataObject) message.getBody(); // The body is typed by the wsdl:message
+ if (body != null) {
+ message.setBody(null); // Clean up the sequence
+ Sequence bodyElements = messageElement.getBodyElement().getAny();
+
+ Type inputType = wsdlOperationType.getInputType();
+ List parts = inputType.getProperties();
+ int index = 0;
+ for (Iterator i = parts.iterator(); i.hasNext(); index++) {
+ Property partProperty = (Property) i.next();
+ Object partValue = body.get(partProperty);
+
+ Part part = operationMetaData.getInputPart(index);
+ if (headerParts.contains(part)) {
+ headerElements.add(partProperty, partValue);
+ } else {
+ bodyElements.add(partProperty, partValue);
+ }
+ }
+
+ // HACK: to reset the bodySet flag
+ messageElement.setBodyElement(messageElement.getBodyElement());
+ }
+
+ // Write to the SOAP envelope
+ writeSOAPEnvelope(moduleContext, message, soapEnvelope);
+
+ // Restore the original body
+ message.setBody(body);
+ }
+
+ /**
+ * @see org.apache.tuscany.binding.axis.mediator.SOAPMediator#writeResponse(ModuleContext, org.apache.tuscany.core.message.Message, org.eclipse.emf.ecore.WSDLOperationType, org.apache.axis.message.SOAPEnvelope)
+ */
+ public void writeResponse(ModuleContext moduleContext, Message message, WSDLOperationType wsdlOperationType,
+ SOAPEnvelope soapEnvelope)
+ throws IOException, SOAPException {
+
+ WebServiceOperationMetaData operationMetaData = portMetaData.getOperationMetaData(wsdlOperationType.getName());
+
+ MessageElement messageElement = (MessageElement) message;
+
+ Sequence headerElements = messageElement.getHeaderElement().getAny();
+ Set headerParts = operationMetaData.getOutputHeaderParts();
+
+ // Adjust the message body to match the given WSDLOperationType
+ EDataObject body = (EDataObject) message.getBody();
+ if (body != null) {
+ message.setBody(null); // Clean up the sequence
+ Sequence bodyElements = messageElement.getBodyElement().getAny();
+
+ Type type = wsdlOperationType.getOutputType();
+ List parts = type.getProperties();
+ int index = 0;
+ for (Iterator i = parts.iterator(); i.hasNext(); index++) {
+ Property partProperty = (Property) i.next();
+ Object partValue = body.get(partProperty);
+
+ Part part = operationMetaData.getInputPart(index);
+ if (headerParts.contains(part)) {
+ headerElements.add(partProperty, partValue);
+ } else {
+ bodyElements.add(partProperty, partValue);
+ }
+ }
+
+ // HACK: to reset the bodySet flag
+ messageElement.setBodyElement(messageElement.getBodyElement());
+ }
+
+ // Write to the SOAP envelope
+ writeSOAPEnvelope(moduleContext, message, soapEnvelope);
+
+ // Restore the original body
+ message.setBody(body);
+ }
+
+ /**
+ * @see org.apache.tuscany.binding.axis.mediator.SOAPMediator#readRequest(ModuleContext, org.apache.axis.message.SOAPEnvelope, org.apache.tuscany.core.message.Message, org.eclipse.emf.ecore.WSDLOperationType)
+ */
+ public void readRequest(ModuleContext moduleContext, SOAPEnvelope soapEnvelope, Message message,
+ WSDLOperationType wsdlOperationType)
+ throws IOException, SOAPException {
+
+ WebServiceOperationMetaData operationMetaData = portMetaData.getOperationMetaData(wsdlOperationType.getName());
+ Set headerParts = operationMetaData.getInputHeaderParts();
+ List bodyPartIndexes = operationMetaData.getBodyPartIndexes(true);
+
+ HelperProvider helperProvider = getHelperProvider(moduleContext);
+ XSDHelper xsdHelper = helperProvider.getXSDHelper();
+
+ MessageElement messageElement = (MessageElement) message;
+
+ // Read the SOAP envelope
+ Message soapMessage = readSOAPEnvelope(moduleContext, soapEnvelope);
+ MessageElement soapMessageElement = (MessageElement) soapMessage;
+
+ Type type = wsdlOperationType.getInputType();
+
+ DataFactory dataFactory = helperProvider.getDataFactory();
+ DataObject request = type == null ? null : dataFactory.create(type);
+
+ // Get the header element
+ Sequence headers = messageElement.getHeaderElement().getAny();
+ Sequence headerElements = soapMessageElement.getHeaderElement().getAny();
+ int size = headers.size();
+ for (int i = 0; i < size; i++) {
+ Property property = (Property) headers.getProperty(i);
+ String ns = xsdHelper.getNamespaceURI(property);
+ String localName = xsdHelper.getLocalName(property);
+
+ QName elementName = new QName(ns, localName);
+ int index = operationMetaData.getHeaderPartIndex(elementName, true);
+ if (index == -1) {
+ headerElements.add(i, property, headers.getValue(i));
+ } else {
+ request.set(index, headers.getValue(i));
+ }
+ }
+
+ // Wrap the SOAP body into the expected wrapper DataObject
+ Sequence bodyElements = soapMessageElement.getBodyElement().getAny();
+
+ for (int i = 0; i < bodyElements.size(); i++) {
+ Object value = bodyElements.getValue(i);
+ int index = ((Integer) bodyPartIndexes.get(i)).intValue();
+ request.set(index, value);
+ }
+ message.setBody(request);
+
+ }
+
+ /**
+ * @see org.apache.tuscany.binding.axis.mediator.SOAPMediator#readResponse(ModuleContext, org.apache.axis.message.SOAPEnvelope, org.apache.tuscany.core.message.Message, org.eclipse.emf.ecore.WSDLOperationType)
+ */
+ public void readResponse(ModuleContext moduleContext, SOAPEnvelope soapEnvelope, Message message,
+ WSDLOperationType wsdlOperationType)
+ throws IOException, SOAPException {
+
+ WebServiceOperationMetaData operationMetaData = portMetaData.getOperationMetaData(wsdlOperationType.getName());
+ Set headerParts = operationMetaData.getOutputHeaderParts();
+ List bodyPartIndexes = operationMetaData.getBodyPartIndexes(false);
+ HelperProvider helperProvider = getHelperProvider(moduleContext);
+ XSDHelper xsdHelper = helperProvider.getXSDHelper();
+
+ MessageElement messageElement = (MessageElement) message;
+
+ // Read the SOAP envelope
+ Message soapMessage = readSOAPEnvelope(moduleContext, soapEnvelope);
+ MessageElement soapMessageElement = (MessageElement) soapMessage;
+
+ Type type = wsdlOperationType.getOutputType();
+
+ DataFactory dataFactory = helperProvider.getDataFactory();
+ DataObject response = type == null ? null : dataFactory.create(type);
+
+ // Get the header element
+ Sequence headers = messageElement.getHeaderElement().getAny();
+ Sequence headerElements = soapMessageElement.getHeaderElement().getAny();
+ int size = headers.size();
+ for (int i = 0; i < size; i++) {
+ Property property = (Property) headers.getProperty(i);
+ String ns = xsdHelper.getNamespaceURI(property);
+ String localName = xsdHelper.getLocalName(property);
+
+ QName elementName = new QName(ns, localName);
+ int index = operationMetaData.getHeaderPartIndex(elementName, false);
+ if (index == -1) {
+ headerElements.add(i, property, headers.getValue(i));
+ } else {
+ response.set(index, headers.getValue(i));
+ }
+ }
+
+ // Wrap the SOAP body into the expected wrapper DataObject
+ Sequence bodyElements = soapMessageElement.getBodyElement().getAny();
+
+ for (int i = 0; i < bodyElements.size(); i++) {
+ Object value = bodyElements.getValue(i);
+ int index = ((Integer) bodyPartIndexes.get(i)).intValue();
+ response.set(index, value);
+ }
+ message.setBody(response);
+
+ }
+
+ public FaultElement readFault(MessageElement messageElement, WSDLOperationType wsdlOperationType) {
+ Property faultProperty = SDOUtil.adaptProperty(MessageElementPackage.eINSTANCE.getDocumentRoot_FaultElement());
+
+ Sequence bodyElements = messageElement.getBodyElement().getAny();
+ int size = bodyElements.size();
+ if (size == 1) {
+ Property property = bodyElements.getProperty(0);
+ if (property == faultProperty) {
+ FaultElement fault = (FaultElement) bodyElements.getValue(0);
+ // Sequence faultParts = fault.getDetail().getAny();
+ return fault;
+ }
+ }
+ return null;
+ }
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentLiteralMediatorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPDocumentLiteralMediatorImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPEnvelopeImpl.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPEnvelopeImpl.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPEnvelopeImpl.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,49 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.mediator.impl;
+
+import org.apache.axis.message.SOAPBody;
+import org.apache.axis.message.SOAPEnvelope;
+import org.apache.axis.message.SOAPHeader;
+import org.apache.axis.soap.SOAPConstants;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Node;
+
+public class SOAPEnvelopeImpl extends SOAPEnvelope {
+
+ /**
+ * Constructor
+ *
+ * @param soapConstants
+ */
+ public SOAPEnvelopeImpl() {
+ super(SOAPConstants.SOAP12_CONSTANTS);
+ }
+
+ /**
+ * @see org.apache.axis.message.NodeImpl#appendChild(org.w3c.dom.Node)
+ */
+ public Node appendChild(Node newChild) throws DOMException {
+ newChild = super.appendChild(newChild);
+ if (newChild instanceof SOAPHeader) {
+ setHeader((SOAPHeader) newChild);
+ } else if (newChild instanceof SOAPBody) {
+ setBody((SOAPBody) newChild);
+ }
+ return newChild;
+ }
+}
\ No newline at end of file
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPEnvelopeImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPEnvelopeImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCEncodedMediatorImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCEncodedMediatorImpl.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCEncodedMediatorImpl.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCEncodedMediatorImpl.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,53 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.mediator.impl;
+
+import java.io.IOException;
+import javax.xml.soap.SOAPException;
+
+import org.apache.axis.message.SOAPEnvelope;
+import org.osoa.sca.ModuleContext;
+
+import org.apache.tuscany.binding.axis2.utils.WebServicePortMetaData;
+import org.apache.tuscany.core.message.Message;
+import org.apache.tuscany.model.types.wsdl.WSDLOperationType;
+
+/**
+ */
+public class SOAPRPCEncodedMediatorImpl extends SOAPBaseMediatorImpl {
+
+ public void readRequest(ModuleContext moduleContext, SOAPEnvelope soapEnvelope, Message message, WSDLOperationType operationType) throws IOException, SOAPException {
+ }
+
+ public void readResponse(ModuleContext moduleContext, SOAPEnvelope soapEnvelope, Message message, WSDLOperationType operationType) throws IOException, SOAPException {
+ }
+
+ public void writeRequest(ModuleContext moduleContext, Message message, WSDLOperationType operationType, SOAPEnvelope soapEnvelope) throws IOException, SOAPException {
+ }
+
+ public void writeResponse(ModuleContext moduleContext, Message message, WSDLOperationType operationType, SOAPEnvelope soapEnvelope) throws IOException, SOAPException {
+ }
+
+ /**
+ *
+ */
+ public SOAPRPCEncodedMediatorImpl(WebServicePortMetaData portMetaData) {
+ super(portMetaData);
+ }
+
+
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCEncodedMediatorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCEncodedMediatorImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Added: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCLiteralMediatorImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCLiteralMediatorImpl.java?rev=379259&view=auto
==============================================================================
--- incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCLiteralMediatorImpl.java (added)
+++ incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCLiteralMediatorImpl.java Mon Feb 20 14:26:19 2006
@@ -0,0 +1,282 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.binding.axis2.serialization.mediator.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import javax.wsdl.Input;
+import javax.wsdl.Operation;
+import javax.wsdl.Output;
+import javax.wsdl.Part;
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPException;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Sequence;
+import commonj.sdo.Type;
+import org.apache.axis.message.SOAPEnvelope;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.sdo.EProperty;
+import org.eclipse.emf.ecore.sdo.EType;
+import org.eclipse.emf.ecore.sdo.util.SDOUtil;
+import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.util.ExtendedMetaData;
+import org.eclipse.emf.ecore.util.FeatureMap;
+import org.eclipse.emf.ecore.xml.type.AnyType;
+import org.eclipse.emf.ecore.xml.type.XMLTypeFactory;
+import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
+import org.osoa.sca.ModuleContext;
+
+import org.apache.tuscany.binding.axis2.serialization.mediator.SOAPMediator;
+import org.apache.tuscany.binding.axis2.utils.WebServiceOperationMetaData;
+import org.apache.tuscany.binding.axis2.utils.WebServicePortMetaData;
+import org.apache.tuscany.core.deprecated.sdo.util.DataFactory;
+import org.apache.tuscany.core.deprecated.sdo.util.HelperProvider;
+import org.apache.tuscany.core.message.Message;
+import org.apache.tuscany.core.message.sdo.MessageElement;
+import org.apache.tuscany.model.types.wsdl.WSDLOperationType;
+
+/**
+ */
+public class SOAPRPCLiteralMediatorImpl
+ extends SOAPDocumentLiteralMediatorImpl
+ implements SOAPMediator {
+
+ public void readRequest(ModuleContext moduleContext, SOAPEnvelope soapEnvelope, Message message,
+ WSDLOperationType operationType)
+ throws IOException, SOAPException {
+ MessageElement messageElement = (MessageElement) message;
+
+ // Read the SOAP envelope
+ Message soapMessage = readSOAPEnvelope(moduleContext, soapEnvelope);
+ MessageElement soapMessageElement = (MessageElement) soapMessage;
+
+ // Get the header element
+ Sequence headers = messageElement.getHeaderElement().getAny();
+ Sequence soapHeaders = soapMessageElement.getHeaderElement().getAny();
+ int size = headers.size();
+ for (int i = 0; i < size; i++) {
+ soapHeaders.add(i, headers.getProperty(i), headers.getValue(i));
+ }
+
+ // Wrap the SOAP body into the expected wrapper DataObject
+ Sequence sequence = soapMessageElement.getBodyElement().getAny();
+ Type type = operationType.getInputType();
+
+ HelperProvider helperProvider = getHelperProvider(moduleContext);
+ DataFactory dataFactory = helperProvider.getDataFactory();
+ DataObject request = type == null ? null : dataFactory.create(type);
+
+ FeatureMap featureMap = ((AnyType) sequence.getValue(0)).getAny(); // The first element is the rpc operation wrapper
+ List values = new ArrayList();
+ for (int i = 0; i < featureMap.size(); i++) {
+ Object value = featureMap.getValue(i);
+ values.add(value);
+ }
+ for (int i = 0; i < values.size(); i++) {
+ Object value = values.get(i);
+ value = getValue(type, i, value);
+ request.set(i, value);
+ }
+
+ message.setBody(request);
+ }
+
+ private Object getValue(Type type, int propertyIndex, Object value) {
+ if (value instanceof AnyType) {
+ Property part = (Property) type.getProperties().get(propertyIndex);
+ EClassifier partType = ((EType) part.getType()).getEClassifier();
+ if (partType instanceof EDataType) {
+ AnyType anyType = (AnyType) value;
+ String str = (String) anyType.getMixed().getValue(0);
+ value = EcoreUtil.createFromString((EDataType) partType, str);
+ }
+ }
+ return value;
+ }
+
+ public void readResponse(ModuleContext moduleContext, SOAPEnvelope soapEnvelope, Message message,
+ WSDLOperationType operationType)
+ throws IOException, SOAPException {
+ MessageElement messageElement = (MessageElement) message;
+
+ // Read the SOAP envelope
+ Message soapMessage = readSOAPEnvelope(moduleContext, soapEnvelope);
+ MessageElement soapMessageElement = (MessageElement) soapMessage;
+ messageElement.setHeaderElement(soapMessageElement.getHeaderElement());
+
+ // Get the header element
+ Sequence headers = messageElement.getHeaderElement().getAny();
+ Sequence soapHeaders = soapMessageElement.getHeaderElement().getAny();
+ int size = headers.size();
+ for (int i = 0; i < size; i++) {
+ soapHeaders.add(i, headers.getProperty(i), headers.getValue(i));
+ }
+
+ // Wrap the SOAP body into the expected wrapper DataObject
+ Sequence sequence = soapMessageElement.getBodyElement().getAny();
+ Type type = operationType.getOutputType();
+
+ HelperProvider helperProvider = getHelperProvider(moduleContext);
+ DataFactory dataFactory = helperProvider.getDataFactory();
+ DataObject response = type == null ? null : dataFactory.create(type);
+
+ FeatureMap featureMap = ((AnyType) sequence.getValue(0)).getAny(); // The first element is the rpc operation wrapper
+ List values = new ArrayList();
+ for (int i = 0; i < featureMap.size(); i++) {
+ Object value = featureMap.getValue(i);
+ values.add(value);
+ }
+ for (int i = 0; i < values.size(); i++) {
+ Object value = values.get(i);
+ value = getValue(type, i, value);
+ response.set(i, value);
+ }
+ message.setBody(response);
+
+ }
+
+ public void writeRequest(ModuleContext moduleContext, Message message, WSDLOperationType operationType,
+ SOAPEnvelope soapEnvelope)
+ throws IOException, SOAPException {
+ Object body = message.getBody();
+
+ message.setBody(null);
+ MessageElement messageElement = (MessageElement) message;
+ Sequence sequence = messageElement.getBodyElement().getAny();
+
+ // Create an element to represent the RPC operation
+ WebServiceOperationMetaData operationMetaData = portMetaData.getOperationMetaData(operationType.getName());
+ QName opName = operationMetaData.getRPCOperationName();
+ ExtendedMetaData extendedMetaData = new BasicExtendedMetaData();
+ EStructuralFeature feature = extendedMetaData.demandFeature(opName.getNamespaceURI(), opName.getLocalPart(),
+ true);
+ feature.setDerived(false);
+ feature.setEType(XMLTypePackage.eINSTANCE.getAnyType());
+
+ // Add "xsd:any"
+ AnyType anyType = XMLTypeFactory.eINSTANCE.createAnyType();
+ Property rpcOperation = SDOUtil.adaptProperty(feature);
+ sequence.add(rpcOperation, anyType);
+
+ if (body != null) {
+ Operation operation = operationType.getWSDLOperation();
+ Input input = operation.getInput();
+ List parts = input.getMessage().getOrderedParts(null);
+ Type type = operationType.getInputType();
+ List properties = type.getProperties();
+ int index = 0;
+ for (Iterator i = parts.iterator(); i.hasNext(); index++) {
+ Part part = (Part) i.next();
+ Property property = (Property) properties.get(index);
+ EStructuralFeature partFeature = ((EProperty) property).getEStructuralFeature();
+ /**
+ * Basic Profile 1.1
+ * 4.7.20 Part Accessors
+ * For rpc-literal envelopes, WSDL 1.1 is not clear what namespace, if any, the accessor elements
+ * for parameters and return value are a part of. Different implementations make different choices,
+ * leading to interoperability problems.
+ * R2735 An ENVELOPE described with an rpc-literal binding MUST place the part accessor elements for
+ * parameters and return value in no namespace.
+ * R2755 The part accessor elements in a MESSAGE described with an rpc-literal binding MUST have a
+ * local name of the same value as the name attribute of the corresponding wsdl:part element.
+ * Settling on one alternative is crucial to achieving interoperability. The Profile places the part
+ * accessor elements in no namespace as doing so is simple, covers all cases, and does not lead to
+ * logical inconsistency.
+ */
+ partFeature = extendedMetaData.demandFeature(null, part.getName(), true,
+ partFeature instanceof EReference);
+ Object value = ((DataObject) body).get(index);
+ anyType.getAny().add(index, partFeature, value);
+ }
+ }
+ writeSOAPEnvelope(moduleContext, message, soapEnvelope);
+
+ // Restore the original body
+ message.setBody(body);
+
+ }
+
+ public void writeResponse(ModuleContext moduleContext, Message message, WSDLOperationType operationType,
+ SOAPEnvelope soapEnvelope)
+ throws IOException, SOAPException {
+ Object body = message.getBody();
+
+ message.setBody(null);
+ MessageElement messageElement = (MessageElement) message;
+ Sequence sequence = messageElement.getBodyElement().getAny();
+
+ // Create an element to represent the RPC operation
+ WebServiceOperationMetaData operationMetaData = portMetaData.getOperationMetaData(operationType.getName());
+ QName opName = operationMetaData.getRPCOperationName();
+ ExtendedMetaData extendedMetaData = new BasicExtendedMetaData();
+ /**
+ * Basic Profile 1.1
+ * 4.7.19 Response Wrappers
+ * WSDL 1.1 Section 3.5 could be interpreted to mean the RPC response wrapper element must be named
+ * identical to the name of the wsdl:operation.
+ * R2729 An ENVELOPE described with an rpc-literal binding that is a response MUST have a wrapper element
+ * whose name is the corresponding wsdl:operation name suffixed with the string "Response".
+ */
+ EStructuralFeature feature = extendedMetaData.demandFeature(opName.getNamespaceURI(), opName.getLocalPart()
+ + "Response", true);
+ feature.setDerived(false);
+ feature.setEType(XMLTypePackage.eINSTANCE.getAnyType());
+
+ // Add "xsd:any"
+ AnyType anyType = XMLTypeFactory.eINSTANCE.createAnyType();
+ Property rpcOperation = SDOUtil.adaptProperty(feature);
+ sequence.add(rpcOperation, anyType);
+
+ if (body != null) {
+ Operation operation = operationType.getWSDLOperation();
+ Output output = operation.getOutput();
+ List parts = output.getMessage().getOrderedParts(null);
+ Type type = operationType.getOutputType();
+
+ List properties = type.getProperties();
+
+ int index = 0;
+ for (Iterator i = parts.iterator(); i.hasNext(); index++) {
+ Part part = (Part) i.next();
+ Property property = (Property) properties.get(index);
+ EStructuralFeature partFeature = ((EProperty) property).getEStructuralFeature();
+ partFeature = extendedMetaData.demandFeature(null, part.getName(), true,
+ partFeature instanceof EReference);
+ Object value = ((DataObject) body).get(index);
+ anyType.getAny().add(index, partFeature, value);
+ }
+ }
+ writeSOAPEnvelope(moduleContext, message, soapEnvelope);
+
+ // Restore the original body
+ message.setBody(body);
+
+ }
+
+ public SOAPRPCLiteralMediatorImpl(WebServicePortMetaData portMetaData) {
+ super(portMetaData);
+ }
+}
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCLiteralMediatorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/serialization/mediator/impl/SOAPRPCLiteralMediatorImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date