Page 1 of 1

SOAP server running on HTTPS

Posted: Fri Oct 21, 2016 8:53 pm
by HMJust
(those who follow the forum will see that my project is progressing)

I now have a SOAP server running and it works. I would like this service to be exposed on HTTPS (on our System i) and I expect we can manage that. However, I would like to be able to determine, from my function, if it is using HTTP or HTTPS at runtime. Is this possible?

Re: SOAP server running on HTTPS

Posted: Sat Oct 22, 2016 3:41 am
by LANSAGuru
You get one of the http header properties for the request.

From the doco, here is how to get a property.
GET PROPERTY(SOAPACTION)
http://docs.lansa.com/14/en/lansa093/in ... engb7_1725

Here is a list of headers for Apache on IBMi
https://publib.boulder.ibm.com/iseries/ ... envvar.htm

Try HTTPS (returns ON or OFF)
so

GET PROPERTY(HTTPS)

Re: SOAP server running on HTTPS

Posted: Mon Oct 24, 2016 5:26 pm
by HMJust
Ah, great. That includes a lot of properties I might use at a later time.

Only problem is, I don't know exactly how to do that. I do

Code: Select all

Change Field(#JSMXCMD) To('SERVICE_LOAD SERVICE(SOAPServerService) SERVICE_CONTENT(*HTTP) TRACE(*YES)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)

* Open SOAP service
Change Field(#JSMXCMD) To('OPEN SERVICE(GROUPMWEBORDRER)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK) With_Parms(#JSMXSTS #JSMXMSG)

* Check for property - https
Change Field(#JSMXCMD) To('GET PROPERTY(HTTPS)')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
but where does the property value end up? It doesn't show up in #JSMXMSG, which I guess is fair enough, and I don't know how to exchange it into a field.

As you can see most of my code is from the automatically generated sample.

Re: SOAP server running on HTTPS

Posted: Tue Oct 25, 2016 12:11 am
by HMJust
Further on GET PROPERTY:

Code: Select all

Change Field(#JSMXCMD) To('GET PROPERTY(HTTPS)')
returns nothing

If I use USER-AGENT, SERVER-NAME or SERVER-PROTOCOL (note the hyphens, not underscores), I do get a value into #JSMXMSG, so I expect that I am using it at least sort-of correctly.

Re: SOAP server running on HTTPS

Posted: Tue Oct 25, 2016 1:38 am
by LANSAGuru
Attach a complete set of Integrator traces. I am interested primarily in the content of protocol.txt. You are not able to retrieve any environment variables which are not specifically populated, so that one may not be getting populated. Everything that is available should be in the protocol.txt file. One of those should have something you can use.

Option 2. This is inbound, so you can insert specific variables into the job stream on purpose by modifying your Apache config.

In your virtual host directive you would add a specific header.

e.g.

<VirtualHost *:443>
...what is there now
SetEnv HTTPS ON {this sets HTTPS to ON}
{or maybe}
SetEnv JOE BLOW {this sets JOE to BLOW}
</VirtualHost>

note: don't include the stuff in curly braces of course

Re: SOAP server running on HTTPS

Posted: Wed Oct 26, 2016 10:03 pm
by HMJust
Regarding the first option, I have tried to upload the files I think you were talking about: http://soap.rto.dk/HTTP_KEYWORDS.TXT and http://soap.rto.dk/HTTP_RESPONSE_PROTOCOL.TXT. Currently the request is performed on HTTP and I would have expected the HTTPS property to have an OFF value.

Other files I have are HTTP_CONTENT.XML (the request data), HTTP_RESPONSE_CONTENT.XML (the response data), SERVICE.TXT and TRANSPORT.TXT

Regarding the second option, I guess that would be a possibility.

Re: SOAP server running on HTTPS

Posted: Fri Oct 28, 2016 2:15 am
by LANSAGuru
I see, you are not running HTTPS yet.
I also see that only some of the headers are available to you, and none provide what you are looking for.

Setup SSL and see if you get some additional headers. Then you blank would indicate not SSL while a value in the new variable would indicate SSL. I see port is there now. You could test that as you typically have 1 port for SSL and 1 for non SSL. So you could use SERVER_PORT.

There is also a way to copy an existing header into another one.
In this post, option 3 is reported to work.
http://serverfault.com/questions/93923/ ... apache-2-2

I have not tried this myself.

There are actually many headers and it appears we are not necessarily passing along all of the headers available.
I will see if I can't scare up an answer for you on this.

Re: SOAP server running on HTTPS

Posted: Sat Oct 29, 2016 4:58 am
by LANSAGuru
I found out some new information.
The LANSA BIF which execute LANSA to process you inbound JSMDIRECT request only intercepts certain http headers and any that start with HTTP_ automatically.

However, there is an exit program you can call from the LANSA function which will retrieve any environment variables inserted into the job stream by virtue of this being a CGI program. The program is JSMGETENV.

However you can not call it directly (currently) because you can not call a 3GL program with RDMLX fields yet. In the future you should be able to call this directly from LANSA like so.

Function Options(*DIRECT)
*
Define Field(#envname) Type(*char) Length(128)
Define Field(#envvalue) Type(*char) Length(1024)
Define Field(#envsts) Type(*char) Length(5)
*
#envname := 'HTTPS'
Call Pgm(JSMGETENV) Parm(#envname #envvalue #envsts) If_Error(*NEXT)
If (#envsts = OK)
/* now use #envvalue */
Else
/* not found */
Endif

So you need to write a wrapper function.
There is a sample of this shipped as a CLP program in the following location.
xxxPGMLIB/QCLSRC(GETREQID)
It shows a sample of returning 1 very specific value.
I would copy this, create your own version, and call and return the values directly to your RDMLX program allowing you to retrieve any value you want.

You will need to truncate the return value to be 256 characters for the time being.
So current solution

==============
RDML(X) code
==============
Function Options(*DIRECT)
*
Define Field(#envname) Type(*char) Length(128)
Define Field(#envvalue) Type(*char) Length(256)
Define Field(#envsts) Type(*char) Length(5)
*
#envname := 'HTTPS'
Call Pgm(MY_CLP) Parm(#envname #envvalue #envsts) If_Error(*NEXT)
If (#envsts = OK)
/* now use #envvalue */
Else
/* not found */
Endif

========
CLP Code
========
PGM PARM(#ENVNAME #ENVVALUE &ENVSTS )

DCL VAR(&ENVNAME) TYPE(*CHAR) LEN(128)
DCL VAR(&ENVVALUE) TYPE(*CHAR) LEN(256)
DCL VAR(&ENVSTS) TYPE(*CHAR) LEN(5)

DCL VAR(&ENVVALUEX) TYPE(*CHAR) LEN(1024)

MONMSG MSGID(CPF0000)

CALL PGM(JSMGETENV) PARM(&ENVNAME &ENVVALUEX &ENVSTS)
CHGVAR &ENVVALUE #ENVVALUEX

END: ENDPGM

= = =
Note: I did not test any of this, and typed this code off the top of my head, but unless there is some error, it should work. Let me know how it goes.

Re: SOAP server running on HTTPS

Posted: Mon Oct 31, 2016 6:53 pm
by HMJust
Wow, that looks really interesting. Thank you.

I will not get to try it out right now - time restraints - but hope to get back to it later.

In the mean time I have a solution that works - I set up a webserver that only runs SSL, set the service to only respond on that site and added a check for the SERVER-PORT. I know that last check isn't the greatest idea and there may not be any rational reason for it but I added it nonetheless.

Thank you for all the help. And I will try out the solution above later.