Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to attach a file while creating Issue in JIRA using Java REST API Client

Eswaran R July 14, 2013

Hi All,

Am creating issue using Java Rest API client by following way,

IssueInputBuilder issueBuilder = new IssueInputBuilder(ProjectName,  Long.parseLong(it.getId().toString()));
issueBuilder.setFieldInput("customfield_10110","Some value");
final BasicIssue bissue = issueClient.createIssue(issueBuilder.build(), pm);
System.out.println(" Issue "+bissue.getKey()+" Created Successfully!");

Now Attachment field in create issue screen is Required attribute. How to add attachement while creating Issue ?

Am using jira-rest-java-client-1.1-m02.jar

Please help. Thanks in advance

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 14, 2013

To attach file using REST API (which is used by JRJC project) you need to create issue first. So in such configuration of create issue screen it is not possible to create new issue using REST API. You have to change configuration of create issue screen to allow creation of issue without attachment.

Eswaran R July 14, 2013

Hi Aleksander,

Thanks for your time. I tried to attach a file in after creating issue.

My java code

FileInputStream fileStreamPath=new FileInputStream("C:\\Users\\eswaranr\\Downloads\\Complete Program.doc");

final Issue issue = restClient.getIssueClient().getIssue("CPS-150", pm);

restClient.getIssueClient().addAttachment(pm, issue.getAttachmentsUri(), fileStreamPath, "Complete Program.doc");

Onkar Ahire
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 14, 2013

Hi,

Will you please share pom.xml dependencies for JIRA6.0+

0 votes
Eswaran R July 14, 2013

Am using eclipse to run my java code.

My pom.xml

<dependencies>
       <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
<dependency>
   <groupId>org.apache.commons</groupId>
   <artifactId>commons-io</artifactId>
   <version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0</version>
</dependency>
<dependency>
   <groupId>com.google.common</groupId>
   <artifactId>guava</artifactId>
   <version>14.0-rc1</version>
</dependency>

<dependency>
   <groupId>org.codehaus.jettison</groupId>
   <artifactId>jettison</artifactId>
   <version>1.0.1</version>
</dependency>

<dependency>
   <groupId>org.apache.commons</groupId>
   <artifactId>commons-logging</artifactId>
   <version>4.0.6</version>
</dependency>

<dependency>
   <groupId>org.apache.commons</groupId>
   <artifactId>commons-httpclient</artifactId>
   <version>3.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
<artifactId>oauth-client</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
<artifactId>oauth-signature</artifactId>
<version>1.5</version>
</dependency>
<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-apache-client</artifactId>
   <version>1.9.1</version>
</dependency>

<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-core</artifactId>
   <version>1.16</version>
</dependency>

<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-client</artifactId>
   <version>1.5</version>
</dependency>

<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-bundle</artifactId>
   <version>1.16</version>
</dependency>

<dependency>
   <groupId>org.joda.time</groupId>
   <artifactId>joda-time</artifactId>
   <version>2.0</version>
</dependency>
  
<dependency>
   <groupId>com.atlassian.jira</groupId>
   <artifactId>Jira-rest-java-client</artifactId>
   <version>1.1-m02</version>
</dependency>
   <dependency>
   <groupId>au.com.bytecode</groupId>
   <artifactId>opencsv</artifactId>
   <version>2.3</version>
</dependency>
<dependency>
  <groupId>org.relique</groupId>
  <artifactId>csvjdbc</artifactId>
  <version>1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.5</version>
</dependency>
<dependency>
	<groupId>com.sun.jersey</groupId>
	<artifactId>jersey-server</artifactId>
	<version>1.8</version>
</dependency>
<dependency>
	<groupId>com.sun.jersey.contribs</groupId>
	<artifactId>jersey-multipart</artifactId>
	<version>1.5</version>
</dependency>
<dependency>
	<groupId>com.sun.jersey.contribs</groupId>
	<artifactId>jersey-apache-client</artifactId>
	<version>1.5</version>
</dependency>
            
  </dependencies>

I got the dependency versions from this link

https://maven-us.nuxeo.org/nexus/content/groups/public/com/atlassian/jira/jira-rest-java-client/1.1-m02/jira-rest-java-client-1.1-m02.pom

But still am havinig same problem.. Please help..

Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 14, 2013

That doesn't look well:

<groupId>com.sun.jersey</groupId>
  <artifactId>jersey-core</artifactId>
  <version>1.16</version>

You should use jersey-core 1.5.

To fight with incorrect dependencies problem first please compare expected dependencies with those effectively used by maven in runtime. Useful commands to see what is maven using (dependency managment and dependencies-of-dependencies sometimes changes versions of used libs):

mvn dependency:tree
mvn dependency:list
mvn help:effective-pom

Unfortunately I don't know the 'mvn tell-me-what-is-wrong' command :(.

Running mvn dependency:copy-dependencies also might be useful. This will copy all dependencies to target/dependency so you can check if jars located there are in expected version.

This is list of jersey dependencies used to build JRJC 1.x:

target/dependency % ls | grep jersey
com.atlassian.jersey-library-2.5.0.pom
jersey-apache-client-1.5.jar
jersey-client-1.5.jar
jersey-core-1.5.jar
jersey-json-1.5.jar
jersey-multipart-1.5.jar

0 votes
Eswaran R July 14, 2013

					
				
			
			
			
				
			
			
			
			
			
			
		
Eswaran R July 14, 2013

Am getting following error

Jul 11, 2013 12:44:57 PM com.sun.jersey.api.client.RequestWriter$RequestEntityWriterImpl <init>

SEVERE: 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_1319874444_1373526897746 was not found

Jul 11, 2013 12:44:57 PM com.sun.jersey.api.client.RequestWriter$RequestEntityWriterImpl <init>

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.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

com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy

Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 14, 2013

Do you use one-jar or similar method to pack all dependencies to single jar? I had such problem while I was creating single-jar for my project.

The reason in short is that Jersey doesn't like that approach as it looks for files in META-INF (or other shared path - it was a long time ago ;)) that describes readers and writers and those files have the same name in each JAR. In effect they're overwritten while doing one-jar, which causes such errors - Jersey don't know which classes he should use for writting multipart/form data.

If that's not the case, then probably you're missing some dependencies (for example other dependecy pulls wrong version of com.sun.jersey.contribs:jersey-multipart:jar).

TAGS
AUG Leaders

Atlassian Community Events