I am starting with Soap and I have to send a soap response with few details along with a pdf file attachment.
AllDetails.java
public class AllDetails implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
String name,address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
GetDetails.java
public interface GetDetails {
public AllDetails getDetails(String name, String address);
}
GetDetailsImp
public class GetDetailsImp implements GetDetails {
@Override
public AllDetails getDetails(String name, String address) {
AllDetails obj = new AllDetails();
obj.setName("siddhesh");
obj.setAddress("badlapur");
try {
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
DataSource dataSource = new FileDataSource("D:\\test\\random.pdf");
AttachmentPart attachmentPart = message.createAttachmentPart(dataSource , "content-type");
message.addAttachmentPart(attachmentPart);
message.saveChanges();
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return obj;
}
}
I have created sample we service but along with Details object I also want to send attachment which is a pdf file
XML Response