Hello there, here I am again with my content issues with restlet
2.0-snapshot (from 2009-07-09):
The Content-Type header of the response is always set to */*
(according to the HttpFox http traffic monitor), no matter which
MediaType I pass to the representation constructor of the returned
representation.
example code for a ServerResource retrieving a file and 'streaming' it
back to the client:
@Get
@Override
public Representation get() throws ResourceException {
long lstart = System.currentTimeMillis();
Session session = null;
try {
session = RepoManager.getInstance().getSessionRO();
StaticContentDAO dao = new StaticContentDAO(session);
Content content = dao.retrieve(ffname);
File tempFile = File.createTempFile(cco, null); // NOI18N
FileUtils.forceDeleteOnExit(tempFile);
FileOutputStream fos = FileUtils.openOutputStream(tempFile);
IOUtils.copy(new AutoCloseInputStream(content.getFstream()), fos);
MediaType mt =
getApplication().getMetadataService().getMediaType(FilenameUtils.getExtension(ffname));
getLogger().info(String.format(%s has media type %s, ffname, mt));
FileRepresentation rep = new FileRepresentation(tempFile, mt);
DateTime dt = new DateTime();
dt = dt.plusYears(2); // 2 yrs from now (far future)
rep.setExpirationDate(dt.toDate());
return rep;
}
catch (Exception e) {
// Error 500
String msg = String.format(Backend (JCR/IO) problem
retrieveing /%s, ffname);
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, msg, e);
}
finally {
if (session != null)
session.logout();
long lstop = System.currentTimeMillis();
getLogger().info(String.format(Request processed in
%2.3f sec.,
(lstop - lstart) / 1000.0));
}
}
ffname is login.html, which is a simple XHTML 1.0 Transitional page.
The logger output is correctly: login.html has media type text/html
However, the Content-Type header of the response is not text/html (as
it should), but */*
This happens also for other media types (correctly identified by the
MetaDataService), not just for html, */* is *always* set as
Content-Type
This little 'feature' is making most web browsers (IE and Safari)
asking me to download the page (which they don't even recognize it's
an html file, they take it to be binary) instead of displaying it.
Firefox works fine, and IIRC, Opera and Chrome too.
Is this is known issue? Am I the only one testing my app in more than
one browser? Was this reported before and fixed in the current 2.0
snapshot?
Thanks in advance for your (as usual) prompt and accurate answers.
--
Fabián Mandelbaum
IS Engineer
--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2380455