Thursday, April 28, 2011

B2B Callout - B2B runtime error: java.lang.IndexOutOfBoundsException


Recently I was approached with a B2B Callout error. The transaction fails with a Generic B2B error B2B-50029:  B2B runtime error: java.lang.IndexOutOfBoundsException.

Error Stack trace

[soa_server1] [ERROR] [] [oracle.soa.b2b.engine] Informational -:  B2B-50029:  B2B runtime error: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0[[ at oracle.tip.b2b.callout.B2BCalloutHandler.handleOutgoingCallout(B2BCalloutHandler.java:498)    at oracle.tip.b2b.msgproc.Request.outgoingRequestPostColab(Request.java:1318)
            at oracle.tip.b2b.msgproc.Request.outgoingRequest(Request.java:841)
            at oracle.tip.b2b.engine.Engine.processOutgoingMessageImpl(Engine.java:1448)
            at oracle.tip.b2b.engine.Engine.processOutgoingMessage(Engine.java:801)

Issue

Looking at the error log, it was evident that the Callout java class was not populating the output list, which was causing the issue. When the B2B Outbound Handler tries to look up the output list it throws this java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 excpetion.

After you play around with the message then you should be populating the output message before exiting the execute method.

           CalloutMessage cmOut = new CalloutMessage(s);
            output.add(cmOut);


Solution

The below code should fix the issue. We get the input, populate the output and return control back to B2B engine.



    public void execute(CalloutContext calloutContext, List input,
                        List output) throws CalloutDomainException,
                                            CalloutSystemException {
        b2blog(" Callout execute() called - Start");
        try {

            CalloutMessage cmIn = (CalloutMessage)input.get(0);
            String s = cmIn.getBodyAsString();
            b2blog((new StringBuilder()).append("Callout execute() - All Parameter = ").append(cmIn.getParameters()).toString());
            b2blog((new StringBuilder()).append("Callout execute() - CalloutMessage body = ").append(s).toString());

                //add logic of the task that needs to be done like archiving, manipulating the payload

           CalloutMessage cmOut = new CalloutMessage(s);
            output.add(cmOut);
            b2blog((new StringBuilder()).append("Callout execute() - End Callout Testing = "));


        } catch (Exception e) {
            // System.out.println("Exception: "+ e.printStackTrace())
            b2blog((new StringBuilder()).append("Callout execute() - Exception = ").append(e).toString());

            e.printStackTrace();

            throw new CalloutDomainException(e);
        }
    }

b2blog method call is explained in one of my previous blogs on B2B logging.


No comments: