Servlet: static files?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Bug Labs Forum Index -> BUG SDK
View previous topic :: View next topic  
Author Message
finsprings



Joined: 25 Sep 2007
Posts: 267
Location: Pittsburgh, PA

PostPosted: Sun Jan 27, 2008 11:16 pm    Post subject: Reply with quote

Any update on this Ken? Basically, how would one server up image files that didn't exist at module deployment?

Also, on a related matter, any further thoughts to file system access from modules? In the emulator, the BUGer log and image files get written to the current working directory, in my case where the eclipse binary is. Some means of exposing module-specific permanent storage in a a file-system agnostic fashion would be nice.
Back to top
View user's profile Send private message Visit poster's website
kengilmer



Joined: 25 Sep 2007
Posts: 183
Location: New York, NY

PostPosted: Mon Jan 28, 2008 12:11 pm    Post subject: Reply with quote

Dave,

Very sorry, let this one slip through the cracks. In the future if you don't get an answer from me within a day or two feel free to email me...

IRT serving dynamic content, my first approach would be to implement doGet() on the servlet and not use a resource at all. This is how the Camera bundle works...see com.buglabs.bug.module.camera.CameraModlet. This is a little more comples though because it's using the PublicWSAdmin service to expose the image via the BUG Services WS API. Another approach would be to implement your own HttpContext class that handles the getResource() method. In this case you can do custom logic to retrieve your dynamic files.

In regards to file system locations, yes this is a very good question, and there is a solution in the OSGi framework already. There is a method on BundleContext that returns a path to a place in the filesystem where files can be written to. See BundleContext.getDataFile(). This should be used in order to be assured that a specific point in the filesystem is not read-only.
_________________
thanks!
ken

Bug Labs
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
finsprings



Joined: 25 Sep 2007
Posts: 267
Location: Pittsburgh, PA

PostPosted: Tue Jan 29, 2008 11:25 pm    Post subject: Reply with quote

Thanks Ken. I got the BundleContext stuff working, so I'm no longer pooping in the Eclipse directory, which is great. I looked at CameraModlet but didn't see a doGet so I will need to do some research on the WSAdmin stuff to get up to speed.
Back to top
View user's profile Send private message Visit poster's website
finsprings



Joined: 25 Sep 2007
Posts: 267
Location: Pittsburgh, PA

PostPosted: Thu Jan 31, 2008 11:04 pm    Post subject: Reply with quote

Ken, I managed to get a static image to work, in a similar manner to your 'buck' test case. I had to make a subdir under my Resources dir in the app jar that matched the alias I registered the resource at, but other than that it wasn't too tricky.

So now it looks a little bit prettier:


I've still got to get to the dynamic image part. That's next. For now, I pushed out v1.0.5 of BUGer to bugnet with the buglogo in it as above.
Back to top
View user's profile Send private message Visit poster's website
kengilmer



Joined: 25 Sep 2007
Posts: 183
Location: New York, NY

PostPosted: Fri Feb 01, 2008 4:54 pm    Post subject: Reply with quote

Dave,

Nice work! For dynamic images you could create a PublicWSProvider that serves up images or you could have just another servlet. I haven't tried this but as I mentioned earlier you should also be able to provide a custom HttpContext class.
_________________
thanks!
ken

Bug Labs
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
finsprings



Joined: 25 Sep 2007
Posts: 267
Location: Pittsburgh, PA

PostPosted: Fri Feb 01, 2008 8:11 pm    Post subject: Reply with quote

Thanks Ken. Since I already had to use an HttpContext to get the static resource, it was fairly easy to create another one to get the dynamic images.

So now BUGer finally displays the images that are captured when motion is detected:
Back to top
View user's profile Send private message Visit poster's website
finsprings



Joined: 25 Sep 2007
Posts: 267
Location: Pittsburgh, PA

PostPosted: Fri Feb 01, 2008 11:48 pm    Post subject: Reply with quote

Although it's working, I'm not sure I'm making use of the HttpContexts properly. For my static image I set the alias to /bugerresources and mapped it to /Resources when I registered the context. I couldn't make the alias /buger or it would just be subsumed by my servlet. But to find the static image resource (the bug logo), I had to put it at Resources/bugerresources/buglogo.jpg and refer to it in the HTML as /bugerresources/buglogo.jpg. That seemed a little clunky to me: if I'm registering a mapping from /bugerresources to /Resources, why do I need the subfolder under Resources to get the mapping to work?

Then, for the captured images I registered another HttpContext for /bugercapture mapped to "". I referred to the images as /bugercapture/<timestamp>.jpg in the HTML. In the getResource() method of my HttpContext I stripped off the leading /bugercapture/ part and called
Code:
return context.getDataFile( fileName ).toURL()
to return a URL for the image file where it resides in the persistent storage area. Again, having to mess with the string made it seem like I wasn't doing something quite right.

So, it's working, but am I doing it the right way?
Back to top
View user's profile Send private message Visit poster's website
finsprings



Joined: 25 Sep 2007
Posts: 267
Location: Pittsburgh, PA

PostPosted: Mon Feb 04, 2008 4:29 pm    Post subject: Reply with quote

While, I'm at it with the questions, is there a more official way of linking the servlet jar? I'm still including a copy in my bug app, which works but is presumably not correct.
Back to top
View user's profile Send private message Visit poster's website
kengilmer



Joined: 25 Sep 2007
Posts: 183
Location: New York, NY

PostPosted: Tue Feb 12, 2008 12:13 pm    Post subject: Reply with quote

Hi Dave,

Regarding the proper usage of HttpContext and servlets, yeah it does seem kind of clunky. I would suggest emailing the OSGI-DEV mailing list regarding the proper use of this. They won't know anything about BUG but the HTTP Service is an OSGi spec. You can find out more about that at http://osgi.org.

Regarding the servlet JAR. it's now being bundled inside com.buglabs.osgi.http. I'm not sure what version you are using but if don't find the classes there (zipinfo com.buglabs.osgi.http.jar) then grab a newer version from our website.

hope that helps
_________________
thanks!
ken

Bug Labs
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
finsprings



Joined: 25 Sep 2007
Posts: 267
Location: Pittsburgh, PA

PostPosted: Tue Feb 12, 2008 4:10 pm    Post subject: Reply with quote

Thanks Ken. I removed the inclusion of servlet.jar from BUGer and it still works, so it must now be picking that app from the SDK - way cool. I also had to make a fix so that if you unplug a module BUGer cares about (camera or motion), it now unregisters the 2 HTTP resources it was registering. Without doing that, it would fail to reregister those resources when you plugged the module back in. Pushed v1.0.7 to bugnet with the changes.

As to the OSGi thing: I'm okay with it being clunky as long as that's the 'approved' way to do it on the bug. I just didn't want to set a bad example when posting this app to bugnet.

Cheers,
Dave
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Bug Labs Forum Index -> BUG SDK All times are GMT - 5 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

FAQ   |   Search   |   Memberlist   |   Usergroups   |   Register   |   Profile

Email forums administrator

Bannersmonster.Com © 2007
Powered by phpBB © 2001, 2002 phpBB Group
Designed by:linux hostingHotel