Link to home
Start Free TrialLog in
Avatar of Theo Kouwenhoven
Theo KouwenhovenFlag for Netherlands

asked on

Storing REST data JSON to an iSeries (as400) IFS file

Hi Experts,

I have to create an iSeries webservcie that receive JSON data and store that on the IFS.
after that I gave to process the data into some files.

How can I write the REST service received data into an IFS file (with a unique filename of course)
Please can I receive an example if possible?

Thanks
Avatar of Gary Patterson, CISSP
Gary Patterson, CISSP
Flag of United States of America image

Personally, I like php for this, but that's not always an option if you don't have php skills in your shop.  Same for Java.

In IBM i shops, most common request I see is for how to develop web services using RPG.  It is a big topic.  Here' are a series of IBM Developerworks articles that explain one approach:

https://www.ibm.com/developerworks/ibmi/library/i-rest-web-services-server1/
Avatar of Theo Kouwenhoven

ASKER

Hi Gary,

Thanks for your quick answer.

I managed to create a app-server and a REST service.
The test-program behind the service has only to write the inparm in a test file, but nothing happend.
File remain empty, and the program that should be called remains on 0 day's used.

I tried to call the webservice with:
http://server:port/web/services/RESTTEST?"qwerty"
http://server:port/web/services/RESTTEST?INPARM="qwerty"
and a lot of other parameter formats, in combination with PUT, POST or GET (no idea what I'm doing here) .

Now I'm even in doubt if the Exportprocedures parameter should be input or output
is it input to the program or output from de interface :-(.
Based on the original question, it looks to me like you want the the remote caller to POST a JSON document to your web service.  

I don't know what response you plan to provide or in what format, since you didn't say - maybe you just want to return an HTTP_OK to let the caller know you received the JSON document?

See the CREATE procedure example in the third article in series above for an example of how to receive a JSON that maps to an RPG data structure if you want to store the data in a database file, or a VARCHAR if you want to just receive a string and write it out to an IFS file.

To test, you'll need to either write a program that performs the POST, or use a testing tool like SOAPUI, which can test SOAP web services or RESTful web services.

https://www.soapui.org/rest-testing/getting-started.html

If you really want to save it to the IFS, here's sample code to do that:

http://www.mysamplecode.com/2011/06/rpgle-write-data-to-ifs-using-c-apis.html
Post screen shots from the setup screens in the web services wizard, and post your code if you need more help with this.
Hi Gary,

What do I need to setup to use the PHP option?
the RPG REST service cost me to much time and I have a deadline.
Plenty of learning curve on the php side, too.  We use the Zend framework for php on IBM i.  You have to install IBM i LPP pre-requisites, install and configure Zend on IBM i, write code for the web service, and deploy the web service in Zend.  

Here are the Zend installation instructions:

http://files.zend.com/help/Zend-Server-IBMi/content/i5_installation_guide.htm

Here is a good guideline for how to design your RESTful API.  Based on the limited info you provided, it looks like you are just implementing a create function (which generally maps to http POST):

http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

If you'd like to provide more information about your requirements, I'd be glad to point you to relevant examples.
Hi Gary,

PHP is my final fallback solution, but RPG is prefered.

Maybe some more info will give you a complete Idea.
On this moment some information is stored in a MySQL db, but it grows too fast to handle.
Round 37.000 entries per message (round 400 Kb) and in the future 20.000 messages per day could be send.
So I have to host webservice that process the requests, that will respond with a OK or ERR (e.g.)
My knowledge on any part of the Apache server is just below zero.

I found a RPG program, that use the QtmhRdStin Api to get  data from the service, but whatever REST-action I try (from SoapUI) I get a
MCH3601 message (Pointer not set for location referenced)
so I have no idea how I can feed the data from a webservice into my RPG program
ASKER CERTIFIED SOLUTION
Avatar of Gary Patterson, CISSP
Gary Patterson, CISSP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Gary,

It's working (partially) , I can send data and get a response, but it seems not be possible to use the GET function with data over 8K.
So I changed the GET to a POST and  save data up to 3Mb, but of cause no response.

I think we have to discuss this internally to see what the next step is.
Thanks for your great help!!!!!
Glad you've got it working.  POST is the typical operation that maps to a "create" operation in a REST web service.  That's what it looks like you're doing, so that's why I said this above:

Based on the original question, it looks to me like you want the the remote caller to POST a JSON document to your web service.  

Here's an example of how HTTP GET/POST/PUT/PATCH/DELETE directives are often mapped from the "Best Practices" article I posted above based on a trouble ticket system API:

    GET /tickets - Retrieves a list of tickets
    GET /tickets/12 - Retrieves a specific ticket
    POST /tickets - Creates a new ticket
    PUT /tickets/12 - Updates ticket #12
    PATCH /tickets/12 - Partially updates ticket #12
    DELETE /tickets/12 - Deletes ticket #12
Hi Gary,

The customer don't like the POST option (because of limited response info) and did setup his own CGI solution.
On 2016-11-08, you mentioned:
I assume the QtmhRdStin approach you describe is using a CGI-BIN call from Apache.  
Not the way I'd go, but you can make it work.

What is the disadvantage to use this solution with JSON  vs. soap/xml ?
Historically, the problem with calling native programs from CGI is performance.  Native programs called via CGI are fully closed after each call, so you suffer program initiation and file open costs each time you execute.  One work-around is to create an async listener process:

CGI program puts entry on data queue and listens for response on second data queue.
Listener program runs as a service and monitors data queue and sends responses to CGI program via data queue.  Files are pre-opened and program is initialized once.  Here's some example code.

http://www.mcpressonline.com/tips-techniques/rpg/tech-tip-make-your-rpg-cgi-programs-perform-better.html

- Gary