Midrange News for the IBM i Community


Posted by: TFisher
Web service on the iSeries
has no ratings.
Published: 11 Apr 2013
Revised: 21 Apr 2015 - 735 days ago
Last viewed on: 25 Apr 2017 (5424 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Web service on the iSeries Published by: TFisher on 11 Apr 2013 view comments(12)

I have been given a project to design and create a web service interface on the iSeries.  My knowledge up to this point is just information that I have read over the past couple of years, I have not actually created a web service.  While I have designed what seems like a very robust web service interfacing application, I am afraid that my lack of experience might end up biting me in the butt when it comes time to start testing.  So I have a couple of questions that I have not been able to figure out from just reading that will really help me in the design phase of this project...

 

1. What happens when we receive multiple requests for the same web service?  Does the system (APACHE) handle this by starting another thread or something like that?

 

2. Something else that has been somewhat vague is what the message will look like in my RPG web service.  When I receive the request (regardless of whether it's SOAP, JSON, or whatever) will I only see the parameters to the web service, or will I also have access to the web service name or the entire URL?  

 

3. Does anyone know of a good book that covers web services for the RPG programmer?  

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: Ringer
Premium member *
Comment on: Web service on the iSeries
Posted: 4 years 12 days 14 hours 30 minutes ago
Edited: Fri, 12 Apr, 2013 at 13:36:31 (1474 days ago)

1. The maximum number of jobs (MaxClients ?) waiting to process incoming requests, the number of requests that can queue up and so forth can be configured in /www/yourwebsvr/conf/httpd.conf . Sorry, I don't recall the directives. http://httpd.apache.org/docs/current/mod/directives.html

2. It just depends. RPG as CGI can access all that (Apache calls RPG directly as CGI) as environment variables (getenv I think). But if Apache calls Java/PHP and then Java/PHP call RPG, RPG is not called as CGI so no. BUT Java/PHP could access the env vars.

The (encoded/escaped) form name/value pair parameters (or SOAP XML) are in the body of the request (after the HTTP headers) for a POST method or in the QUERY_STRING HTTP Header for a GET method (sent from browser or by a programmer). The HTTP Headers are, well, headers, above the payload/body of the request.

3. Books? Not sure. Here is nice IWS PDF by Klement.

http://www.scottklement.com/presentations/Web%20Services%20for%20RPGers.pdf

You could always take a given RPG and wrap a SOAP (java) web service around it with the built-in IWS (Integrated Web Services). Scott Klement wrote some articles on this a while back. My issue with IWS is the parm definitions coming into RPG are rigid, not much wiggle room. Whereas with a web requests, the amount of data is basically unlimited (XML, etc). The two don't marry up well.

Having said all this, a PHP class can be deployed as a SOAP web service in Zend Studio and call RPG on the backend as an SQL Stored proc. So PHP could parse all that unlimited XML and call RPG in a loop for each part/line/etc. Or maybe that muddies the waters!

The advantage of the SOAP, is all the config/prototype data is contained in the WSDL document. A tool (not a person) analyzes that file and determines how to call the web services). If you roll your own web service that is not SOAP, you write the specs in a document that someone has to read to understand / connect to your web service. Web people prefer the standardized SOAP instead of a proprietary format.

Chris Ringer

Posted by: TFisher
Premium member *
Comment on: Web service on the iSeries
Posted: 4 years 12 days 8 hours 8 minutes ago

Thanks for the response Chris!

 

1. So it sounds like APACHE will support multiple simultaneous requests.

 

2. I was sure that I would be able to access the entire message that contains the URL.  What I am attempting to do is create a single application that will handle receiving requests and converting the request to data queue messages and sending the messages to the appropriate data queue for processing. It will also handle receiving the response from another keyed data queue, convert the response to XML, or whatever format it needs to be in and send it out.  The key to making this work is being able to find the actual name of the service being called (well, one of the keys to making this work).

 

I am familiar with environment variables.  Is that where APACHE will stick the incoming request?

 

3. I had already found Scott's site.  Good information there, but not all my questions were answered.

 

THANKS AGAIN!!! 

Posted by: Ringer
Premium member *
Comment on: Web service on the iSeries
Posted: 4 years 9 days 17 hours 37 minutes ago

1. Yes. It uses one of the waiting jobs in subsystem QHTTPSVR for a given web server. A client may or may not connect to the same backend job on each request.

2. It depends on the web language. Don't write your "API" to get that info. For PHP, it just pre-loads the HTTP headers (~similar to our RPG PSDS) in the array $_SERVER and the form variables into $_REQUEST/$_POST/$_GET. And you can access the HTTP body directly with $body=file_get_contents('php://input');

For RPG CGI, IBM has some API's you can call to get HTTP headers (getenv()) form data, read std input. And so on for other languages.

And your method is called the Front Controller Pattern. One front end app is the "traffic cop", directs requests to the relevant process.

Chris Ringer

Posted by: TFisher
Premium member *
Comment on: Web service on the iSeries
Posted: 4 years 9 days 16 hours 42 minutes ago

I will probably have to refer back to what you are saying later when I am writing the code.  Because this will be my first web service on the iSeries this sort of makes sense, but not really.

 

If I do this right then this will also be my last web service.  The idea is to create a web service that is table driven.  The business logic will be in a separate program and will receive transactions through a data queue.  My web service program will handle converting the request to a fixed-length data queue message and it will receive the response back from the application, convert the fixed-length data queue message to the proper format for the internet.  This is the idea anyway...that is why I need to access the entire request, so I can determine which web service is being requested in order to send to the correct data queue.


THANKS!

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Web service on the iSeries
Posted: 4 years 9 days 16 hours 23 minutes ago

Fish, if you end up using XML or SOAP remember that XML sent over HTTP requires that the percent sign is encoded ($) instead of using %. We have some SAP customers sending ups an XML/SOAP request and they don't realize they have to escape the percent sign--first time we chased this for a month because they refused to believe their were doing anything wrong. The 2nd time, we a bit easier to track down--only took 3 minutes to search the original data stream for a percent sign in the data--escaped it, and it worked!

 

Posted by: TFisher
Premium member *
Comment on: Web service on the iSeries
Posted: 4 years 9 days 16 hours 6 minutes ago

We are starting off with SOAP (XML) for phase 1.  After that is working I will be adding code to support JSON.  The idea is to be able to use either format.

Posted by: Ringer
Premium member *
Comment on: Web service on the iSeries
Posted: 4 years 9 days 14 hours 22 minutes ago
Edited: Mon, 15 Apr, 2013 at 13:25:18 (1471 days ago)

Bob,

Do you mean in the URL? That would make sense, else % is seen as a blank so it should be URL encoded. And I think #36 is $ not % in ASCII. For the actual XML in the body of the request, AFAIK, only ' " < > & data characters must be encoded as entities like & lt; & gt; etc.

Chris Ringer\

PS: Ooops, ignore the % as a blank in URL. That would be the + plus sign!

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Web service on the iSeries
Posted: 4 years 9 days 13 hours 6 minutes ago

Ringer, you are illustrating why people continue to make the mistake of NOT encoding the % in XML data. I did not say the URL, I said in the data and I meant in the data.

Unless you change your HTTP server config to use only a single-byte character set, UTF-8 is NOT one of those, you must also enclode the % in addition to the other 5 symbols that XML normally requires to be encoded.

I have this denial conversation with SAP and Windows developers so often, that I've bookmarked the link and just send it to them. Here it is:

http://www-03.ibm.com/systems/i/software/http/services/faq.html#cgixml

Posted by: Ringer
Premium member *
Comment on: Web service on the iSeries
Posted: 4 years 8 days 12 hours 25 minutes ago

Bob,

I'm not in denial, I've just never heard/read about this before. Not on any website or in any book. So is not well known I'd say. I'm not sure what UTF-8 has to do with this though, since a % is still a single byte in UTF-8. hey I wish I knew everything but I don't! :o) Thanks.

Chris Ringer

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Web service on the iSeries
Posted: 4 years 8 days 4 hours 5 minutes ago

UTF-8 is a multibyte character set, whilmods any people assume it's name implies it is only a single-byte character set and therefore not covered by the clause on the web pace I referenced, as being multibyte. It is, albeit technically a variable byte character set. 

Posted by: Ringer
Premium member *
Comment on: Web service on the iSeries
Posted: 4 years 7 days 19 hours 11 minutes ago
Edited: Wed, 17 Apr, 2013 at 08:23:26 (1469 days ago)

That's the beauty of UTF-8. Basic ASCII fits into one byte UTF-8 without any programming changes, even though UTF-8 can be from 1 to 6 bytes long.

I guess I can start encoding % and + in data values since those both have special meaning in an encoded URL key/value pairs in both GET and POST. It sure won't hurt anything. Here's what I don't get: Those 2 characters only have special meaning if the HTTP header Content-Type is application/x-www-form-urlencoded. Otherwise the web server should not be trying to decode the value of the POST body. SOAP/XML Content-Type should be text/xml or maybe application/soap+xml for SOAP 1.2.

I did find this: https://en.wikipedia.org/wiki/Percent-encoding

"Because the percent ("%") character serves as the indicator for percent-encoded octets, it must be percent-encoded as "%25" for that octet to be used as data within a URI."

(so that implies a GET not a POST).

And that link seems to be for CGI. I haven't seen this issue with PHP. Again, doesn't hurt to encode % and + and an ounce of prevention is worth a pound of cure as they say. Thanks Bob!

Chris Ringer

Posted by: egrabski
Premium member *
Comment on: Web service on the iSeries
Posted: 2 years 4 days 12 hours 50 minutes ago

Hi this is for Chris.

I want to ask about what you wrote:

"Having said all this, a PHP class can be deployed as a SOAP web service in Zend Studio and call RPG on the backend as an SQL Stored proc. So PHP could parse all that unlimited XML and call RPG in a loop for each part/line/etc. Or maybe that muddies the waters! "

We have this limitation you are talking about and have to loop for each line/complext type etc.

So we have performance issues because the xml is so huge with multiple lists within lists.

If you know of a way to solve this in RPG or on the iseries somehow the most elegant way maybe with Rational?

If you want you can contact me not sure how to exchange contact info here. If you have any experience dealing with this and I don't find a solution and you have one we can pay as consultant ..