Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 659
  • Last Modified:

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?

theo kouwenhoven
theo kouwenhoven
  • 7
  • 5
1 Solution
Gary PattersonVP Technology / Senior Consultant Commented:
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:

theo kouwenhovenAuthor Commented:
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:
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 :-(.
Gary PattersonVP Technology / Senior Consultant Commented:
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.


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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Gary PattersonVP Technology / Senior Consultant Commented:
This expert suggested creating a Gigs project.
Post screen shots from the setup screens in the web services wizard, and post your code if you need more help with this.
theo kouwenhovenAuthor Commented:
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.
Gary PattersonVP Technology / Senior Consultant Commented:
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:


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):


If you'd like to provide more information about your requirements, I'd be glad to point you to relevant examples.
theo kouwenhovenAuthor Commented:
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
Gary PattersonVP Technology / Senior Consultant Commented:

There are lots of approaches you can use.  Some are harder than others.  

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.  I just think it is a lot more work then using the web publishing wizard.  Can't begin to imagine what the problem is without seeing your Apache setup and the code you're trying to run.

I steered you to the integrated Create Web Services Server wizard in my first post because I think it is the fastest and easiest way for an RPG programmer new to web services to get one up and running.  Developing and deploying a web service does, like most technologies, does require some basic knowledge, though, even with this tool there is a little learning curve.  You need to understand what  POST is, and you need to understand how to set up the parameter mapping.   The series of articles I pointed you to contains pretty robust sample code, and I think you could adapt the CREATE procedure to do just what you say you need to do.

If you're on a tight deadline, this might be a good place to bring in an expert to help you.

I encourage you to go back to the top of the thread, and follow my initial advice and concentrate on the Create Web Services Server wizard.  Among other things, It handles most of the configuration for you, and all of the mapping into and out of RPG parameters.  Using this approach, you don't have to deal with stdin/stdout, and you don't how to figure out how to handle  multiple requests at the same time.

Follow the example in the article, and get that application up and running.  From there, it should be pretty simple to modify it to do what you want to do.  

Yes, it takes a little work and research to figure out how to set up parameter mapping, (but I'm happy to help you with that.)  All things considered, I think this is the easiest native way for an RPG programmer to get a web service up and running.


- Gary
theo kouwenhovenAuthor Commented:
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!!!!!
Gary PattersonVP Technology / Senior Consultant Commented:
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
theo kouwenhovenAuthor Commented:
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 ?
Gary PattersonVP Technology / Senior Consultant Commented:
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.


- Gary

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now