6

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

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 项目。

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

4

3 回答 3

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();
        }
    }
}
于 2013-06-18T06:40:20.960 回答
0

404错误意味着

404 或 Not Found 错误消息是一个 HTTP 标准响应代码,表示客户端能够与服务器通信,但服务器找不到请求的内容。(来源维基百科

所以可能有两种可能。

要么是网址

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

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

第二

您尝试在此处访问的资源

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

不可用。

于 2012-11-01T04:47:41.580 回答
-1

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

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

于 2012-11-01T04:41:24.403 回答