wood burning stoves 2.0*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Attachment problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Attachment problem" Watch "Attachment problem" New topic

Attachment problem

Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
I am trying to add a file as attachment in the handler but it is not getting attached.

//handleRequest method of handler
public boolean handleRequest(MessageContext context)
try {
SOAPMessageContext messageContext = (SOAPMessageContext) context;
SOAPMessage soapMessage = messageContext.getMessage();
File file = new File("E:/RAJ/Web Services Documents/Presentation/Slides_Presentation.txt");
DataHandler dh = new DataHandler(new FileDataSource(file));
AttachmentPart ap = soapMessage.createAttachmentPart(dh);
ap.setContentId("simple txt file");
catch(Exception e)
System.out.println("Exception caught in handlerequest method"+e);

return true;
//handleResponse method of handler
public boolean handleResponse(MessageContext context)
SOAPMessageContext messageContext = (SOAPMessageContext) context;
SOAPMessage soapMessage = messageContext.getMessage();
java.util.Iterator it = soapMessage.getAttachments();
AttachmentPart attachment =(AttachmentPart)it.next();
Object content = attachment.getContent();
catch (Exception e)
System.out.println("Exception caught in handleResponse method"+e);
return true;

I have debugged this code and found that attachment is not getting attached because during handling the response it is not entering into the while loop,which means no attachments were there.
Kindly let me know how can i get this problem solved.
It is sorta covered in the JavaRanch Style Guide.
subject: Attachment problem
Similar Threads
WSWS3192E: Error: return code: ( 400 ) Bad Request when trying to invoked webservice
Soap & attachments: encoded or literal??
Problem in Attachments
Question about design of WS clients and their handlers
Question about message handlers and their interaction with a WS client