JIRA REST CLIENT:无法发送附件

时间:2014-03-14 13:48:59

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

通过jira rest client将附件发送到jira的

问题异常(请参阅下面的stacktrace)

重要!

  1. 通过Jira在localhost上启动应用程序时效果很好。
  2. 它不适用于环境或是通过mvn clean package命令制作jar并通过' java -jar .jar'命令!
  3. 问题:是什么原因?我该怎么办?

    代码:

    public static void handleProfileAttachments(Profile profile, JiraRestClient restClient, BasicIssue issue, ProgressMonitor pm) {
        List<FileInfo> attachments = profile.getFiles();
        if (attachments != null && !attachments.isEmpty()) {
            addAttachmentToIssue(restClient, issue.getKey(), attachments, pm);
        }
    }
    
    private static void addAttachmentToIssue(JiraRestClient restClient, String issueKey, List<FileInfo> attachments, ProgressMonitor pm) {
        FileInfo attachment = attachments.get(attachments.size() - 1);
        restClient.getIssueClient().addAttachment(pm, getIssue(restClient, issueKey, pm).getAttachmentsUri(),
                new ByteArrayInputStream(attachment.getFileContent().getContent()), attachment.getFileName() + "." + attachment.getFileExtension());
    }
    

    依赖关系:

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.18.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-multipart</artifactId>
            <version>1.18.1</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
                <artifactId>jira-rest-java-client</artifactId>
            <version>1.1-m02</version>
        </dependency>
    

    堆栈跟踪

    com.atlassian.jira.rest.client.RestClientException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java class com.sun.jersey.multipart.MultiPart, and Java type class com.sun.jersey.multipart.MultiPart, and MIME media type multipart/f
    orm-data; boundary=Boundary_2_61827_1394804460392 was not found
            at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.invoke(AbstractJerseyRestClient.java:75)
            at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.addAttachments(JerseyIssueRestClient.java:345)
            at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.addAttachment(JerseyIssueRestClient.java:338)
            at com.levi9.levirs.jiraexport.JiraExportService.addAttachmentToIssue(JiraExportService.java:140)
            at com.levi9.levirs.jiraexport.JiraExportService.handleProfileAttachments(JiraExportService.java:227)
            at com.levi9.levirs.jiraexport.JiraExportService.updateIssueAttachment(JiraExportService.java:221)
            at com.levi9.levirs.communication.file.FileRequestHandler$Update.saveSession(FileRequestHandler.java:112)
            at com.levi9.levirs.communication.file.FileRequestHandler$Update.handle(FileRequestHandler.java:88)
            at com.levi9.levirs.core.Peer.onWebSocketText(Peer.java:33)
            at org.eclipse.jetty.websocket.common.events.ListenerEventDriver.onTextMessage(ListenerEventDriver.java:127)
            at org.eclipse.jetty.websocket.common.message.SimpleTextMessage.messageComplete(SimpleTextMessage.java:69)
            at org.eclipse.jetty.websocket.common.events.ListenerEventDriver.onTextFrame(ListenerEventDriver.java:119)
            at org.eclipse.jetty.websocket.common.events.EventDriver.incomingFrame(EventDriver.java:127)
            at org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:309)
            at org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:203)
            at org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:200)
            at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:237)
            at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.read(AbstractWebSocketConnection.java:551)
            at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:459)
            at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
            at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:596)
            at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:527)
            at java.lang.Thread.run(Unknown Source)
    Caused by: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java class com.sun.jersey.multipart.MultiPart, and Java type class com.sun.jersey.multipart.MultiPart, and MIME media type multipart/form-data; boundary=Boundary_2_61827_13948
    04460392 was not found
            at com.sun.jersey.api.client.RequestWriter$RequestEntityWriterImpl.<init>(RequestWriter.java:198)
            at com.sun.jersey.api.client.RequestWriter.getRequestEntityWriter(RequestWriter.java:259)
            at com.sun.jersey.client.apache.DefaultApacheHttpMethodExecutor.executeMethod(DefaultApacheHttpMethodExecutor.java:121)
            at com.sun.jersey.client.apache.ApacheHttpClientHandler.handle(ApacheHttpClientHandler.java:175)
            at com.sun.jersey.api.client.Client.handle(Client.java:629)
            at com.sun.jersey.api.client.WebResource.voidHandle(WebResource.java:625)
            at com.sun.jersey.api.client.WebResource.access$400(WebResource.java:74)
            at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:495)
            at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.postFileMultiPart(JerseyIssueRestClient.java:413)
            at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.access$300(JerseyIssueRestClient.java:85)
            at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient$9.call(JerseyIssueRestClient.java:359)
            at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient$9.call(JerseyIssueRestClient.java:345)
            at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.invoke(AbstractJerseyRestClient.java:54)
            ... 22 more
    

0 个答案:

没有答案