Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hi All,
I have a requirement. I have a value Stream associated with a thing. I am using this data to display on time series chart by using service QueryPropertyHistory. It works perfectly. Now I want to apply some complex logic on this value stream data , which can be easily doable in Java. So, I have decided to go with Java Server Side extension. How to start with this? Any example which can help me to start with this? How can get value stream data using service QueryPropertyHistory in java?
Thanks,
Azim
Solved! Go to Solution.
As per my understanding TRACE will include ERROR and INFO mode so we don't require separate entries for ERROR and INFO for the same package.
Try to log WARN log entry in the code to see if it shows? Also, try to change the ROOT level to INFO.
I hope it helps.
Could you please provide clarification on which extension you are talking about - did you download it from Marketplace, is it an officially ptc supported extension?
Hi azim hawaldar,
To begin with Java Extension, You need to:
1. Download Java Extension SDK from here.
2. Download Thingworx Eclipese plugin from Marketplace and check the user guide in the same place(Eclipse plugin is optional but it's very helpful for
your to convenienctly create a Thing/ThingTemplate, etc.)
3. Now you are ready to play with Java on Thingworx entity and services(QueryPropertyHistory for example). If you are not sure how to arrange your project structure and how to utilize the ThingWorx SDK,etc, please take reference to the document (I also attached the document here in case you could not open it).
Thanks,
Br,
Anna
Hi Anna An,
I have started with this. I got this document in one of the ptc's link. But this did not answer my question about how to test the code in extension before we import that into composer, so that I am sure that all my code works fine. Also, i could not find how to use QueryPropertyHistory. Appreciate your help if you can give me some sample code of how to consume QueryPropertyHistory and test the code something like junit will be helpful.
Thanks,
Azim
Hi azim hawaldar,
Please refer to following article to see if it answers your query: https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS250862
Hi azim hawaldar,
Full coverage unit tests are not possible in ThingWorx, but partial coverage is. If the logic that needs to be preserved is isolated from the statements that require context, then unit tests can be beneficial and functional.
Per my understanding; we would need to compile our project/ make an extension and then import it via composer. Then based on the application logs we can debug our code.
Hello Ankit Gupta,
As per your suggestions, I added log to debug the code. But these logs are not printing in application logs. Below if my code
// class level static logger variable
private static Logger _logger = LogUtilities.getInstance().getApplicationLogger(RollingStockThingTemplate.class);
somewhere in one of the method
_logger.info("Entering Service: GenerateFFTFromStream");
Am I doing anything wrong here?
Thanks,
Azim
Hello Ankit Gupta,
DId you got a chance to look into this? I am waiting for your response. Please check and let me know.
Thanks,
Azim
Hi azim hawaldar,
Please refer to this article: https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS229833&lang=en_US
Please add logback.xml and it will work. Just tested on my instance and it worked.
Hello Ankit Gupta,
I configured logback.xml and placed under D:\ThingworxPlatform. I see that logs are being generated here, however these are logs of extensions library not my codes logs.Below is the logback.xml, please can u explain me what I have done wrong here.
<configuration>
<!-- Create an appender for standard out using the following format
DateTime [L: LEVEL] [O: class] [T: Thread] message -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSSZ} [L: %level] [O: %logger{8}] [T: %thread]
%msg%n%rootException
</pattern>
</encoder>
</appender>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/thingworx/logs/application.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>/thingworx/application-%d.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSSZ} [L: %level] [O: %logger{8}]
[T: %thread] %msg%n%rootExceptionpattern>%date{yyyy-MM-dd HH:mm:ss.SSSZ}
[L: %level] [O: %logger{8}] [T: %thread] %msg%n%rootException</pattern>
</encoder>
</appender>
<!-- Log the SteamSensor at TRACE level -->
<logger name="com.thingworx" level="TRACE"></logger>
<!-- Log all classes in the com.ThingWorx namespace at ERROR level -->
<logger name="com.thingworx" level="ERROR"></logger>
<logger name="com.thingworx" level="INFO"></logger>
<!-- Set the default log level to WARN and log to the standard output and to a file -->
<root level="WARN">
<appender-ref ref="STDOUT" />
<appender-ref ref="ROLLING" />
</root>
</configuration>
Hi azim hawaldar,
This seems as the logs when the restart was done.
You will have to create a Thing based on the ThingTemplate you created in Extension and run the service to see the logs.
I hope it helps.
Hi Ankit Gupta,
I did the same. A thing was created in composer based on imported thing template. But no luck.
Thanks,
Azim
Strange! It worked for me. What is your ThingWorx version?
Also, could you please share the logback.xml
And was ThingWorx Tomcat restarted after placing the logback.xml in D:\ThingworxPlatform
Hi Ankit Gupta,
Version : 7.4
Tomcat was restarted after placing the logback.xml in D:\ThingworxPlatform. Below is the code for logback.xml
<configuration>
<!-- Create an appender for standard out using the following format
DateTime [L: LEVEL] [O: class] [T: Thread] message -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSSZ} [L: %level] [O: %logger{8}] [T: %thread]
%msg%n%rootException
</pattern>
</encoder>
</appender>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/thingworx/logs/application.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>/thingworx/application-%d.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSSZ} [L: %level] [O: %logger{8}]
[T: %thread] %msg%n%rootExceptionpattern>%date{yyyy-MM-dd HH:mm:ss.SSSZ}
[L: %level] [O: %logger{8}] [T: %thread] %msg%n%rootException</pattern>
</encoder>
</appender>
<!-- Log the SteamSensor at TRACE level -->
<logger name="com.thingworx" level="TRACE"></logger>
<!-- Log all classes in the com.ThingWorx namespace at ERROR level -->
<logger name="com.thingworx" level="ERROR"></logger>
<logger name="com.thingworx" level="INFO"></logger>
<!-- Set the default log level to WARN and log to the standard output and to a file -->
<root level="WARN">
<appender-ref ref="STDOUT" />
<appender-ref ref="ROLLING" />
</root>
</configuration>
As per my understanding TRACE will include ERROR and INFO mode so we don't require separate entries for ERROR and INFO for the same package.
Try to log WARN log entry in the code to see if it shows? Also, try to change the ROOT level to INFO.
I hope it helps.
Hi Ankit Gupta,
Thanks for the help. I missed to change the root level to INFO. I have marked your answer as correct. Once again a big thank you.
Thanks,
Azim
I am glad it helped.