I have a very simple web service that echos back the xml given that
looks like this:
public class MessageService
{
public Document echoDocument(Document doc) throws Exception
{
return doc;
}
}
On the client I have the various methods setup to retrieve the result
vector and print out the document.
So far so good.
Now when I try to add an attachment from the server the result vector on
the client is empty. Using TCPMonitor I can see that the mime message is
coming through just fine. A perl client using SOAP::Lite is able to see
the data too.
public class MessageService
{
public Document echoDocument(Document doc) throws Exception
{
DataSource ds = new FileDataSource("/tmp/msg.pdf");
AttachmentPart att = new AttachmentPart(new DataHandler(ds));
Message msg =
(Message)MessageContext.getCurrentContext().getResponseMessage();
msg.addAttachmentPart(att);
msg.saveChanges();
return doc;
}
}
Has anyone written an axis client for a document style service that can
handle an attachment?
-a.
For completeness here is the MessageClient:
public class MessageClient
{
public static void main(String[] args) throws Exception
{
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(args[0]);
System.out.println("sending " + XMLUtils.DocumentToString(doc));
Service service = new Service();
Call call = (Call) service.createCall();
String endpoint =
"http://localhost:8080/msgservice/services/MessageService";
call.setTargetEndpointAddress(new URL(endpoint));
call.setOperation(new QName(endpoint, "echoDocument"),
"echoDocument");
Object ret = call.invoke(new Object[] {new
SOAPBodyElement(doc.getDocumentElement())});
Vector result = (Vector) call.invoke(new Object[] {new
SOAPBodyElement(doc.getDocumentElement())});
System.out.println(result);
/*
SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);
Document retDoc = sbe.getAsDocument();
System.out.println("received " +
XMLUtils.DocumentToString(retDoc));
*/
}
}