Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JIRA rest calls are failing with 401 Http error code

Vinutha Vasan
Contributor
February 28, 2012

Hi All,

I am trying to make a rest call for version creation but I am facing 401, authentication is failing.

2012-02-29 11:03:18,782 http-8090-3 WARN vinutha.vasan 663x29x1 17x9ns8 10.41.190.185 /secure/admin/AddIpVersions.jspa [apache.commons.httpclient.HttpMethodDirector] Unable to respond to any of these challenges: {oauth=OAuth realm="http%3A%2F%2Fjira-dev%3A8090"}
method.getStatusCode:::::::::::401
{"status-code":401,"message":"Client must be authenticated to access this resource.

I am setting JSESSIONID in HttpClient cookie. As shown below,

client.getState().addCookie(
new Cookie(getDomain(), "JSESSIONID", sessionId, "/", null,
false));

Still authentication is failing in standalone jira 4.4. But this was successful @ plugin test environemt using SDK.

Please let me know if I am missing something.

Thanks,

Vinutha

1 answer

1 accepted

0 votes
Answer accepted
Doug Bass January 31, 2013

I'm using this code. Hope this helps.

String auth = new String(Base64.encode(userName + ":" + password));
Client client = Client.create();
WebResource webResource = client.resource(url + "/rest/api/2/project");
ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json")
.accept("application/json").get(ClientResponse.class);
int statusCode = response.getResponseStatus().getStatusCode();
if (statusCode == 401) {
throw new AuthenticationException("Invalid Username or Password");
}
String s = response.getEntity(String.class);
log.error("The project rcvd from JIRA are: " + s);

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events