I managed to get the example provided here to work.
https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+OAuth+authentication
But the example does not illustrate how a JSON body should be added to a request. Obviously, this is necessary in order to perform most POST operations such as creating an issue.
I tried to figure this out by myself but no luck so far. The problem is the OAuthClient class in the library used in the example does not seem to support adding a body to the request.
Any help would be appreciated.
Community moderators have prevented the ability to post new answers.
I overloaded AtlassianOAuthClient.makeAuthenticatedRequest to support request body. Seems to work.
public String makeAuthenticatedRequest(String url, String accessToken, InputStream bodyAsStream, String contentLength) throws Exception { boolean suppressNPE = false; //System.out.println("URL: " + url); String method = OAuthMessage.POST; if(url.matches(".*/issue/.+")){ //System.out.println("Changing method to PUT..."); method = OAuthMessage.PUT; suppressNPE = true; } OAuthAccessor accessor = getAccessor(); OAuthClient client = new OAuthClient(new HttpClient4()); accessor.accessToken = accessToken; OAuthMessage request = accessor.newRequestMessage(method, url, Collections.<Map.Entry<?,?>>emptySet(), bodyAsStream); List<Map.Entry<String,String>> headers = request.getHeaders(); headers.add(new OAuth.Parameter(HttpMessage.CONTENT_TYPE, "application/json")); headers.add(new OAuth.Parameter(HttpMessage.CONTENT_LENGTH, contentLength)); OAuthMessage response = client.invoke(request, ParameterStyle.QUERY_STRING); String responseString = ""; try{ responseString = response.readBodyAsString(); }catch(NullPointerException npe){ if(!suppressNPE){ throw npe; } } return responseString; }
HI Patrick, When i execute makeAuthenticatedRequest method i got Method Not Allowed exception. Please advise, What i need to do further? Caused by: net.oauth.OAuthProblemException: HTTP/1.1 405 Method Not Allowed at net.oauth.client.OAuthResponseMessage.toOAuthProblemException(OAuthResponseMessage.java:83) at net.oauth.client.OAuthClient.invoke(OAuthClient.java:306) at AtlassianOAuthClient.sendRequest Thanks in Advance. Thanks, Para.
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.