用于 REST 服务的 GSN 虚拟传感器包装器

GSN virtual sensor wrapper for a REST service

我正在尝试为 REST 服务编写 GSN 包装器,returns 从浏览器调用时会输出以下内容:

1, 23.22

然而,我写的包装器并没有真正起作用。知道我做错了什么吗?

WRAPPER

<?xml version="1.0" encoding="UTF-8"?>
<virtual-sensor name="ForecastService" priority="10" >
<processing-class>
    <class-name>org.openiot.gsn.vsensor.BridgeVirtualSensor</class-name>
    <init-params>
        <param name="allow-nulls">false</param>
        <param name="publish-to-lsm">true</param>
    </init-params>
    <output-structure>
        <field name="rain" type="Integer" />
        <field name="temperature" type="Double" />
    </output-structure>
</processing-class>
<description>weather forecast station</description>
<life-cycle pool-size="10"/>
<addressing>
    <predicate key="geographical"></predicate>
</addressing>
<storage history-size="1" />
<streams>
    <stream name="input1">
        <source alias="source1" sampling-rate="1" storage-size="1">
            <address wrapper="http-get">
                <predicate key="url">http://192.168.1.100:8080/ForecastService/webresources/forecastservice/forecast/true/csv</predicate>
                <predicate key="rate">1000</predicate>
            </address>
            <query>select * from wrapper</query>
        </source>
        <query>select * from source1</query>
    </stream>
</streams>

输出

18:16:11.229 [VSensorLoader-Thread0] DEBUG org.openiot.gsn.beans.StreamSource - validate() called
18:16:11.229 [VSensorLoader-Thread0] DEBUG org.openiot.gsn.VSensorLoader - Preparing input streams for: forecastservice
18:16:11.230 [VSensorLoader-Thread0] DEBUG o.o.g.w.general.HttpGetWrapper - AXISWirelessCameraWrapper is now running @1000 Rate.
18:16:11.230 [VSensorLoader-Thread0] DEBUG org.openiot.gsn.VSensorLoader - Wrapper name: Http Receiver -- view name _774699928
18:16:11.230 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.240 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.240 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - The create table statement is : CREATE TABLE _774699928 (PK BIGINT NOT NULL IDENTITY, timed BIGINT NOT NULL, DATA Binary)
18:16:11.242 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - The create index statement is : CREATE  UNIQUE  INDEX _774699928_INDEX ON _774699928 (timed DESC)
18:16:11.244 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.250 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.251 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Dropping table structure: _sql_view_helper_ With query: Drop table if exists _sql_view_helper_
18:16:11.263 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.264 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - The create table statement is : CREATE TABLE _sql_view_helper_ (PK BIGINT NOT NULL IDENTITY, timed BIGINT NOT NULL, U_ID varchar(17))
18:16:11.264 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - The create index statement is : CREATE  INDEX _sql_view_helper__INDEX ON _sql_view_helper_ (timed DESC)
18:16:11.266 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.270 [VSensorLoader-Thread0] DEBUG o.o.g.b.w.TupleBasedSlidingHandler - The original Query : select * from wrapper
18:16:11.271 [VSensorLoader-Thread0] DEBUG o.o.g.b.w.TupleBasedSlidingHandler - The merged query : select * from  (select * from _774699928 where timed >= (select distinct(timed) from _774699928 where timed in (select timed from _774699928 order by timed desc limit 1 offset 0 )) order by timed desc ) of the StreamSource source1 of the InputStream: input1
18:16:11.271 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.271 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Creating a view:create view __911689473 AS ( select * from  (select * from _774699928 where timed >= (select distinct(timed) from _774699928 where timed in (select timed from _774699928 order by timed desc limit 1 offset 0 )) order by timed desc ) )
18:16:11.274 [VSensorLoader-Thread0] DEBUG o.o.gsn.wrappers.AbstractWrapper - Adding listeners:  Stream Source object:  Alias: source1 uidS: __911689473 Active source: [http-geturl = http://192.168.1.100:8080/ForecastService/webresources/forecastservice/forecast/true/csv,rate = 1000,]
18:16:11.274 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.277 [VSensorLoader-Thread0] ERROR org.openiot.gsn.VSensorLoader - The column : RAIN in the >forecastservice< table is not compatible with type : Integer. The actual type for this table (currently in the database): 2005
org.openiot.gsn.utils.GSNRuntimeException: The column : RAIN in the >forecastservice< table is not compatible with type : Integer. The actual type for this table (currently in the database): 2005
    at org.openiot.gsn.storage.StorageManager.tableExists(StorageManager.java:241) ~[classes/:na]
    at org.openiot.gsn.storage.StorageManager.tableExists(StorageManager.java:270) ~[classes/:na]
    at org.openiot.gsn.VSensorLoader.loadPlugin(VSensorLoader.java:255) ~[classes/:na]
    at org.openiot.gsn.VSensorLoader.loadPlugin(VSensorLoader.java:210) ~[classes/:na]
    at org.openiot.gsn.VSensorLoader.run(VSensorLoader.java:134) ~[classes/:na]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]

基本上您需要编写自己的 REST 服务包装器并读取结果。在我的例子中,我有一个天气预报服务,并编写了一个名为 ForecastServiceWrapper 的包装器。我使用 forecast-service-get 在 wrapper.properties 中映射了这个包装器,并编写了虚拟传感器的描述并将其添加到 VirtualSensor 文件夹中。以下是传感器的描述。

<?xml version="1.0" encoding="UTF-8"?>
<virtual-sensor name="ForecastService" priority="10" >
    <processing-class>
        <class-name>org.openiot.gsn.vsensor.BridgeVirtualSensor</class-name>
        <init-params>
            <param name="allow-nulls">false</param>
            <param name="publish-to-lsm">true</param>
        </init-params>
        <output-structure>
            <field name="rain" type="Integer" />
            <field name="temperature" type="Double" />
        </output-structure>
    </processing-class>
    <description>weather forecast station</description>
    <life-cycle pool-size="10"/>
    <addressing>
        <predicate key="geographical"></predicate>
    </addressing>
    <storage history-size="1" />
    <streams>
        <stream name="input1">
            <source alias="source1" sampling-rate="1" storage-size="1">
                <address wrapper="forecast-service-get">
                    <predicate key="url">http://192.168.1.100:8080/ForecastService/webresources/forecastservice/forecast/true/csv</predicate>
                    <predicate key="rate">1000</predicate>
                </address>
                <query>select * from wrapper</query>
            </source>
            <query>select * from source1</query>
        </stream>
    </streams>
</virtual-sensor>