On Mar 25, 3:39 pm, d95sld95 steen.laur...@gmail.com wrote:
Environment: GWT 2.0.3 + Image serving -- using Apache CXF restful
service
I am working on an application that shows thumbnails in a list/grid
view. Each row resembles a media item (picture, video, audio, etc).
Some media has thumbnails like picture and video, other do not like
audio. Also some media items will fail to generate a thumbnail even
though it is a picture or video.
I am currently loading the thumbnail in the grid using GWT Image
class. I call the setUrl('...'). That works great.
Image image = new Image()
image.setUrl(RESTful/url/to/media/thumbnail/ + mediaItem.getId());
My problem is audio-like media items and exception handling when no
thumbnail was generated. I would like to show a default thumbnail for
audio and another default thumbnail for a failed video thumbnail for
example.
The idea is that the restful service returns a HTTP status code of 204
- No Content.
Official description of 204:
The server has fulfilled the request but does not need to return an
entity-body, and might want to return updated metainformation. The response
MAY include new or updated metainformation in the form of entity-headers,
which if present SHOULD be associated with the requested variant.
If the client is a user agent, it SHOULD NOT change its document view
from that which caused the request to be sent. This response is
primarily intended to allow input for actions to take place without
causing a change to the user agent's active document view, although
any new or updated metainformation SHOULD be applied to the document
currently in the user agent's active view.
The 204 response MUST NOT include a message-body, and thus is always
terminated by the first empty line after the header fields.
Ok - so I do not want to return a standard thumbnail from the server
because I want the application to be skinnable and our Web Service
users might not want to use our standard error or audio thumbnails. So
I think it is better not to return any thumbnail and just return a 204
+ set a response header with a status (1=audio, 2=no video thumbnail,
3=no picture thumbnail, etc. ). That way the client can use this
information to show a standard thumbnail and skin it as suitable.
Now, Image has an addErrorHandler(new ErrorHandler()); method. But the
ErrorEvent does not give me any information about HTTP status nor can
I access the Response object.
I would like to do something like this:
Image image = new Image();
image.addErrorHandler(new ErrorHandler() {
public void onError(ErrorEvent errorEvent) {
// somehow access the HTTPResponse object
if (response.getStatus == Response.SC_NO_CONTENT) {
String thumbnailType = response.getHeader(thumbnail-
type);
if (1.equals(thumbnailType)) {
// show default audio thumbnail
} else if (2.equals(thumbnailType)) {
// show default missing video thumbnail
}
} else {
// show error thumbnail
}
}});
image.setUrl(RESTful/url/to/media/thumbnail/ + mediaItem.getId());
Showing the thumbnails in audio and error situations would be done
using a CSS stylesheet by adding a class to the thumbnail div.
I see two solutions (which are not mutually exclusive):
1. the media gives you its thumbnail URL if it has one, so you
choose upfront whether you show a standard thumbail or not (i.e.
image.setUrl(mediaItem.getThumbnailUrl())); this also has the
advantage of being more RESTful (HATEOAS)
2. the server redirects to a new URL (303) instead of returning a 204
(when there's no thumbail to display) or an error code (in case it
cannot generate the thumbnail). Then on the onload event you grab the
image's final URL and act accordingly (i.e. if it's a known
standard thumbnail URL then you replace it with your skinned image)
You'd likely use 1. for audio and 2. for videos and pictures.
Other solutions include:
* passing the standard thumbnail and error thumbnail as part of
the request (as paths or some kind of IDs on the query-string) and let
the server return either the actual thumbnail for the media or one of
the images you pass (either forwarding on the server-side or
redirecting with a 303 as in 2. above)
* making a pre-flight request (RequestBuilder) to get the status-
code and handle exceptions, and if the server returns a 200 (or
304?) meaning it can give you an image, then create the Image with the
very same URL to display it (if cache is properly managed, the browser
could re-use the just-returned image from its cache instead of issuing
a new request)
On Mar 25, 3:46 pm, d95sld95 steen.laur...@gmail.com wrote:
By the way, I looked at using the RequestBuilder but I believe it does
not handle binary data. Am I correct?
Yes.
--
You received this message because you are subscribed to the Google Groups
Google Web Toolkit