You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by wo...@apache.org on 2008/03/03 19:48:24 UTC

svn commit: r633234 [9/24] - in /webservices/axis2/trunk/java: ./ modules/jaxws-integration/ modules/jaxws-integration/test/ modules/jaxws-integration/test/client/ modules/jaxws-integration/test/org/ modules/jaxws-integration/test/org/apache/ modules/j...

Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/BlockTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/BlockTests.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/BlockTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/BlockTests.java Mon Mar  3 10:47:38 2008
@@ -0,0 +1,1119 @@
+/*
+ * 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.axis2.jaxws.message;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBIntrospector;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.util.JAXBSource;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axis2.datasource.jaxb.JAXBDSContext;
+import org.apache.axis2.datasource.jaxb.JAXBDataSource;
+import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
+import org.apache.axis2.jaxws.message.databinding.JAXBUtils;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.message.factory.OMBlockFactory;
+import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
+import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.jaxws.TestLogger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+import test.EchoString;
+import test.ObjectFactory;
+
+/**
+ * BlockTests
+ * Tests to create and validate blocks.
+ * These are not client/server tests.
+ */
+public class BlockTests extends TestCase {
+
+    // String test variables
+    private static final String sampleText =
+        "<pre:a xmlns:pre=\"urn://sample\">" +
+        "<b>Hello</b>" +
+        "<c>World</c>" +
+        "</pre:a>";
+    private static final QName sampleQName = new QName("urn://sample", "a");
+
+
+    private static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+    private static XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+
+
+
+    public BlockTests() {
+        super();
+    }
+
+    public BlockTests(String arg0) {
+        super(arg0);
+    }
+
+    /**
+     * Create a Block representing an XMLString and simulate a 
+     * normal Dispatch<String> flow
+     * @throws Exception
+     */
+    public void testStringOutflow() throws Exception {
+        // Get the BlockFactory
+        XMLStringBlockFactory f = (XMLStringBlockFactory)
+        FactoryRegistry.getFactory(XMLStringBlockFactory.class);
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS dispatch<String> client
+        Block block = f.createFrom(sampleText, null, null);
+
+        // We didn't pass in a qname, so the following should return false
+        assertTrue(!block.isQNameAvailable());
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+
+    }
+
+    /**
+     * Create a Block representing an XMLString and
+     * simulate a different Dispatch<String> flow
+     * @throws Exception
+     */
+    public void testStringOutflow2() throws Exception {
+        // Get the BlockFactory
+        XMLStringBlockFactory f = (XMLStringBlockFactory)
+        FactoryRegistry.getFactory(XMLStringBlockFactory.class);
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS dispatch<String> client
+        Block block = f.createFrom(sampleText, null, null);
+
+        // We didn't pass in a qname, so the following should return false
+        assertTrue(!block.isQNameAvailable());
+
+        // Assume that we need to find the QName (perhaps to identify the operation and 
+        // determine if handlers are installed).   This is not very perfomant since 
+        // it causes an underlying parse of the String...but we need to support this.
+        QName qName = block.getQName();
+        assertTrue("Expected: " + sampleQName + " but found: " + qName, sampleQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+
+    }
+
+    /**
+     * Create a Block representing an XMLString and
+     * simulate a different String parameter flow
+     * @throws Exception
+     */
+    public void testStringOutflow3() throws Exception {
+        // Get the BlockFactory
+        XMLStringBlockFactory f = (XMLStringBlockFactory)
+        FactoryRegistry.getFactory(XMLStringBlockFactory.class);
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS String parameter on the client.
+        // In this case, we know the QName prior to creating the Block...so let's pass it in.
+        Block block = f.createFrom(sampleText, null, sampleQName);
+
+        // Make sure the QName is correct.
+        QName qName = block.getQName();
+        assertTrue(sampleQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+    }
+
+    /**
+     * Create a Block representing an XMLString and simulate a 
+     * normal Dispatch<String> input flow
+     * @throws Exception
+     */
+    public void testStringInflow() throws Exception {
+        // Get the BlockFactory
+        XMLStringBlockFactory f = (XMLStringBlockFactory)
+        FactoryRegistry.getFactory(XMLStringBlockFactory.class);
+
+        // On inbound, there will already be a XMLStreamReader (probably from OM)
+        // which represents the message.  We will simulate this with inflow.
+        StringReader sr = new StringReader(sampleText);
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+
+        // Create a Block from the inflow.  
+        Block block = f.createFrom(inflow, null, null);
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object (String).
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof String);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check the String for accuracy
+        assertTrue(sampleText.equals(bo.toString()));
+
+    }
+
+    /**
+     * Create a Block representing an XMLString and simulate a 
+     * slightly more complicated Dispatch<String> inflow
+     * @throws Exception
+     */
+    public void testStringInflow2() throws Exception {
+        // Get the BlockFactory
+        XMLStringBlockFactory f = (XMLStringBlockFactory)
+        FactoryRegistry.getFactory(XMLStringBlockFactory.class);
+
+        // On inbound, there will already be a XMLStreamReader (probably from OM)
+        // which represents the message.  We will simulate this with inflow.
+        StringReader sr = new StringReader(sampleText);
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+
+        // Create a Block from the inflow.  
+        Block block = f.createFrom(inflow, null, null);
+
+        // Let's assume we need to get the QName to find the operation name.
+        // This will cause an underlying parse
+        QName qName = block.getQName();
+        assertTrue(sampleQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object (String).
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof String);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check the String for accuracy
+        assertTrue(sampleText.equals(bo.toString()));
+
+    }
+
+    /**
+     * Create a Block representing an XMLString and simulate a 
+     * slightly more complicated String  inflow
+     * @throws Exception
+     */
+    public void testStringInflow3() throws Exception {
+        // Get the BlockFactory
+        XMLStringBlockFactory f = (XMLStringBlockFactory)
+        FactoryRegistry.getFactory(XMLStringBlockFactory.class);
+
+        // On inbound, there will already be a XMLStreamReader (probably from OM)
+        // which represents the message.  We will simulate this with inflow.
+        StringReader sr = new StringReader(sampleText);
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+
+        // Create a Block from the inflow.  Assume that we know the QName already
+        Block block = f.createFrom(inflow, null, sampleQName);
+
+        // Let's assume we need to get the QName to find the operation name.
+        QName qName = block.getQName();
+        assertTrue(sampleQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object (String).
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof String);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check the String for accuracy
+        assertTrue(sampleText.equals(bo.toString()));
+
+    }
+
+    /**
+     * Create a Block representing an JAXB and simulate a 
+     * normal Dispatch<JAXB> flow
+     * @throws Exception
+     */
+    public void testJAXBOutflow() throws Exception {
+        // Get the BlockFactory
+        JAXBBlockFactory f = (JAXBBlockFactory)
+        FactoryRegistry.getFactory(JAXBBlockFactory.class);
+
+        // Create a jaxb object
+        ObjectFactory factory = new ObjectFactory();
+        EchoString jaxb = factory.createEchoString(); 
+        jaxb.setInput("Hello World");
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
+
+        JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
+        QName expectedQName = jbi.getElementName(jaxb);
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS dispatch<JAXB> client
+        Block block = f.createFrom(jaxb, context, null);
+
+        // JAXB objects set the qname from their internal data
+        assertTrue(block.isQNameAvailable());
+
+        // Assume that we need to find the QName (perhaps to identify the operation and 
+        // determine if handlers are installed).   This is not very perfomant since 
+        // it causes an underlying parse of the String...but we need to support this.
+        QName qName = block.getQName();
+        assertTrue("Expected: " + expectedQName + " but found: " + qName, expectedQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(newText.contains("Hello World"));
+        assertTrue(newText.contains("echoString"));
+
+    }
+
+    /**
+     * Create a Block representing an JAXB and simulate a 
+     * slightly more complicated Dispatch<JAXB> flow
+     * @throws Exception
+     */
+    public void testJAXBOutflow2() throws Exception {
+        // Get the BlockFactory
+        JAXBBlockFactory f = (JAXBBlockFactory)
+        FactoryRegistry.getFactory(JAXBBlockFactory.class);
+
+        // Create a jaxb object
+        ObjectFactory factory = new ObjectFactory();
+        EchoString jaxb = factory.createEchoString(); 
+        jaxb.setInput("Hello World");
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
+
+        JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
+        QName expectedQName = jbi.getElementName(jaxb);
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs with an outbound JAX-WS JAXB parameter
+        Block block = f.createFrom(jaxb, context, expectedQName);
+
+        // We did pass in a qname, so the following should return false
+        assertTrue(block.isQNameAvailable());
+
+        // Assume that we need to find the QName (perhaps to identify the operation and 
+        // determine if handlers are installed).   This is not very perfomant since 
+        // it causes an underlying parse of the String...but we need to support this.
+        QName qName = block.getQName();
+        assertTrue("Expected: " + expectedQName + " but found: " + qName, expectedQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(newText.contains("Hello World"));
+        assertTrue(newText.contains("echoString"));
+
+    }
+
+    /**
+     * Create a Block representing an JAXB and simulate a 
+     * normal Dispatch<JAXB> input flow
+     * @throws Exception
+     */
+    public void testJAXBInflow() throws Exception {
+        // Get the BlockFactory
+        JAXBBlockFactory f = (JAXBBlockFactory)
+        FactoryRegistry.getFactory(JAXBBlockFactory.class);
+
+        // Create a jaxb object
+        ObjectFactory factory = new ObjectFactory();
+        EchoString jaxb = factory.createEchoString(); 
+        jaxb.setInput("Hello World");
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
+
+        // On inbound, there will already be a XMLStreamReader (probably from OM)
+        // which represents the message.  We will simulate this with inflow.
+        StringWriter sw = new StringWriter();
+        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
+        Marshaller marshaller = JAXBUtils.getJAXBMarshaller(context.getJAXBContext());
+        marshaller.marshal(jaxb, writer);
+        JAXBUtils.releaseJAXBMarshaller(context.getJAXBContext(), marshaller);
+        writer.flush();
+        sw.flush();
+        StringReader sr = new StringReader(sw.toString());
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+
+        // Create a Block from the inflow.  
+        Block block = f.createFrom(inflow, context, null);
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object.
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof EchoString);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check for accuracy
+        assertTrue("Unexpected:" + ((EchoString)bo).getInput(), ((EchoString)bo).getInput().equals(jaxb.getInput()));
+
+    }
+
+    /**
+     * Create a Block representing an JAXB and simulate a 
+     * normal Dispatch<JAXB> input flow
+     * @throws Exception
+     */
+    public void testJAXBInflow2() throws Exception {
+        // Get the BlockFactory
+        JAXBBlockFactory f = (JAXBBlockFactory)
+        FactoryRegistry.getFactory(JAXBBlockFactory.class);
+
+        // Create a jaxb object
+        ObjectFactory factory = new ObjectFactory();
+        EchoString jaxb = factory.createEchoString(); 
+        jaxb.setInput("Hello World");
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
+
+        JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
+        QName expectedQName = jbi.getElementName(jaxb);
+
+        // On inbound, there will already be a XMLStreamReader (probably from OM)
+        // which represents the message.  We will simulate this with inflow.
+        StringWriter sw = new StringWriter();
+        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
+        Marshaller marshaller = JAXBUtils.getJAXBMarshaller(context.getJAXBContext());
+        marshaller.marshal(jaxb, writer);
+        JAXBUtils.releaseJAXBMarshaller(context.getJAXBContext(), marshaller);
+        writer.flush();
+        sw.flush();
+        StringReader sr = new StringReader(sw.toString());
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+
+        // Create a Block from the inflow.  
+        Block block = f.createFrom(inflow, context, null);
+
+        // Assume that we need to find the QName (perhaps to identify the operation and 
+        // determine if handlers are installed).   This is not very perfomant since 
+        // it causes an underlying parse of the String...but we need to support this.
+        QName qName = block.getQName();
+        assertTrue("Expected: " + expectedQName + " but found: " + qName, expectedQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object.
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof EchoString);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check for accuracy
+        assertTrue("Unexpected:" + ((EchoString)bo).getInput(), ((EchoString)bo).getInput().equals(jaxb.getInput()));
+
+    }
+
+    /**
+     * Create a Block representing an JAXB and simulate a 
+     * normal Dispatch<JAXB> input flow
+     * @throws Exception
+     */
+    public void testJAXBInflow3() throws Exception {
+        // Get the BlockFactory
+        JAXBBlockFactory f = (JAXBBlockFactory)
+        FactoryRegistry.getFactory(JAXBBlockFactory.class);
+
+        // Create a jaxb object
+        ObjectFactory factory = new ObjectFactory();
+        EchoString jaxb = factory.createEchoString(); 
+        jaxb.setInput("Hello World");
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
+
+        JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
+        QName expectedQName = jbi.getElementName(jaxb);
+
+        // On inbound, there will already be a XMLStreamReader (probably from OM)
+        // which represents the message.  We will simulate this with inflow.
+        StringWriter sw = new StringWriter();
+        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
+        Marshaller marshaller = JAXBUtils.getJAXBMarshaller(context.getJAXBContext());
+        marshaller.marshal(jaxb, writer);
+        JAXBUtils.releaseJAXBMarshaller(context.getJAXBContext(), marshaller);
+        writer.flush();
+        sw.flush();
+        StringReader sr = new StringReader(sw.toString());
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+
+        // Create a Block from the inflow.  
+        Block block = f.createFrom(inflow, context, expectedQName);
+
+        // We passed in a qname, so the following should return true
+        assertTrue(block.isQNameAvailable());
+
+        // Assume that we need to find the QName (perhaps to identify the operation and 
+        // determine if handlers are installed).   This is not very perfomant since 
+        // it causes an underlying parse of the String...but we need to support this.
+        QName qName = block.getQName();
+        assertTrue("Expected: " + expectedQName + " but found: " + qName, expectedQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object.
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof EchoString);
+        assertTrue(bo != jaxb);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check for accuracy
+        assertTrue("Unexpected:" + ((EchoString)bo).getInput(), ((EchoString)bo).getInput().equals(jaxb.getInput()));
+
+    }
+
+    /**
+     * Create a Block representing an JAXB and simulate a 
+     * normal Dispatch<JAXB> input flow
+     * @throws Exception
+     */
+    public void testJAXBInflow4() throws Exception {
+        // Get the BlockFactory
+        JAXBBlockFactory f = (JAXBBlockFactory)
+        FactoryRegistry.getFactory(JAXBBlockFactory.class);
+
+        // Create a jaxb object
+        ObjectFactory factory = new ObjectFactory();
+        EchoString jaxb = factory.createEchoString(); 
+        jaxb.setInput("Hello World");
+        JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
+        JAXBContext jaxbContext = context.getJAXBContext();
+
+        JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(jaxbContext);
+        QName expectedQName = jbi.getElementName(jaxb);
+
+        // On inbound, there will already be a probably be an OM
+        // which represents the message.  In this scenario, the OM contains
+        // a OMSourcedElement that is backed by EchoString.
+        OMFactory omFactory = OMAbstractFactory.getOMFactory();
+        JAXBDSContext dsContext = new JAXBDSContext(jaxbContext);
+        JAXBDataSource ds = new JAXBDataSource(jaxb, dsContext);
+        OMNamespace ns = omFactory.createOMNamespace(expectedQName.getNamespaceURI(), "pre");
+        OMElement om = omFactory.createOMElement(ds, expectedQName.getLocalPart(), ns);
+        
+
+        // Create a Block from the inflow.  
+        Block block = f.createFrom(om, context, expectedQName);
+
+        // We passed in a qname, so the following should return true
+        assertTrue(block.isQNameAvailable());
+
+        // Assume that we need to find the QName (perhaps to identify the operation and 
+        // determine if handlers are installed).   
+        QName qName = block.getQName();
+        assertTrue("Expected: " + expectedQName + " but found: " + qName, expectedQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object.
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof EchoString);
+        
+        // Since the EchoString was already provided in a data source, this
+        // object should be same as the original echoString
+        assertTrue(bo == jaxb);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check for accuracy
+        assertTrue("Unexpected:" + ((EchoString)bo).getInput(), ((EchoString)bo).getInput().equals(jaxb.getInput()));
+
+    }
+
+    /**
+     * Create a Block representing an OM and simulate a 
+     * normal Dispatch<OMElement> flow
+     * @throws Exception
+     */
+    public void testOMOutflow() throws Exception {
+        // Get the BlockFactory
+        OMBlockFactory f = (OMBlockFactory)
+        FactoryRegistry.getFactory(OMBlockFactory.class);
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS dispatch<OMElement> client
+        StringReader sr = new StringReader(sampleText);
+        XMLStreamReader inputReader = inputFactory.createXMLStreamReader(sr);
+        StAXOMBuilder builder = new StAXOMBuilder(inputReader);  
+        OMElement om = builder.getDocumentElement();
+        Block block = f.createFrom(om, null, null);
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+
+    }
+
+
+    /**
+     * Create a Block representing an OM and simulate a 
+     * different Dispatch<OMElement> flow
+     * @throws Exception
+     */
+    public void testOMOutflow2() throws Exception {
+        // Get the BlockFactory
+        OMBlockFactory f = (OMBlockFactory)
+        FactoryRegistry.getFactory(OMBlockFactory.class);
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS dispatch<OMElement> client
+        StringReader sr = new StringReader(sampleText);
+        XMLStreamReader inputReader = inputFactory.createXMLStreamReader(sr);
+        StAXOMBuilder builder = new StAXOMBuilder(inputReader);  
+        OMElement om = builder.getDocumentElement();
+        Block block = f.createFrom(om, null, null);
+
+        // Assume that we need to find the QName (perhaps to identify the operation and 
+        // determine if handlers are installed).   This is not very perfomant since 
+        // it causes an underlying parse of the String...but we need to support this.
+        QName qName = block.getQName();
+        assertTrue("Expected: " + sampleQName + " but found: " + qName, sampleQName.equals(qName));
+
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+
+    }
+
+    /**
+     * Create a Block representing an XMLString and simulate a 
+     *  Dispatch<OMElement> inflow
+     * @throws Exception
+     */
+    public void testOMInflow() throws Exception {
+        // Get the BlockFactory
+        OMBlockFactory f = (OMBlockFactory)
+        FactoryRegistry.getFactory(OMBlockFactory.class);
+
+        // On inbound, there will already be a XMLStreamReader (probably from OM)
+        // which represents the message.  We will simulate this with inflow.
+        StringReader sr = new StringReader(sampleText);
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+
+        // Create a Block from the inflow.  
+        Block block = f.createFrom(inflow, null, null);
+
+        // Let's assume we need to get the QName to find the operation name.
+        // This will cause an underlying parse
+        QName qName = block.getQName();
+        assertTrue(sampleQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object (String).
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof OMElement);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check the String for accuracy
+        assertTrue(sampleText.equals(bo.toString()));
+
+    }
+
+    /**
+     * Create a Block representing a Source and simulate a 
+     * normal Dispatch<Source> flow
+     * @throws Exception
+     */
+    public void testStreamSourceOutflow() throws Exception {
+        // Get the BlockFactory
+        SourceBlockFactory f = (SourceBlockFactory)
+        FactoryRegistry.getFactory(SourceBlockFactory.class);
+
+        StreamSource ss = new StreamSource(new StringReader(sampleText));
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS dispatch<Source> client
+        Block block = f.createFrom(ss, null, null);
+
+        // We didn't pass in a qname, so the following should return false
+        assertTrue(!block.isQNameAvailable());
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+
+    }
+
+    /**
+     * Create a Block representing a Source and
+     * simulate a different Dispatch<Source> flow
+     * @throws Exception
+     */
+    public void testStreamSourceOutflow2() throws Exception {
+        // Get the BlockFactory
+        SourceBlockFactory f = (SourceBlockFactory)
+        FactoryRegistry.getFactory(SourceBlockFactory.class);
+
+        StreamSource ss = new StreamSource(new StringReader(sampleText));
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS dispatch<Source> client
+        Block block = f.createFrom(ss, null, null);
+
+        // We didn't pass in a qname, so the following should return false
+        assertTrue(!block.isQNameAvailable());
+
+        // Assume that we need to find the QName (perhaps to identify the operation and 
+        // determine if handlers are installed).   This is not very perfomant since 
+        // it causes an underlying parse of the String...but we need to support this.
+        QName qName = block.getQName();
+        assertTrue("Expected: " + sampleQName + " but found: " + qName, sampleQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+
+    }
+
+    /**
+     * Create a Block representing a Source and
+     * simulate a different Source parameter flow
+     * @throws Exception
+     */
+    public void testStreamSourceOutflow3() throws Exception {
+        // Get the BlockFactory
+        SourceBlockFactory f = (SourceBlockFactory)
+        FactoryRegistry.getFactory(SourceBlockFactory.class);
+
+        StreamSource ss = new StreamSource(new StringReader(sampleText));
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS String parameter on the client.
+        // In this case, we know the QName prior to creating the Block...so let's pass it in.
+        Block block = f.createFrom(ss, null, sampleQName);
+
+        // We passed in a qname, so it should be immediately available
+        assertTrue(block.isQNameAvailable());
+
+        // Make sure the QName is correct.
+        QName qName = block.getQName();
+        assertTrue(sampleQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+    }
+
+    /**
+     * Create a Block representing an XMLString and simulate a 
+     * normal Dispatch<Source> input flow
+     * @throws Exception
+     */
+    public void testStreamSourceInflow() throws Exception {
+        // Get the BlockFactory
+        SourceBlockFactory f = (SourceBlockFactory)
+        FactoryRegistry.getFactory(SourceBlockFactory.class);
+
+        // On inbound, there will already be a XMLStreamReader (probably from OM)
+        // which represents the message.  We will simulate this with inflow.
+        StringReader sr = new StringReader(sampleText);
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+
+        // Create a Block from the inflow.  
+        Block block = f.createFrom(inflow, null, null);
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object (String).
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof Source);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check the String for accuracy
+        XMLStreamReader reader = inputFactory.createXMLStreamReader((Source) bo);
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+
+    }
+
+    /**
+     * Create a Block representing an XMLString and simulate a 
+     * slightly more complicated Dispatch<Source> inflow
+     * @throws Exception
+     */
+    public void testStreamSourceInflow2() throws Exception {
+
+        // Get the BlockFactory
+        SourceBlockFactory f = (SourceBlockFactory)
+        FactoryRegistry.getFactory(SourceBlockFactory.class);
+
+        // On inbound, there will already be a XMLStreamReader (probably from OM)
+        // which represents the message.  We will simulate this with inflow.
+        StringReader sr = new StringReader(sampleText);
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+
+        // Create a Block from the inflow.  
+        Block block = f.createFrom(inflow, null, null);
+
+        // Let's assume we need to get the QName to find the operation name.
+        // This will cause an underlying parse
+        QName qName = block.getQName();
+        assertTrue(sampleQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object (String).
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof Source);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check the String for accuracy
+        XMLStreamReader reader = inputFactory.createXMLStreamReader((Source) bo);
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+
+    }
+
+    /**
+     * Create a Block representing an Source and simulate a 
+     * slightly more complicated Source inflow
+     * @throws Exception
+     */
+    public void testStreamSourceInflow3() throws Exception {
+
+        // Get the BlockFactory
+        SourceBlockFactory f = (SourceBlockFactory)
+        FactoryRegistry.getFactory(SourceBlockFactory.class);
+
+        // On inbound, there will already be a XMLStreamReader (probably from OM)
+        // which represents the message.  We will simulate this with inflow.
+        StringReader sr = new StringReader(sampleText);
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+
+        // Create a Block from the inflow.  Assume that we know the QName already
+        Block block = f.createFrom(inflow, null, sampleQName);
+
+        // We passed in a qname, so the following should return false
+        assertTrue(block.isQNameAvailable());
+
+        // Let's assume we need to get the QName to find the operation name.
+        QName qName = block.getQName();
+        assertTrue(sampleQName.equals(qName));
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is the proxy code will ask for the business object (String).
+        Object bo = block.getBusinessObject(true);
+        assertTrue(bo instanceof Source);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // Check the String for accuracy
+        XMLStreamReader reader = inputFactory.createXMLStreamReader((Source) bo);
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+
+    }
+    /*
+     * Testing JAXBSource, Creating Source Block using JAXBSource and then
+     * Serializing it.
+     */
+    public void testJAXBSourceInFlow1()throws Exception{
+        //  Create a jaxb object
+        try{
+            ObjectFactory factory = new ObjectFactory();
+            EchoString jaxb = factory.createEchoString(); 
+            jaxb.setInput("Hello World");
+            JAXBContext context = JAXBContext.newInstance("test");
+
+            JAXBSource src = new JAXBSource(context.createMarshaller(), jaxb);
+            BlockFactory f = (SourceBlockFactory)
+            FactoryRegistry.getFactory(SourceBlockFactory.class);
+
+            Block block =f.createFrom(src, null, null);
+
+            MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+            Message msg = mf.create(Protocol.soap11);
+            msg.setBodyBlock(block);
+            org.apache.axiom.soap.SOAPEnvelope env = (org.apache.axiom.soap.SOAPEnvelope)msg.getAsOMElement();
+            // Serialize the Envelope using the same mechanism as the 
+            // HTTP client.
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            env.serializeAndConsume(baos, new OMOutputFormat());
+
+            // To check that the output is correct, get the String contents of the 
+            // reader
+            String newText = baos.toString();
+            TestLogger.logger.debug(newText);
+            assertTrue(block.isConsumed());
+        }catch(Exception e){
+            e.printStackTrace();
+        }     
+    }
+
+    public void testJAXBSourceOutflow() throws Exception {
+
+        //Sample text for JAXBSource
+        String echoSample = "<echoString xmlns=\"http://test\"><input>Hello World</input></echoString>";
+
+        // Get the BlockFactory
+        SourceBlockFactory f = (SourceBlockFactory)
+        FactoryRegistry.getFactory(SourceBlockFactory.class);
+        //Create a JAXBSource
+
+        JAXBContext context = JAXBContext.newInstance("test");
+
+        Unmarshaller u = context.createUnmarshaller();
+        ByteArrayInputStream inputStream = new ByteArrayInputStream(echoSample.getBytes());
+        EchoString jaxb = (EchoString)u.unmarshal(inputStream);
+        JAXBSource src = new JAXBSource(context.createMarshaller(), jaxb);
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS dispatch<Source> client
+        Block block = f.createFrom(src, null, null);
+
+        // We didn't pass in a qname, so the following should return false
+        assertTrue(!block.isQNameAvailable());
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(echoSample.equals(newText));
+    }
+    /**
+     * Create a Block representing a DOMSource instance and simulate an 
+     * outbound flow
+     * @throws Exception
+     */
+    public void testDOMSourceOutflow() throws Exception {
+        // Get the BlockFactory
+        SourceBlockFactory f = (SourceBlockFactory)
+        FactoryRegistry.getFactory(SourceBlockFactory.class);
+
+        // Turn the content into a stream
+        ByteArrayInputStream bais = new ByteArrayInputStream(sampleText.getBytes());
+
+        // Create a DOM tree from the sample text
+        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
+        domFactory.setNamespaceAware(true);
+        DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
+        Document domTree = domBuilder.parse(bais);
+        Node node = domTree.getDocumentElement();
+        TestLogger.logger.debug(node.toString());
+
+        // Create a DOMSource object from the DOM tree
+        DOMSource ds = new DOMSource(node);
+        node = ds.getNode();
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS dispatch<Source> client
+        Block block = f.createFrom(ds, null, null);
+
+        // We didn't pass in a qname, so the following should return false
+        assertTrue(!block.isQNameAvailable());
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+    }
+
+    /**
+     * Create a Block representing a SAXSource instance and simulate an 
+     * outbound flow
+     * @throws Exception
+     */
+    public void testSAXSourceOutflow() throws Exception {
+        // Get the BlockFactory
+        SourceBlockFactory f = (SourceBlockFactory)
+        FactoryRegistry.getFactory(SourceBlockFactory.class);
+
+        // Create a SAXSource from the sample text
+        byte[] bytes = sampleText.getBytes();
+        ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+        InputSource input = new InputSource(stream);
+        SAXSource ss = new SAXSource(input);
+
+        // Create a Block using the sample string as the content.  This simulates
+        // what occurs on the outbound JAX-WS dispatch<Source> client
+        Block block = f.createFrom(ss, null, null);
+
+        // We didn't pass in a qname, so the following should return false
+        assertTrue(!block.isQNameAvailable());
+
+        // Assuming no handlers are installed, the next thing that will happen
+        // is a XMLStreamReader will be requested...to go to OM.   At this point the
+        // block should be consumed.
+        XMLStreamReader reader = block.getXMLStreamReader(true);
+
+        // The block should be consumed
+        assertTrue(block.isConsumed());
+
+        // To check that the output is correct, get the String contents of the 
+        // reader
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String newText = r2w.getAsString();
+        assertTrue(sampleText.equals(newText));
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/FaultTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/FaultTests.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/FaultTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/FaultTests.java Mon Mar  3 10:47:38 2008
@@ -0,0 +1,338 @@
+/*
+ * 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.axis2.jaxws.message;
+
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+import java.util.Locale;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+
+/**
+ * MessageTests
+ * Tests to create and validate Message processing
+ * These are not client/server tests.
+ */
+public class FaultTests extends TestCase {
+
+	private static final String faultString = "Internal server error from WAS";
+	
+	// String test variables
+	private static final String sampleSOAP11FaultEnvelope1 = 
+		"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+		+ "<soapenv:Body>"
+		+ "<soapenv:Fault>"
+		+ "<faultcode>soapenv:Server</faultcode>"
+		+ "<faultstring>" + faultString + "sampleSOAP11FaultEnvelope1</faultstring>"
+		+ "</soapenv:Fault>"
+		+ "</soapenv:Body>"
+		+ "</soapenv:Envelope>";
+	
+    private static final String sampleSOAP11FaultEnvelope2 =
+        "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"" +
+        " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
+		" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
+		" xmlns:cwmp=\"http://cwmp.com\">" +
+		" <soapenv:Header>" +
+		" <cwmp:ID soapenv:mustUnderstand=\"1\">HEADERID-7867678</cwmp:ID>" +
+		" </soapenv:Header>" +
+		" <soapenv:Body>" +
+		" <soapenv:Fault>" +
+		" <faultcode>soapenv:Client</faultcode>" +
+		" <faultstring>" + faultString + "sampleSOAP11FaultEnvelope2</faultstring>" +
+		" <faultactor>http://gizmos.com/order</faultactor>" +
+		" <detail>" +
+		" <cwmp:Fault>" +
+		" <cwmp:FaultCode>This is the fault code</cwmp:FaultCode>" +
+		" <cwmp:FaultString>Fault Message</cwmp:FaultString>" +
+		" <cwmp:Message>This is a test fault</cwmp:Message>" +
+		" </cwmp:Fault>" +
+		" </detail>" + /**/
+		" </soapenv:Fault>" +
+		" </soapenv:Body>" +
+		" </soapenv:Envelope>";
+	
+    private final static String sampleSOAP12FaultEnvelope1 =
+        //"<?xml version='1.0' encoding='UTF-8'?>"
+        "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\">"
+        + "<env:Body>"
+        + "<env:Fault>"
+        + "<env:Code><env:Value>env:Receiver</env:Value></env:Code>"
+        + "<env:Reason><env:Text lang=\""+ Locale.getDefault().getLanguage() +"\">"
+        + faultString + "sampleSOAP12FaultEnvelope1</env:Text></env:Reason>"
+        + "</env:Fault>"
+        + "</env:Body>"
+        + "</env:Envelope>";
+    
+    // missing namespace for faultcode value
+    private final static String sampleSOAP12FaultEnvelope2 =
+        //"<?xml version='1.0' encoding='UTF-8'?>"
+        "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\">"
+        + "<env:Body>"
+        + "<env:Fault>"
+        + "<env:Code><env:Value>Sender</env:Value></env:Code>"
+        + "<env:Reason><env:Text lang=\""+ Locale.getDefault().getLanguage() +"\">"
+        + faultString + "sampleSOAP12FaultEnvelope2</env:Text></env:Reason>"
+        + "</env:Fault>"
+        + "</env:Body>"
+        + "</env:Envelope>";
+    
+	private static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+	
+	public FaultTests() {
+		super();
+	}
+
+	public FaultTests(String arg0) {
+		super(arg0);
+	}
+	
+	/**
+	 * This test effectively tests XMLFault construction from
+	 * 
+	 * org.apache.axiom.soap.SOAPFault soapfault, List<Block> detailBlks
+	 * 
+	 * which is a client-side operation.  Also tests the "serialization" of the
+	 * XMLFault object into a Message object which is a server-side operation.
+	 * 
+	 * @throws Exception
+	 */
+
+	public void testStringInflow1() throws Exception {
+		
+		try {
+		// On inbound, there will already be an OM
+		// which represents the message.  The following code simulates the input
+		// OM
+		StringReader sr = new StringReader(sampleSOAP11FaultEnvelope1);
+		XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+		StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
+		OMElement omElement = builder.getSOAPEnvelope();
+		
+		// The JAX-WS layer creates a Message from the OM
+		MessageFactory mf = (MessageFactory)
+			FactoryRegistry.getFactory(MessageFactory.class);
+		Message m = mf.createFrom(omElement, null);
+		
+		assertTrue(m.isFault());
+		
+		if (m.isFault()) {
+			XMLFault x = m.getXMLFault();
+			assertEquals(faultString + "sampleSOAP11FaultEnvelope1", x.getReason().getText());
+			assertEquals("Server", x.getCode().
+                    toQName("http://schemas.xmlsoap.org/soap/envelope/").getLocalPart());
+		} else {
+			fail("Message should be marked as a fault.");
+		}
+		
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail(e.toString());
+		}
+
+	}
+	
+	
+	public void testStringInflow2() throws Exception {
+
+		try {
+			// On inbound, there will already be an OM
+			// which represents the message. The following code simulates the
+			// input
+			// OM
+			StringReader sr = new StringReader(sampleSOAP11FaultEnvelope2);
+			XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+			StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow,
+					null);
+			OMElement omElement = builder.getSOAPEnvelope();
+
+			// The JAX-WS layer creates a Message from the OM
+			MessageFactory mf = (MessageFactory) FactoryRegistry
+					.getFactory(MessageFactory.class);
+			Message m = mf.createFrom(omElement, null);
+
+			assertTrue(m.isFault());
+			
+			if (m.isFault()) {
+				XMLFault x = m.getXMLFault();
+				assertEquals(faultString + "sampleSOAP11FaultEnvelope2", x.getReason().getText());
+                assertEquals("Client", x.getCode().
+                        toQName("http://schemas.xmlsoap.org/soap/envelope/").getLocalPart());
+				
+				// drill down to the faultcode text in the detail to make sure it's there and it's set
+				Block[] blocks = x.getDetailBlocks();
+				Block block = blocks[0];
+				OMElement element = block.getOMElement();
+				OMElement child = (OMElement)element.getChildElements().next();
+				String text = child.getText();
+				
+				
+				assertEquals("This is the fault code", text);
+			} else {
+				fail("Message should be marked as a fault.");
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail(e.toString());
+		}
+
+	}
+	
+	/**
+	 * This test effectively tests XMLFault construction from
+	 * 
+	 * org.apache.axiom.soap.SOAPFault soapfault, List<Block> detailBlks
+	 * 
+	 * which is a client-side operation.  Also tests the "serialization" of the
+	 * XMLFault object into a Message object which is a server-side operation.
+	 * 
+	 * @throws Exception
+	 */
+
+	public void testStringInflow3() throws Exception {
+		
+		try {
+		// On inbound, there will already be an OM
+		// which represents the message.  The following code simulates the input
+		// OM
+		StringReader sr = new StringReader(sampleSOAP12FaultEnvelope1);
+		XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+		StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
+		OMElement omElement = builder.getSOAPEnvelope();
+		
+		// The JAX-WS layer creates a Message from the OM
+		MessageFactory mf = (MessageFactory)
+			FactoryRegistry.getFactory(MessageFactory.class);
+		Message m = mf.createFrom(omElement, null);
+		
+		assertTrue(m.isFault());
+		
+		if (m.isFault()) {
+			XMLFault x = m.getXMLFault();
+			assertEquals(faultString + "sampleSOAP12FaultEnvelope1", x.getReason().getText());
+            assertEquals("Receiver", x.getCode().
+                    toQName("http://www.w3.org/2003/05/soap-envelope").getLocalPart());
+		} else {
+			fail("Message should be marked as a fault.");
+		}
+		
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail(e.toString());
+		}
+	}
+    
+    public void testStringInflow4() throws Exception {
+        
+        try {
+        // On inbound, there will already be an OM
+        // which represents the message.  The following code simulates the input
+        // OM
+        StringReader sr = new StringReader(sampleSOAP12FaultEnvelope2);
+        XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
+        StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
+        OMElement omElement = builder.getSOAPEnvelope();
+        
+        // The JAX-WS layer creates a Message from the OM
+        MessageFactory mf = (MessageFactory)
+            FactoryRegistry.getFactory(MessageFactory.class);
+        Message m = mf.createFrom(omElement, null);
+        
+        assertTrue(m.isFault());
+        
+        if (m.isFault()) {
+            XMLFault x = m.getXMLFault();
+            assertEquals(faultString + "sampleSOAP12FaultEnvelope2", x.getReason().getText());
+            assertEquals("Sender", x.getCode().
+                    toQName("http://www.w3.org/2003/05/soap-envelope").getLocalPart());
+        } else {
+            fail("Message should be marked as a fault.");
+        }
+        
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+    }
+    
+    
+    public void testGetSOAP11XMLFaultAsOM() throws Exception {
+        MessageFactory factory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+        Message msg = factory.create(Protocol.soap11);
+
+        XMLFaultReason reason = new XMLFaultReason("sample fault reason");
+        XMLFault fault = new XMLFault(XMLFaultCode.SENDER, reason);
+        msg.setXMLFault(fault);
+        
+        OMElement om = msg.getAsOMElement();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        om.serializeAndConsume(baos);
+        
+        String env = new String(baos.toByteArray());
+        assertTrue(env.indexOf("faultcode") > 0);
+        assertTrue(env.indexOf("faultstring") > 0);
+    }
+    
+    public void testGetSOAP11XMLFaultAsBlock() throws Exception {
+        MessageFactory factory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+        Message msg = factory.create(Protocol.soap11);
+
+        XMLFaultReason reason = new XMLFaultReason("sample fault reason");
+        XMLFault fault = new XMLFault(XMLFaultCode.SENDER, reason);
+        msg.setXMLFault(fault);
+        
+        BlockFactory bf = (BlockFactory) FactoryRegistry.getFactory(SourceBlockFactory.class);
+        Block b = msg.getBodyBlock(null, bf);
+        
+        Source content = (Source) b.getBusinessObject(true);
+        byte[] bytes = _getBytes(content);
+        String faultContent = new String(bytes);
+        
+        System.out.println(">> fault content: " + faultContent); 
+        assertTrue(faultContent.indexOf("faultcode") > 0);
+        assertTrue(faultContent.indexOf("faultstring") > 0);
+    }
+    
+    private byte[] _getBytes(Source input) throws Exception {
+        TransformerFactory tf = TransformerFactory.newInstance();
+        Transformer t = tf.newTransformer();
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        StreamResult output = new StreamResult(baos);
+        
+        t.transform(input, output);
+        
+        return baos.toByteArray(); 
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/MessagePersistanceTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/MessagePersistanceTests.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/MessagePersistanceTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/message/MessagePersistanceTests.java Mon Mar  3 10:47:38 2008
@@ -0,0 +1,592 @@
+/*
+ * Copyright 2004,2007 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.axis2.jaxws.message;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.ds.ByteArrayDataSource;
+import org.apache.axiom.om.util.CopyUtils;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.Constants.Configuration;
+import org.apache.axis2.datasource.jaxb.JAXBDataSource;
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
+import org.apache.axis2.jaxws.message.databinding.impl.JAXBBlockImpl;
+import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.message.util.MessageUtils;
+import org.apache.axis2.jaxws.provider.DataSourceImpl;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.test.mtom.ImageDepot;
+import org.test.mtom.SendImage;
+
+import test.EchoStringResponse;
+import test.ObjectFactory;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.imageio.ImageIO;
+import javax.imageio.stream.FileImageInputStream;
+import javax.imageio.stream.ImageInputStream;
+
+import java.awt.Image;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * These tests simulate the outbound processing 
+ * from JAX-WS with Message Persistance.  The tests validate that the
+ * message is properly cloned/written/read and that the OM is not
+ * unnecessarily expanded (which is a performance concern).
+ */
+public class MessagePersistanceTests extends TestCase {
+
+    DataSource stringDS, imageDS;
+    public String imageResourceDir = "test-resources" + File.separator + "image";
+    private final String sampleText = "Sample Text";
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        // Create a DataSource from a String
+        stringDS = new org.apache.axiom.attachments.ByteArrayDataSource(sampleText.getBytes(), "text/plain");
+
+        // Create a DataSource from an image 
+        File file = new File(imageResourceDir + File.separator + "test.jpg");
+        ImageInputStream fiis = new FileImageInputStream(file);
+        Image image = ImageIO.read(fiis);
+        imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
+    }
+    
+    /**
+     * Create a JAXBBlock containing a JAX-B business object and simulate a normal Dispatch<Object>
+     * output flow
+     * 
+     * @throws Exception
+     */
+    public void testPersist_File() throws Exception {
+        
+        // Create the JAX-B object that is typical from a JAX-WS app
+        String sampleJAXBText = "sample return value";
+        ObjectFactory of = new ObjectFactory();
+        EchoStringResponse obj = of.createEchoStringResponse();
+        obj.setEchoStringReturn("sample return value");
+        
+        // The JAXB object is stored in the Axiom tree as an OMSourcedElement.
+        // The typical structure is
+        //   OM SOAPEnvelope
+        //   OM SOAPBody
+        //   OMSourcedElement that is sourced by a JAXBBlockImpl which is backecd by a JAXB Object.
+        Message m = createMessage(obj);
+        
+        // The Message is set on the JAXWS MessageContext
+        MessageContext jaxwsMC = new MessageContext();
+        jaxwsMC.setMessage(m);
+        
+        // Check to see if the message is a fault. The engine will always call this method.
+        // The Message must respond appropriately without doing a conversion.
+        boolean isFault = m.isFault();
+        assertTrue(!isFault);
+        assertTrue("XMLPart Representation is " + m.getXMLPartContentType(),
+                   "SPINE".equals(m.getXMLPartContentType()));
+        
+        // The JAX-WS MessageContext is converted into an Axis2 MessageContext
+        org.apache.axis2.context.MessageContext axisMC = jaxwsMC.getAxisMessageContext();
+        MessageUtils.putMessageOnMessageContext(m, jaxwsMC.getAxisMessageContext());
+        
+        // Make sure the Axiom structure is intact
+        SOAPEnvelope env = axisMC.getEnvelope();
+        SOAPBody body = env.getBody();
+        OMElement child = body.getFirstElement();
+        assertTrue(child instanceof OMSourcedElement);
+        OMSourcedElement omse = (OMSourcedElement) child;
+        assertTrue(!omse.isExpanded());
+        OMDataSource ds = omse.getDataSource();
+        assertTrue(ds instanceof JAXBBlockImpl);
+        
+        // Now simulate persisting the message
+        File theFile = null;
+        String theFilename = null;
+        theFile = File.createTempFile("MessagePersistTest", null);
+        //theFile.deleteOnExit();
+        theFilename = theFile.getName();
+        System.out.println("temp file = [" + theFilename + "]");
+        
+        // Setup an output stream to a physical file
+        FileOutputStream outStream = new FileOutputStream(theFile);
+
+        // Attach a stream capable of writing objects to the 
+        // stream connected to the file
+        ObjectOutputStream outObjStream = new ObjectOutputStream(outStream);
+
+        // Try to save the message context
+        System.out.println("saving message context.....");
+        outObjStream.writeObject(axisMC);
+
+        // Close out the streams
+        outObjStream.flush();
+        outObjStream.close();
+        outStream.flush();
+        outStream.close();
+        System.out.println("....saved message context.....");
+        long filesize = theFile.length();
+        System.out.println("file size after save [" + filesize
+                + "]   temp file = [" + theFilename + "]");
+        
+        // Make sure the Axiom structure is intact.  
+        env = axisMC.getEnvelope();
+        body = env.getBody();
+        child = body.getFirstElement();
+        assertTrue(child instanceof OMSourcedElement);
+        omse = (OMSourcedElement) child;
+        assertTrue(!omse.isExpanded());
+        ds = omse.getDataSource();
+        assertTrue(ds instanceof JAXBBlockImpl);
+        
+        // Simulate transport
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        env.serializeAndConsume(baos, new OMOutputFormat());
+
+        // To check that the output is correct, get the String contents of the
+        // reader
+        String newText = baos.toString();
+        System.out.println(newText);
+        assertTrue(newText.contains(sampleJAXBText));
+        assertTrue(newText.contains("soap"));
+        assertTrue(newText.contains("Envelope"));
+        assertTrue(newText.contains("Body"));
+        
+        
+        // Now read in the persisted message
+        // Setup an input stream to the file
+        FileInputStream inStream = new FileInputStream(theFile);
+
+        // attach a stream capable of reading objects from the 
+        // stream connected to the file
+        ObjectInputStream inObjStream = new ObjectInputStream(inStream);
+
+        // try to restore the message context
+        System.out.println("restoring a message context.....");
+
+        org.apache.axis2.context.MessageContext restoredMC = 
+            (org.apache.axis2.context.MessageContext) inObjStream.readObject();
+        inObjStream.close();
+        inStream.close();
+        System.out.println("....restored message context.....");
+        
+        // At this point in time, the restoredMessage will be a full tree.
+        // TODO If this changes, please add more assertions here.
+        
+        // Simulate transport
+        baos = new ByteArrayOutputStream();
+        env = restoredMC.getEnvelope();
+        env.serializeAndConsume(baos, new OMOutputFormat());
+        String restoredText = baos.toString();
+        System.out.println(restoredText);
+        assertTrue(restoredText.contains(sampleJAXBText));
+        assertTrue(restoredText.contains("soap"));
+        assertTrue(restoredText.contains("Envelope"));
+        assertTrue(restoredText.contains("Body"));
+        assertTrue(restoredText.equals(newText));
+        
+    }
+    
+    /**
+     * Create a JAXBBlock containing a JAX-B business object and simulate a normal Dispatch<Object>
+     * output flow
+     * 
+     * @throws Exception
+     */
+    public void testPersist_InMemory() throws Exception {
+        
+        // Create the JAX-B object that is typical from a JAX-WS app
+        String sampleJAXBText = "sample return value";
+        ObjectFactory of = new ObjectFactory();
+        EchoStringResponse obj = of.createEchoStringResponse();
+        obj.setEchoStringReturn("sample return value");
+        
+        // The JAXB object is stored in the Axiom tree as an OMSourcedElement.
+        // The typical structure is
+        //   OM SOAPEnvelope
+        //   OM SOAPBody
+        //   OMSourcedElement that is sourced by a JAXBBlockImpl which is backecd by a JAXB Object.
+        Message m = createMessage(obj);
+        
+        // The Message is set on the JAXWS MessageContext
+        MessageContext jaxwsMC = new MessageContext();
+        jaxwsMC.setMessage(m);
+        
+        // Check to see if the message is a fault. The engine will always call this method.
+        // The Message must respond appropriately without doing a conversion.
+        boolean isFault = m.isFault();
+        assertTrue(!isFault);
+        assertTrue("XMLPart Representation is " + m.getXMLPartContentType(),
+                   "SPINE".equals(m.getXMLPartContentType()));
+        
+        // The JAX-WS MessageContext is converted into an Axis2 MessageContext
+        org.apache.axis2.context.MessageContext axisMC = jaxwsMC.getAxisMessageContext();
+        MessageUtils.putMessageOnMessageContext(m, jaxwsMC.getAxisMessageContext());
+        
+        // Make sure the Axiom structure is intact
+        SOAPEnvelope env = axisMC.getEnvelope();
+        SOAPBody body = env.getBody();
+        OMElement child = body.getFirstElement();
+        assertTrue(child instanceof OMSourcedElement);
+        OMSourcedElement omse = (OMSourcedElement) child;
+        assertTrue(!omse.isExpanded());
+        OMDataSource ds = omse.getDataSource();
+        assertTrue(ds instanceof JAXBBlockImpl);
+        
+        // Now simulate persisting the message in memory
+        SOAPEnvelope env2 = CopyUtils.copy(env);
+        
+        // Make sure the Axiom structure is intact.  
+        env = axisMC.getEnvelope();
+        body = env.getBody();
+        child = body.getFirstElement();
+        assertTrue(child instanceof OMSourcedElement);
+        omse = (OMSourcedElement) child;
+        assertTrue(!omse.isExpanded());
+        ds = omse.getDataSource();
+        assertTrue(ds instanceof JAXBBlockImpl);
+        
+        // Simulate transport
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        env.serializeAndConsume(baos, new OMOutputFormat());
+
+        // To check that the output is correct, get the String contents of the
+        // reader
+        String newText = baos.toString();
+        System.out.println(newText);
+        assertTrue(newText.contains(sampleJAXBText));
+        assertTrue(newText.contains("soap"));
+        assertTrue(newText.contains("Envelope"));
+        assertTrue(newText.contains("Body"));
+        
+        
+        // Now check the copied envelope
+        body = env2.getBody();
+        child = body.getFirstElement();
+        assertTrue(child instanceof OMSourcedElement);
+        omse = (OMSourcedElement) child;
+        assertTrue(!omse.isExpanded());
+        ds = omse.getDataSource();
+        assertTrue(ds instanceof JAXBDataSource);
+        
+        // Simulate transport
+        baos = new ByteArrayOutputStream();
+        env2.serializeAndConsume(baos, new OMOutputFormat());
+        String restoredText = baos.toString();
+        System.out.println(restoredText);
+        assertTrue(restoredText.contains(sampleJAXBText));
+        assertTrue(restoredText.contains("soap"));
+        assertTrue(restoredText.contains("Envelope"));
+        assertTrue(restoredText.contains("Body"));
+        assertTrue(restoredText.equals(newText));
+        
+    }
+    
+    /**
+     * Create a JAXBBlock containing a JAX-B business object and simulate a normal Dispatch<Object>
+     * output flow
+     * 
+     * @throws Exception
+     */
+    public void testPersist_Attachments_File() throws Exception {
+        
+        // TODO Add a SWARef and a raw attachment
+        
+        // Create the JAX-B object with an attachment
+        // Create a DataHandler with the String DataSource object
+        DataHandler dataHandler = new DataHandler(stringDS);
+
+        //Store the data handler in ImageDepot bean
+        org.test.mtom.ObjectFactory of = new org.test.mtom.ObjectFactory();
+        ImageDepot imageDepot = new org.test.mtom.ObjectFactory().createImageDepot();
+        imageDepot.setImageData(dataHandler);
+        SendImage obj = of.createSendImage();
+        obj.setInput(imageDepot);
+        
+        // The JAXB object is stored in the Axiom tree as an OMSourcedElement.
+        // The typical structure is
+        //   OM SOAPEnvelope
+        //   OM SOAPBody
+        //   OMSourcedElement that is sourced by a JAXBBlockImpl which is backecd by a JAXB Object.
+        Message m = createMessage(obj);
+        m.setMTOMEnabled(true);
+        
+        // The Message is set on the JAXWS MessageContext
+        MessageContext jaxwsMC = new MessageContext();
+        jaxwsMC.setMessage(m);
+        
+        // Check to see if the message is a fault. The engine will always call this method.
+        // The Message must respond appropriately without doing a conversion.
+        boolean isFault = m.isFault();
+        assertTrue(!isFault);
+        assertTrue("XMLPart Representation is " + m.getXMLPartContentType(),
+                   "SPINE".equals(m.getXMLPartContentType()));
+        
+        // The JAX-WS MessageContext is converted into an Axis2 MessageContext
+        org.apache.axis2.context.MessageContext axisMC = jaxwsMC.getAxisMessageContext();
+        MessageUtils.putMessageOnMessageContext(m, jaxwsMC.getAxisMessageContext());
+        axisMC.setProperty(Configuration.ENABLE_MTOM, "true" );
+        
+        // Make sure the Axiom structure is intact
+        SOAPEnvelope env = axisMC.getEnvelope();
+        SOAPBody body = env.getBody();
+        OMElement child = body.getFirstElement();
+        assertTrue(child instanceof OMSourcedElement);
+        OMSourcedElement omse = (OMSourcedElement) child;
+        assertTrue(!omse.isExpanded());
+        OMDataSource ds = omse.getDataSource();
+        assertTrue(ds instanceof JAXBBlockImpl);
+        
+        // Now simulate persisting the message
+        File theFile = null;
+        String theFilename = null;
+        theFile = File.createTempFile("MessagePersistTest", null);
+        //theFile.deleteOnExit();
+        theFilename = theFile.getName();
+        System.out.println("temp file = [" + theFilename + "]");
+        
+        // Setup an output stream to a physical file
+        FileOutputStream outStream = new FileOutputStream(theFile);
+
+        // Attach a stream capable of writing objects to the 
+        // stream connected to the file
+        ObjectOutputStream outObjStream = new ObjectOutputStream(outStream);
+
+        // Try to save the message context
+        System.out.println("saving message context.....");
+        outObjStream.writeObject(axisMC);
+
+        // Close out the streams
+        outObjStream.flush();
+        outObjStream.close();
+        outStream.flush();
+        outStream.close();
+        System.out.println("....saved message context.....");
+        long filesize = theFile.length();
+        System.out.println("file size after save [" + filesize
+                + "]   temp file = [" + theFilename + "]");
+        
+        // Make sure the Axiom structure is intact.  
+        env = axisMC.getEnvelope();
+        body = env.getBody();
+        child = body.getFirstElement();
+        assertTrue(child instanceof OMSourcedElement);
+        omse = (OMSourcedElement) child;
+        assertTrue(!omse.isExpanded());
+        ds = omse.getDataSource();
+        assertTrue(ds instanceof JAXBBlockImpl);
+        
+        // Simulate transport
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OMOutputFormat outputFormat = new OMOutputFormat();
+        outputFormat.setDoOptimize(true);
+        outputFormat.setMimeBoundary("MIMEBoundary_Axis2Rocks");
+        env.serializeAndConsume(baos, outputFormat);
+
+        // Make sure the output is correct
+        String newText = baos.toString();
+        System.out.println(newText);
+        assertTrue(newText.contains("soap"));
+        assertTrue(newText.contains("Envelope"));
+        assertTrue(newText.contains("Body"));
+        assertTrue(newText.indexOf("MIMEBoundary_Axis2Rocks") > 0);
+        assertTrue(newText.indexOf(sampleText) > 0);
+        assertTrue(newText.indexOf("<soapenv:Body><sendImage xmlns=\"urn://mtom.test.org\"><input><imageData><xop:Include") > 0);
+
+        
+        // Now read in the persisted message
+        // Setup an input stream to the file
+        FileInputStream inStream = new FileInputStream(theFile);
+
+        // attach a stream capable of reading objects from the 
+        // stream connected to the file
+        ObjectInputStream inObjStream = new ObjectInputStream(inStream);
+
+        // try to restore the message context
+        System.out.println("restoring a message context.....");
+
+        org.apache.axis2.context.MessageContext restoredMC = 
+            (org.apache.axis2.context.MessageContext) inObjStream.readObject();
+        inObjStream.close();
+        inStream.close();
+        System.out.println("....restored message context.....");
+        
+        // At this point in time, the restoredMessage will be a full tree.
+        // TODO If this changes, please add more assertions here.
+        
+        // Simulate transport on the restored message
+        baos = new ByteArrayOutputStream();
+        env = restoredMC.getEnvelope();
+        outputFormat = new OMOutputFormat();
+        outputFormat.setDoOptimize(true);
+        outputFormat.setMimeBoundary("MIMEBoundary_Axis2Rocks");
+        env.serializeAndConsume(baos, outputFormat);
+        String restoredText = baos.toString();
+        System.out.println(restoredText);
+        assertTrue(restoredText.contains("soap"));
+        assertTrue(restoredText.contains("Envelope"));
+        assertTrue(restoredText.contains("Body"));
+        assertTrue(restoredText.indexOf("MIMEBoundary_Axis2Rocks") > 0);
+        assertTrue(restoredText.indexOf(sampleText) > 0);
+        assertTrue(restoredText.indexOf("<soapenv:Body><sendImage xmlns=\"urn://mtom.test.org\"><input><imageData><xop:Include") > 0);
+        
+    }
+    
+    /**
+     * Create a JAXBBlock containing a JAX-B business object and simulate a normal Dispatch<Object>
+     * output flow
+     * 
+     * @throws Exception
+     */
+    public void testPersist_Attachments_InMemory() throws Exception {
+        
+        // TODO Add a SWARef and a raw attachment
+        
+        // Create the JAX-B object with an attachment
+        // Create a DataHandler with the String DataSource object
+        DataHandler dataHandler = new DataHandler(stringDS);
+
+        //Store the data handler in ImageDepot bean
+        org.test.mtom.ObjectFactory of = new org.test.mtom.ObjectFactory();
+        ImageDepot imageDepot = new org.test.mtom.ObjectFactory().createImageDepot();
+        imageDepot.setImageData(dataHandler);
+        SendImage obj = of.createSendImage();
+        obj.setInput(imageDepot);
+        
+        // The JAXB object is stored in the Axiom tree as an OMSourcedElement.
+        // The typical structure is
+        //   OM SOAPEnvelope
+        //   OM SOAPBody
+        //   OMSourcedElement that is sourced by a JAXBBlockImpl which is backecd by a JAXB Object.
+        Message m = createMessage(obj);
+        m.setMTOMEnabled(true);
+        
+        // The Message is set on the JAXWS MessageContext
+        MessageContext jaxwsMC = new MessageContext();
+        jaxwsMC.setMessage(m);
+        
+        // Check to see if the message is a fault. The engine will always call this method.
+        // The Message must respond appropriately without doing a conversion.
+        boolean isFault = m.isFault();
+        assertTrue(!isFault);
+        assertTrue("XMLPart Representation is " + m.getXMLPartContentType(),
+                   "SPINE".equals(m.getXMLPartContentType()));
+        
+        // The JAX-WS MessageContext is converted into an Axis2 MessageContext
+        org.apache.axis2.context.MessageContext axisMC = jaxwsMC.getAxisMessageContext();
+        MessageUtils.putMessageOnMessageContext(m, jaxwsMC.getAxisMessageContext());
+        axisMC.setProperty(Configuration.ENABLE_MTOM, "true");
+        
+        // Make sure the Axiom structure is intact
+        SOAPEnvelope env = axisMC.getEnvelope();
+        SOAPBody body = env.getBody();
+        OMElement child = body.getFirstElement();
+        assertTrue(child instanceof OMSourcedElement);
+        OMSourcedElement omse = (OMSourcedElement) child;
+        assertTrue(!omse.isExpanded());
+        OMDataSource ds = omse.getDataSource();
+        assertTrue(ds instanceof JAXBBlockImpl);
+        
+        // Now simulate persisting the message in memory
+        SOAPEnvelope env2 = CopyUtils.copy(env);
+        
+        // Make sure the Axiom structure is intact.  
+        env = axisMC.getEnvelope();
+        body = env.getBody();
+        child = body.getFirstElement();
+        assertTrue(child instanceof OMSourcedElement);
+        omse = (OMSourcedElement) child;
+        assertTrue(!omse.isExpanded());
+        ds = omse.getDataSource();
+        assertTrue(ds instanceof JAXBBlockImpl);
+        
+        // Simulate transport
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OMOutputFormat outputFormat = new OMOutputFormat();
+        outputFormat.setDoOptimize(true);
+        outputFormat.setMimeBoundary("MIMEBoundary_Axis2Rocks");
+        env.serializeAndConsume(baos, outputFormat);
+
+        String newText = baos.toString();
+        System.out.println(newText);
+        assertTrue(newText.contains("soap"));
+        assertTrue(newText.contains("Envelope"));
+        assertTrue(newText.contains("Body"));
+        assertTrue(newText.indexOf("MIMEBoundary_Axis2Rocks") > 0);
+        assertTrue(newText.indexOf(sampleText) > 0);
+        assertTrue(newText.indexOf("<soapenv:Body><sendImage xmlns=\"urn://mtom.test.org\"><input><imageData><xop:Include") > 0);     
+        
+        // Now check the copied envelope
+        body = env2.getBody();
+        child = body.getFirstElement();
+        assertTrue(child instanceof OMSourcedElement);
+        omse = (OMSourcedElement) child;
+        assertTrue(!omse.isExpanded());
+        ds = omse.getDataSource();
+        assertTrue(ds instanceof JAXBDataSource);
+        
+        // Simulate transport on the copied message
+        baos = new ByteArrayOutputStream();
+        outputFormat = new OMOutputFormat();
+        outputFormat.setDoOptimize(true);
+        outputFormat.setMimeBoundary("MIMEBoundary_Axis2Rocks");
+        env2.serializeAndConsume(baos, outputFormat);
+        String restoredText = baos.toString();
+        System.out.println(restoredText);
+        assertTrue(restoredText.contains("soap"));
+        assertTrue(restoredText.contains("Envelope"));
+        assertTrue(restoredText.contains("Body"));
+        assertTrue(restoredText.indexOf("MIMEBoundary_Axis2Rocks") > 0);
+        
+        // Make sure that attachment is not inlined
+        assertTrue(restoredText.indexOf(sampleText) > 0);
+        assertTrue(restoredText.indexOf("<soapenv:Body><sendImage xmlns=\"urn://mtom.test.org\"><input><imageData><xop:Include") > 0);
+        
+    }
+    
+    private Message createMessage(Object jaxbObj) throws Exception {
+        // Create a SOAP 1.1 Message
+        MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+        Message m = mf.create(Protocol.soap11);
+
+        // Get the BlockFactory
+        JAXBBlockFactory bf = (JAXBBlockFactory) FactoryRegistry.getFactory(JAXBBlockFactory.class);
+
+        // Create the JAXBContext
+        JAXBBlockContext context =
+                new JAXBBlockContext(jaxbObj.getClass().getPackage().getName());
+
+        // Create a JAXBBlock using the Echo object as the content. This simulates
+        // what occurs on the outbound JAX-WS Dispatch<Object> client
+        Block block = bf.createFrom(jaxbObj, context, null);
+
+        // Add the block to the message as normal body content.
+        m.setBodyBlock(block);
+        return m;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org