Hi,
I couldn't detect any probs in your code at the first glance..
Try sending some file other than XML.. I'm just getting the feeling that it might be a bug in Axis2.
If it works then try avoiding the returning of the same file from the server...
Please let us know the progress
Thanks,
~Thilina
PS: I'm really sorry that I will not be able to test your code for next two weeks due to me busy with my exams.
On 6/13/06, Jenny ZHANG <[EMAIL PROTECTED]> wrote:
Dear all,
I was trying to use MTOM attachement to send a test.xml to server. Unfortunately no SOAP
messages were catched by SOAPMonitor, and I got errors in windows's console (listed below).
It looked like that the SOAP envelop did not generate successfully, I tried both SOAP1.1 and SOAP1.2,
but get the same error result. The service and client code are attached, Can anyone pls tell me
what's wrong with my codes? Thanks very much!
P.S. I've deployed the service (MTOMServiceWS) successfully on Tomcat 5.5.17 with Axis2 1.0.
Jenny
[EMAIL PROTECTED]
2006-06-13
------------------------Error-----------------
"
[java] log4j:WARN No appenders could be found for logger (org.apache.axiom.om.impl.builder.StAXOMBuilder).
[java] log4j:WARN Please initialize the log4j system properly.
[java] org.apache.axis2.AxisFault: Transport error 500 . Error Message is <html><head><title>Apache Tomcat/5.5.17 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this req
uest.</u></p><p><b>exception</b> <pre>org.apache.axiom.om.OMException: SOAPEnvelope must contain a body element which is either first or second child element of the SOAPEnvelope.
[java] org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.getBody(SOAPEnvelopeImpl.java:142)
[java] org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.addChild(SOAPEnvelopeImpl.java:103)
[java] org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.getHeader (SOAPEnvelopeImpl.java:82)
[java] org.apache.axis2.engine.AxisEngine.createFaultMessageContext(AxisEngine.java:183)
[java] org.apache.axis2.transport.http.AxisServlet.handleFault(AxisServlet.java:168)
[java] org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:153)
[java] javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
[java] javax.servlet.http.HttpServlet.service (HttpServlet.java:802)
[java] </pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.5.17</h3></body></html>;
........ (repeated the above error again)
"
----------------client side code: MTOMClient.java-----------
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement ;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMText;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import javax.activation.DataHandler ;
import javax.activation.FileDataSource;
import javax.xml.namespace.QName;
import java.io.File;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader ;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import java.io.StringReader;
public class MTOMClient {
public static void main(String[] args) throws XMLStreamException {
PrivacyServiceClient client = new PrivacyServiceClient();
try {
OMElement result = client.testEchoXMLSync("test1.xml");
} catch (Exception e) {
e.printStackTrace();
}
}
private OMElement createEnvelope(String fileName) throws Exception {
DataHandler expectedDH;
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://example.org/mtom/data ", "x");
OMElement data = "" omNs);
File dataFile = new File(fileName);
FileDataSource dataSource = new FileDataSource(dataFile);
expectedDH = new DataHandler(dataSource);
OMText textData = fac.createOMText(expectedDH, true);
data.addChild(textData);
return data;
}
public OMElement testEchoXMLSync(String fileName) throws Exception {
EndpointReference targetEPR = new EndpointReference(" http://localhost:8080/axis2/services/MTOMServiceWS");
// QName operationName = new QName("MTOMService");
OMElement payload = createEnvelope(fileName);
Options options = new Options();
options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
// options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
options.setTo(targetEPR);
// enabling MTOM in the client side
options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP );
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
return sender.sendReceive(payload);
}
}
----------------Server side code: MTOMServiceWS.java---------
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMAbstractFactory;
import java.util.Iterator;
public class MTOMServiceWS {
public OMElement MTOMService(OMElement element) throws Exception {
element.build ();
element.detach();
return element;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
"May the SourcE be with u"
http://webservices.apache.org/~thilina/
http://thilinag.blogspot.com/ http://www.bloglines.com/blog/Thilina
