Hi Anirban,
As you mentioned you should use both my article: http://scn.sap.com/docs/DOC-26528& and my blog: http://scn.sap.com/community/pi-and-soa-middleware/blog/2010/03/28/sap-xipi-storing-binaries-images-pdfs-etc-in-the-database-blobs-using-jdbc-adapter colletively to achieve your requirement.
Few corrections,
1) Create only Zip file Stream (no physical file) with all the available attachments from incoming SOAP message.
2) Use Graphical mapping with UDF. The UDF should have both attachments zipping fuctionality and as well toHexString(byte[] bytes) functionality
3) Don't forget to enable read attachments option in operation/interface mapping
4) try the below UDF code and let me know the result
Questions,
1) how many stored procedures do you have in your requirement? I mean do you pass both payload content and hex decimal zipcontent to single stored procedure?
2) what is your pi version?
Combined UDF code with Zip and hexadecimal functionality (Note:-map this UDF output to BLOB field of JDBC structure in graphical mapping. Map rest of the stored procedure fields with payload fields as per requirement)
String attachmentID = null; String contentIDS = ""; StringBuffer sb = new StringBuffer(); java.util.Map map; AbstractTrace trace; //Hexadecimal characters corresponding to each half byte value. char[] HexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; //gets the input attachment from the source message GlobalContainer globalContainer = container.getGlobalContainer(); InputAttachments inputAttachments = globalContainer.getInputAttachments(); OutputAttachments outputAttachments = globalContainer.getOutputAttachments(); trace = container.getTrace(); map = globalContainer.getParameters(); DynamicConfiguration conf = (DynamicConfiguration) map.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); DynamicConfigurationKey contentIDSKey = DynamicConfigurationKey.create("http://test.com", "contentIDS"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(baos); try { //checks for the availability of attachments in the input message if(inputAttachments.areAttachmentsAvailable()) { trace.addInfo("Attachments Available"); //gets the attachmentIds and store it in an Object array Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true); Object[] arrayObj = CollectionIDs.toArray(); //Loops at the input attachments to get the content of the attachment for(int i =0;i<arrayObj.length;i++) { attachmentID =(String)arrayObj[i]; contentIDS = contentIDS + (i+1) + ") " + attachmentID + "; "; trace.addInfo("Attachment no: " + (i+1) + " & Name: " + attachmentID); Attachment attachment = inputAttachments.getAttachment(attachmentID); byte[] attachmentBytes = attachment.getContent(); trace.addInfo("Creating Zip Entry for attachmet no: " + (i+1)); zos.putNextEntry(new ZipEntry(attachmentID)); zos.write(attachmentBytes); zos.closeEntry(); //Close each zipentry after writing it to stream //remove each attachment if required. Uncommonent below //trace.addInfo("Removing Attachment no: " + (i+1) + " & Name: " + attachmentID); //outputAttachments.removeAttachment(attachmentID); } zos.close(); conf.put(contentIDSKey, contentIDS); byte[] bytes = baos.toByteArray(); int i; for (i=0; i < bytes.length; i++) { sb.append( HexChars[( bytes[i] & 0xf0 ) >>> 4] ); sb.append( HexChars[bytes[i] & 0x0f] ); //sb.append(HexChars[(bytes[i] >> 4) & 0xf]); //sb.append(HexChars[bytes[i] & 0xf]); } } } catch (Exception e) { e.printStackTrace(); } return ("aa" + sb.toString()); //**IMPORTANT: map this generating UDF output (no input to UDF required) to BLOB field of JDBC. If required remove "aa" extra byte if it works without extra byte.
Regards,
Praveen Gujjeti
Message was edited by: PRAVEEN GUJJETI (** Java code updated)