Hi,
We're attempting to move from using the Sun "Reference Implementation"
(JAX pack etc), to using Axis. I've been using the 1.1RC1 release.
Basically we have a system where a client makes a call to a server,
which implements a SOAP service using a JAXMservlet (basically an
extension of a HttpServlet, which replies to POST's by calling an
onMessage method). This constructs a reply by creating a SOAPMessage
(which in our case includes a number of attachments) and dumping this
reply back to the invoking client (using a SOAPMessage.writeTo()).
This all worked fine with the Sun reference implementation, but fails
horribly with Axis.
I've attached a simple piece of example code (which I'm running within
WebLogic, but should work in any servlet engine). This happily receives
a "multipart" SOAP message but fails to send anything sensible back as a
reply. However, if you remove the attachment from the reply then all is
fine, since it simply returns a simple xml document in that case.
Essentially what seems to happen is that suitable MimeHeaders are never
set/created when constructing a SOAPMessage under Axis, in particular
the rather crucial "Content-Type" is never set, so that the reply just
seems to be a streamed together set of attachment parts, which is
obviously unintelligible to the receiver.
Its not entirely clear if what we are doing _should_ work, although its
exactly along the lines of many of Sun's example codes, and its hard to
see what else could be done.
Anyone else tried doing something along these lines and have any
suggestions?
Regards,
Mark
--
Mark Hagger
Senior Developer
m-spatial ltd.
(T) +44 (0) 1223 421534
(F) +44 (0) 1223 420844
The Information contained in this e-mail and any subsequent
correspondence is private and is intended solely for the intended
recipient(s). If received in error please inform the sender and delete
it. For those other than the recipient any disclosure, copying,
distribution, or any action taken or omitted to be taken in reliance on
such information is prohibited and may be unlawful. Any information
relating to m-spatial technology is for information purposes only and no
warranties are made by m-spatial. Opinions, conclusions and other
information expressed in this message are not given or endorsed by
m-spatial unless otherwise indicated by an authorized representative
independent of this message.
________________________________________________________________________
This email has been scanned for all known viruses by the MessageLabs SkyScan service.
package bounce;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.xml.messaging.JAXMServlet;
import javax.xml.messaging.ReqRespListener;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.*;
import javax.activation.DataHandler;
import java.awt.Image;
import java.net.URL;
import java.util.*;
public class control extends JAXMServlet implements ReqRespListener {
public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
System.out.println( "doPost()" );
try {
MimeHeaders mimeHeaders = getHeaders( request );
ServletInputStream sInputStream = request.getInputStream();
//Create the SOAPMessage from the reply
//msgFactory is a protected field of JAXMServlet
SOAPMessage soapMessage = msgFactory.createMessage ( mimeHeaders, sInputStream );
System.out.println( "======= Incoming message =======" );
System.out.println( "Request headers" );
Iterator it = mimeHeaders.getAllHeaders();
while ( it.hasNext() ) {
MimeHeader head = (MimeHeader) it.next();
System.out.println( head.getName() + " " + head.getValue() );
}
soapMessage.writeTo( System.out );
System.out.println();
SOAPMessage soapMessageReply = null;
soapMessageReply = this.onMessage( soapMessage );
if ( soapMessageReply != null ){
if ( soapMessageReply.saveRequired() )
soapMessageReply.saveChanges();
}
//Send the response back to the sender
//by placing the mime headers into the response, and externalizing
//the soapmessage onto the response object.
putHeaders( soapMessageReply.getMimeHeaders(), response );
System.out.println( "======= Outgoing message =======" );
System.out.println( "Response headers" );
it = soapMessageReply.getMimeHeaders().getAllHeaders();
while ( it.hasNext() ) {
MimeHeader head = (MimeHeader) it.next();
System.out.println( head.getName() + " " + head.getValue() );
}
soapMessageReply.writeTo( System.out );
ServletOutputStream sOutputStream = response.getOutputStream();
soapMessageReply.writeTo( sOutputStream );
sOutputStream.flush();
}
catch ( Exception ex ) {
ex.printStackTrace();
}
}
public SOAPMessage onMessage( SOAPMessage message ) {
try{
SOAPMessage reply = null;
reply = msgFactory.newInstance().createMessage();
SOAPEnvelope envelope = reply.getSOAPPart().getEnvelope();
SOAPBody body = envelope.getBody();
SOAPElement msgElement = body.addBodyElement( envelope.createName( "Hello", "msptl", "http://www.m-spatial.com/" ) );
AttachmentPart attachment = reply.createAttachmentPart();
attachment.setContent( "This is some text", "text/plain" );
reply.addAttachmentPart( attachment );
return reply;
}
catch ( Exception ex ) {
ex.printStackTrace();
}
return null;
}
}