Hi all,
I would like to simulate a user connection in my java class (for my jira service).
I mean, i want to set a local context to have administrator rights to do some actions :
I use the Power Report plugin, and i want to do an Http Get method to a specific servlet to this plugin. But to get back the stream from the servlet, I need to be connected, and it doesn't seem to work without being connected (the result stream I receive is an Http response like "403 forbidden : Access to the specified resouce has been forbidden).
Regards.
I found a solution to my problem.
I did not able to get my pdf file (the stream I told in the post) because I didn't send session cookies with my get request.
Here the code I wrote to work it well :
(temp.txt)
Hope it could be useful to someone in the future.
PS : Thank you Brice !
It would be even easier use the Birt Reports for JIRA instead because it runs Birt right inside JIRA and BIRT reports are accessible as JIRA urls.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bastien,
Yes, it is right. To get the result stream you have to be logged into JIRA application, otherwise you won't be able to retrieve it (Forbidden access : 403 HTTP error code)
As your service is executed on server side, I'm not sure you can simulate a client side behaviour...The Http Get request has to be made from client side.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is my code to simulate the user login :
HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "Jira Client"); PostMethod post = new PostMethod("http://localhost:8080/jira/rest/gadget/1.0/login"); NameValuePair[] data = { new NameValuePair("os_username", "admin"), new NameValuePair("os_password", "*********"), new NameValuePair("os_captcha", "") }; post.setRequestBody(data); BufferedReader br = null; try{ System.out.println("Connexion en post ..."); int returnCode = client.executeMethod(post); if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) { System.err.println("The Post method is not implemented by this URI"); post.getResponseBodyAsString(); } else { br = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream())); String readLine; while(((readLine = br.readLine()) != null)) { System.out.println(readLine); } }catch(Exception e){}
My last syso prints :
{"allowCookies":true,"externalUserManagement":false,
"isPublicMode":false,"isElevatedSecurityCheckShown":false,
"loginSucceeded":true,"captchaFailure":false,"loginError":false,
"communicationError":false,"loginFailedByPermissions":false}
So I guess i'm connected.
But i think the problem comes from cookies ... I have to put the correct cookie to jira and/or birt during the connectin, right ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried to add cookies to my get request, through this code :
Cookie[] cookies = client.getState().getCookies(); for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; initialState.addCookie(cookie); } client.setState(initialState); ... client.executeMethod(method);
But i've got the same error "403 - forbidden".
I analysed the network stream (with firebug) when i generated my pdf file by Power Report gadget, and all is same as my java code.
I don't understand why Birt engine doesn't allow me to get the file from my service ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.