Implementation HTTPCA driver error cases.

Implementation HTTPCA driver error cases.

book

Article ID: KB0084820

calendar_today

Updated On:

Products Versions
TIBCO KPSA - Mobile -
Not Applicable -

Description

Resolution:
Description:
============
By default when an error occures in the HTTPCA driver for instance, in case of duplicate request or parsing failures, this driver doesn't respond to the north bound application. The HTTPCA framework offers the possibility to redefine some virutal operations in order to send an error response to the HTTP server.

Environment:
===========
Solaris 5.10 64 bits platform
Linux Redhat 5.0 x86_64

Resolution:
==========
To send a response to the northbound application you have to implement a custom ServiceContext where the onFramingFailed and onFrameParsed operations have to be overwritten. Those operation will be used to send your HTTP response.

Here is a default implemetation of those three operations:

The soc file:
package httpcatest
{
    //----------------------------------------------------------------------
    const string soapFaultStart = "<?xml version=\"1.0\" ?>\r\n"&ltsoap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">&ltsoap:Body>&ltsoap:Fault>&ltfaultcode&gtsoap:Server</faultcode>&ltfaultstring>";
    const string soapFaultEnd = "</faultstring></soap:Fault></soap:Body></soap:Envelope>";

    //create its own service context
    interface ServiceContext : httpca::ServiceContext
    {
    };

    entity ServiceContextImpl
    {
        [ virtual ]
        void onFramingFailed(
            in string i_message);
            
        [ virtual ]
        void onRequestTimeout();            
            
        [ virtual ]
        void onFrameParsed(
            in provca::Parser::Result i_parsingResult,
            in string i_orderId,
            in string i_message);            
    };

    expose entity ServiceContextImpl with interface ServiceContext;

    //----------------------------------------------------------------------
    //create its own service context factory
    interface ServiceContextFactory : httpca::ServiceContextFactory
    {
    };

    entity ServiceContextFactoryImpl
    {
        [ virtual ]
        void createServiceContext(
            in string i_serviceContextId,
            out provca::ServiceContext o_serviceContext);
    };

    expose entity ServiceContextFactoryImpl with interface ServiceContextFactory;
};

And now the act file:

//------------------------------------------------------------------------------
// Operation Name
//        httpcatest::ServiceContextImpl::onFramingFailed
//
void
action httpcatest::ServiceContextImpl::onFramingFailed(
            in string i_message)
{`
    declare httputil::Message    response;
    declare kablet::Part        part;

    // Get targetAddress
    //
    declare kablet::ServiceContext    serviceContext;
    serviceContext = self.kabletContext;

    declare string            targetAddress;
    targetAddress = serviceContext.targetAddress;
    
    declare swbuiltin::EngineServices engineServices;
    declare string s = "@OGN_targetAddress:";
    s+= targetAddress;
    engineServices.traceMsgInfo(s);

    // Init response
    create response;
    response.setStatusCode(httputil::G_InternalServerError);
        
    // Add SOAP fault to response
    create part;
    part.content = soapFaultStart +  i_message + soapFaultEnd;
    response.addPart(part);

    // Result
    serviceContext.response = response;
    self.kabletContext = serviceContext;

    self.sendResponse(self.eventOriginator);

`};

//******************************************************************************
// Operation Name
//        httpcatest::ServiceContextImpl::onFrameParsed
//
action httpcatest::ServiceContextImpl::onFrameParsed
{`
    declare string soid = i_orderId;
    
    declare httputil::Message    response;
    declare kablet::Part        part;
    declare kablet::ServiceContext    serviceContext;
    
    //in case of duplicate request the status returned by onFrameParsed is Parser::Duplicate
    if (i_parsingResult == Parser::Duplicate)
    {
        SWBuiltIn::traceMsgInfo("httpcatest::ServiceContextImpl::onFrameParsed Duplicate" + soid);


        // Get targetAddress
        //
        serviceContext = self.kabletContext;

        declare string            targetAddress;
        targetAddress = serviceContext.targetAddress;
        
        declare swbuiltin::EngineServices engineServices;
        declare string s = "@OGN_targetAddress:";
        s+= targetAddress;
        engineServices.traceMsgInfo(s);

        // Init response
        create response;
        response.setStatusCode(httputil::G_InternalServerError);
            
        // Add SOAP fault to response
        create part;
        part.content = soapFaultStart +  i_message + soapFaultEnd;
        response.addPart(part);

        // Result
        serviceContext.response = response;
        self.kabletContext = serviceContext;

        self.sendResponse(self.eventOriginator);
    }
    else
    {
        SWBuiltIn::traceMsgInfo("httpcatest::ServiceContextImpl::onFrameParsed OK" + soid);
    }

    
`};

//------------------------------------------------------------------------------
// Operation Name
//        httpcatest::ServiceContextImpl::onRequestTimeout
//
void
action httpcatest::ServiceContextImpl::onRequestTimeout()
{`
    declare httputil::Message    response;
    declare kablet::Part        part;

    // Get targetAddress
    //
    declare kablet::ServiceContext    serviceContext;
    serviceContext = self.kabletContext;

    declare string    targetAddress;
    targetAddress = serviceContext.targetAddress;
    
    declare swbuiltin::EngineServices engineServices;
    declare string s = "@OGN_targetAddress:";
    s+= targetAddress;
    engineServices.traceMsgInfo(s);

    // Init response
    create response;
    response.setStatusCode(httputil::G_InternalServerError);
        
    // Add SOAP fault to response
    create part;
    part.content = soapFaultStart +  "add your error message in case of time out" + soapFaultEnd;
    response.addPart(part);

    // Result
    serviceContext.response = response;
    self.kabletContext = serviceContext;

    //now send the response
    self.sendResponse(self.eventOriginator);

`};

//******************************************************************************
// Operation Name
//        httpcatest::ServiceContextFactoryImpl::createServiceContext
//
void
action httpcatest::ServiceContextFactoryImpl::createServiceContext(
            in string i_serviceContextId,
            out provca::ServiceContext o_serviceContext)
{`
    declare ServiceContext sc;
    create sc values (id : i_serviceContextId);
    o_serviceContext = sc;
`};

Issue/Introduction

Implementation HTTPCA driver error cases.