将zip文件附加到jira问题时出错

时间:2014-11-07 05:54:34

标签: jira jira-rest-api

我正在使用JiraRestClient创建新问题,问题已成功创建,但在使用IssueClient附加文件时,我遇到异常。 附加文件的代码是

issueClient.addAttachments(pm, newIssue.getAttachmentsUri(), zipFile); //here zipFile is File

,例外是

Caused by: 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/form-data;boundary=Boundary_1_1171352834_1415267724337 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:346)
        at test.service.TestServiceImpl.createJiraIssue(TestServiceImpl.java:95)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy2806.createJiraIssue(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy2964.createJiraTicket(Unknown Source)
        at org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink$1.onSubmit(AjaxSubmitLink.java:116)
        at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior$1.onSubmit(AjaxFormSubmitBehavior.java:179)
        at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1266)
        at org.apache.wicket.markup.html.form.Form.process(Form.java:938)
        at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:770)
        at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(AjaxFormSubmitBehavior.java:156)
        at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:123)
        at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:633)
        ... 28 more
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 m
edia type multipart/form-data;boundary=Boundary_1_1171352834_1415267724337 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:379)
        at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.access$300(JerseyIssueRestClient.java:89)
        at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient$10.call(JerseyIssueRestClient.java:354)
        at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient$10.call(JerseyIssueRestClient.java:346)
        at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.invoke(AbstractJerseyRestClient.java:54)
        ... 73 more
什么可能是错的?我错过了什么吗?这个例外意味着什么?

我与此相处的另一条消息是

SEVERE: The registered message body writers compatible with the MIME media type are:
*/* ->
  com.sun.jersey.core.impl.provider.entity.FormProvider
  com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider
  com.sun.jersey.core.impl.provider.entity.StringProvider
  com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
  com.sun.jersey.core.impl.provider.entity.FileProvider
  com.sun.jersey.core.impl.provider.entity.InputStreamProvider
  com.sun.jersey.core.impl.provider.entity.DataSourceProvider
  com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
  com.sun.jersey.core.impl.provider.entity.ReaderProvider
  com.sun.jersey.core.impl.provider.entity.DocumentProvider
  com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
  com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
  com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONWithPaddingProvider
  com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General

2 个答案:

答案 0 :(得分:0)

看起来内容类型可能没有自动设置,因此JIRA不知道如何处理该文件。 jira-python add_attachment函数中的代码给出了一个想法:

content_type = mimetypes.guess_type(fname)[0]
    if not content_type:
        content_type = 'application/octet-stream'

    files = {
        'file': (fname, attachment, content_type)
    }
    r = self._session.post(url, files=files, headers=self._options['headers'])

答案 1 :(得分:0)

我通过改变我正在使用的罐子集来解决这个问题,我升级到了以下罐子

jersey-apache-client-1.18.jar
jersey-client-1.18.jar
jersey-core-1.18.jar
jersey-json-1.18.jar
jersey-multipart-1.18.jar
jersey-server-1.18.jar
jersey-servlet-1.18.jar
jettison-1.3.3.jar
jira-api-6.1.1.jar
jira-rest-java-client-1.0-javadoc.jar
jira-rest-java-client-1.0-sources.jar
jira-rest-java-client-1.0.jar

它按预期工作。