Jira REST client implementation, where do i call my client?

mpopa June 11, 2013
Hi there, i'm new to jira and i wanted to make a simple custom field plugin which takes my output from a web service and puts it into a dropdown box , i have the client but i don't know where to invoke it , i tried to put it in my ClassCFType , but i get a class not found exception , please help! Thanx! the code for my client (jersey client)is this : public String getService() { WebResource webResource = client .resource("http://localhost:8080/service/hello"); ClientResponse response = webResource .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } String output = response.getEntity(String.class); System.out.println("Output from Server .... \n"); System.out.println(output); return output; } and the code for my ClassCFType is this: public Map<string, object=""> getVelocityParameters(final Issue issue, final CustomField field, final FieldLayoutItem fieldLayoutItem) { final Map<string, object=""> map = super.getVelocityParameters(issue, field, fieldLayoutItem); map.put("serviceValues", (String)new RestClient().getService()); return map; } as you can see i call my client when i create the map. don't know if it's the right thing to do...

2 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
mpopa June 19, 2013
Hi, i added the fallowing dependencies <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-core</artifactid> <version>1.9.1</version> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-json</artifactid> <version>1.9.1</version> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-client</artifactid> <version>1.9.1</version> </dependency> went to console and send the comand atlas-mvn eclipse:eclipse , after this i inserted the code for my jersey client and it worked
0 votes
Deleted user June 13, 2013

I am trying to do something similar, call a web service from a MultiStringCFType.

To fix the ClassNotFound Exception errors I added the following dependecies in the pom:

&lt;dependency&gt;
	      	&lt;groupId&gt;com.atlassian.jira&lt;/groupId&gt;
	      	&lt;artifactId&gt;jira-rest-plugin&lt;/artifactId&gt;
	      	&lt;version&gt;${jira.version}&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
	    &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.atlassian.jira&lt;/groupId&gt;
            &lt;artifactId&gt;jira-rest-api&lt;/artifactId&gt;
            &lt;version&gt;5.2&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.atlassian.plugins.rest&lt;/groupId&gt;
            &lt;artifactId&gt;atlassian-rest-common&lt;/artifactId&gt;
            &lt;version&gt;1.0.2&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
            &lt;artifactId&gt;jsr311-api&lt;/artifactId&gt;
            &lt;version&gt;1.0&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
        &lt;/dependency&gt;
            &lt;dependency&gt;
	        &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
	        &lt;artifactId&gt;jersey-client&lt;/artifactId&gt;
	        &lt;version&gt;${jersey.client.version}&lt;/version&gt;
	    &lt;/dependency&gt;

The problem I have now is that I am getting a ClientHandlerException: A message body reader for Java type, class java.lang.String, and MIME media type, application/json;charset=UTF-8, was not found

I get this when calling the web service from the custom field.

If I call the same jersey code from a rest service, it works. I created a question for my error here: https://answers.atlassian.com/questions/180499/calling-jira-rest-service-from-multistringcftype

TAGS
AUG Leaders

Atlassian Community Events