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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Problems connecting to the Thingworx platform with Java SDK

mbonelli1
1-Visitor

Problems connecting to the Thingworx platform with Java SDK

Hello everyone!!

I'm trying to connect my java application to the thingworx istance. The goal was reading the value of a property to see if the connection to the thingworx istance was working but the reason I'm here is exactly that it's not even working!

I already saw a bunch of posts about this and some of them are really close to the situation I have but I decided to open a new post because in the log I get some errors that in the other posts I haven't seen yet.

Here is the log. The first underlined lines are the ones that I haven't found in the other posts. Apperantly I have a problem with javassist but I don't know how to solve it and I'm not even sure if that's actually the cause that doesn't allow me to connect to the istance.

The application has started...

11:43:30.681 [main] INFO  c.t.c.c.p.ClientMessageProcessor - Created new ClientMessageProcessor [minPoolSize: 4, maxPoolSize: 10, maxThreadLife: 10000, maxQueueSize: 1000]

11:43:30.716 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework

11:43:30.723 [main] DEBUG i.n.c.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 16

11:43:30.734 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.nio.ch.DirectBuffer.cleaner(): available

11:43:30.735 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Buffer.address: available

11:43:30.735 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available

11:43:30.736 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available

11:43:30.737 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: true

11:43:30.737 [main] DEBUG i.n.util.internal.PlatformDependent - Platform: Windows

11:43:30.737 [main] DEBUG i.n.util.internal.PlatformDependent - Java version: 8

11:43:30.737 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noUnsafe: false

11:43:30.738 [main] DEBUG i.n.util.internal.PlatformDependent - sun.misc.Unsafe: available

11:43:30.738 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noJavassist: false

11:43:30.739 [main] DEBUG i.n.util.internal.PlatformDependent - Javassist: unavailable

11:43:30.739 [main] DEBUG i.n.util.internal.PlatformDependent - You don't have Javassist in your class path or you don't have enough permission to load dynamically generated classes.  Please check the configuration for better performance.

11:43:30.739 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\WHATSA~1\AppData\Local\Temp (java.io.tmpdir)

11:43:30.739 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model)

11:43:30.740 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false

11:43:30.754 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false

11:43:30.754 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512

11:43:30.843 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8

11:43:30.844 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8

11:43:30.844 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192

11:43:30.844 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11

11:43:30.844 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216

11:43:30.844 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512

11:43:30.844 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256

11:43:30.844 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64

11:43:30.844 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768

11:43:30.844 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192

11:43:30.844 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheCleanupInterval: 5000 ms

11:43:30.851 [main] DEBUG c.t.c.c.e.m.CommunicationEndpointMonitorTask - Initializing CommunicationEndpoint Connection Monitor...

11:43:30.852 [Client-EndpointMonitor-1] DEBUG c.t.c.c.e.m.CommunicationEndpointMonitorTask - CommunicationEndpoint Monitor - checking for disconnected endpoints

11:43:30.852 [Client-EndpointMonitor-1] INFO  c.t.c.c.e.m.CommunicationEndpointMonitorTask - Endpoint not connected [name: EventClient, id: 0]. Attempting [re]connect...

11:43:30.852 [Client-EndpointMonitor-1] DEBUG c.t.c.c.e.ClientCommunicationEndpoint - Clearing endpoint authentication data [id: 0]

11:43:30.852 [Client-EndpointMonitor-1] INFO  c.t.c.c.e.ClientCommunicationEndpoint - Needed to refill connections on client endpoint [id: 0] : [active: 0, max: 1]

11:43:30.998 [Client-EndpointMonitor-1] DEBUG i.n.util.internal.ThreadLocalRandom - -Dio.netty.initialSeedUniquifier: 0x5f50c9f995c33738

11:43:31.004 [Client-EndpointMonitor-1] DEBUG i.n.channel.ChannelOutboundBuffer - -Dio.netty.threadLocalDirectBufferSize: 65536

