【问题标题】:Exception while fetching issue in jira在jira中获取问题时出现异常
【发布时间】:2012-10-21 16:20:42
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:
    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】:

      404错误表示

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

      所以可能有两种可能性。

      网址

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

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

      其次

      您在此处尝试访问的资源

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

      不可用。

      【讨论】:

      • 第一个 jira.companyname.net:8080/jira 存在我在浏览器中访问它。其次,我检查了网站上的资源 RRT-123456,它也存在。我的怀疑是身份验证方法错误或者我在项目设置时做错了什么
      • @BhavikShah ,如果它不是这两个中的任何一个。嗯.. 您能否确认您的 JIRA 主机正在使用createWithBasicHttpAuthentication
      • @BhavikShah ,把你的代码放在 try 块中,捕获 com.atlassian.jira.rest.client.RestClientException 并打印 exceptionobject.getCause() and exceptionobject.getMessage() ,也许我们可以通过这种方式获得更多的调试信息
      • 原因打印出异常但无论如何我都试过了,输出是 _com.sun.jersey.api.client.UniformInterfaceException: Client response status: 404跨度>
      • @BhavikShah,我希望它能打印一些额外的信息。无论如何做了一些查找.. 看起来像一个 URL 问题。但是你说它存在。所以没有建议。顺便说一句.. 你能在line 24 上输入Debug 和debug,然后在访问主机之前检查URL 最终形成的内容,看看是否正确?
      【解决方案3】:

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

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

      【讨论】:

      • 我直接在网站上使用问题密钥检查了问题,它就在那里。唯一的问题是在 java 中获取它
      • jira.companyname.net:8080/jira 是别名 URL,用于保护公司机密。我有完整的网址
      猜你喜欢
      • 2012-09-23
      • 2016-07-26
      • 2015-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多