cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Connecting with incorrect appKey does not throw any exception on Java SDK

rkandasamy
7-Bedrock

Connecting with incorrect appKey does not throw any exception on Java SDK

We are trying to use an incorrect appKey while connecting to a Remote Thing on the TW Server from a JAVA SDK. However, we do not receive any exception or error on SDK. Is there any way to get the error/exception on the SDK.

7 REPLIES 7
Aanjan
12-Amethyst
(To:rkandasamy)

Rdhakrishnan, does that generate any message at all or just simply doesn't connect?

It simply does not connect. No message or exception is received at SDK end.

supandey
19-Tanzanite
(To:rkandasamy)

Hi Rdhakrishnan, a very specific error is thrown in the SDK when there is an issue with AppKey, something like this :

ERROR c.t.c.c.e.ClientCommunicationEndpoint - Exception refilling connections was:

java.lang.Exception: Connection authentication/registration FAILED

[cause: invalid AppKey SecurityClaim provided]]

I tested this in Eclipse and I virtually can't run my code without catching the exception (with try & catch) this should definitely help you in catching the exception should there be any during the connection process.

Would it be possible for you to share the part of the code you are writing to connect to the platform?

Sushant

Hi Sushant,

Thanks for your inputs.We are not getting any error exception in SDK code. It is getting cached in system level and we are not receiving any exception in our program code while starting the client.

Please find the requested sample code below,

private static void executeClient(String ThingName) throws Exception {

CPAssetThing connectionThing = new CPAssetThing(ThingName ,"Thing" ,client);

client.bindThing(connectionThing);

client.start();

log.info("\nConnecting client to server ************************* ");

while(!client.isShutdown()) {

if(client.isConnected()) {

try{

log.info("\nThe client is now connected.");

InfoTable result;

ValueCollection params = new ValueCollection();

params.put(key, value);

result = client.invokeService(ThingworxEntityTypes.Things, ThingName, "seviceName", params, 5000);

}catch (Exception eProcessing){

log.error("\nError in sevice Request for [" + ThingName + "] :  " , eProcessing);

}

break;

}

}

}

Please let me know if you were able to catch the exception in SDK code, so that we can change the flow of program execution accordingly.

if you are able to catch explicitly, please share your code.

Rdhakrishnan,

The error messages are definitely visible in the output logging, as Sushant is saying, but they do not bubble up through the SteamSensorClient class file for you to catch and do something with. As of right now, other than the client.isShutdown() and client.isConnected() methods, there is not really much else you can access to tell you the status of your connection with the SteamSensorClient class.

Meghan

supandey
19-Tanzanite
(To:rkandasamy)

Thanks Meghan for pointing that out.

Rdhakrishnan, here's a sample code for connecting and binding to the platform within the try & catch

try {

  // Setting the server URL and the appkey to enable this client to

  // connect to the ThingWorx platform

  String serverURL = "ws://localhost/Thingworx/WS";

  String appKey = "<AppKey>";

  // configure client

  ClientConfigurator config = new ClientConfigurator();

  config.setUri(serverURL);

  config.setAppKey(appKey);

  config.getSecurityClaims().addClaim(appKey, appKey);

  // connected to client

  ConnectedThingClient client = new ConnectedThingClient(config, null);

  // start the client

  client.start();

  //create and bind the virtual thing to the platform

  TractorVirtualThing tractorThing = new TractorVirtualThing("GreenCo.Tractor1", "A virtual thing", client);

 

  LOG.debug("Binding to " + serverURL + "to register thing" + tractorThing.getName());

 

  // binding happens just once with 1 connection

  client.bindThing(tractorThing);

 

  LOG.debug("Connecting to " + serverURL + "using key" + appKey);

  //

  while (true) {

  if(client.getEndpoint().isConnected()) {

  tractorThing.processScanRequest();

  }

  Thread.sleep(6000); // cycle every miliseconds

  }

  } catch (Exception e) {

  // Catching the exception in case the connection or the binding fails

  LOG.error("An error occured", e);

  e.printStackTrace();

  }

Sushant

I've submitted an Improvement Request JIRA against this issue as PLATFORM-2760. This article can be used to track any updates on the JIRA.

Meghan

Announcements


Top Tags