Keep fighting content issues with restlet 2.0-snapshot (from July 9th)

2009-08-05 Thread Fabian Mandelbaum
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


SecurityContext with JaxRS Extension

2009-08-05 Thread Jonas Huckestein
Hello,

first of all, thanks for the amazing restlet framework and the awesome
Jax-RS extension.

I am currently trying to understand how to use @Context SecurityContext. I
do not know how I can make the injected SecurityContext do anything.


This is what I have:
- A function which takes an Authorization header and returns the 
username
and a list of roles (as strings) or throws an exception
This is what I want to do:
- Have access to a SecurityContext in all my resources, which returns 
the
username and can check whether or not he is in a specific role

How can I achieve this?

- Do I have to implement SecurityContext?
- Is security Context automatically (due to the Jax-RS runtime) aware of
Restlet guards?

When I try implementing SecurityContext (as per the JSR 311 Specs)

public class StockWatchSecurity implements ContextResolverSecurityContext,
SecurityContext { ... }

my resource is not even loaded (an error 404 is returned on its path).

I have also implemented a Guard, but since I am using the 2.0 M3 release and
there is not much documentation, I am confused which classes I need to use
how. For a start, I did this:

public class MyJaxRSApp extends JaxRsApplication {
   public MyJaxRSApp() {
   super(Context.getCurrent());
   getContext().getLogger().setLevel(Level.FINE);
   getContext().setVerifier(new MyVerifier());
   this.add(new MyJaxRSAppConfig());
   this.setGuard(new ChallengeGuard(getContext(),ChallengeScheme.CUSTOM,
realm));
   }
}

Thanks in advance and kind regards, Jonas
-- 
View this message in context: 
http://n2.nabble.com/SecurityContext-with-JaxRS-Extension-tp3395983p3395983.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2380678