Hi,
I am trying to access REST service (developed using OpenEdge 11.6 ) through Progress 4GL client. Below is the code I have used
/*------------------------------------------------------------------------
File : getProperties.p
Purpose :
Syntax :
Description :
Author(s) :
Created : Wed Mar 30 13:25:00 IST 2016
Notes :
----------------------------------------------------------------------*/
/* *************************** Definitions ************************** */
BLOCK-LEVEL ON ERROR UNDO, THROW.
/* ******************** Preprocessor Definitions ******************** */
/* *************************** Main Block *************************** */
USING OpenEdge.Net.HTTP.*.
USING OpenEdge.Net.URI.
USING Progress.Json.ObjectModel.JsonObject.
DEFINE VARIABLE oClient AS IHTTPClient NO-UNDO.
DEFINE VARIABLE oURI AS URI NO-UNDO.
DEFINE VARIABLE oCredentials AS Credentials NO-UNDO.
DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.
DEFINE VARIABLE oCookies AS Cookie NO-UNDO.
oClient = ClientBuilder:Build():KeepCookies():Client. /*CookiesJarBuilder:Build():CookieJar*/
oURI = NEW URI('http', 'ctsc00520904801.cts.com', 8810).
oURI:Path = '/myOEABLWebApp/rest/myOEABLWebAppService/postCustomer/'.
oCredentials = NEW Credentials('Tomcat Manager Application', 'tomcat', 'tomcat').
oRequest = RequestBuilder:Build('GET', oURI)
:usingBasicAuthentication(oCredentials)
:acceptJson()
:Request.
oResponse = ResponseBuilder:Build():Response.
/*oClient:execute(oRequest, oResponse).*/
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
IF oResponse:StatusCode <> 200 THEN
DISPLAY "Request Error" + String(oResponse:StatusCode).
ELSE
CAST(oResponse:entity, JsonObject):WriteFile('response.json', TRUE).
But, when I execute the above code, I am getting below error. Can anyone let me know what could be the possible problem with the code?
Set the LOG-MANAGER:LOGGING-LEVEL to 5 at the beginning of the application. This writes the files "request-raw.txt" and "response-data-received.txt" into the temporary directory or working directory for debugging purposes.
Thanks for your response.
I am getting the following information in log file.
[16/04/05@13:09:16.259+2300] P-006824 T-002000 1 4GL -- Logging level set to = 2
[16/04/05@13:09:16.259+2300] P-006824 T-002000 1 4GL -- No entry types are activated
[16/04/05@13:09:16.259+2300] P-006824 T-002000 1 4GL -- Logging level set to = 5
[16/04/05@13:09:16.408+2300] P-006824 T-002000 1 4GL HTTPCLIB REQUEST: FILE= C:\OpenEdge\WRK\request-raw.txt
[16/04/05@13:09:16.411+2300] P-006824 T-002000 1 4GL HTTPCLIB RESPONSE: FILE= C:\OpenEdge\WRK\response-data-received.txt
[16/04/05@13:09:16.413+2300] P-006824 T-002000 1 4GL SOCKET CONNECT: -H ctsc00520904801.cts.com -S 8810
[16/04/05@13:09:16.939+2300] P-006824 T-002000 1 4GL SOCKET CONNECT: TIME(ms)=526
[16/04/05@13:09:16.940+2300] P-006824 T-002000 1 4GL SOCKET WRITE: TIME(ms)=0
[16/04/05@13:09:16.940+2300] P-006824 T-002000 1 4GL SOCKET WRITE: SIZE(b)=270
[16/04/05@13:09:16.944+2300] P-006824 T-002000 1 4GL SOCKET READ: AVAIL(b)=331
[16/04/05@13:09:16.944+2300] P-006824 T-002000 1 4GL SOCKET READ: TIME(ms)=0
[16/04/05@13:09:16.944+2300] P-006824 T-002000 1 4GL SOCKET READ: SIZE(b)=331
[16/04/05@13:09:16.944+2300] P-006824 T-002000 1 4GL HTTPCLIB CHUNK: NUM= 1
[16/04/05@13:09:16.944+2300] P-006824 T-002000 1 4GL HTTPCLIB CHUNK: SIZE(b)= 8192
[16/04/05@13:09:16.944+2300] P-006824 T-002000 1 4GL HTTPCLIB CHUNK: READ(b)= 331
[16/04/05@13:09:16.969+2300] P-006824 T-002000 1 4GL SOCKET READ: COMPLETE= yes
[16/04/05@13:09:16.969+2300] P-006824 T-002000 1 4GL SOCKET READ: ERROR= ?
[16/04/05@13:09:16.969+2300] P-006824 T-002000 1 4GL SOCKET READ: TOTAL TIME(ms)=27
[16/04/05@13:09:17.001+2300] P-006824 T-002000 1 4GL -- Challenge cannot be empty
[16/04/05@13:09:17.001+2300] P-006824 T-002000 1 4GL -- ** ABL Debug-Alert Stack Trace **
[16/04/05@13:09:17.001+2300] P-006824 T-002000 1 4GL -- --> adecomm/_runcode.p at line 671 (adecomm/_runcode.r)
In request-raw.txt
POST /myOEABLWebApp/rest/myOEABLWebAppService/postCustomer/ HTTP/1.1
User-Agent: OpenEdge-HttpClient/0.3.0 (WIN32/64) OpenEdge/11.6.0.0.1233 Lib-ABLSockets/0.3.0
Host: ctsc00520904801.cts.com:8810
Authorization: Basic YWh1c3NhaW46UEBzc3cwckQ=
Accept: application/json
And in response-data-received.txt
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=2630A3FE65F5290A2EB8252408912F11ED0BD5C2AA3B.oepas1; Path=/myOEABLWebApp/; HttpOnly
Content-Type: application/.*json;charset=ISO-8859-1
Content-Length: 57
Date: Tue, 05 Apr 2016 11:58:00 GMT
{ "status_code": 401, "status_txt": "Not authenticated" }
Could you please let me know what userid and password I need to give?
Thanks in advance!!
What authentication model have you configured in your REST Application. If you are testing basic-local security and using defaults then username would be "restuser" and password would be "password"
This is a (couple of) issues
1. PASOE doesn't return the WWW-Authenticate header when it returns a 401.
2. The HTTP client doesn't deal well with this situation.
If you can log a bug for the latter with TS that's be great.
Reference: PASOE doesn't return the WWW-Authenticate header when it returns a 401.
Does anyone know if this has been resolved or if there is a work around (running 11.6.4).
thanks in advance.