failed: Connection timed out: connect

I can connect to Real Time Optimized by entering the machine ID, password and AppKey into the speed guide application. But I cannot connect via the spring boot project. It gives the error below.


"Failed to get endpoints:failed to submit authorization request, exception = Connect to api.refinitiv.com:443 [api.refinitiv.com/75.2.0.254, api.refinitiv.com/99.83.242.11] failed: Connection timed out: connect"


Also I don't know how do I use AppKey for serviceEndpointDiscoveryOption. My connection code is as follows.


String clientId = "my_machine_id";
String clientSecret = "my_password";
String AppKey = "my_appkey"


//prepare appclient
AppClient appClient = new AppClient();

//set options
ServiceEndpointDiscoveryOption serviceEndpointDiscoveryOption = EmaFactory.createServiceEndpointDiscoveryOption();
serviceEndpointDiscoveryOption.clientId(clientId);
serviceEndpointDiscoveryOption.clientSecret(clientSecret);
//**********I don't know how do I use AppKey for serviceEndpointDiscoveryOption *********
serviceEndpointDiscoveryOption.transport(ServiceEndpointDiscoveryOption.TransportProtocol.TCP);

//use ServiceEndpoint from EMA
ServiceEndpointDiscovery serviceEndpointDiscovery = EmaFactory.createServiceEndpointDiscovery();
serviceEndpointDiscovery.registerClient(serviceEndpointDiscoveryOption, appClient);

Best Answer

  • wasin.w
    wasin.w admin
    Answer ✓

    Hello @SelcukYAPICI

    Based on the given trace log, your RTO credentials can login to the RDP Authentication service and get the list of RTO endpoint from the RDP Service Discovery API.

    POST https://api.refinitiv.com/auth/oauth2/v1/token HTTP/1.1
        No proxy is used
        ContentLength: 210
        Content-Type: application/x-www-form-urlencoded; charset=UTF-8
        Content of request:
            grant_type: password
            username: GE-A-********
            client_id: 06************
            takeExclusiveSignOnControl: true
            scope: trapi.streaming.pricing.read
            password: <*** password ***>

    .....
    HTTP/1.1 200 OK
        Date: Wed, 20 Sep 2023 07:05:01 GMT
        Content-Type: application/json
        Transfer-Encoding: chunked
        Connection: keep-alive
        X-Amzn-Trace-Id: Root=1-650a999c-5793fe740fde9adc587fe767
        X-Served-By: region=eu-west-1; cid=a98ca41813154e3a99688ecf3661a965
        X-Tr-Requestid: 7e94c174-2156-4fc0-8c28-57ffe267fa96
        Content string:
            { "access_token":"eyJ...Y3koel_g", "refresh_token":"f6e...c", "expires_in":"600" , "scope":"trapi.streaming.pricing.read", "token_type":"Bearer" }  
    ...
    GET https://api.refinitiv.com/streaming/pricing/v1/?transport=tcp HTTP/1.1
        Authorization: Bearer eyJ0e...oel_g
        No proxy is used
    ....
    HTTP/1.1 200 OK
        Date: Wed, 20 Sep 2023 07:05:01 GMT
        Content-Type: application/json; charset=utf-8
        Connection: keep-alive
        Access-Control-Allow-Origin: *
        Access-Control-Expose-Headers: content-encoding, content-length, x-tr-requestid, x-tr-correlationid
        X-Amzn-Trace-Id: Root=1-650a999d-63c8d915725c98d55883ddd6
        X-Served-By: region=eu-west-1; cid=f4a3ef57d42d41919c69f724bc40d78a
        X-Tr-Requestid: 75002b82-3539-4d0b-9c8e-16fb6619cb9e
        Content string:
            {"services":[{"port":14002,"location":["ap-northeast-1a"],"transport":"tcp","provider":"aws","endpoint":"ap-northeast-1-aws-1-sm.optimized-pricing-api.refinitiv.net","dataFormat":["rwf"]},...]}

    However, the trace log shows the following error message:

    2023-09-20T10:05:01.569+03:00 ERROR 16732 --- [   scheduling-1] c.refinitiv.ema.access.OmmConsumerImpl   : loggerMsg
        ClientName: ChannelCallbackClient
        Severity: Error
        Text:    Failed to add RsslChannel(s) to RsslReactor. Channel name(s) Channel_1
        Instance Name Consumer_1_1
        RsslReactor @2674ce40
        RsslChannel null
        Error Id -6
        Internal sysError 0
        Error Location Reactor.copyOAuthCredentialForSessionManagement
        Error Text Failed to copy OAuth credential for enabling the session management; OAuth client ID does not exist.
    loggerMsgEnd


    I recheck your OmmConsumerConfig source code. I found that you does not set the Machine-ID information to the OmmConsumerConfig.userName method.

    String userName = "my_machine_id";
    String password = "my_password";
    String clientId = "my_appkey"


    OmmConsumerConfig ommConsumerConfig = EmaFactory.createOmmConsumerConfig();
    ommConsumerConfig.config(configDb);
     
    String tokenServiceUrlV1 = "https://api.refinitiv.com/auth/oauth2/v1/token";
     
    ommConsumerConfig.consumerName("Consumer_1");
    ommConsumerConfig.userName(userName);
    ommConsumerConfig.clientId(appKey);
    ommConsumerConfig.password(password);
    ommConsumerConfig.tokenServiceUrlV1(tokenServiceUrlV1);
    ommConsumerConfig.userName(userName);
    OmmConsumer ommConsumer = EmaFactory.createOmmConsumer(ommConsumerConfig);

    If the problem still persists after you set the OmmConsumerConfig.userName(), please share the source code that using the EMA API library.

