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

How to implement remote ThingTemplate from "RemoteThingWithTunnelsAndFileTransfer" in a Java extension?

SOLVED
Level 1

How to implement remote ThingTemplate from "RemoteThingWithTunnelsAndFileTransfer" in a Java extension?

Hello,

I want to implement a custom ThingTemplate in a Java extension that implements "RemoteThingWithTunnelsAndFileTransfer". This template will have several properties and services, and a remote agent will use it to send its data to Thingworx. This seems to be a rather easy task to do, but I can't get it to work properly. Based on the eclipse plugin, this is what I came up with:

Java:

@ThingworxBaseTemplateDefinition(name = "RemoteThingWithTunnelsAndFileTransfer")

public class TestTemplate extends Thing

{

    public TestTemplate()

    {

    }

    @ThingworxServiceDefinition(name = "TestService", description = "", category = "", isAllowOverride = false, aspects = {

            "isAsync:false" })

    @ThingworxServiceResult(name = "result", description = "", baseType = "STRING", aspects = {})

    public String TestService()

    {

        return "Hello World!";

    }

}

metadata.xml:

<ThingPackages>

    <ThingPackage className="com.test.TestTemplate" description="" name="TestTemplatePackage"/>

</ThingPackages>

<ThingTemplates>

    <ThingTemplate aspect.isEditableExtensionObject="false" description="" name="TestTemplate" thingPackage="TestTemplatePackage"/>

<ThingTemplates>

If I import this extension to Thingworx and create a Thing from "TestTemplate", I can call service "TestService" correctly, but none of the services defined in sub templates or shapes. Calling one of these services (e.g. "GetTunnels") gives me the following exception:

Unable to Invoke Service GetTunnels on TestThing : object is not an instance of declaring class

Now I found out that if I modify metadata.xml to contain "baseThingTemplate" like:

<ThingPackages>

    <ThingPackage className="com.test.TestTemplate" description="" name="TestTemplatePackage"/>

</ThingPackages>

<ThingTemplates>

    <ThingTemplate aspect.isEditableExtensionObject="false" description="" name="TestTemplate" thingPackage="TestTemplatePackage" baseThingTemplate="RemoteThingWithTunnelsAndFileTransfer"/>

<ThingTemplates>

it is now possible to call services from sub templates and shapes correctly, but my "TestService" has disappeared. It doesn't show up in Composer anymore.

Does anyone know what is going on?

I am implementing with Thingworx 7.2.5 and extensions sdk 7.2.5.

Thanks,

Norman

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to implement remote ThingTemplate from "RemoteThingWithTunnelsAndFileTransfer" in a Java extension?

Hi,

For reference, here is how I fixed it. It might be useful for anyone who has the same problem.

When creating a RemoteThingWithTunnelsAndFileTransfer in an extension, the class itself must not be derived from "Thing" but from "RemoteThingWithTunnelsAndFileTransfer" since there are additional functions defined in this base class that are not defined in the "Thing" base class. The problem is that RemoteThingWithTunnelsAndFileTransfer is not part of the SDK by default. Instead, I used the file thingworx-platform-common-*.jar from Thingworx/WEB-INF inside the Tomcat directory.

So the original example code only needs a slight modification:

@ThingworxBaseTemplateDefinition(name = "RemoteThingWithTunnelsAndFileTransfer")

public class TestTemplate extends RemoteThingWithTunnelsAndFileTransfer

{ ... }


The exception

Unable to Invoke Service GetTunnels on TestThing : object is not an instance of declaring class

basically means that a function was requested to be called on the instance that does not exist, i.e. it is not part of any of the base classes.


Best regards,

Norman

4 REPLIES 4
Highlighted

Re: How to implement remote ThingTemplate from "RemoteThingWithTunnelsAndFileTransfer" in a Java extension?

Hello Norman,

You got your ans on this link : How to Transfer file EMS to Thingworx ?

I am using same Java sdk for file transfer to Thingworx.

Thanks,

Mayank

Re: How to implement remote ThingTemplate from "RemoteThingWithTunnelsAndFileTransfer" in a Java extension?

Hi Mayank,

Sorry, I don't see an answer to my question in the link you sent. The link was about file transfer, I wanted to know how to implement a remote ThingTemplate in Java. The exception I am getting seems to be related to inheritance or inspection problems.

Best regards,

Norman

Re: How to implement remote ThingTemplate from "RemoteThingWithTunnelsAndFileTransfer" in a Java extension?

Please go through the link and let me know if you are able to do it right.

Tunneling with ThingWorx and an Edge Device

Re: How to implement remote ThingTemplate from "RemoteThingWithTunnelsAndFileTransfer" in a Java extension?

Hi,

For reference, here is how I fixed it. It might be useful for anyone who has the same problem.

When creating a RemoteThingWithTunnelsAndFileTransfer in an extension, the class itself must not be derived from "Thing" but from "RemoteThingWithTunnelsAndFileTransfer" since there are additional functions defined in this base class that are not defined in the "Thing" base class. The problem is that RemoteThingWithTunnelsAndFileTransfer is not part of the SDK by default. Instead, I used the file thingworx-platform-common-*.jar from Thingworx/WEB-INF inside the Tomcat directory.

So the original example code only needs a slight modification:

@ThingworxBaseTemplateDefinition(name = "RemoteThingWithTunnelsAndFileTransfer")

public class TestTemplate extends RemoteThingWithTunnelsAndFileTransfer

{ ... }


The exception

Unable to Invoke Service GetTunnels on TestThing : object is not an instance of declaring class

basically means that a function was requested to be called on the instance that does not exist, i.e. it is not part of any of the base classes.


Best regards,

Norman