Sunday, January 10, 2010

Oracle FMW B2B 11g: How to collect HTTP header info from inbound messages using Java Callouts

In Oracle FMW B2B 11g the Java callout functionality makes it possible to add Java hooks to an inbound or oubound message flow. Callouts van be written and configured per agreement or per delivery channel (transport callouts). More info about managing callouts can be found here

In this blog posting, I will show how you how an agreement callout can be used to collect HTTP headers from an inbound message, which is received by the default B2B transportServlet. I use an agreement callout because it is not possible to define a transport callout for an inbound http host channel.

The callout implementation is rather simple:

import oracle.tip.b2b.callout.Callout;
import oracle.tip.b2b.callout.CalloutContext;
import oracle.tip.b2b.callout.CalloutMessage;
import oracle.tip.b2b.callout.exception.CalloutDomainException;
import oracle.tip.b2b.callout.exception.CalloutSystemException;

public class HttpHeaderAgrCallout implements Callout {

    public void execute(CalloutContext arg0, List input,
                        List output) throws CalloutDomainException,
                                            CalloutSystemException {
        try {
            CalloutMessage cm1 = (CalloutMessage)input.get(0);
            System.out.println("parameters - "+cm1.getParameters().toString());
            CalloutMessage cmOut = null;
            String msg = cm1.getBodyAsString();

            String headerStr = cm1.getParameters().toString();
            System.out.println("Print transport header ::");

            cmOut = new CalloutMessage(msg);

        } catch (Exception e) {


The getParameters() methods returns all the HTTP transport header attributes in a Properties object.

Compile the callout code and deploy it to a jar file. The jar file has to be copied a location that can be accessed by the B2B server (or all B2B nodes if you have a clustered environment). Have a look at the B2B callout documentation to find out how you configure the callout with your inbound agreement.

It is wise to put Agr or Transport in the callout name to make a clear distinction between the types of callouts as they appear together in the callout selection drop down list in the B2B management console.

So why do you need this anyway..well for example to extract a specific HTTP header attribute that is, for example, set by the front-end HTTP Server and enrich the message with it.

1 comment:

Anonymous said...


I want to add headers to the outbound (payload)before sending to the trading partner .i am using the below code to do that
import java.util.*;
import oracle.tip.b2b.callout.*;
import oracle.tip.b2b.callout.exception.*;

public class SampleCallout implements Callout {
public void execute(CalloutContext context,List input,List output)
throws CalloutDomainException, CalloutSystemException {
try {
CalloutMessage cmIn = (CalloutMessage)input.get(0);
String s =cmIn.getBodyAsString();

//for getting the CUSTOM_HEADER
Properties params = (Properties)cmIn.getParameters();
String customHeader = (String)params.get("CUSTOM_HEADER");

//for setting the CUSTOM_HEADER
CalloutMessage cmOut = new CalloutMessage(s);
cmOut.setParameter("CUSTOM_HEADER", "your_value");

} catch (Exception e) {
throw new CalloutDomainException(e);

what parameters do i need to pass for the context ,input..?otherthan callouts do we have any properties to use to add the custom headers ?