【问题标题】:How to add attachment to an existing JIRA Issue using rest-client API如何使用 rest-client API 将附件添加到现有的 JIRA 问题
【发布时间】:2013-01-15 13:10:47
【问题描述】:

我可以使用其余客户端 API 创建 jira 问题,但我无法将屏幕截图/附件附加到现有的 JIRA 问题。如果有人能提供一个非常感谢的解决方案,那将非常有帮助。

我刚刚编写了以下代码 sn-p 用于将 jpeg 文件附加到现有的JIRA Issue。但后来我遇到了“线程“主”中的异常java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpConnectionManager"

代码片段:-

private static String addAttachment(String attachmentfilepath) throws URISyntaxException, FileNotFoundException{

    final java.net.URI jiraServerUri = new java.net.URI("https://oliveits.atlassian.net");
    FileInputStream fileStreamPath = new FileInputStream(attachmentfilenamepath);
    JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
    NullProgressMonitor pm = new NullProgressMonitor();
    System.out.println("Server Url  :"+jiraServerUri);
    JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri,"mobileqa","MobileQA1234");
    Issue issue1 = restClient.getIssueClient().getIssue(newKey, pm);
    final java.net.URI AttachmentUri = new java.net.URI(jiraServerUri+"/rest/api/2/issue/"+newKey+"/attachments");
    System.out.println("URI    :"+issue1.getAttachmentsUri());
    //restClient.getIssueClient().addAttachment(pm,issue1.getAttachmentsUri(), fileStreamPath , imageName);
    restClient.getIssueClient().addAttachment(pm, AttachmentUri, fileStreamPath, imageName);
    return attachmentfilepath;
}

例外:-

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpConnectionManager
at com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory.create(JerseyJiraRestClientFactory.java:34)
at com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory.createWithBasicHttpAuthentication(JerseyJiraRestClientFactory.java:39)
at com.jtricks.JTricksRESTClient.addAttachment(JTricksRESTClient.java:157)
at com.jtricks.JTricksRESTClient.main(JTricksRESTClient.java:101)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpConnectionManager
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 4 more

刚刚将丢失的 jar 文件添加到类路径中。但我遇到了一个例外,如下所述。

Exception Msg-1:com.sun.jersey.api.client.ClientHandlerException:Java 类 com.sun.jersey.multipart.MultiPart 和 Java 类型类 com.sun.jersey.multipart.MultiPart 的消息体编写器, 和 MIME 媒体类型 multipart/form-data;边界=Boundary_1_18541827_1358346116249 没有找到

Exception Msg-2:com.sun.jersey.api.client.ClientHandlerException:Java 类 com.sun.jersey.multipart.MultiPart 和 Java 类型类 com.sun.jersey.multipart.MultiPart 的消息体编写器, 和 MIME 媒体类型 multipart/form-data;边界=Boundary_1_18541827_1358346116249 没有找到

【问题讨论】:

    标签: java attachment jira-rest-java-api


    【解决方案1】:

    您的问题来自无法找到org.apache.commons.httpclient.HttpConnectionManager 类。在您的类路径中查找 commons-httpclient JAR。

    【讨论】:

    • 非常感谢您的回复,我刚刚将commons-httpclient jar文件添加到类路径中。它仍然不起作用,但后来我得到了一个不同的例外
    • 线程“主”java.lang.NoClassDefFoundError 中的异常:com/sun/jersey/client/apache/config/ApacheHttpClientConfig
    • 现在你缺少 jersey-apache-client:mvnrepository.com/artifact/com.sun.jersey.contribs/…
    • 您能否删除此评论并将其作为问题描述的更新发布?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-09
    • 2015-03-17
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 2016-10-14
    • 2015-03-20
    相关资源
    最近更新 更多