Layer7 API Management

  • 1.  Pass the one unique value when see null

    Posted Sep 03, 2016 07:11 AM

    Hi All,

     

          I have a requirement like below.

        

         I am using webservice to retrieve the data from DB.I am just passing product number, when the product number found in DB i am getting the result for below attributes.

     

    product name,address,date,phone number,customer name.

             

    There are few product numbers don't have phone numbers information. So i need to pass some unique number when ever i see null as phone number.

     

    Could you please suggest me the details how to do it.

     

    Thanks&Regards

    Rajasekhar

     

     



  • 2.  Re: Pass the one unique value when see null

    Broadcom Employee
    Posted Sep 03, 2016 01:23 PM
      |   view attached

    Raja,

     

    Good morning.  Below you will find a simple example of taken one product returned with a NULL value and convert it to 378-123-7654.  (Note: The compare expression could also look for a single numeric value instead of a fixed number format)

     

    Creation of the DB and tables:

    mysqladmin create product

    mysql product
    CREATE TABLE products (
      product_name varchar(255),
      address varchar(255),
      date varchar(128),
      phone_number varchar(255),
      customer_name varchar(4096)
    ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;

     

    insert into products (product_name,address,date,phone_number,customer_name) values ("Green Goblet","1234 Wall St.","09/07/1977","555-555-5555","Homer the Great"),("Blue Beret","45 Main St.","03/09/1982",NULL,"William Shakespeare");

     

    In the Policy Manager, the JDBC connection will need to be created to connect to the new DB then the attached policy will produce the results listed below using the URL http://<gateway name>:<port>/product?prodName=Blue Beret.

     

    {"product": {
        "Product Name": "Blue Beret",
        "Address": "45 Main St.",
        "Date": "03/09/1982",
        "Phone Number": "378-123-7654",
        "Customer Name": "William Shakespeare"
        }
    }}

    Attachment(s)



  • 3.  Re: Pass the one unique value when see null

    Broadcom Employee
    Posted Sep 04, 2016 07:50 PM

    Stephen provided a perfect solution.

    I usually do it in SQL, using Stephen's example,

     

    select product_name, address, date, customer_name, phone_number from products

    where phone_number is not null

    union

    select product_name, address, date, customer_name, '378-123-7654' from products

    where phone_number is null