4 Replies Latest reply on Nov 18, 2016 5:06 AM by nlink RSS
    nlink Newbie

    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