rbrastad
rbrastad

Reputation: 36

Endpoint authentication, Trying to add header JSESSION to ClientService in JAVA API

I'm implementing a custom API on top of SBT. I'm doing this so I can manipulate and transform the response from connections before returning it to the user.

The basic auth with username and password is working. But I can't seem to find out how I can add the JSESSIONID header to ClientService (ClientService.Args) on a request before its sent.

Any idea how this can be done ?

Upvotes: 0

Views: 180

Answers (2)

Manish Kataria
Manish Kataria

Reputation: 78

Since REST is stateless, in theory you should not be needing JSESSIONID cookie, which is used for preserving state of loggedin user. However if you do wish to add that you should be doing it in below way :

In the specific endpoint class ( like BasicEndpoint.java for Basic Authentication ), look for the initialize method, it would be registering an interceptor, BasicInterceptor in this case. In process method of BasicInterceptor you can add the cookie like

request.setHeader("Cookie", "JESSION string goes here");

This code intercepts all outgoing requests and would add the cookie header.

Hope this helps.

Upvotes: 1

Paul Bastide
Paul Bastide

Reputation: 1503

when you make the request, the JSESSIONID cookie should already be in the response when you do the BASICAUTH.

Also JSESSIONID is not guaranteed to be the unique identifier for a WAS appserver.

Upvotes: 0

Related Questions