FileDocCategorySizeDatePackage
TestMessageProperty2.javaAPI DocApache Axis 1.42947Sat Apr 22 18:57:26 BST 2006test.saaj

TestMessageProperty2

public class TestMessageProperty2 extends TestCase

Fields Summary
private static String
GoodSoapMessage
Constructors Summary
public TestMessageProperty2(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(java.lang.String encoding, boolean xmlDecl)


            
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message = factory.createMessage();
        SOAPPart sp = message.getSOAPPart();
        SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
        SOAPHeader header = envelope.getHeader();

        ByteArrayInputStream bais =
                new ByteArrayInputStream(GoodSoapMessage.getBytes(encoding));
        StreamSource ssrc = new StreamSource(bais);
        sp.setContent(ssrc);

        message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encoding);
        message.setProperty(SOAPMessage.WRITE_XML_DECLARATION, xmlDecl ? "true" : "false");

        return message;
    
public voidtestUTF16withXMLDecl()

        SOAPMessage msg = createTestMessage("UTF-16", true);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        msg.writeTo(baos);
        String xml = new String(baos.toByteArray(),"UTF-16");
        assertTrue(xml.indexOf("UTF-16") != -1);
        assertTrue(xml.indexOf("<Bozo>") != -1);
    
public voidtestUTF8withXMLDecl()

        SOAPMessage msg = createTestMessage("UTF-8", true);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        msg.writeTo(baos);
        String xml = new String(baos.toByteArray(),"UTF-8");
        assertTrue(xml.indexOf("UTF-8") != -1);
        assertTrue(xml.indexOf("<Bozo>") != -1);