You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ia...@apache.org on 2004/05/18 10:04:56 UTC
cvs commit: ws-axis/java/src/org/apache/axis/message SAXOutputter.java
ias 2004/05/18 01:04:56
Modified: java/src/org/apache/axis/message SAXOutputter.java
Log:
Fix - without this change, if you try to send a SOAP message, for example,
<?xml version='1.0' encoding='UTF-8'?>
<!-- Ias -->
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:enc='http://schemas.xmlsoap.org/soap/encoding/' xmlns:ns0='http://apache.org/wsdl'>
<env:Body><ns0:helloWorld/></env:Body>
</env:Envelope>
with SAAJ, Axis serializes the message on the wire as below
<!-- Ias -->
<?xml version='1.0' encoding='UTF-8'?>
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:enc='http://schemas.xmlsoap.org/soap/encoding/' xmlns:ns0='http://apache.org/wsdl'>
<env:Body><ns0:helloWorld/></env:Body>
</env:Envelope>
, and this is absolutely wrong. The reason is timing of writing XML declaration.
If a comment is before the first element, XML declaration is written behind the comment because SerializationContextImpl handles elements and XML declaration simultaneously.
Revision Changes Path
1.25 +10 -0 ws-axis/java/src/org/apache/axis/message/SAXOutputter.java
Index: SAXOutputter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/SAXOutputter.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- SAXOutputter.java 25 Feb 2004 14:02:43 -0000 1.24
+++ SAXOutputter.java 18 May 2004 08:04:56 -0000 1.25
@@ -17,6 +17,7 @@
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.encoding.SerializationContext;
+import org.apache.axis.utils.XMLUtils;
import org.apache.commons.logging.Log;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@@ -40,6 +41,15 @@
}
public void startDocument() throws SAXException {
+ try {
+ context.writeString("<?xml version=\"1.0\" encoding=\"");
+ String encoding = XMLUtils.getEncoding(context.getMessageContext());
+ context.writeString(encoding);
+ context.writeString("\"?>\n");
+ context.setSendDecl(false);
+ } catch (IOException e) {
+ throw new SAXException(e);
+ }
}
public void endDocument() throws SAXException {
RE: cvs commit: ws-axis/java/src/org/apache/axis/message SAXOutputter.java
Posted by Ias <ia...@tmax.co.kr>.
I'd like to add a test case for this change, but feel difficulty finding a
good place for it. I guess
String xmlString =
"<?xml version='1.0' encoding='UTF-8'?>" +
"<!-- Ias -->" +
"<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
"<env:Body><echo><arg0>Hello</arg0></echo></env:Body>" +
"</env:Envelope>";
SOAPConnectionFactory scFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection con = scFactory.createConnection();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message =
factory.createMessage(new MimeHeaders(), new
ByteArrayInputStream(xmlString.getBytes()));
URLEndpoint endpoint = new
URLEndpoint("http://localhost:8080/jws/EchoHeaders.jws");
SOAPMessage response = con.call(message, endpoint);
would do.
Thanks,
Ias
> -----Original Message-----
> From: ias@apache.org [mailto:ias@apache.org]
> Sent: Tuesday, May 18, 2004 5:05 PM
> To: ws-axis-cvs@apache.org
> Subject: cvs commit: ws-axis/java/src/org/apache/axis/message
> SAXOutputter.java
>
> ias 2004/05/18 01:04:56
>
> Modified: java/src/org/apache/axis/message SAXOutputter.java
> Log:
> Fix - without this change, if you try to send a SOAP
> message, for example,
>
> <?xml version='1.0' encoding='UTF-8'?>
> <!-- Ias -->
> <env:Envelope
> xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'
> xmlns:xsd='http://www.w3.org/2001/XMLSchema'
> xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
> xmlns:enc='http://schemas.xmlsoap.org/soap/encoding/'
> xmlns:ns0='http://apache.org/wsdl'>
> <env:Body><ns0:helloWorld/></env:Body>
> </env:Envelope>
>
> with SAAJ, Axis serializes the message on the wire as below
>
> <!-- Ias -->
> <?xml version='1.0' encoding='UTF-8'?>
> <env:Envelope
> xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'
> xmlns:xsd='http://www.w3.org/2001/XMLSchema'
> xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
> xmlns:enc='http://schemas.xmlsoap.org/soap/encoding/'
> xmlns:ns0='http://apache.org/wsdl'>
> <env:Body><ns0:helloWorld/></env:Body>
> </env:Envelope>
>
> , and this is absolutely wrong. The reason is timing of
> writing XML declaration.
> If a comment is before the first element, XML declaration
> is written behind the comment because
> SerializationContextImpl handles elements and XML declaration
> simultaneously.
>
> Revision Changes Path
> 1.25 +10 -0
> ws-axis/java/src/org/apache/axis/message/SAXOutputter.java
>
> Index: SAXOutputter.java
> ===================================================================
> RCS file:
> /home/cvs/ws-axis/java/src/org/apache/axis/message/SAXOutputter.java,v
> retrieving revision 1.24
> retrieving revision 1.25
> diff -u -r1.24 -r1.25
> --- SAXOutputter.java 25 Feb 2004 14:02:43 -0000 1.24
> +++ SAXOutputter.java 18 May 2004 08:04:56 -0000 1.25
> @@ -17,6 +17,7 @@
>
> import org.apache.axis.components.logger.LogFactory;
> import org.apache.axis.encoding.SerializationContext;
> +import org.apache.axis.utils.XMLUtils;
> import org.apache.commons.logging.Log;
> import org.xml.sax.Attributes;
> import org.xml.sax.SAXException;
> @@ -40,6 +41,15 @@
> }
>
> public void startDocument() throws SAXException {
> + try {
> + context.writeString("<?xml
> version=\"1.0\" encoding=\"");
> + String encoding =
> XMLUtils.getEncoding(context.getMessageContext());
> + context.writeString(encoding);
> + context.writeString("\"?>\n");
> + context.setSendDecl(false);
> + } catch (IOException e) {
> + throw new SAXException(e);
> + }
> }
>
> public void endDocument() throws SAXException {
>
>
>
>