org.apache.http.client.ClientProtocolException Java API

Hi I am trying to run an example (example450__MarketPrice__QueryServiceDiscovery) and facing an error

in serviceDiscovery.registerClient

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/ClientProtocolException

at com.thomsonreuters.upa.valueadd.reactor.RestClient.<init>(RestClient.java:62)

at com.thomsonreuters.upa.valueadd.reactor.Reactor$1.<init>(Reactor.java:971)

at com.thomsonreuters.upa.valueadd.reactor.Reactor.createRestClient(Reactor.java:970)

at com.thomsonreuters.upa.valueadd.reactor.Reactor.initRestClientForQueryServiceDiscovery(Reactor.java:1057)

at com.thomsonreuters.upa.valueadd.reactor.Reactor.queryServiceDiscovery(Reactor.java:932)

at com.thomsonreuters.ema.access.ServiceEndpointDiscoveryImpl.registerClient(ServiceEndpointDiscoveryImpl.java:192)

at com.thomsonreuters.ema.access.ServiceEndpointDiscoveryImpl.registerClient(ServiceEndpointDiscoveryImpl.java:99)

at testSample.Consumer.main(Consumer.java:293)

Caused by: java.lang.ClassNotFoundException: org.apache.http.client.ClientProtocolException

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

... 8 more


I have the following code, which reads machineid/userName, password,clientid, keyfile and keypasswd. I have these vales stored in config.properties files

static boolean readCommandlineArgs(String[] args, OmmConsumerConfig config)

{

try

{

int argsCount = 0;

Consumer cons = new Consumer();

Properties properties = new Properties();

InputStream fs = cons.getClass().getClassLoader().getResourceAsStream("config.properties"); //new InputStreamReader("config.properties");

properties.load(fs);

userName = properties.getProperty("userName");

password = properties.getProperty("password");

clientId = properties.getProperty("clientId");

config.tunnelingKeyStoreFile(properties.getProperty("keyfile"));

config.tunnelingKeyStorePasswd(properties.getProperty("keypasswd"));

if ( userName == null || password == null || clientId == null)

{

System.out.println("Username, password, and clientId must be specified on the command line. Exiting...");

printHelp();

return false;

}

}

catch (Exception e)

{

printHelp();

return false;

}

return true;

}

And my properties file is like this

userName=GE-A-11111111-1-1111

