SOAP with Attachments in OSB
This post is aimed for inline attachments
There are different ways to read the attachment and send back as SOAP attachment.
Here are the steps
Step1:
How to construct response for SOAP with attachments? Is there any change required in WSDL?
Here is WSDL sample for Response
<wsdl:output name="generateDocumentResponse">
<mime:multipartRelated>
<mime:part>
<soap:body parts="generateDocumentResponse pdfAttachment" use="literal" namespace="http://eai.officedepot.com/model/GenerateDocument"/>
</mime:part>
<mime:part>
<mime:content part="pdfAttachment" type="application/pdf"/>
</mime:part>
</mime:multipartRelated>
</wsdl:output>
Do you need complete WSDL? Comment / email me and respond back with sample code
Step2: Read the PDF Document.
There are multiple ways to read the document.
- You can use the File Adapter to read the document
- Use Java code to read attachment. Here is the example for Java code.
public static byte[] readFileInputStream(String filename) throws IOException {
// fileName = C:/Temp/TestFiles/Poll/testAttachment.pdf
byte [] buffer =null;
File a_file = new File(filename);
try
{
FileInputStream fis = new FileInputStream(filename);
int length = (int)a_file.length();
buffer = new byte [length];
fis.read(buffer);
fis.close();
}
catch(IOException e)
{
System.out.println("Error in reading the File...");
}
return buffer;
}
}
Use the Java callout in OSB to read attachment through Java.
Step 3: Use insert activity to attach document inline
Step4: Use reply activity to respond back.
Still confused? Enter comment here or send me an email with your requirement
No comments:
Post a Comment