Mailing List webobjects-dev@wocommunity.org Message #448
From: Markus Ruggiero (rucotec) <markus.ruggiero@rucotec.ch>
Subject: Re: [WO-DEV] Https request examples?
Date: Thu, 18 May 2023 18:36:57 +0200
To: WebObjects & WOnder Development <webobjects-dev@wocommunity.org>
Signed Data (Text SHA256)
> On 8 May 2023, at 19:16, Hugi Thordarson <hugi@karlmenn.is> wrote:
>
> Hi Markus,
>
> is the server using a self-signed certificate? If not, i.e. it's just good ol' https with a cert issued by a trusted CA, you should be fine using the build in java http client with https, something like…
>
> -----------------------
>
> public static String post( final String url, final String requestBody ) throws IOException, InterruptedException {
> // Create a client (the client can be reused so for performance sensitive code, I wouldn't do this within the method)
> final HttpClient client = HttpClient
> .newBuilder()
> .build();
>
> // Construct a request to submit
> final HttpRequest request = HttpRequest
> .newBuilder()
> .uri( URI.create( url ) )
> .POST( BodyPublishers.ofString( requestBody, StandardCharsets.UTF_8 ) )
> .build();
>
> // Submit the request
> final HttpResponse<String> response = client.send( request, HttpResponse.BodyHandlers.ofString( StandardCharsets.UTF_8 ) );
> return response.body();
> }
>

Hugi,

thanks a lot, this works perfectly.

But (there is always a but)

What do I do with the returned result?
My problem is that no matter what I try the resultant string is not properly used as the content of the iFrame. I am probably just thoroughly confused but WO seems to mix and match things in a way that either the initial POST body is displayed instead of the result or the resultant string is parsed but no linked resources are found as they are all tried to be accessed through my application. And of course there they aren’t.

I have the following def in my WOD

iFrame : ERXIFrame {
action = createMyIFrameContent;
style = "width:100%; height:90vh; border:solid 2px green";
}

I cannot use either pageName nor src bindings because I need to create some xml content and a POST request. So I use the action createMyIFrameContent() to create the content for the iFrame. But how?

Inside createMyIFrameContent() I built the xml and used your code to submit the POST. Worked and I did get a result back. But then? When I create a new WOResponse and set the result as its content WO displays the original request body (the xml), not the resulting content.
So I created a new WOComponent that createMyIFrameContent() instantiates with pageWithName(), passes some data to it for the generation of the xml and returns this to the iFrame. In the new component I override appendToResponse(), execute the POST and set the result as the content. I also tried overriding generateResponse(). In both cases I do get the result from the POST rendered but no externally linked resources are found because they are seen as relative to my application (css, images, etc).

Basically the question is “how do I break out of my application and have that dynamically generated remote page inside my iFrame?” As I said, I am confused and don’t see the forest for the trees anymore.

---markus---

> -----------------------
>
> - hugi
>
>
>> On 8 May 2023, at 14:34, Markus Ruggiero (rucotec) <markus.ruggiero@rucotec.ch> wrote:
>>
>> I need to make a https POST request to a 3rd party web server sending xml along in the body of the request. The server is supposed to return a html page which I should then display inside an iFrame.
>>
>> Does any body have some example code how to do such an https request? Easy to create the xml but I am not quite sure about the SSL/TLS part.
>>
>> Thanks a lot
>> ---markus---
>>
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list <webobjects-dev@wocommunity.org>.
> To unsubscribe, E-mail to: <webobjects-dev-off@wocommunity.org>
> To switch to the DIGEST mode, E-mail to <webobjects-dev-digest@wocommunity.org>
> To switch to the INDEX mode, E-mail to <webobjects-dev-index@wocommunity.org>
> Send administrative queries to  <webobjects-dev-request@wocommunity.org>
>


Content Unaltered as verified By:
<markus.ruggiero@rucotec.ch>
Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster