API Management
13.2 13.1 13.0 12.2 12.1 12.0 11.0
13.2 13.1 13.0 12.2 12.1 12.0 11.0

Java Callout


Contents

The Java Callout policy provides a way to inject custom Java modules as part of the message flow. The call out handler implements a Java interface onto which complete processing context is passed.  

Configuration

The properties that have to be configured to use the policy are described below.

image2015-10-5 15:35:41.png
Figure 1: Java Call Out Policy Configuration attributes

Qualified Class Name

The fully qualified name of the class which implements the interface Call OutProcessor. 

image2014-12-26 16:16:0.png

Location of Jar File

The jar location must be added to the configuration of gateway servers. Navigate to FIORANO_HOME > esb > server > bin. Add the path (location) of the jar file in the server.conf file under the tag <java.classpath>.    

Is Streaming Supported

This option can be checked if the class does not access or modify the payload and that it works only with parameters and context variables.

Accessing Processor Context

This method has the variable processor context whose methods are listed below. The methods can be used to access or modify the message.

image2014-12-26 16:10:35.png

Example

The following class demonstrates the use of Java call out. The class inspects the parameter ID and verifies whether or not the details corresponding to the ID are present in a local database. If present, the details are set as payload and a flag RETRIEVED_FROM_DB will be set so that the execution of other policies can be controlled by rules based on this flag. 

Java
package com.fiorano.samples.callout;

import com.fiorano.api.policies.handlers.callout.java.CallOutProcessor;
import com.fiorano.api.policies.handlers.callout.java.ProcessorContext;

public class SampleCallOutProcessor implements CallOutProcessor {
    @Override
      public void process(ProcessorContext context) throws CallOutFailedException {
        List<String> id = context.getQueryParameter("ID");
        String paylod = retrieveFromDB(id);
        if(!paylod.isEmpty()){
            context.setContextVariable("RETRIEVE_FROM_DB",true);
            context.setPayload(paylod);
        } else{
           context.setContextVariable("RETRIEVE_FROM_DB",false);
        }
    }
    public String retrieveFromDB(List<String> id){
        String paylod = null;
        /**
         * This method will check in local database and retrieve the data corresponding to ID if present.
         */
        return paylod;
    }