password=NWfcW@g)>(Q[abcd_2(RdRmY#QhsN`/r/f9^~8.)q<&j9<Q<z3

clientId=2a93d054b1cd4f00a7b12345c5ee890a2ad7b18b

keyfile=c:\\KeyStore\\local.keystore

keypasswd=abcd123@

Can anybody help in fixing this issue?

Thanks

Best Answer

  • wasin.w
    wasin.w admin
    Answer ✓

    Hello @dhruv.arora

    I can replicate the issue in Eclipse IDE by manual adding the jar files library. I found the that the EMA Java application also requires the following jar files library:

    • json-20180130.jar
    • httpclient-4.5.3.jar
    • httpclient-cache-4.5.3.jar
    • httpcore-4.4.12.jar
    • httpcore-nio-4.4.12.jar
    • httpmime-4.5.3.jar

    The above jar files are available at <Elektron-SDK>\Elektron-SDK-BinaryPack\Java\Eta\Libs\ApacheClient <Elektron-SDK>\Elektron-SDK-BinaryPack\Java\Eta\Libs folders.

    After I added the above jar files, I can run example 450 successfully.

    image

    By the way, I always prefer using Apache Maven to handle EMA Java dependency for the application instead of manual add jar files.

Answers

  • Hi @dhruv.arora

    A few points:

    1. Can you confirm if the example works fine if you use the command line before you made the changes to use your properties file?
    2. I can see in the snippet above that you are populating the OmmConsumerConfig with the values you read from your file, but I can't see how that is then used subsequently in the remainder of the OmmConsumer initialising and startup code.
    3. Also, it is not clear if the credential values are being correctly passed to the serviceDiscovery.registerClient() as well

    Assuming the unmodified example works, I would recommend you revert your code changes to the most basic i.e. replacing the readCommandlineArgs function to read from your properties file rather than the command line and no other changes (e.g. you are creating a Consumer instance which is at least one difference I can see). Verify that works and then make incremental changes. This should help you identify any possible issues with your code changes.


  • Umer Nalla


    I am getting the following error when trying to execute from the command prompt

    A problem occurred evaluating root project

    Could not set unknown property 'mainClass' for extension 'application' of type org.gradle.api.plugins.internal.DefaultJavaApplication.


    Can you please help me? I have been struggling to execute the example for last 2 days.

    Thanks, Dhruv


  • Hello @dhruv.arora

    I can run the EMA Java Consumer450 with the following steps:

    1. In the <ESDK Java>/Java folder, run gradlew.bat jar command
    2. Once gradle download all dependencies and build the library success, run gradlew.bat Ema:Examples:tasks --all command
    3. Then run EMA Java Consumer450 with the following command
    .\gradlew.bat runconsumer450 --args='-username GE-A-XXXXX -password password -clientId clientid -keyfile C:\keystores\keystore.jks -keypasswd keypasswd'

    Note: My environment is Windows 10, Oracle JDK 1.8.0 update 241 and Gradle 6.2.2.

    Did you run gradlew jar and gradlew Ema:Examples:tasks --all commands yet?

    Could you please give me your environment detail such as OS, JDK version and Gradle version?

    Which command that returns Could not set unknown property 'mainClass' ... error message?

  • Hi @Wasin Waeosri

    I followed the instructions given by you and was able to execute the example and no more facing any error. When I executed the command

    \gradlew.bat runconsumer450 --args='-username GE-A-XXXXX -password password -clientId clientid -keyfile C:\keystores\keystore.jks -keypasswd keypasswd' with my credentials

    I started seeing the various services(9 in total) like the following one but also seeing a lot of error messages (please see in bold below). I can't see any market price information for "IBM.N"

    I am using Gradle 6.5.1 and Java version is "1.8.0_251" on Windows 10.

    Service :

    Provider : aws

    Transport : tcp

    Endpoint : amer-2.pricing.streaming.edp.thomsonreuters.com

    Port : 14002

    Data Format : rwf

    Location : us-east-1b

    Jul 15, 2020 10:48:37 AM com.thomsonreuters.ema.access.ChannelCallbackClient reactorChannelEventCallback

    INFO: loggerMsg

    ClientName: ChannelCallbackClient

    Severity: Info

    Text: Received ChannelUp event on channel Channel_1

    Instance Name Consumer_1_1

    Component Version ads3.2.1.L1.linux.tis.rrg 64-bit

    loggerMsgEnd

    StatusMsg

    streamId="5"

    domain="MarketPrice Domain"

    state="Closed / Suspect / Not entitled / 'Access Denied: User req to PE(62)'"

    name="IBM.N"

    nameType="1"

    serviceId="257"

    serviceName="ELEKTRON_DD"

    StatusMsgEnd

    Jul 15, 2020 10:52:36 AM com.thomsonreuters.ema.access.ChannelCallbackClient reactorChannelEventCallback

    WARNING: loggerMsg

    ClientName: ChannelCallbackClient

    Severity: Warning

    Text: Received Channel warning event on channel Channel_1

    Instance Name Consumer_1_1

    RsslReactor @4b86d968

    RsslChannel @589a880b

    Error Id 0

    Internal sysError 0

    Error Location Reactor.processWorkerEvent

    Error text Failed REST request from HTTP status code 400 for user: GE-A-01444311-3-2480. Text: {"error_description":"iPlanet session has been expired.","error":"access_denied"}

    loggerMsgEnd

    Jul 15, 2020 10:56:42 AM com.thomsonreuters.ema.access.ChannelCallbackClient reactorChannelEventCallback

    WARNING: loggerMsg

    ClientName: ChannelCallbackClient

    Severity: Warning

    Text: Received Channel warning event on channel Channel_1

    Instance Name Consumer_1_1

    RsslReactor @4b86d968

    RsslChannel @589a880b

    Error Id 0

    Internal sysError 0

    Error Location Reactor.processWorkerEvent

    Error text Failed REST request from HTTP status code 400 for user: GE-A-01444311-3-2480. Text: {"error_description":"iPlanet session has been expired.","error":"access_denied"}

    loggerMsgEnd

    Jul 15, 2020 11:00:48 AM com.thomsonreuters.ema.access.ChannelCallbackClient reactorChannelEventCallback

    WARNING: loggerMsg

    ClientName: ChannelCallbackClient

    Severity: Warning

    Text: Received Channel warning event on channel Channel_1

    Instance Name Consumer_1_1

    RsslReactor @4b86d968

    RsslChannel @589a880b

    Error Id 0

    Internal sysError 0

    Error Location Reactor.processWorkerEvent

    Error text Failed REST request from HTTP status code 400 for user: GE-A-01444311-3-2480. Text: {"error_description":"iPlanet session has been expired.","error":"access_denied"}

    loggerMsgEnd

    Jul 15, 2020 11:03:39 AM com.thomsonreuters.ema.access.ChannelDictionary processCallback

    WARNING: loggerMsg

    ClientName: ChannelDictionary

    Severity: Warning

    Text: RDMDictionary stream was closed with status message

    streamId 3

    Reason State: Closed/Suspect/None - text: "Login stream was closed."

    loggerMsgEnd

    Jul 15, 2020 11:03:39 AM com.thomsonreuters.ema.access.ChannelDictionary processCallback

    WARNING: loggerMsg

    ClientName: ChannelDictionary

    Severity: Warning

    Text: RDMDictionary stream was closed with status message

    streamId 4

    Reason State: Closed/Suspect/None - text: "Login stream was closed."

    loggerMsgEnd

    Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.

    Use '--warning-mode all' to show the individual deprecation warnings.

    See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

    BUILD SUCCESSFUL in 15m 17s

    11 actionable tasks: 2 executed, 9 up-to-date

    Thanks

    Dhruv

  • Hi @Umer Nalla


    I followed Wasin Waeosri's instructions and was able to connect to service and execute the example consumer450 from the command line

    but when tried to execute the example using code in eclipse (gave the same credentials), I come across the same error like the below

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/ClientProtocolException

    at com.thomsonreuters.upa.valueadd.reactor.RestClient.<init>(RestClient.java:62)

    at com.thomsonreuters.upa.valueadd.reactor.Reactor$1.<init>(Reactor.java:971)

    at com.thomsonreuters.upa.valueadd.reactor.Reactor.createRestClient(Reactor.java:970)

    at com.thomsonreuters.upa.valueadd.reactor.Reactor.initRestClientForQueryServiceDiscovery(Reactor.java:1057)

    at com.thomsonreuters.upa.valueadd.reactor.Reactor.queryServiceDiscovery(Reactor.java:932)

    at com.thomsonreuters.ema.access.ServiceEndpointDiscoveryImpl.registerClient(ServiceEndpointDiscoveryImpl.java:192)

    at com.thomsonreuters.ema.access.ServiceEndpointDiscoveryImpl.registerClient(ServiceEndpointDiscoveryImpl.java:99)

    at EMAConsumer.Consumer.main(Consumer.java:306)

    Caused by: java.lang.ClassNotFoundException: org.apache.http.client.ClientProtocolException

    at java.net.URLClassLoader.findClass(Unknown Source)

    at java.lang.ClassLoader.loadClass(Unknown Source)

    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

    at java.lang.ClassLoader.loadClass(Unknown Source)

    ... 8 more


    when the code comes at "serviceDiscovery.registerClient" as mentioned in my original question also before. Although, I am using the same credentials which I used to execute from the command line. Can you please help me with this error?


    Thanks

    Dhruv

  • Hello @dhruv.arora

    Do you manual add the ESDK library files to the Eclipse project? Beside the ema-<version>.jar, upa-<version>.jar and upaValueAdd-<version>.jar files, the EMA Java application also requires the following jar files dependency:

    • commons-collections-3.2.2.jar
    • commons-configuration-1.10.jar
    • commons-lang-2.6.jar
    • commons-logging-1.2.jar
    • slf4j-api-1.7.12.jar
    • slf4j-jdk14-1.7.12.jar

    The above files are available at <Elektron-SDK>\Elektron-SDK-BinaryPack\Java\Ema\Libs folder.

  • Hello @dhruv.arora

    The example 450 subscribes "IBM.N" item (RIC) by default. The "Closed / Suspect / Not entitled / 'Access Denied: User req to PE(62)'" error message means you do not have a permission to subscribe IBM.N item.

    You can change the RIC name in Example 450 Consumer.java file line:

    consumer.registerClient(EmaFactory.createReqMsg().serviceName("ELEKTRON_DD").name("IBM.N"), appClient);

    Then rebuild the project and re-run the application.

  • Hi Wasin, thanks, it worked with another RIC

  • Hi @Wasin Waeosri,

    I am using the following jars in the example code in eclipse

    commons-collections-3.2.2.jar, commons-configuration-1.10.jar, commons-lang-2.6.jar, commons-logging-1.2.jar, ema-3.5.0.0.jar, ema-3.5.0.0-javadoc.jar, httpcore-4.4.12.jar, httpcore-nio-4.4.12.jar, slf4j-api-1.7.12.jar, slf4j-jdk14-1.7.12.jar, upa-3.5.0.0.jar, upaValueAdd-3.5.0.0.jar

    I am using the same credentials which I used to run the example from command prompt but the code throws error when calling method serviceDiscovery.registerClient". In this method, username (which is the machineid), password and clientId are the mandatory inputs and other inputs like proxyHostName, proxyPort,proxyUserName, proxyPassword,proxyDomain and proxyKrb5Configfile can remain null.

    I am getting the following error:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/ClientProtocolException

    at com.thomsonreuters.upa.valueadd.reactor.RestClient.<init>(RestClient.java:62)

    at com.thomsonreuters.upa.valueadd.reactor.Reactor$1.<init>(Reactor.java:971)

    I have uploaded the file in text as here it was not taking file with java extension.

    Consumer.txt

    Using the values in config.properties

    userName=GE-A-01111111-3-1111

    password=NPcnS@g)>(Q[trBU_2(EkLOY#QhsN`/r/f9^~8.)q<&a7<Q<c8

    clientId=2a93d054b1cd4f00a7b60231c5ee901a3ad7b18b

    keyfile=c:\\KeyStore\\dhruv_keystore.jks

    keypasswd=pass1234@

    Thanks a lot,

    Dhruv

  • Thank you very much Wasin. It worked very well. Thanks again