Problems downloading a file through OpenEdge Request Builder

Posted by Eduardo Aceves Ledezma on 21-Oct-2016 17:18

Hi!

Right now, we're trying to control the access of some images/files that are stored in another server. We're interested that, with an image link, that Request Builder downloads it and then, using HttpResponse, Write it so the user can see it as a transparent image link.

For example:

server1.com?image=whatever.png (This is an existing, and valid image link)

server2.com/web/callserver1?image=whatever.png (We're using a webhandler)

Right now, the code is something like:

ASSIGN
vcRutaLogo = "voorttbtpnwpqbhzph.png". //Image filename
ASSIGN
voCredReq = NEW Credentials('domain','root','demopassword'); //Credentials for Basic Auth
voUriReq = URI:Parse("localhost:8810/.../logo"). //Server 1 file URL

voUriReq:AddQuery("ruta",vcRutaLogo). //Server1 Querystring for getting image

ASSIGN
voReqBody = RequestBuilder:Get(voUriReq):AcceptJson()
:UsingBasicAuthentication(voCredReq):Request
voRespBody = HttpClient:Instance():Execute(voReqBody).

At this part, it's suppossed than the entity would have the data of the image, but instead voRespBody:Entity is equal to ? (Unknown).

Also, I've checked voRespBody:StatusCode and it's returning a 200 (OK).

Is there something I'm missing? or is there a limit with the response size?

Regards!

Posted by Irfan on 22-Oct-2016 04:48

Hi Eduardo,

I wrote similar code to get an image(almost 2MB of size) from the WebHandler and it worked fine. Please find below the code I used

using OpenEdge.Core.Memptr.
using OpenEdge.Net.HTTP.ClientBuilder.
using OpenEdge.Net.HTTP.IHttpClient.
using OpenEdge.Net.HTTP.RequestBuilder.
using OpenEdge.Net.HTTP.HttpClient.
using OpenEdge.Net.HTTP.IHttpRequest.
using OpenEdge.Net.HTTP.IHttpResponse.
using OpenEdge.Net.HTTP.Credentials.
USING OpenEdge.Net.HTTP.HttpHeader FROM PROPATH.
USING OpenEdge.Core.ByteBucket FROM PROPATH.

/* ********************  PREPROCESSOR DEFINITIONS  ******************** */

DEFINE VARIABLE oReq    AS IHttpRequest  NO-UNDO.
DEFINE VARIABLE OResp   AS IHttpResponse NO-UNDO.
def    var      oImage  as class         memptr NO-UNDO.
define variable oCreds  as Credentials   no-undo.
def    var      oHeader as HttpHeader    no-undo.
def    var      oBody   as ByteBucket.

oBody = new ByteBucket().


oHeader = new HttpHeader("Accept","image/jpg").

oCreds = new Credentials('application', 'tomcat', 'tomcat').

oReq = requestbuilder
:get("http://localhost:4511/AccessImage/web/getimage?imageId=bill123") :request. oReq:SetHeader(oHeader). oResp = HttpClient:Instance():Execute(oReq). oBody = cast(oResp:Entity,ByteBucket). oImage = oBody:GetBytes(). message oResp:statuscode view-as alert-box. copy-lob from oImage:value to file "C:/OpenEdge/WRK/temp.jpg".

All Replies

Posted by Irfan on 22-Oct-2016 04:48

Hi Eduardo,

I wrote similar code to get an image(almost 2MB of size) from the WebHandler and it worked fine. Please find below the code I used

using OpenEdge.Core.Memptr.
using OpenEdge.Net.HTTP.ClientBuilder.
using OpenEdge.Net.HTTP.IHttpClient.
using OpenEdge.Net.HTTP.RequestBuilder.
using OpenEdge.Net.HTTP.HttpClient.
using OpenEdge.Net.HTTP.IHttpRequest.
using OpenEdge.Net.HTTP.IHttpResponse.
using OpenEdge.Net.HTTP.Credentials.
USING OpenEdge.Net.HTTP.HttpHeader FROM PROPATH.
USING OpenEdge.Core.ByteBucket FROM PROPATH.

/* ********************  PREPROCESSOR DEFINITIONS  ******************** */

DEFINE VARIABLE oReq    AS IHttpRequest  NO-UNDO.
DEFINE VARIABLE OResp   AS IHttpResponse NO-UNDO.
def    var      oImage  as class         memptr NO-UNDO.
define variable oCreds  as Credentials   no-undo.
def    var      oHeader as HttpHeader    no-undo.
def    var      oBody   as ByteBucket.

oBody = new ByteBucket().


oHeader = new HttpHeader("Accept","image/jpg").

oCreds = new Credentials('application', 'tomcat', 'tomcat').

oReq = requestbuilder
:get("http://localhost:4511/AccessImage/web/getimage?imageId=bill123") :request. oReq:SetHeader(oHeader). oResp = HttpClient:Instance():Execute(oReq). oBody = cast(oResp:Entity,ByteBucket). oImage = oBody:GetBytes(). message oResp:statuscode view-as alert-box. copy-lob from oImage:value to file "C:/OpenEdge/WRK/temp.jpg".

Posted by Peter Judge on 24-Oct-2016 09:10

Eduardo,
 
You can log the request and response as it is sent on the wire (via the socket).
 
Set
log-manager:logfile-name = ‘mylog.log’.
log-manager:logging-level = 6.
 
And you’ll get files called request-raw.txt and response-data-received.txt in your session:temp-dir (-T). You can see there whether the data came back to the client or not.
 

This thread is closed