11:43:31.004 [Client-EndpointMonitor-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacity.default: 262144

11:43:31.015 [Client-EndpointMonitor-1] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: unpooled

11:43:31.033 [NettyClient-NIO-1] DEBUG c.t.c.c.c.n.NettyClientConnectionFactory - initializing a secure websocket connection [ignore ssl errors: true]

11:43:31.282 [NettyClient-NIO-1] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetectionLevel: simple

11:43:41.027 [Client-EndpointMonitor-1] INFO  c.t.c.c.c.n.NettyClientConnectionFactory - forcing underlying tcp channel closed [is open: true, is active: false]

11:43:41.028 [Client-EndpointMonitor-1] ERROR c.t.c.c.e.ClientCommunicationEndpoint - Refilling connections on [endpoint 0, uri: wss://ubol.cloud.thingworx.com:443/Thingworx/WS] failed : timeout waiting for websocket handshake to complete

11:43:41.028 [Client-EndpointMonitor-1] INFO  c.t.c.c.e.m.CommunicationEndpointMonitorTask - Endpoint reconnection was unsuccessful [name: EventClient, id: 0]

Here is my code. I've posted this because I use a while so that the app waits until the connection is enstablished. If I don't use the while the application keeps running and just ends printing "Terminating the application..." even if the client hasn't even started the websocket protocol yet. So the next question is, do you think is okay to have that while or am I using the wrong primitives here and there is a better way to wait for the connection to be enstablished?

System.out.println("The application has started...");

  ClientConfigurator config = new ClientConfigurator();

  config.setUri(URI);

  //Contesto sicurezza

  SecurityClaims claims = SecurityClaims.fromAppKey(appkey);

  config.setSecurityClaims(claims);

  config.setName("EventClient");

  config.setAsSDKType();

  config.ignoreSSLErrors(true);

  /* CREAZIONE DEL CLIENT - PROVA */

  try

  {

  EventClient client = new EventClient(config);

  client.start();

/* the while stops the program until the client is connected, if I don't do this the app just terminates before even trying to initialize the secure websocket connection, I don't know why */

  while(!client.isConnected());

  if(client.isConnected())

  {

  System.out.println("Currently connected to "+URI);

  InfoTable result = client.readProperty(ThingworxEntityTypes.Things, "AndroidDevice_356768063537221", "cpuUsage", 15000);

  String temp = result.getFirstRow().getStringValue("cpuUsage");

  System.out.println("Value of the property cpuUsage: "+temp);

  }

  }

  catch (Exception e)

  {

  System.out.println("The application is not connected to ThingWorx, terminating...");

  e.printStackTrace();

  }

  System.out.println("Terminating the application...");

I really hope you guys can help me because for now I can't really see a way out!!

Michael

ACCEPTED SOLUTION

Accepted Solutions
vmihai
12-Amethyst
(To:mbonelli1)

Hi Michael,

Have you tried to successfully connect to ThingWorx until now using ThingWorx Java Edge SDK ? The problem seems to be caused by your network not accepting websocket connections. Please run the echo websocket test without TLS in your browser to make sure websocket connections are indeed allowed on your network. Simply press connect in the url I linked to above. If you see Connected as in the picture below then websocket connections are allowed on your network.

On the other hand if your network fails the echo websocket test, please contact your network administrator to have them enabled or try using a different network. We are currently working on updating all academic hosted instances to https ThingWorx 6.6 instances, this will solve the websocket handshake problem in the future. Unfortunately we don't have an estimated time when this process will be completed.

Plese let me know if you are in need of further assistance.

Thank you,

Veronica

View solution in original post

2 REPLIES 2
vmihai
12-Amethyst
(To:mbonelli1)

Hi Michael,

Have you tried to successfully connect to ThingWorx until now using ThingWorx Java Edge SDK ? The problem seems to be caused by your network not accepting websocket connections. Please run the echo websocket test without TLS in your browser to make sure websocket connections are indeed allowed on your network. Simply press connect in the url I linked to above. If you see Connected as in the picture below then websocket connections are allowed on your network.

On the other hand if your network fails the echo websocket test, please contact your network administrator to have them enabled or try using a different network. We are currently working on updating all academic hosted instances to https ThingWorx 6.6 instances, this will solve the websocket handshake problem in the future. Unfortunately we don't have an estimated time when this process will be completed.

Plese let me know if you are in need of further assistance.

Thank you,

Veronica

Hi Veronica,

I tried to run the test as you said and this was the result:

websocket.png

What is incredible though is that I run again the application after the test without changing anything and now it works!!! I don't have really know how but it does! The only explanation is that something in my network wasn't working well before!

Thank you for answering in such a short amount of time! The test was useful to understand if it was a problem that I had or not! I really appreciate it!

Michael

Announcements


Top Tags