Re: Wattdepot problem

8 views
Skip to first unread message

Robert Brewer

unread,
May 26, 2011, 3:51:09 PM5/26/11
to Levesque, Martin, yashj...@gmail.com, wattdep...@googlegroups.com
On Thu, May 26, 2011 at 6:15 AM, Levesque, Martin <leve...@emt.inrs.ca> wrote:
> Hello,
>
> We are working on wattdepot and we have some problems.
>
> Here the code:
>
> ------------------
>
> WattDepotClient client = WattDepotUtil.getWattDepotClient();
>
>
>                SensorData data;
>
>            try {
>              XMLGregorianCalendar timestamp = Tstamp.makeTimestamp();
>
>              System.out.println("TIMEEEEEEEEEE = " + timestamp);
>
>              Property temperature = new Property(SensorData.POWER_CONSUMED, 6);
>
>              String sourceUri = Source.sourceToUri(smart_grid.Constants.sensorNameTemperature(1), smart_grid.Constants.WATTDEPOT_SERV);
>              System.out.println("source from blurp. " + sourceUri);
>              data = new SensorData(timestamp, "PrettySensor", sourceUri);
>              data.addProperty(temperature);
>
>
>              System.out.println("source from data " + data.getSource());
>
>              client.storeSensorData(data);
>            }
>            catch (Exception e) {
>              e.printStackTrace();
>
>              return;
>            }
>
> -----------------------------
>
>
> And we have the following error:
>
> org.wattdepot.client.BadXmlException: 400: Request generated error: SensorData payload Source field does not match source field in URI:   Request: PUT http://127.0.0.1:8182/wattdepot/sources/temp/sensordata/2011-05-26T12:01:20.219-04:00
>        at org.wattdepot.client.WattDepotClient.storeSensorData(WattDepotClient.java:997)
>        at smart_grid.home.InsertDummyTemperatures.main(InsertDummyTemperatures.java:45)
>
> I used wireshark (like tcpdump) to capture the real TCP requests and the XML really contains <Source>http://127.0.0.1:8182/wattdepot/sources/temp</Source>
>
> Do you have any idea/tips ?
>
> Thanks !
>
> --
> Martin Lévesque
> PhD student
> Optical Zeitgeist Laboratory
> Institut National de la Recherche Scientifique (INRS)
> Montreal, QC, H5A 1K6
> Canada

Hello Martin. I hope you don't mind, but I've Cc'ed the
wattdepot-users mailing list so others may benefit from the debugging.
You might want to subscribe to the list, it's very low traffic at this
point.

The section of server code that does the check is this:

// Return failure if the SensorData Source doesn't match the uriSource
Source source = dbManager.getSource(uriSource);
if (!source.toUri(server).equals(data.getSource())) {
setStatusMiscError("SensorData payload Source field does not
match source field in URI");
return;
}

From the look of the error message and your Wireshark sniffing, it
appears that the source name is "temp" in both places, as it should
be. I think the problem might be that the server error message doesn't
quite describe the check being performed. The error message says that
the source names don't match, but here I am actually checking that the
whole Source URI contained in the SensorData matches the URI that the
server thinks the Source should have.

Does your wattdepot-server.properties file have a
"wattdepot-server.hostname" property entry? If so, the WattDepot
server will listen on the specified IP address and expect that to be
the canonical form of its URI, but it will also accept requests from
localhost (127.0.0.1). If you are using the hostname property to
listen on a particular IP address, when the server starts up it will
print something like:

2010/02/26 18:25:31 Host: http://server.wattdepot.org:8182/wattdepot/

If you see that, then your client needs to send SensorData objects
that have a source URI that looks like

http://server.wattdepot.org:8182/wattdepot/sources/temp

and not like

http://127.0.0.1:8182/wattdepot/sources/temp

If your server outputs something like this on startup:

2011/05/26 09:39:57 Host: http://127.0.0.1:8182/wattdepot/

then I am still stumped as to what is going on.

In the short term, I will add an issue to change the error message to
be more descriptive by indicating the that source URIs don't match and
actually printing the server's expected Source URI.

Longer term, requiring that SensorData include the Source URI was a
bad design decision stemming from drinking the REST API kool aid.
While there are aspects of RESTfulness in the REST API, it isn't fully
RESTful, yet we still incur the cost of silly things like Source URIs
in the SensorData representation. If I ever get around to a major
rewrite, this kind of thing will be removed, making life easier for
server and client.

Can I ask what project you are using WattDepot for?

--
Robert Brewer
http://excitedcuriosity.wordpress.com/
https://www.facebook.com/kukuicup

Reply all
Reply to author
Forward
0 new messages