Home > OSB > OSB11G Java Callout Example

OSB11G Java Callout Example

In this example , will see how the JavaCallout activity can be used in OSB11G.



* This Java Callout activity is used to invoke java custom code.
* This is used when the OSB predefined functions is not sufficient to complete the requirement.
* This Java code must be packages as jar
* The method written for java callout must be static method. Then only the method will be visible in OSB Proxy Service for selection.

Here the requirement is , the partner system will recognize request passed from consumer, if the request passed is Base64 Encoded.

I have written one simple Java class to encode the content passed to Base64 and packaged it as Base64Encoder.jar
Placed this Base64Encoder jar inside OSB Project.

My OSB project structure is look like the below

ProjectStructure

ProjectStructure





1. Created a sample partner webservice WSDL just to accept the encoded request value and give back response as “Success”.
Attached the sample partner service AmazonWSDummy.war used to create AmazonWSDummy.WSDL

2. Created proxy service PS_SendMessage.proxy with AmazonWSDummy.WSDL.
And added a log activity to print consumer input.

ProxyServiceWLog

ProxyServiceWLog

3. Added Java Callout activity to encode the consumer message and pass it to partner service.
3.1. Select the Base64Encoder.jar by browsing to the location resources/jar.
Then Click Ok to select method.
3.2. Select decode method. Then Click OK.
3.3. The consumer request is passed to this Base64Encoder for encoding and the response is stored in encodedValue variable.

JavaCallout_SelectJar

JavaCallout_SelectJar


JavaCallout_SelectMethod

JavaCallout_SelectMethod


JavaCallout_Complete

JavaCallout_Complete





3.4. Java code is written using Apache commons-codec-1.9.jar to encode and decode the content.
This supporting jar should be in server classpath to execute the custom java encoding or decoding. This jar commons-codec-1.9.jar is placed in OSB server domain lib location

			${MIDDLEWARE_HOME}/user_projects/domains/osb_domain/lib
		 



Java Code

		 package com.wordpress.rathinasaba.encoder;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;

public class Base64Encoder {
	
	public static void main(String[] args) {
		String encoded=testEncode();
		testDecode(encoded);
	}

	public static String encode(String xmlString) throws UnsupportedEncodingException {
		byte[] encodedBytes = Base64.encodeBase64(xmlString.getBytes("UTF8"));
		return new String(encodedBytes);
	}
	
	public static String decode(String xmlString) throws UnsupportedEncodingException {
		byte[] decodedBytes = Base64.decodeBase64(xmlString);
		return new String(decodedBytes);
	}
	
	private static String testEncode(){
		String xmlStr="<root>TestEncoding</root>";
		String encodedResponse=null;
		try {
			encodedResponse=encode(xmlStr);
			System.out.println("Encoded content:"+encodedResponse);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return encodedResponse;
	}
	
	private static void testDecode(String xmlStr){
		try {
			String decodedResponse=decode(xmlStr);
			System.out.println("Decoded content:"+decodedResponse);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
}

		 



5. Added Replace activity to replace value need to be passed to partner system with encoded content as shown.
And Log action is added to verify the content passing to partner is correctly encoded.

ReplaceWithEncodedContent

ReplaceWithEncodedContent

6. Business Service BS_SendMessage.biz has been created with the partner WSDL AmazonWSDummy.wsdl
This Business Services is used in Routing activity to send the encoded message to partner system from Proxy Service.

RoutingToPartner

RoutingToPartner



7. Download this OSB11G Java Callout sample : OSB11G_JavaCallout.zip

Advertisements
Categories: OSB Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: