I have developed a rest service plugin on my jira instance which acts as a middle man service. This service does some magic before eventually calling the standard create Issue service in the standard Jira Rest API.
I'm trying to get the user context / credentials used in the call to my middle man service and pass them in the call to standard create issue rest service. I'm trying to do this by using a cookie in the header, something like this:-
ClientResponse response = webResource.header("Cookie", "JSESSIONID=" + sessionId) .type("application/json") .accept("application/json") .post(ClientResponse.class, json);
The problem is that I don't know how to find the session id within the rest service (sessionId variable in the above code). I've done a similar thing in a table panel plugin which calls a rest service and this works fine, something like this:-
Map sessionMap = ActionContext.getSession(); String sessionId = ((String) sessionMap.get("ASESSIONID")).replaceAll("[0-9a-z]*-", "");
How can I get the session Id within a rest service?
Community moderators have prevented the ability to post new answers.
You can inject an HttpHeaders parameter into your REST method:
@GET @AnonymousAllowed @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response getSomething(@Context HttpHeaders headers, @QueryParam("username") String username) { ... Map<String, Cookie> existingCookies = headers.getCookies(); }
Alternatively, you could use @CookieParam if you just wanted the JSESSIONID, viz:
@GET @AnonymousAllowed @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response getSomething(@CookieParam("JSESSIONID") String jsessionId, @QueryParam("username") String username) { .... }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.