Start of Content Area

This graphic is explained in the accompanying text Example Coding for a GRMG Application  Locate the document in its SAP Library structure

To be able to process the GRMG request, the GRMG application must be able to perform the following steps in the specified order:

·        It processes the data stream of an HTTP POST request in accordance with the XML syntax

·        It performs the actual monitoring functions

·        It generates the GRMG response as an XML document

Use the Java classes listed in Creating a GRMG Application - Principle to simplify these tasks:

public void doPost(HttpServletRequest req , HttpServletResponse res) 
    Throws ServletException, IOException
{
    ServletOutputStream out = res.getOutputStream(); 
    // Get output stream of the servlet
    InputStream is=req.getInputStream(); 
    // Get input stream of servlet
    try
    {
        GrmgRequest ix=new GrmgRequest(is);    
        // Create new GrmgRequest object  from 
        //serlvlet’s input stream and parse XML structure

        GrmgScenario sc = ix.getScenario();
        // Get GrmgScenario object from GrmgRequest
        processing(sc);        

    /* You must include your own code here to 
       process the parameters passed by XML document 
       and to carry out any testing that is required */

        GrmgResponse ox=new GrmgResponse(sc);
        // Create new  GrmgResponse object using 
        // GrmgScenario object as parameter
        ByteArrayOutputStream bytearray=ox.getOutput(); 
        // Get XML document as result of processing
        bytearray.writeTo(out); 
        // give back result to servlet’s output stream
    }
    catch (Exception e)
    {
        // Exception handling    
    }
} 

The shaded part could be as follows (this coding is based on the Example GRMG Request):

void processing(GrmgScenario sc) throws Exception
{
    try
    {
        URL conn = new URL(sc.getComponentByName("WEBTEST").
        getPropertyByName("url").getValue()); 
        // getting URL
        HttpURLConnection hcon = (HttpURLConnection) 
        conn.openConnection(); 
        // trying to connect to URL
        if(hcon.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) 
            //checking response from connection 

            sc.getComponentByName("WEBTEST").addMessage().
            setMessageParameters("ERROR","255","RT","001","","","","",
            "page not found");  

            // Page not found and we generate Message for GRMG
        else 

            sc.getComponentByName("WEBTEST").addMessage().
            setMessageParameters("OKAY","000","RT","003","","","","",
            "relatively okay (for test)");  

            // OKAY and we generate Message for GRMG
    }
    catch(Exception e)
    { 

        sc.getComponentByName("WEBTEST").addMessage().
        SetMessageParameters("ERROR","255","RT","002",e.getMessage(),
        "","","",e.getMessage()); 

    }
    try 
    {
        JCO.createClient(sc.getComponentByName("R3TEST").
        getPropertyByName("SAPClient").getValue();
        sc.getComponentByName("R3TEST).
        getPropertyByName("userid").getValue();
        sc.getComponentByName("R3TEST).
        getPropertyByName("password").getValue();
        sc.getComponentByName("R3TEST).
        getPropertyByName("language").getValue();
        sc.getComponentByName("R3TEST).
        getPropertyByName("sid").getValue();
        sc.getComponentByName("R3TEST).
        getPropertyByName("system_number").getValue()); 
        // trying to connect to SAP system 

        sc.getComponentByName("R3TEST").
        addMessage().setMessageParameters("OKAY","001","RT","004",
        "","","","","Connected!");  

        //Everything is fine and we generate Message for GRMG
    }
    catch(Exception e)
    {
        // Exception handling
    }
} 

You set the component and message parameters for the GRMG response in the shaded coding areas. You can transfer the following parameters here:

sc.getComponentByName("<compname>").addMessage().setMessageParameters
("<messalert>","<messseverity>","<messarea>","<messnumber>",
"<messpara1>","<messpara2>","<messpara3>","<messpara4>","<messtext>"); 

For more information about the meaning of the individual parameters, see Structure of the GRMG Response.

This graphic is explained in the accompanying text Monitoring with the Generic Request and Message Generator start page

 

End of Content Area