在jira中获取问题时出现异常

时间:2012-11-01 04:31:36

标签: java maven-2 jira jira-rest-java-api

我是JIRA的新手,并使用JIRA REST API从远程主机获取问题。我写了一个简单的程序来根据这个tutorial来获取问题 以下是代码

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);
}

有这个例外

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

对于我正在使用**cisco vpn**连接到主机的记录(否则它会产生UnknownHostException)我也安装了 m2e 插件并创建了一个maven项目。

异常的原因是什么?我使用的是错误的网址,还是应该尝试使用其他身份验证方法?

3 个答案:

答案 0 :(得分:0)

404错误表示

  

404或Not Found错误消息是HTTP标准响应代码,表示客户端能够与服务器通信,但服务器无法找到所请求的内容。 (来源Wikipedia

所以可能有两种可能性。

url

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

不存在。确认它确实存在。

其次

您尝试访问的资源

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

不可用。

答案 1 :(得分: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();
        }
    }
}

答案 2 :(得分:-1)

响应状态为404表示客户端可以联系服务器,但服务器找不到请求的内容。

也许您应该尝试获取托管的jira Web服务的确切URL