Connection Timed Out: Connect + TRTH Rest API Call
I am getting connection timeout when I try to run the DSS2SearchByRIC.java.
Is there a proxy setting that I need to change in my eclipse?
The postman GET request works just fine.
Best Answer
-
I got the same exception after adding a "https" parameter while creating HttpHost.
HttpHost proxy = new HttpHost(proxyHostName, proxyPortNumber, "https");
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
However, if I remove the "https" parameter, it works fine.
HttpHost proxy = new HttpHost(proxyHostName, proxyPortNumber);
0
Answers
-
Please try to set connection timeout in the code.
private int timeout=30;
private RequestConfig config = RequestConfig.custom()
.setConnectTimeout( timeout * 1000)
.setConnectionRequestTimeout(timeout * 1000)
.setSocketTimeout(timeout * 1000).build();
private CloseableHttpClient httpclient = HttpClientBuilder.create().setDefaultRequestConfig(config).disableContentCompression().build();I found this code at http://www.baeldung.com/httpclient-timeout.
0 -
Thank you for the reply! I still get the same timeout error.
0 -
I get the following error:javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Any idea why I get that?0 -
Are you using proxy?
This error was mentioned in stack overflow.
0 -
Yes. We have proxy and I have programmatically setup the system proxy.
0 -
Do I need to setup something for the SSL?
0 -
It may relate to the Proxy. Can you share the code? I will try it in my environment.
0 -
Please find below the sample code:
It's one of the example files in Java tutorials.
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import org.apache.http.HttpHost;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.DefaultProxyRoutePlanner;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.conn.params.ConnRoutePNames;
import org.json.JSONObject;
/**
* Hello world!
*
*/
public class App
{
private String urlHost = "https://hosted.datascopeapi.reuters.com/RestApi/v1";
private String sessionToken = "";
private CloseableHttpClient httpclient = HttpClientBuilder.create().disableContentCompression().build();
public static void main(String[] args) throws Exception {
Properties props = System.getProperties();
props.setProperty("https.proxyHost", "*****");
props.setProperty("https.proxyPort", "****");
// Port Number and Proxy set above
if(args.length < 2) {
System.out.println("Please enter DSS2 Username as 1st command line parameter, Password as 2nd");
System.exit(-1);
}
App dss2 = new App();
dss2.getSessionToken(args[0], args[1]);
dss2.httpclient.close();
}
/**
* Request DSS2 for a Session Token (24 hour life)
*
* @param username
* @param password
*/
public void getSessionToken(String username, String password) {
try {
HttpPost httppost = new HttpPost(urlHost + "/Authentication/RequestToken");
httppost.addHeader("content-type", "application/json; charset=UTF-8");
JSONObject TokenRequest = new JSONObject()
.put("Credentials", new JSONObject()
.put("Username", username)
.put("Password", password));
StringEntity requestBody = new StringEntity(TokenRequest.toString());
httppost.setEntity(requestBody);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
httpclient = (CloseableHttpClient) createHttpClientOrProxy();
String response = httpclient.execute(httppost, responseHandler);
JSONObject jsonResponse = new JSONObject(response);
sessionToken = jsonResponse.get("value").toString();
System.out.println("Session Token (expires in 24 hours):\n" + sessionToken);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private HttpClient createHttpClientOrProxy() {
HttpClientBuilder hcBuilder = HttpClients.custom();
// Set HTTP proxy, if specified in system properties
if( System.getProperty("https.proxyHost") !=null ) {
int port = 8080;
if( System.getProperty("https.proxyPort") !=null ) {
port = Integer.parseInt(System.getProperty("https.proxyPort"));
}
HttpHost proxy = new HttpHost(System.getProperty("https.proxyHost"), port, "https");
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
hcBuilder.setRoutePlanner(routePlanner);
}
CloseableHttpClient httpClient = hcBuilder.build();
return httpClient;
}
}0 -
Seriously!
That worked!!
Thanks a lot. I owe you a treat for sure.0
Categories
- All Categories
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 684 Datastream
- 1.4K DSS
- 613 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 248 ETA
- 552 WebSocket API
- 37 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 629 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 26 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 191 TREP Infrastructure
- 228 TRKD
- 915 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 84 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