PUT request via a proxy

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

PUT request via a proxy

#1

Postby Steve James » Thu Jun 21, 2018 5:17 pm

Quite a specific one (and blooming irritating).....

I've got a form that calls external REST services. GET/POST/PUT etc. As I need to go via a proxy I have to use Java net openConnection(proxy) ie https://docs.oracle.com/javase/7/docs/a ... net.Proxy)

I use this a lot with various forms and it works very well.

I have a significant issue when making a PUT request. I have to loop through a table and make a request per record.
The first PUT request gets a response great. The second hangs and after 2 minutes the error is end of file....

It also looks like the request may not be even getting to the proxy as we've been monitoring traffic. The first PUT request shows up on the logs but the seconds doesn't.

I got a temporary exemption to allow the server to go direct to the remote server. Hey presto all PUT calls fly through.

Anyone any knowledge of a bug in the Java code or any idea what may be causing the issue?

Thanks
0 x

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

Re: PUT request via a proxy

#2

Postby Segi » Thu Jun 21, 2018 6:03 pm

Does the external REST resource only allow a certain number of connections ?

I have an Angular app that connects to a REST resource running in Ebase that gets many requests and does not have this issue.
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

Re: PUT request via a proxy

#3

Postby Steve James » Thu Jun 21, 2018 6:22 pm

Thanks Segi, it's definitely something to do with the proxy as the calls all work fine when I go direct.

I've even tried putting a 3 second delay between calls.

Thanks
0 x

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

Re: PUT request via a proxy

#4

Postby Segi » Thu Jun 21, 2018 6:26 pm

You are using a try catch right ?

What is the trapped error ?
0 x

Steve
Moderator
Moderator
Posts: 414
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

Re: PUT request via a proxy

#5

Postby Steve » Fri Jun 22, 2018 8:56 am

Hi Steve,

You can only set the proxy for the whole JVM and the settings need to go in the startup of the server. The REST call is made by the server, so this is acting as the client.

If you are running this as a service, you need to set:

-Dhttp.proxyHost=
-Dhttp.proxyPort=
#For HTTPS connection
-Dhttps.proxyHost=
-Dhttps.proxyPort=
#if authentication is required:
-Dhttp.proxyRequiresAuthentication=true/false
-Dhttp.proxyUsername=
-Dhttp.proxyPassword=

in the service settings...otherwise these go in the start_verj_server.bat file.

It maybe that you have set these, but you are using a SSL connection?

I hope this helps.

Steve
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

Re: PUT request via a proxy

#6

Postby Steve James » Mon Jun 25, 2018 7:58 am

Thanks Steve.
We've taken the stance that we do not want to set the proxy at JVM level because most calls can go direct (ie internal).

Where we need a proxy I use Java url.openConnection
eg

Code: Select all

importPackage(java.net);
importPackage(java.io);

var proxyO  = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.thingie.net",8080));
var conn1 = url.openConnection(proxyO);
The solution in question calls several dozen GETs and POSTs before it needs to issue the PUT calls. All calls are to the same base uri on ssl.
I've a niggling doubt that the issue could be to do with writing the body, that said I call POSTs before it and they all have a body.

I'll carry on with my investigations.

Thanks
0 x

Steve
Moderator
Moderator
Posts: 414
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

Re: PUT request via a proxy

#7

Postby Steve » Thu Jun 28, 2018 8:53 am

Hi Steve,

Are you creating a new URL connection for each request?

Reading about on the internet, someone has suggested you might have a stale connection and to try this:

Code: Select all

System.setProperty("http.keepAlive", "false");
connection.setRequestProperty("Connection", "close");
Could it be that you need to set the content-length header? If possible it might be worth debugging the headers and content coming out from the server. If you call an Ebase RESTful web service for your test to see if there is anything obvious here.

I cannot see why the proxy would not be used the second time unless the previous connection has not been closed properly?

Steve
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

Re: PUT request via a proxy

#8

Postby Steve James » Thu Jun 28, 2018 9:58 am

Ha-blooming-za :lol: :lol: :lol:

Thanks Steve, that's done the trick. I only had to set the request property ie

Code: Select all

conn1.setRequestProperty("Connection", "close");
Why it's fine for GETs and POSTs I am not sure but PUT is more fussy.

Thanks again
0 x

Steve
Moderator
Moderator
Posts: 414
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

Re: PUT request via a proxy

#9

Postby Steve » Thu Jun 28, 2018 11:40 am

I am please to help :D

Steve
0 x


Who is online

Users browsing this forum: No registered users and 9 guests