Skip to main content
1-Visitor
July 5, 2016
Question

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

  • July 5, 2016
  • 7 replies
  • 3301 views

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

5-Regular Member
July 5, 2016

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

1-Visitor
July 13, 2016

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

5-Regular Member
July 14, 2016

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

5-Regular Member
July 14, 2016

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

5-Regular Member
July 14, 2016

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