For a deeper look into our DataScope Select REST API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials

question

Upvotes
Accepted
16 1 3 4

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 !

dss-rest-apidatascope-selectdssapijavaauthenticationproxy
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi, @gregory

Thank you for your participation in the forum.

Is the reply below satisfactory in resolving your query? If yes please click the 'Accept' text next to the reply. This will guide all community members who have a similar question. Otherwise please post again offering further insight into your question. Thanks,

AHS

Upvote
Accepted
16 1 3 4

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(); } }
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thank you for sharing, glad you got it to work.

Upvotes
13.7k 26 8 12

@gregory, the way to setup proxy settings of a java application is explained in the java documentation available on the Oracle portal.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
16 1 3 4

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.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
28.3k 30 11 15

Hello @Gregory,

When you run the example, please try adding on the command line:

-Dhttps.proxyHost=YOURPROXYHOST -Dhttps.proxyPort=YOURPROXYPORT

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
14.7k 39 12 18

@zoya.farberov @gregory

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.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
14.7k 39 12 18

@gregory

Can you please try the attached example and let me know if it works for you. dss2proxytokenclient.zip


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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.

@gregory

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 ...

That's better but our proxy needs username and password too.

Error message:

org.apache.http.client.HttpResponseException: authenticationrequired

Show more comments
Upvotes
1 0 0 0

I ran through the proxy client, but i get the below error "org.apache.http.client.HttpResponseException: Method Not Allowed"

any help here

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I will contact you offline to understand the issue.