Frage

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

War es hilfreich?

Lösung

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.

Andere Tipps

You can also use the org.restlet.engine.header.HeaderConstants#ATTRIBUTE_HEADERS class variable instead of "org.restlet.http.headers".

If you're not afraid of class casting:

((HttpRequest) getRequest()).getHeaders();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top