Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
Hi,
I am exploring the rest apis and java sdk apis for ThingWorx 8.5. I want to fetch the metadata of a Thing. I can do the same via REST api - <server/Thingworx/Things/{thing_name}. It returns json that contains all the services listed under key serviceMappings with their implementation under key serviceImplementations -
But the parallel java api on ConnectedThingClient getThing(<name>).getMetadata() returns _serviceDefinitionCollection and _serviceProcessors as null.
Am I missing anything here? How can I fetch the metadata for the Things' services ?
Update : Java sdk version latest - 6.1.0.679, ThingWorx Foundation version - 8.5
Solved! Go to Solution.
You can make the same calls that the platform uses like EntityServices.getEntityList() but be careful because collecting this kind of data can return a lot of rows. This makes is hard to get your timeout correctly. Use the row limits parameter and do not try to make a single call to get it all because the total number of entities grows over time and eventually you will start timing out on your service calls.
Have you called initializeFromAnnotations() in your VirtualThing constructor?
The classes you are getting back from the getMetaData() call are not obtained from the platform, they are generated from the annotations on your Thing.
If you want to make the same service call you did using REST you would have to connect to ThingWorx using the SDK and then call:
InfoTable theMetaData = thing.invokeService("getMetadata", new ValueCollection());
This call would cause the SDK to make a service request to the platform, like you did with your original REST request.
Hi,
I have a Thing named MyHouse on the platform. I am trying to connect to the platform using following snippet -
VirtualThing myHouse = new VirtualThing("MyHouse", "Sample Description", client);
client.bindThing(myHouse);
client.start();
InfoTable metadata = myHouse.invokeService("GetMetadata", new ValueCollection());
This returns an empty InfoTable instance.
When I used invokeService() api, I get the correct result InfoTable -
InfoTable metadata = client.invokeService(RelationshipTypes.ThingworxEntityTypes.Things, "MyHouse", "GetMetadata", new ValueCollection(), 30000);
Is this a correct way to connect to the platform?
Both methods should work the same. Client.InvokeService() needs to know what Thing you want to talk to. VirtualThing.invokeService() already knows this. The calls work the same way. The difference is that VirtualThing.invokeService() is dependent on the presence of Metadata either provided through annotations or through service bindings established on the platform. You bypass all that with Client.InvokeService() and I should have offered that to you as an option in the first place. You are doing things the correct way.
Also, you are now doing the exact same thing you were doing when you were using the REST interface.
Hi @billrei ,
I need to fetch the metadata of ThingWorx entities from my foundation via java client program i.e. all Things, ThingTemplates, ThingShapes and so on. After going through the REST api guide, it seems that we can fetch these via a simple call -
GET <server>/Thingworx/{entityType}?<appkey_header>
To achieve the same via java apis, I tried -
ConnectedThingClient client = new ConnectedThingClient(config);
client.start();
Collection<VirtualThing> virtualThingCollection = connectedThingClient.getThings().values();
But, as you mentioned in previous reply, VirtualThing.invokeService() will fetch the details defined by the annotations. And similarly this client.getThings() also runs only on the bound Things and won't work for the use case where we don't know the entity name.
So how can we replicate the above rest api in java? Like CreateThing service, are there any fetch services under EntityServices that I can use?
POST /Resources/EntityServices/Services/{serviceName}
What information are you after? Which properties have been bound?
I want to fetch all the existing Thingworx entities, like in Oracle we can get the metadata of the whole data base - list and definitions of tables, views, procedures etc. Similarly, I want all the metadata in some specified ThingWorx foundation.
You can make the same calls that the platform uses like EntityServices.getEntityList() but be careful because collecting this kind of data can return a lot of rows. This makes is hard to get your timeout correctly. Use the row limits parameter and do not try to make a single call to get it all because the total number of entities grows over time and eventually you will start timing out on your service calls.
Thank you @billrei for the help. Now I can replicate all the rest calls via java apis. And you are right, we need to take care while fetching the list of all existing entities.