0

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

Community
  • 1
  • 1
Ben
  • 1,579
  • 4
  • 20
  • 34

2 Answers2

1

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.

Caleryn
  • 1,084
  • 3
  • 18
  • 23
0

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();
user229044
  • 232,980
  • 40
  • 330
  • 338
Thierry Boileau
  • 866
  • 5
  • 8