FileDocCategorySizeDatePackage
TestMessageProperty.javaAPI DocApache Axis 1.43228Sat Apr 22 18:57:28 BST 2006test.saaj

TestMessageProperty

public class TestMessageProperty extends TestCase

Fields Summary
private static final String
textValue
Constructors Summary
public TestMessageProperty(String name)

        super(name);
    
Methods Summary
private javax.xml.soap.SOAPMessagecreateMessageFromInputStream(java.io.InputStream is)

        MessageFactory mf = MessageFactory.newInstance();
        return mf.createMessage(new MimeHeaders(), is);
    
private javax.xml.soap.SOAPMessagecreateTestMessage()

    
         
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage msg = mf.createMessage();
        SOAPBody sb = msg.getSOAPBody();
        SOAPElement se1 = sb.addChildElement("echoString", "ns1", "http://tempuri.org");
        SOAPElement se2 = se1.addChildElement("string");
        se2.addTextNode(textValue);
        
        return msg;
    
private voidtestEncoding(java.lang.String encoding)

        SOAPMessage msg = createTestMessage();
        
        msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
        msg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encoding);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        msg.writeTo(baos);
        
        String msgString = new String(baos.toByteArray(), encoding);
        System.out.println("msgString (" + encoding + ")=" + msgString);
        assertTrue(msgString.startsWith("<?xml version=\"1.0\" encoding=\"" + encoding + "\""));

        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        SOAPMessage msg1 = createMessageFromInputStream(bais);
        SOAPElement se1 = (SOAPElement) msg1.getSOAPBody().getChildElements().next();
        SOAPElement se2 = (SOAPElement) se1.getChildElements().next();
        Text text = (Text)se2.getChildElements().next();
        
	assertEquals(textValue, text.getValue());
    
public voidtestEncodingPropertyUTF16()

        testEncoding("UTF-16");               
    
public voidtestEncodingPropertyUTF8()

        testEncoding("UTF-8");                
    
public voidtestWriteXmlDeclPropertyFalse()

        testXmlDecl("false", "<soapenv:Envelope");
    
public voidtestWriteXmlDeclPropertyTrue()

        testXmlDecl("true", "<?xml");        
    
private voidtestXmlDecl(java.lang.String xmlDecl, java.lang.String expected)

        SOAPMessage msg = createTestMessage();
        
        msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, xmlDecl);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        msg.writeTo(baos);
        String msgString = new String(baos.toByteArray(), "UTF-8");
        System.out.println("msgString =" + msgString);
        assertTrue(msgString.startsWith(expected));