6

I am new to JIRA and using JIRA REST API to fetch issue from the remote host. I wrote a simple program to fetch the issue according to this tutorial following is the code

public class JIRAClient
{
     public static void main(String[] args) throws URISyntaxException {
            final JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
            final URI jiraServerUri = new URI("http://jira.companyname.net:8080/jira/");
            final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "abc", "xyz");
            final NullProgressMonitor pm = new NullProgressMonitor();
            final Issue issue = restClient.getIssueClient().getIssue("RRT-123456", pm);//<--line 24
     
            System.out.println(issue);
}

with this exception

Exception in thread "main" com.atlassian.jira.rest.client.RestClientException: com.sun.jersey.api.client.UniformInterfaceException: Client response status: 404
    at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.invoke(AbstractJerseyRestClient.java:70)
    at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.getAndParse(AbstractJerseyRestClient.java:80)
    at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.getIssue(JerseyIssueRestClient.java:145)
    at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.getIssue(JerseyIssueRestClient.java:136)
    at client.JIRAClient.main(JIRAClient.java:24)
Caused by: com.sun.jersey.api.client.UniformInterfaceException: Client response status: 404
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:676)
    at com.sun.jersey.api.client.WebResource.get(WebResource.java:191)
    at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient$1.call(AbstractJerseyRestClient.java:84)
    at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.invoke(AbstractJerseyRestClient.java:54)
    ... 4 more

For the record I'm using **cisco vpn** to connect to the host(otherwise it gives UnknownHostException) also I installed m2e plugin and created a maven project.

What would be the cause of the exception?. Am I using the wrong URL or should I try using another authentication method?.

Community
  • 1
  • 1
Bhavik Shah
  • 5,125
  • 3
  • 23
  • 40

3 Answers3

0

404 error means

The 404 or Not Found error message is a HTTP standard response code indicating that the client was able to communicate with the server, but the server could not find what was requested. (Source Wikipedia)

So there could be two possibilities.

either the url

http://jira.companyname.net:8080/jira/

Does not exist. confirm that it does exist.

Secondly

the resource you are trying to access here

restClient.getIssueClient().getIssue("RRT-123456", pm); 

is not available.

Mukul Goel
  • 8,387
  • 6
  • 37
  • 77
  • first _http://jira.companyname.net:8080/jira/_ exists I accessed it in my browser. Secondly I checked the resource RRT-123456 on the site and that exists too. My suspicion is either the authentication method is wrong or I have done something wrong while project setup – Bhavik Shah Nov 01 '12 at 04:50
  • @BhavikShah , IF it aint any of these two. hmmm.. Could you confirm that your JIRA host is using the `createWithBasicHttpAuthentication`? – Mukul Goel Nov 01 '12 at 04:55
  • @BhavikShah , enclose your code in a try block, catch the `com.atlassian.jira.rest.client.RestClientException` , and print `exceptionobject.getCause() and exceptionobject.getMessage() ` , maybe we can get more debug info that way – Mukul Goel Nov 01 '12 at 04:57
  • the cause is printed with the exception but anyway I tried it and the output is __com.sun.jersey.api.client.UniformInterfaceException: Client response status: 404_ – Bhavik Shah Nov 01 '12 at 05:00
  • @BhavikShah , i was hoping it might print some additional info. anyway did some lookup.. looks like a URL issue. But you saying that it exists. So out of suggestions. by the way.. can you enter Debug and debug on `line 24` and check what `URL` is being formed ultimately before hitting host and see if that is correct? – Mukul Goel Nov 01 '12 at 05:08
  • k i'll try but I don't think that would help – Bhavik Shah Nov 01 '12 at 05:25
  • @BhavikShah, I am not sure either :D (y) – Mukul Goel Nov 01 '12 at 05:26
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/18897/discussion-between-bhavik-shah-and-mukul-goel) – Bhavik Shah Nov 01 '12 at 05:31
0
try with the following rest client 
package com.rest.client;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
public class RESTclient {
    public static void main(String[] args) {
        try {
    Client client = Client.create();    
    client.addFilter(new HTTPBasicAuthFilter("admin", "admin"));
    WebResource webResource = lient.resource("http://localhost:8080/rest/api/2/issue");
    ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
    String output = response.getEntity(String.class);
    System.out.println("Output from Server .... \n");
    System.out.println(output);         
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Ram
  • 66
  • 4
-1

The response status being 404 means that the client could contact the server but the server could not find what was requested.

Maybe you should try to obtain the exact URL for the jira web service being hosted

Ashish
  • 510
  • 3
  • 14
  • 1
    I checked the issue with the issue key directly on the site, it is there. The only problem is fetching it in java – Bhavik Shah Nov 01 '12 at 04:44
  • and _http://jira.companyname.net:8080/jira/_ is an alias URL to protect company's confidentiality. I have the Complete URL – Bhavik Shah Nov 01 '12 at 04:46