Saturday, April 30, 2011

OSB getting file content with a File Proxy Service

I would start by polling with a Proxy Service :
Service Type: Messaging Service
Request Message Type . binary Type
Endpoint URI : file:///c:/temp/files

when OSB polls the file, the body is populated with this:

con:binary-content ref="cid:3042380f:12fa58f6644:-7fd8" xmlns:con="http://www.bea.com/wli/sb/context"


you assign a OSB variable as explained here
http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/context.html#wp1104506

assign $body/ctx:binary-content to myBinaryData




then you invoke a java Callout with that myBinaryData variable

This post explains a little more
http://frommyworkshop.blogspot.com/2009/04/send-e-mail-with-attachment-through-osb.html


Here is the Java Callout code

package com.pierre.filefromosb;

public class FileFromOSB {
public static void processFile(Object param) {
System.out.println("class=" + param.getClass().getName());
System.out.println("param=" + param);
byte[] bytes = (byte[])param;

String content = new String(bytes);
System.out.println("content=" + content);
}
}

the result is:

class=[B
param=[B@47b291
content=ciao


(the file's content was "ciao")


Once you have the binary content (byte[]) of the file you can do anything you want with it.

No comments: