Discussion:
[Axis2][SOAP]Can not output XML declaration, after other output has already been done.
Tony Fang
2006-11-12 11:57:00 UTC
Permalink
Hi, there.

I always get the exception like "org.apache.axis2.AxisFault: Can not output
XML declaration, after other output has already been done.; nested exception
is: " when I try to run the following code. Does some one also meet this
AxisFault before?

you can find the Web Service here, both WSDL file, and SOAP Request and
Response sample. (I am sure, I can get the response when I using Axis1.1)

Any commonts would help me.

Thanks
Tony

---- Flowing the test code ----------------


package tony.axis.test;

import org.apache.axiom.om.*;
import org.apache.axiom.soap.*;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.*;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.MessageContextConstants;
import org.apache.axis2.client.async.*;

public class SoapTest2 {

public static void main(String[] args) {

//String url = "http://www.xignite.com/xFutures.asmx/GetFutureSymbol";
String url ="http://www.xignite.com/services/GetFutureSymbol";

Options options = new Options();
//options.setProperty(MessageContextConstants.CHUNKED,
Constants.VALUE_FALSE);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setTo(new EndpointReference(url));


try {
ServiceClient serviceClient = new ServiceClient();
serviceClient.setOptions(options);
SOAPFactory omFactory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = omFactory.getDefaultEnvelope();
OMNamespace xsi = omFactory.createOMNamespace("
http://www.w3.org/2001/XMLSchema-instance", "xsi");
OMNamespace xsd = omFactory.createOMNamespace("
http://www.w3.org/2001/XMLSchema", "xsd");
OMNamespace soap = omFactory.createOMNamespace("
http://schemas.xmlsoap.org/soap/envelope/", "soap");
OMNamespace defNs = omFactory.createOMNamespace("
http://www.xignite.com/services/", "");
OMNamespace nullNs = omFactory.createOMNamespace("", "");

OMElement operation =
omFactory.createOMElement("GetFutureSymbol",
"",
"");
operation.setNamespace(defNs);

SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
body.addChild(operation);

envelope.setNamespace(xsi);
envelope.setNamespace(xsd);
envelope.setNamespace(soap);

OMElement username = omFactory.createOMElement("Username", nullNs);
username.setText("");
header.addChild(username);
OMElement password = omFactory.createOMElement("Password", nullNs);
password.setText("");
header.addChild(password);
OMElement tracer = omFactory.createOMElement("Tracer", nullNs);
tracer.setText("");
header.addChild(tracer);
OMElement symbol = omFactory.createOMElement("Symbol", nullNs);
symbol.setText("CL");
operation.addChild(symbol);
OMElement month = omFactory.createOMElement("Month", nullNs);
month.setText("9");
operation.addChild(month);
OMElement year = omFactory.createOMElement("Year", nullNs);
year.setText("2002");
operation.addChild(year);

System.out.println(envelope);
OMElement result = serviceClient.sendReceive(envelope);
System.out.print(result);

} catch (AxisFault e1) {
System.out.println("AxisFault");
System.out.println(e1.getFaultRole());
e1.printStackTrace();
}
}
}
Paul Fremantle
2006-11-12 13:26:59 UTC
Permalink
Tony

I can't see the SOAP response. Can you please repost it?

Ta
Paul
Post by Tony Fang
Hi, there.
I always get the exception like "org.apache.axis2.AxisFault: Can not output
XML declaration, after other output has already been done.; nested exception
is: " when I try to run the following code. Does some one also meet this
AxisFault before?
you can find the Web Service here, both WSDL file, and SOAP Request and
Response sample. (I am sure, I can get the response when I using Axis1.1)
Any commonts would help me.
Thanks
Tony
---- Flowing the test code ----------------
package tony.axis.test;
import org.apache.axiom.om.*;
import org.apache.axiom.soap.*;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.* ;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.MessageContextConstants;
import org.apache.axis2.client.async.*;
public class SoapTest2 {
public static void main(String[] args) {
//String url =
"http://www.xignite.com/xFutures.asmx/GetFutureSymbol";
String url ="
http://www.xignite.com/services/GetFutureSymbol";
Options options = new Options();
//options.setProperty(MessageContextConstants.CHUNKED,Constants.VALUE_FALSE);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setTo(new EndpointReference(url));
try {
ServiceClient serviceClient = new ServiceClient();
serviceClient.setOptions(options);
SOAPFactory omFactory =
OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = omFactory.getDefaultEnvelope ();
OMNamespace xsi =
omFactory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance",
"xsi");
OMNamespace xsd = omFactory.createOMNamespace
("http://www.w3.org/2001/XMLSchema", "xsd");
OMNamespace soap = omFactory.createOMNamespace("
http://schemas.xmlsoap.org/soap/envelope/", "soap");
OMNamespace defNs =
omFactory.createOMNamespace("http://www.xignite.com/services/",
"");
OMNamespace nullNs = omFactory.createOMNamespace("", "");
OMElement operation =
omFactory.createOMElement("GetFutureSymbol",
"",
"");
operation.setNamespace(defNs);
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
body.addChild(operation);
envelope.setNamespace(xsi);
envelope.setNamespace(xsd);
envelope.setNamespace(soap);
OMElement username = omFactory.createOMElement("Username", nullNs);
username.setText("");
header.addChild(username);
OMElement password = omFactory.createOMElement("Password", nullNs);
password.setText("");
header.addChild(password);
OMElement tracer = omFactory.createOMElement("Tracer", nullNs);
tracer.setText("");
header.addChild(tracer);
OMElement symbol = omFactory.createOMElement("Symbol", nullNs);
symbol.setText("CL");
operation.addChild(symbol);
OMElement month = omFactory.createOMElement("Month", nullNs);
month.setText("9");
operation.addChild(month);
OMElement year = omFactory.createOMElement("Year", nullNs);
year.setText("2002");
operation.addChild(year);
System.out.println(envelope);
OMElement result = serviceClient.sendReceive(envelope);
System.out.print(result);
} catch (AxisFault e1) {
System.out.println("AxisFault");
System.out.println(e1.getFaultRole());
e1.printStackTrace();
}
}
}
--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair

http://bloglines.com/blog/paulfremantle
***@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com
Paul Fremantle
2006-11-12 13:27:42 UTC
Permalink
Also, can you please use TCPMON to capture the actual request/response
that you are getting from Axis2.

Paul
Post by Paul Fremantle
Tony
I can't see the SOAP response. Can you please repost it?
Ta
Paul
Post by Tony Fang
Hi, there.
I always get the exception like "org.apache.axis2.AxisFault: Can not output
XML declaration, after other output has already been done.; nested exception
is: " when I try to run the following code. Does some one also meet this
AxisFault before?
you can find the Web Service here, both WSDL file, and SOAP Request and
Response sample. (I am sure, I can get the response when I using Axis1.1)
Any commonts would help me.
Thanks
Tony
---- Flowing the test code ----------------
package tony.axis.test;
import org.apache.axiom.om.*;
import org.apache.axiom.soap.*;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.* ;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.MessageContextConstants;
import org.apache.axis2.client.async.*;
public class SoapTest2 {
public static void main(String[] args) {
//String url =
"http://www.xignite.com/xFutures.asmx/GetFutureSymbol";
String url ="
http://www.xignite.com/services/GetFutureSymbol";
Options options = new Options();
//options.setProperty(MessageContextConstants.CHUNKED,Constants.VALUE_FALSE);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setTo(new EndpointReference(url));
try {
ServiceClient serviceClient = new ServiceClient();
serviceClient.setOptions(options);
SOAPFactory omFactory =
OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = omFactory.getDefaultEnvelope ();
OMNamespace xsi =
omFactory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance",
"xsi");
OMNamespace xsd = omFactory.createOMNamespace
("http://www.w3.org/2001/XMLSchema", "xsd");
OMNamespace soap = omFactory.createOMNamespace("
http://schemas.xmlsoap.org/soap/envelope/", "soap");
OMNamespace defNs =
omFactory.createOMNamespace("http://www.xignite.com/services/",
"");
OMNamespace nullNs = omFactory.createOMNamespace("", "");
OMElement operation =
omFactory.createOMElement("GetFutureSymbol",
"",
"");
operation.setNamespace(defNs);
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
body.addChild(operation);
envelope.setNamespace(xsi);
envelope.setNamespace(xsd);
envelope.setNamespace(soap);
OMElement username = omFactory.createOMElement("Username", nullNs);
username.setText("");
header.addChild(username);
OMElement password = omFactory.createOMElement("Password", nullNs);
password.setText("");
header.addChild(password);
OMElement tracer = omFactory.createOMElement("Tracer", nullNs);
tracer.setText("");
header.addChild(tracer);
OMElement symbol = omFactory.createOMElement("Symbol", nullNs);
symbol.setText("CL");
operation.addChild(symbol);
OMElement month = omFactory.createOMElement("Month", nullNs);
month.setText("9");
operation.addChild(month);
OMElement year = omFactory.createOMElement("Year", nullNs);
year.setText("2002");
operation.addChild(year);
System.out.println(envelope);
OMElement result = serviceClient.sendReceive(envelope);
System.out.print(result);
} catch (AxisFault e1) {
System.out.println("AxisFault");
System.out.println(e1.getFaultRole());
e1.printStackTrace();
}
}
}
--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
http://bloglines.com/blog/paulfremantle
"Oxygenating the Web Service Platform", www.wso2.com
--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair

http://bloglines.com/blog/paulfremantle
***@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com
Tony Fang
2006-11-12 14:04:07 UTC
Permalink
HI, Paul

you can find the all the related source here.
http://www.xignite.com/xFutures.asmx/GetFutureSymbol

the response should like

<?xml version="1.0" encoding="utf-8" ?>
<FutureSymbol xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns="
http://www.xignite.com/services/">
<Outcome>Success</Outcome>
<Identity>IP</Identity>
<Delay>0</Delay>
<FutureSymbol>CLU2</FutureSymbol>
<CommoditySymbol>CL</CommoditySymbol>
<Year>2002</Year>
<Month>9</Month>
</FutureSymbol>
Post by Paul Fremantle
Tony
I can't see the SOAP response. Can you please repost it?
Ta
Paul
Post by Tony Fang
Hi, there.
I always get the exception like "org.apache.axis2.AxisFault: Can not
output
Post by Tony Fang
XML declaration, after other output has already been done.; nested
exception
Post by Tony Fang
is: " when I try to run the following code. Does some one also meet this
AxisFault before?
you can find the Web Service here, both WSDL file, and SOAP Request and
Response sample. (I am sure, I can get the response when I using Axis1.1
)
Post by Tony Fang
Any commonts would help me.
Thanks
Tony
---- Flowing the test code ----------------
package tony.axis.test;
import org.apache.axiom.om.*;
import org.apache.axiom.soap.*;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.* ;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.MessageContextConstants;
import org.apache.axis2.client.async.*;
public class SoapTest2 {
public static void main(String[] args) {
//String url =
"http://www.xignite.com/xFutures.asmx/GetFutureSymbol";
String url ="
http://www.xignite.com/services/GetFutureSymbol";
Options options = new Options();
//options.setProperty(MessageContextConstants.CHUNKED,
Constants.VALUE_FALSE);
Post by Tony Fang
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setTo(new EndpointReference(url));
try {
ServiceClient serviceClient = new ServiceClient();
serviceClient.setOptions(options);
SOAPFactory omFactory =
OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = omFactory.getDefaultEnvelope ();
OMNamespace xsi =
omFactory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance",
"xsi");
OMNamespace xsd = omFactory.createOMNamespace
("http://www.w3.org/2001/XMLSchema", "xsd");
OMNamespace soap = omFactory.createOMNamespace("
http://schemas.xmlsoap.org/soap/envelope/", "soap");
OMNamespace defNs =
omFactory.createOMNamespace("http://www.xignite.com/services/",
"");
OMNamespace nullNs = omFactory.createOMNamespace("", "");
OMElement operation =
omFactory.createOMElement("GetFutureSymbol",
"",
"");
operation.setNamespace(defNs);
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
body.addChild(operation);
envelope.setNamespace(xsi);
envelope.setNamespace(xsd);
envelope.setNamespace(soap);
OMElement username = omFactory.createOMElement("Username", nullNs);
username.setText("");
header.addChild(username);
OMElement password = omFactory.createOMElement("Password", nullNs);
password.setText("");
header.addChild(password);
OMElement tracer = omFactory.createOMElement("Tracer", nullNs);
tracer.setText("");
header.addChild(tracer);
OMElement symbol = omFactory.createOMElement("Symbol", nullNs);
symbol.setText("CL");
operation.addChild(symbol);
OMElement month = omFactory.createOMElement("Month", nullNs);
month.setText("9");
operation.addChild(month);
OMElement year = omFactory.createOMElement("Year", nullNs);
year.setText("2002");
operation.addChild(year);
System.out.println(envelope);
OMElement result = serviceClient.sendReceive(envelope);
System.out.print(result);
} catch (AxisFault e1) {
System.out.println("AxisFault");
System.out.println(e1.getFaultRole());
e1.printStackTrace();
}
}
}
--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
http://bloglines.com/blog/paulfremantle
"Oxygenating the Web Service Platform", www.wso2.com
---------------------------------------------------------------------
--
Regards
Tony
Martin Gainty
2006-11-12 16:00:08 UTC
Permalink
The attempt to create null QNames and null Elements appears problematic as you sub nulls for name AND prefix/localname
(note that TestingUtils has a method createDummyOMElement which accomplishes the objective implemented via)
OMElement payload = TestingUtils.createDummyOMElement();

What happens when you run the testcase supplied here
http://kickjava.com/src/org/apache/axis2/engine/CommonsHTTPEchoRawXMLTest.java.htm

?
M-
This e-mail communication and any attachments may contain confidential and privileged information for the use of the
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its
contents
----- Original Message -----
From: "Paul Fremantle" <***@gmail.com>
To: <axis-***@ws.apache.org>
Sent: Sunday, November 12, 2006 8:27 AM
Subject: Re: [Axis2][SOAP]Can not output XML declaration, after other output has already been done.
Post by Paul Fremantle
Also, can you please use TCPMON to capture the actual request/response
that you are getting from Axis2.
Paul
Post by Paul Fremantle
Tony
I can't see the SOAP response. Can you please repost it?
Ta
Paul
Post by Tony Fang
Hi, there.
I always get the exception like "org.apache.axis2.AxisFault: Can not output
XML declaration, after other output has already been done.; nested exception
is: " when I try to run the following code. Does some one also meet this
AxisFault before?
you can find the Web Service here, both WSDL file, and SOAP Request and
Response sample. (I am sure, I can get the response when I using Axis1.1)
Any commonts would help me.
Thanks
Tony
---- Flowing the test code ----------------
package tony.axis.test;
import org.apache.axiom.om.*;
import org.apache.axiom.soap.*;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.* ;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.MessageContextConstants;
import org.apache.axis2.client.async.*;
public class SoapTest2 {
public static void main(String[] args) {
//String url =
"http://www.xignite.com/xFutures.asmx/GetFutureSymbol";
String url ="
http://www.xignite.com/services/GetFutureSymbol";
Options options = new Options();
//options.setProperty(MessageContextConstants.CHUNKED,Constants.VALUE_FALSE);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setTo(new EndpointReference(url));
try {
ServiceClient serviceClient = new ServiceClient();
serviceClient.setOptions(options);
SOAPFactory omFactory =
OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = omFactory.getDefaultEnvelope ();
OMNamespace xsi =
omFactory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance",
"xsi");
OMNamespace xsd = omFactory.createOMNamespace
("http://www.w3.org/2001/XMLSchema", "xsd");
OMNamespace soap = omFactory.createOMNamespace("
http://schemas.xmlsoap.org/soap/envelope/", "soap");
OMNamespace defNs =
omFactory.createOMNamespace("http://www.xignite.com/services/",
"");
OMNamespace nullNs = omFactory.createOMNamespace("", "");
OMElement operation =
omFactory.createOMElement("GetFutureSymbol",
"",
"");
operation.setNamespace(defNs);
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
body.addChild(operation);
envelope.setNamespace(xsi);
envelope.setNamespace(xsd);
envelope.setNamespace(soap);
OMElement username = omFactory.createOMElement("Username", nullNs);
username.setText("");
header.addChild(username);
OMElement password = omFactory.createOMElement("Password", nullNs);
password.setText("");
header.addChild(password);
OMElement tracer = omFactory.createOMElement("Tracer", nullNs);
tracer.setText("");
header.addChild(tracer);
OMElement symbol = omFactory.createOMElement("Symbol", nullNs);
symbol.setText("CL");
operation.addChild(symbol);
OMElement month = omFactory.createOMElement("Month", nullNs);
month.setText("9");
operation.addChild(month);
OMElement year = omFactory.createOMElement("Year", nullNs);
year.setText("2002");
operation.addChild(year);
System.out.println(envelope);
OMElement result = serviceClient.sendReceive(envelope);
System.out.print(result);
} catch (AxisFault e1) {
System.out.println("AxisFault");
System.out.println(e1.getFaultRole());
e1.printStackTrace();
}
}
}
--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
http://bloglines.com/blog/paulfremantle
"Oxygenating the Web Service Platform", www.wso2.com
--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
http://bloglines.com/blog/paulfremantle
"Oxygenating the Web Service Platform", www.wso2.com
---------------------------------------------------------------------
Paul Fremantle
2006-11-13 13:04:31 UTC
Permalink
Tony

The URL you are using is not a SOAP endpoint URL.

Maybe that is what is wrong!?

Paul
Post by Tony Fang
Hi, there.
I always get the exception like "org.apache.axis2.AxisFault: Can not output
XML declaration, after other output has already been done.; nested exception
is: " when I try to run the following code. Does some one also meet this
AxisFault before?
you can find the Web Service here, both WSDL file, and SOAP Request and
Response sample. (I am sure, I can get the response when I using Axis1.1)
Any commonts would help me.
Thanks
Tony
---- Flowing the test code ----------------
package tony.axis.test;
import org.apache.axiom.om.*;
import org.apache.axiom.soap.*;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.* ;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.MessageContextConstants;
import org.apache.axis2.client.async.*;
public class SoapTest2 {
public static void main(String[] args) {
//String url =
"http://www.xignite.com/xFutures.asmx/GetFutureSymbol";
String url ="
http://www.xignite.com/services/GetFutureSymbol";
Options options = new Options();
//options.setProperty(MessageContextConstants.CHUNKED,Constants.VALUE_FALSE);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setTo(new EndpointReference(url));
try {
ServiceClient serviceClient = new ServiceClient();
serviceClient.setOptions(options);
SOAPFactory omFactory =
OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = omFactory.getDefaultEnvelope ();
OMNamespace xsi =
omFactory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance",
"xsi");
OMNamespace xsd = omFactory.createOMNamespace
("http://www.w3.org/2001/XMLSchema", "xsd");
OMNamespace soap = omFactory.createOMNamespace("
http://schemas.xmlsoap.org/soap/envelope/", "soap");
OMNamespace defNs =
omFactory.createOMNamespace("http://www.xignite.com/services/",
"");
OMNamespace nullNs = omFactory.createOMNamespace("", "");
OMElement operation =
omFactory.createOMElement("GetFutureSymbol",
"",
"");
operation.setNamespace(defNs);
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
body.addChild(operation);
envelope.setNamespace(xsi);
envelope.setNamespace(xsd);
envelope.setNamespace(soap);
OMElement username = omFactory.createOMElement("Username", nullNs);
username.setText("");
header.addChild(username);
OMElement password = omFactory.createOMElement("Password", nullNs);
password.setText("");
header.addChild(password);
OMElement tracer = omFactory.createOMElement("Tracer", nullNs);
tracer.setText("");
header.addChild(tracer);
OMElement symbol = omFactory.createOMElement("Symbol", nullNs);
symbol.setText("CL");
operation.addChild(symbol);
OMElement month = omFactory.createOMElement("Month", nullNs);
month.setText("9");
operation.addChild(month);
OMElement year = omFactory.createOMElement("Year", nullNs);
year.setText("2002");
operation.addChild(year);
System.out.println(envelope);
OMElement result = serviceClient.sendReceive(envelope);
System.out.print(result);
} catch (AxisFault e1) {
System.out.println("AxisFault");
System.out.println(e1.getFaultRole());
e1.printStackTrace();
}
}
}
--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair

http://bloglines.com/blog/paulfremantle
***@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com
Tony Fang
2006-11-14 03:46:46 UTC
Permalink
Yes, I find I
Used wrong URL, and I should send the Operation instead of send whole
SOAP Envelope.

Thanks
Tony
Post by Paul Fremantle
Tony
The URL you are using is not a SOAP endpoint URL.
Maybe that is what is wrong!?
Paul
Post by Tony Fang
Hi, there.
I always get the exception like "org.apache.axis2.AxisFault: Can not
output
Post by Tony Fang
XML declaration, after other output has already been done.; nested
exception
Post by Tony Fang
is: " when I try to run the following code. Does some one also meet this
AxisFault before?
you can find the Web Service here, both WSDL file, and SOAP Request and
Response sample. (I am sure, I can get the response when I using Axis1.1
)
Post by Tony Fang
Any commonts would help me.
Thanks
Tony
---- Flowing the test code ----------------
package tony.axis.test;
import org.apache.axiom.om.*;
import org.apache.axiom.soap.*;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.* ;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.MessageContextConstants;
import org.apache.axis2.client.async.*;
public class SoapTest2 {
public static void main(String[] args) {
//String url =
"http://www.xignite.com/xFutures.asmx/GetFutureSymbol";
String url ="
http://www.xignite.com/services/GetFutureSymbol";
Options options = new Options();
//options.setProperty(MessageContextConstants.CHUNKED,
Constants.VALUE_FALSE);
Post by Tony Fang
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setTo(new EndpointReference(url));
try {
ServiceClient serviceClient = new ServiceClient();
serviceClient.setOptions(options);
SOAPFactory omFactory =
OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = omFactory.getDefaultEnvelope ();
OMNamespace xsi =
omFactory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance",
"xsi");
OMNamespace xsd = omFactory.createOMNamespace
("http://www.w3.org/2001/XMLSchema", "xsd");
OMNamespace soap = omFactory.createOMNamespace("
http://schemas.xmlsoap.org/soap/envelope/", "soap");
OMNamespace defNs =
omFactory.createOMNamespace("http://www.xignite.com/services/",
"");
OMNamespace nullNs = omFactory.createOMNamespace("", "");
OMElement operation =
omFactory.createOMElement("GetFutureSymbol",
"",
"");
operation.setNamespace(defNs);
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
body.addChild(operation);
envelope.setNamespace(xsi);
envelope.setNamespace(xsd);
envelope.setNamespace(soap);
OMElement username = omFactory.createOMElement("Username", nullNs);
username.setText("");
header.addChild(username);
OMElement password = omFactory.createOMElement("Password", nullNs);
password.setText("");
header.addChild(password);
OMElement tracer = omFactory.createOMElement("Tracer", nullNs);
tracer.setText("");
header.addChild(tracer);
OMElement symbol = omFactory.createOMElement("Symbol", nullNs);
symbol.setText("CL");
operation.addChild(symbol);
OMElement month = omFactory.createOMElement("Month", nullNs);
month.setText("9");
operation.addChild(month);
OMElement year = omFactory.createOMElement("Year", nullNs);
year.setText("2002");
operation.addChild(year);
System.out.println(envelope);
OMElement result = serviceClient.sendReceive(envelope);
System.out.print(result);
} catch (AxisFault e1) {
System.out.println("AxisFault");
System.out.println(e1.getFaultRole());
e1.printStackTrace();
}
}
}
--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
http://bloglines.com/blog/paulfremantle
"Oxygenating the Web Service Platform", www.wso2.com
---------------------------------------------------------------------
--
Regards
Tony
Loading...