• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in Attachments

 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
soapMessage.addAttachmentPart(ap);
}
catch(Exception e)
{
System.out.println("Exception caught in handlerequest method"+e);
}

return true;
}
//handleResponse method of handler
public boolean handleResponse(MessageContext context)
{
try
{
SOAPMessageContext messageContext = (SOAPMessageContext) context;
SOAPMessage soapMessage = messageContext.getMessage();
java.util.Iterator it = soapMessage.getAttachments();
while(it.hasNext()){
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic