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:
package nl.oracle.com.b2bcallout;
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 ::");
System.out.println(headerStr);
cmOut = new CalloutMessage(msg);
output.add(cmOut);
} catch (Exception e) {
e.printStackTrace();
}
}
}
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.

0 comments:
Post a Comment