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=""

you assign a OSB variable as explained here

assign $body/ctx:binary-content to myBinaryData

then you invoke a java Callout with that myBinaryData variable

This post explains a little more

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:


(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: