axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/test/saaj TestMessageProperty2.java
Date Mon, 28 Feb 2005 15:57:07 GMT
dims        2005/02/28 07:57:07

  Modified:    java/src/org/apache/axis SOAPPart.java
  Added:       java/test/saaj TestMessageProperty2.java
  Log:
  add missing xml declaration
  
  Revision  Changes    Path
  1.77      +9 -2      ws-axis/java/src/org/apache/axis/SOAPPart.java
  
  Index: SOAPPart.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/SOAPPart.java,v
  retrieving revision 1.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- SOAPPart.java	10 Feb 2005 15:36:06 -0000	1.76
  +++ SOAPPart.java	28 Feb 2005 15:57:07 -0000	1.77
  @@ -319,8 +319,15 @@
               return;
           }
   
  -        writer.write(this.getAsString());
  -        // easy, huh?
  +        String xml = this.getAsString();
  +        if(inclXmlDecl){
  +            if(!xml.startsWith("<?xml")){
  +                writer.write("<?xml version=\"1.0\" encoding=\"");
  +                writer.write(currentEncoding);
  +                writer.write("\"?>");
  +            }
  +        }
  +        writer.write(xml);
       }
   
       /**
  
  
  
  1.1                  ws-axis/java/test/saaj/TestMessageProperty2.java
  
  Index: TestMessageProperty2.java
  ===================================================================
  package test.saaj;
  
  import org.apache.axis.Message;
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.InputStream;
  import javax.xml.soap.MessageFactory;
  import javax.xml.soap.MimeHeaders;
  import javax.xml.soap.SOAPBody;
  import javax.xml.soap.SOAPElement;
  import javax.xml.soap.SOAPMessage;
  import javax.xml.soap.Text;
  import javax.xml.soap.SOAPHeader;
  import javax.xml.soap.SOAPEnvelope;
  import javax.xml.soap.SOAPPart;
  import javax.xml.transform.stream.StreamSource;
  
  import junit.framework.Assert;
  
  public class TestMessageProperty2 extends junit.framework.TestCase {
      public TestMessageProperty2(String name) {
          super(name);
      }
  
      private static String GoodSoapMessage = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns=\"http://helloservice.org/wsdl\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body
soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><tns:hello><String_1
xsi:type=\"xsd:string\">&lt;Bozo&gt;</String_1></tns:hello></soap:Body></soap:Envelope>";
  
      private SOAPMessage createTestMessage(String encoding, boolean xmlDecl) throws Exception
{
          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;
      }
  
  
      private SOAPMessage createMessageFromInputStream(InputStream is) throws Exception {
          MessageFactory mf = MessageFactory.newInstance();
          return mf.createMessage(new MimeHeaders(), is);
      }
  
      public void testUTF8withXMLDecl() throws Exception {
          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("&lt;Bozo&gt;") != -1);
      }
  
      public void testUTF16withXMLDecl() throws Exception {
          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("&lt;Bozo&gt;") != -1);
      }
  }
  
  
  

Mime
View raw message