Basic Rules APIs for HTTP Message Manipulation

Following are the different ways to manipulate the HTTP Request/Response:

  • Get/Update Http URL:
    m.getURL(“http://oracle.com”)
    m.setURL(“http://oracle.com”)
  • Get/Update Http Method:
    m.getMethod()
    m.setMethod(“POST”)
  • Get/Update Http Status Code:
    m.getHttpStatusCode() 
    m.setHttpStatusCode(201) 
  • Get/Add/Update/Delete Header:
    m.header("Content-Type")  OR m.header(m.GET,"Content-Type"")
    m.header(m.ADD,"Content-Type","application/xml")
    m.header(m.UPDATE,"Content-Type","application/xml")
    m.header(m.DEL,"Content-Type","application/xml") 
  • Get/Add/Update/Delete Body:
    m.body("tai:tac") OR m.body(m.GET"tai:tac") 
    m.body(m.ADD,     "tai:tac","000001")
    m.body(m.UPDATE, "tai:tac:mnc","281")
    m.body(m.DELETE, "nf-id","28145") 
  • Converting JSON to XML:
    m.header(m.UPDATE,"Content-Type","application/xml") 
  • Converting XML to JSON:
    m.header(m.UPDATE,"Content-Type","application/json")
  • Regular Expression:
       rule "iwf_test_rule40_3"
               salience 20
               when
                      m : IWFHttpResponse(body("company[1]:x") matches "[^A-Za-z]")
               then
                      m.body(m.ADD, "company[2]:y", "sap")
                      m.header(m.UPDATE, "Content-Type", "application/json")
               end
  • Other Primitive DataTypes (like int, float...):
      rule "iwf_test_rule40_4"
              salience 20
              when
                     m : IWFHttpRequest( body("nf-id") == 0.001)
              then
                   m.body(m.ADD, "company[2]:y", 1)
                   m.header(m.UPDATE, "Content-Type", "application/json")
              end
  • Using Functions:
    • Function Definition:
       function String charLength(String name) {  
                         return name.length();
                  } 
    • Function Invoked:
      rule "iwf_test_rule40_6"
                salience 20
                when
                           m : IWFHttpRequest(charLength(body("nf-id")) == "ORACLE")
               then
                          m.body(m.ADD, "company[2]:y", 1000)
              end