问题:通过 jira rest 客户端向 jira 发送附件时出现异常(参见下面的堆栈跟踪)
重要的!
- 通过 Jira 在 localhost 上启动应用程序时效果很好。
- 它不适用于环境,或者如果通过命令制作 jar
mvn clean package
并通过“java -jar .jar”命令启动!
问:是什么原因?我应该尝试什么?
代码:
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