How do I access my IBM i RPG program using a stateful REST service?
I'm trying to use the section titled 'Accessing IBM i programs as Web services' (within the help documentation) to help me do this, but I'm struggling.
There are three steps outlined in the documentation:
1) Create an external type (type HostProgram)
I'm fairly happy with this bit as there is an example in the documentation to work from, so I created the following EGL code in a new EGL source file.
package programs; externaltype IPROG1 type HostProgram {platformData=[@i5OSProgram{ programName="IPROG1", programType=NATIVE, isServiceProgram=false, libraryName="RXMEGL"}]} function IPROG1(text char(40)){ hostName="IPROG1"}; end
As I understand it this makes my IBM i RPG program known to EGL. It tells EGL that my RPG program is called IPROG1 and sits in library RXMEGL, and that it accepts a single 40 long character parameter.
2) In the Services deployment section of the EGL deployment descriptor editor, select that external type and enter other appropriate information.
This is where it all starts getting a bit tricky. I go to my deployment descriptor editor, select the Service deployment tab and then press the Add button. In the 'Add Web Services' wizard I can see the external type that I just created so I select that, I leave the generate as SOAP Service and TEST service ticked and press the Add --> button. I then press the Finish button.
Is that all I need to do? I'm not sure whether the '... enter other appropriate information.' means I need to enter anything else or not. I am leaving the SOAP Web Service Properties and REST Web Service Properties on the Generate Web Service panel as they are, mainly because I don't know what to enter in them! I then press CTRL-S and exit the deployment descriptor editor.
3) Deploy the resulting Web service to a JEE-compliant application server.
I think I'm OK with this bit. I select Deploy EGL Project and then restart my tomcat server, once the deployment has completed.
Now that's complete I'm not sure what to do next. I somehow want to access the service from my EGL code and I also need to point the service to my IBM i server but I'm not sure how to do that. I've been reviewing the forum and the help documentation but haven't been able to find any documentation that takes me to the next step.
This is what I tried.
I created a new RUI handler that had a single TextField, I then added the following code.
function start() myService pgmIPROG1{}; text string; call myService.IPROG1(text) returning to myCallback; end function myCallback(text string in) TextField.text = text; end
The EGL editor came up with an error on the 'myService.IPROG1' function stated it must be defined as a service or interface part.
When I was trawling through the help documentation I remembered seeing something about an interface part so I found a section titled 'Creating an Interface part to access a REST service', which I then followed to create the following interface part.
package interfaces; interface pgmIPROG1 {@xml{name="pgmIPROG1" }} function IPROG1( text string inout ) {@xml{name="IPROG1"}}; end
I then updated my RUI handler to call my new interface part rather than the external part. When I saved my RUI handler I get the following EGL generation result.
IWN.VAL.8008.e 18/0 The service variable 'myService' uses an interface part 'pgmIPROG1' which requires a binding annotation or no initialization block. Back in the help documentation I found a section called 'Adding a REST binding to the deployment descriptor'. So I went in to the Service client bindings in the deployment descriptor editor and clicked the Add button. I then selected a binding type of REST Web Binding and pressed the Next button. The 'Add a Service Client Binding' wizard then asked for the REST binding name, I hit the Browse button and selected my interface part. It then asked for a BASE URI, I'm not sure what this should be, based on the on screen example text I entered
http://localhost:8080/testWEB/restservices/pgmIPROG1. I left the Session Cookie ID blank and pressed Finish. I pressed CTRL-S and closed the deployment descriptor editor.
I went back to my RUI handler but it still comes up with the same message.
So, I think the questions for me to move forward are ...
a) Is everything I've tried above correct?
b) How does the service know about my IBM i server?
Any and all help, pointers, links would be very much appreciated.
Richard
SystemAdmin