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

Accessing a restful service from Jira

Terry Jeske November 14, 2012

We have our own rest services that our custom plugins depend on. I keep getting the following error when I try to access the response string:

com.sun.jersey.api.client.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 am using some sample code I found on the web. This code works fine when run from a main method in a stand alone project but I get the above error when trying to run it in the Jira container:

try{
	    	Client client = Client.create();
			 WebResource webResource = client.resource("http://mydevbox:8080/user-webservice/api/v2/user/managerfor/username/jshmo");

			 ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
			 
			 if (response.getStatus() != 200) {
				   throw new RuntimeException("Failed : HTTP error code : "
					+ response.getStatus());
				}
		 //error here
				String output = response.getEntity(String.class);
		 
				System.out.println("Output from Server .... \n");
				System.out.println(output);
		 
			  } catch (Exception e) {
		 
				e.printStackTrace();
		 
			  }
.

I downgraded the Jersey jars to 1.0.3 to make sure I was comparing apple to apples. Can someone please shed some light on this? I implemented a work around using httpclient directly, but that causes other jar conflicts when I deploy the plugin

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Terry Jeske November 15, 2012

I think I solved it. Changing the the client creation by adding a ClientConfig with the StringProvider worked for me.

ClientConfig cc = new DefaultClientConfig();	   	    cc.getClasses().add(StringProvider.class);
Client client = Client.create(cc);

0 votes
Tim B November 15, 2012

Well, this probably has to do with the OSGi usage inside JIRA for plugins. OSGi secures that each plugin has it's own classpath when launched. If you are a JAR & dependencies hero you might be able to figure it out (I have had no success with it so far).

Until Atlassian posts a good example of this I use http client for SOAP like you did for your REST. However with this approach I do not get any jar conflicts.

Terry Jeske November 15, 2012

Thanks for the response. Pretty frustrating, Atlassian is all gungho on using rest, but seems that only their services can join the party. I dl'd the Jersey 1.0.3 source and step it through. The StringProvider is missing when Jersey tries to get the entity (just as the error message said). Seems like Atlassian might have purposely removed that provider. I am going to try and add it back.

TAGS
AUG Leaders

Atlassian Community Events