Answers

  • Hello @SelcukYAPICI

    Please confirm if your machine-id has the "GE-A-XXXXXXXX-X-XXXX" pattern. If so, you are using the Version 1 authentication.

    There are two points in the issue.

    ### HTTP Connection Timeout ###

    You can configure the HTTP connection timeout via the EMA "RestRequestTimeout" configuration parameter.

    1695112338743.png

    • The default timeout is 45000 milliseconds

    You may verify if the machine can connect to the RDP Authentication service from this cURL command

    curl --location --request POST 'https://api.refinitiv.com/auth/oauth2/v1/token' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --header 'Authorization: Bearer ' \
    --data-urlencode 'username=<Machine ID>' \
    --data-urlencode 'password=<Password>' \
    --data-urlencode 'grant_type=password' \
    --data-urlencode 'scope=trapi' \
    --data-urlencode 'takeExclusiveSignOnControl=true' \
    --data-urlencode 'client_id=<App Key>'

    ### App Key and how to set the Credentials ###

    When using the Version 1 authentication,

    • machine-id is "username"
    • password is "password"
    • App Key is "client id"

    So, the code for setting the Version 1 credentials are as follows:

    String userName = "my_machine_id";
    String password = "my_password";
    String clientId = "my_appkey"
    ...
    serviceDiscovery.registerClient(EmaFactory.createServiceEndpointDiscoveryOption().username(userName)
        .password(password).clientId(clientId)
        .transport(connectWebSocket ? ServiceEndpointDiscoveryOption.TransportProtocol.WEB_SOCKET : ServiceEndpointDiscoveryOption.TransportProtocol.TCP)
        .takeExclusiveSignOnControl(takeExclusiveSignOnControl), appClient);
    ...

    consumer  = EmaFactory.createOmmConsumer(config.consumerName("Consumer_1").username(userName).password(password)
        .clientId(clientId).takeExclusiveSignOnControl(takeExclusiveSignOnControl));

    I hope this information helps.

  • Hello,

    With the information I learned from you, I set the "serviceEndpointDiscoveryOption" properly.

    String machine_id = "GE-A-*********";
    String password = "TChq*********";
    String appKey ="06b69********";

    //prepare appclient
    AppClient appClient = new AppClient();

    //set options
    ServiceEndpointDiscoveryOption serviceEndpointDiscoveryOption = EmaFactory.createServiceEndpointDiscoveryOption();
    serviceEndpointDiscoveryOption.clientId(appKey);
    serviceEndpointDiscoveryOption.username(machine_id);
    serviceEndpointDiscoveryOption.password(password);
    serviceEndpointDiscoveryOption.transport(ServiceEndpointDiscoveryOption.TransportProtocol.TCP);

    //use ServiceEndpoint from EMA
    ServiceEndpointDiscovery serviceEndpointDiscovery = EmaFactory.createServiceEndpointDiscovery();
    serviceEndpointDiscovery.registerClient(serviceEndpointDiscoveryOption, appClient);
    //Servis veri alamayınca aşağıdaki hatayı veriyor.
    //unable to find valid certification path to requested target

    log.info("Host: " + appClient.host);
    log.info("Port: " + appClient.port);


    Now I can get a host and a port information as follows.

    Host: ap-northeast-1-aws-1-sm.optimized-pricing-api.refinitiv.net

    Port: 14002



  • I noticed that "ommConsumerConfig" was also set in the lower lines of the code. I made the necessary settings as follows.

     String tokenServiceUrlV2 = "https://api.refinitiv.com/auth/oauth2/v2/token";

    ommConsumerConfig.consumerName("Consumer_1");
    ommConsumerConfig.clientId(appKey);
    ommConsumerConfig.clientSecret(password);
    ommConsumerConfig.tokenServiceUrlV2(tokenServiceUrlV2);

    OmmConsumer ommConsumer = EmaFactory.createOmmConsumer(ommConsumerConfig);


    Despite this, I get an error like the one below.


    capture.jpg

  • Hello @SelcukYAPICI

    Since you are using the Version 1 Authentication, the RDP Authentication URL is https://api.refinitiv.com/auth/oauth2/v1/token endpoint. The method for setting this Version 1 URL is OmmConsumerConfig.tokenServiceUrlV1(String v1 url).

    Example:

    String tokenServiceUrlV1 = "https://api.refinitiv.com/auth/oauth2/v1/token";
    config.tokenServiceUrlV1(tokenServiceUrlV1);

    The suggested example is ex450_MP_QueryServiceDiscovery (also available in the SDK package).

  • Hello,

    I changed the url to v1 as you wrote.

    OmmConsumerConfig ommConsumerConfig = EmaFactory.createOmmConsumerConfig();
    ommConsumerConfig.config(configDb);

    String tokenServiceUrlV1 = "https://api.refinitiv.com/auth/oauth2/v1/token";

    ommConsumerConfig.consumerName("Consumer_1");
    ommConsumerConfig.clientId(appKey);
    ommConsumerConfig.password(password);
    ommConsumerConfig.tokenServiceUrlV1(tokenServiceUrlV1);

    OmmConsumer ommConsumer = EmaFactory.createOmmConsumer(ommConsumerConfig);


    With this change, the error also changed. I started getting an error that my username or password is invalid. Do you have any suggestions on this matter?

    capture.jpg


  • Hello @SelcukYAPICI

    The error "access_denied" and "Invalid username or password." messages indicate that your RTO credentials are invalid.

    Please try to run the following cURL script to verify your credentials.

    curl --location --request POST 'https://api.refinitiv.com/auth/oauth2/v1/token' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --header 'Authorization: Bearer ' \
    --data-urlencode 'username=<Machine ID>' \
    --data-urlencode 'password=<Password>' \
    --data-urlencode 'grant_type=password' \
    --data-urlencode 'scope=trapi' \
    --data-urlencode 'takeExclusiveSignOnControl=true' \
    --data-urlencode 'client_id=<App Key>'

    Please also enable the EMA REST log messages and share us the log (please hide your credentials before posting). You can enable the REST log message via the Java Logging API configurations file (logging.properties) as follows:

    .level=FINEST
    handlers=java.util.logging.FileHandler
    java.util.logging.FileHandler.level=FINEST
    java.util.logging.FileHandler.pattern=<path_to_log>/api.log <- Must be match your machine folder structure
     
    # Write 100000 bytes before rotating this file
    java.util.logging.FileHandler.limit=50000000
     
    # Number of rotating files to be used
    #java.util.logging.FileHandler.count=20
    #java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
    # Format timestamp as date/time with millisecond
    java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$-7s %2$s %n%5$s

    Then run the EMA application with the following JVM argument:

    -Djava.util.logging.config.file=<your paht>/logging.properties
  • hello @wasin.w,

    When I run curl, I get an error like the following.


    untitled.jpg

  • I also tried adding the certificate but that didn't work either.

    untitled2.jpg

  • Then I tried to adjust the log settings, but when I couldn't do it in Intelij Idea, I reduced the log level to trace from IntelIdea settings and recorded the log. I hope this will be useful to you in understanding the problem.


    trace_log.txt