Search code examples
javaresthttprequestrestletrestlet-2.0

Read out custom Header from a Restlet Request


I need to read out a custom header from a Restlet Request. According to this I tried

Form headers = (Form) request.getAttributes().get("org.restlet.http.headers");
String ltpaToken = headers.getFirstValue("LtpaToken2");

But this results in the following exception:

java.lang.ClassCastException: org.restlet.util.Series cannot be cast to org.restlet.data.Form

Therefore, how can I read out this custom header?

Thanks and best regards Ben


Solution

  • that was how to achive this in restlet 2.0.x I'm assuming that you are using a more recent version? at 2.1.x try

        Series<Header> series = (Series<Header>)getRequestAttributes().get("org.restlet.http.headers");
        series.getFirst("LtpaToken2");
    

    there was mention of a short cut method, so that you did not need the magic String org.restlet.http.headers but I'm not sure which version that was / is being introduced in.