maloney
maloney

Reputation: 1653

GET REST error 415

I am getting the following error message when trying to execute a GET REST command:

"returned a response status of 415 Unsupported Media Type"

This is the code:

<code> whenGetPatternByGroupName() {
        Client client = Client.create(new DefaultClientConfig());

        URI uri = UriBuilder.fromUri("http://bla:7979/bla/rest/pattern/").build();
        WebResource service = client.resource(uri);

        List <PatternList> patternList = new ArrayList<PatternList>();
        patternList = service.path("getAll").type(MediaType.APPLICATION_XML).get(patternList.getClass());

        assertThat(patternList.size(), greaterThan(0));
     }
</code>

<code> @GET
    @Path("getAll")
    @Consumes({MediaType.APPLICATION_JSON})
    public List<PatternList> getAllPatterns() { 
        ArrayList<PatternList> list = new ArrayList<PatternList>();

        // put group names here
        String[] groups = new String[] {"Group 1"};

        for (String groupName : groups) {

            List<String> patterns = patternPersistenceService.getListByGroupName(groupName);

            PatternList patternList = new PatternList();
            patternList.setGroupName(groupName);
            patternList.setPatterns(patterns);

            list.add(patternList); 
        }
        return list;
    }
</code>

Does anyone have any ideas what could be causing this??

Thanks,

Upvotes: 0

Views: 3258

Answers (2)

J&#246;rn Horstmann
J&#246;rn Horstmann

Reputation: 34014

Setting the media type for a GET request and using @Consumes in the handler seems strange since a GET request does not have a body. Don't you mean to use the accept method in the client and @Produces on the server side?

Upvotes: 1

Thor
Thor

Reputation: 6656

You have mixed the MediaType (and your methods does not consume anything at all ...):

  • Client: MediaType.APPLICATION_XML
  • Rest: MediaType.APPLICATION_JSON

Upvotes: 0

Related Questions