Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-11-03
12
Medium Priority
?
529 Views
Last Modified: 2016-11-29
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
0
Comment
Question by:theo kouwenhoven
  • 7
  • 5
12 Comments
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 41872015
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/
0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 41872500
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 :-(.
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 41872692
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
1
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 35

Expert Comment

by:Gary Patterson
ID: 41872703
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.
0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 41878062
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.
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 41878744
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.
0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 41879044
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
0
 
LVL 35

Accepted Solution

by:
Gary Patterson earned 2000 total points
ID: 41879273
Theo,

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.

Regards,

- Gary
0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 41881825
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!!!!!
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 41882135
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
0
 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 41900193
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 ?
0
 
LVL 35

Expert Comment

by:Gary Patterson
ID: 41905739
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
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Integration Management Part 2
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question