Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!

REST API Timeout

Avatar

Level 3

Hi Team,

We are calling an API endpoint from Adobe Campaign Java script activity by using :

var http = new HttpClientRequest(<Our API URL>) and the request is timing out before it could get a response from the End point/API (timing out at approximately 5 mins),

Is there any attribute in server config file which would set the timeout value to a higher number > 5 mins? OR

Do we have to add timeout attribute in the code itself. Do you have a sample code to share?

Thanks,

Ishani

5 Replies

Avatar

Level 8

Hello Ishani,

Try the following

  1. var http = new HttpClientRequest("yourhost.com"
  2. http.execute() 
  3. var response = http.response 
  4. for(var i in response.header) 
  5.   logInfo("header[" + i + "] => " + response.header[i]) 

Should give you something like

js3 header[Date] => Wed, 05 Jul 2017 10:10:13 GMT

js3 header[Server] => Apache/2.2.22 (Debian)

js3 header[Vary] => Accept-Encoding

js3 header[Content-Length] => 291

js3 header[Keep-Alive] => timeout=5, max=100

js3 header[Connection] => Keep-Alive

js3 header[Content-Type] => text/html; charset=iso-8859-1  

You can use the following code as well

var API = 'http://yourwebserviceendpoint.com'

var http = new  HttpClientRequest(API);

http.method = "GET";

http.header["Content-Type"] = "application/json";

http.header["Accept"] = "application/json";

http.header["Authorization"] = "Basic Z3XNlbmRleHRlc3QxQGdtYWlsLmNvbTpsb2dpbjEyMzQ="; // replace with your authorization code

http.execute();

var response = http.response;

Regards,

Venu

Avatar

Level 3

Thanks Venu.

We are able to send the request but it seems to time out after 5 minutes. My questions is - How do we increase the time out to 10 mins instead?

Avatar

Level 8

Hello Ishani,

The default connect timeout for outgoing http connection is 5sec.

You can change the connection timeout in server.conf file using the attribute value http_connect_timeout.

Click here for more details http://docs.graylog.org/en/3.0/pages/configuration/server.conf.html#web-rest-api

Regards,

Venu

Avatar

Level 10

Hi Isha,

Please change your serverConf.xml file, the section with urlPermission to allow outgoing connection.

This is documented in section "Outgoing connection protection" in this documentation:

Configuring Campaign server

It was added about 2 years ago in a build for security reasons.

Regards
J-Serge

Avatar

Level 10

Hi Isha,

Moreover, you should always use:
try{

     <your code>

}

catch(e){

     logWarning("Error number: " + e );
}

so the timeout message would have been much more clearer.
Same for other kind of errors.

Then you have a look in the web.log file (on mta server or on applicative server depending on the pbject type) to read the error details.

Regards
J-Serge