DSS Java API - Extract via https proxy
Hi,
I downloaded the java test code from TR to retrieve data from DSS.
I'm trying to run DSS2EndOfDayClient.java but I can't pass through my proxy servers.
Can you give me the code to add the proxy server name and user/password ?
Thank you !
Best Answer
-
Hi, I solved my issues, see below.
/* * ==================================================================== * This Java example demonstrate how to make an HTTPS request to DSS2 * to retrieve a Session Token. This sample is written for use with a * proxy server. * * To run this example, you must provide a DSS2 username, password and * the proxy server hostname and proxy port. * ==================================================================== */package bnpparibas.ip.datascopehttps;
import org.apache.http.Header;import org.apache.http.HttpHost;import org.apache.http.HttpResponse;import org.apache.http.auth.AuthScope;import org.apache.http.auth.UsernamePasswordCredentials;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.CredentialsProvider;import org.apache.http.client.ResponseHandler;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.conn.ssl.SSLConnectionSocketFactory;import org.apache.http.conn.ssl.SSLContextBuilder;import org.apache.http.conn.ssl.TrustSelfSignedStrategy;import org.apache.http.entity.StringEntity;import org.apache.http.impl.client.BasicCredentialsProvider;import org.apache.http.impl.client.BasicResponseHandler;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClients;import org.apache.http.impl.conn.DefaultProxyRoutePlanner;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import org.json.JSONOrderedObject;
import java.io.*;import java.net.MalformedURLException;import java.security.KeyManagementException;import java.security.KeyStoreException;import java.security.NoSuchAlgorithmException;import java.util.ArrayList;import java.util.List;import java.util.Scanner;
public class DSS2ProxyTokenClient { private static final String urlHost = "https://hosted.datascopeapi.reuters.com/RestApi/v1"; private String sessionToken = ""; private CloseableHttpClient httpClient;
public static void main(String[] args) throws Exception {
if (args.length < 4) { System.out.println("Please enter ARGS : Reuters UserName / Reuters User Pwd / Proxy Name / Proxy Port / Proxy UserName / Proxy User Pwd"); System.exit(-1); }
int pPort = Integer.parseInt(args[3]);
DSS2ProxyTokenClient dss2 = new DSS2ProxyTokenClient(); dss2.getSessionToken(args[2], pPort, args[4], args[5], args[0], args[1]); promptEnterKey();
// End Of Day On Demand Extraction report dss2.endOfDayExtractRequest();
dss2.httpClient.close(); }
public void getSessionToken(String proxyHostName, int proxyPortNumber, String proxyUsername, String proxyPassword, String username, String password) {
try { // Set proxy information for HTTP Components HttpHost proxy = new HttpHost(proxyHostName, proxyPortNumber); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyHostName, proxyPortNumber, AuthScope.ANY_REALM), new UsernamePasswordCredentials(proxyUsername, proxyPassword));
SSLContextBuilder sslContextBuilder = new SSLContextBuilder(); sslContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContextBuilder.build()); httpClient = HttpClients.custom() .setSSLSocketFactory(sslsf) .setRoutePlanner(routePlanner) .setDefaultCredentialsProvider(credsProvider) .build();
// Issue a POST request 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();
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 (MalformedURLException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } }
0
Answers
-
@gregory_deprecated_0, the way to setup proxy settings of a java application is explained in the java documentation available on the Oracle portal.
0 -
yes, I know, but I'm not a dev guy, I don't know how to use it or where to copy the new code.
I just need this for a test with DSS. In fact, the exemple from TR in not complete, proxy management is missing.
0 -
Hello @gregory_deprecated_0,
When you run the example, please try adding on the command line:
-Dhttps.proxyHost=YOURPROXYHOST -Dhttps.proxyPort=YOURPROXYPORT
0 -
@zoya faberov @gregory_deprecated_0
The command line proxy properties to JVM will not be picked up by Apache HTTP Components, unless HTTPClient is specifically instructed to do so. Following code snippet will do the trick.
HttpHost proxy = new HttpHost(proxyHostName, proxyPortNumber);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
CloseableHttpClient httpclient = HttpClients.custom()
.setRoutePlanner(routePlanner)
.build();We are working on an example which will show how to use DSS with proxy server. Will let you know when it is available.
0 -
Can you please try the attached example and let me know if it works for you. dss2proxytokenclient.zip
0 -
Hi, when I build this file, I'm getting only this message:
Please enter DSS2 Username, Password, Proxy hostname, Proxy Port
Process finished with exit code -1
and I do not have any prompt asking me for some credentials.0 -
The program expects those 4 parameters in the run command. When you run it, add the 4 params in the command line, somewhat like this:
java -classpath "C:\Java\DSS2_Java_Examples\src;C:\Java\DSS2_Java_Examples\lib\commons-codec-1.9.jar;C:\Java\DSS2_Java_Examples\lib\commons-logging-1.2.jar;C:\Java\DSS2_Java_Examples\lib\httpclient-4.4.jar;C:\Java\DSS2_Java_Examples\lib\httpcore-4.4.jar;C:\Java\DSS2_Java_Examples\src" com.thomsonreuters.dss.api.example.DSS2ProxyTokenClient 123456 password proxyhost proxyport
Adapt this to your own classpath, and set your values for the 4 parameters ...
0 -
That's better but our proxy needs username and password too.
Error message:
org.apache.http.client.HttpResponseException: authenticationrequired
0 -
Unfortunately there are many different types of proxy authentication like Basic, NTLM, Digest, OAuth etc, and supporting every type is beyond the scope of samples provided. Please use a development resource to help build the one specific to your network.
0 -
I ran through the proxy client, but i get the below error "org.apache.http.client.HttpResponseException: Method Not Allowed"
any help here
0 -
I will contact you offline to understand the issue.
0 -
Thank you for sharing, glad you got it to work.
0
Categories
- All Categories
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 33 Data Model Discovery
- 682 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.8K Refinitiv Data Platform
- 625 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
- 83 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