How to include HTTP status codes in the response of a WADL file generated by Jersey

1.1k views Asked by At

I've developed a simple RESTful WS with a few methods which will respond different HTTP status codes if a resource is available or a parameter left empty for example.

From the view of the source code I've no problems to send own status codes or just the 200 ok as a result.

For example two possible return statements for one method:

return Response.status(460).entity("Key not found").build();

or

return Response.ok(text,MediaType.TEXT_HTML).build();

When I take a look at the generated WADL file the entry for the possible response is only defined as the following

<method name="DELETE" id="aMethod">
  <response><representation mediaType="text/html"/>
  </response>
</method>

Is it possible to use some kind of annotations or do an other workaround to instruct the WADL generator to generate entries like the following?

<response status="201">  
  [...]
</response>  

and in general multiple responses with parameters for example.

 <response status="201">
   <param name="location" style="header" type="xsd:anyURI" required="true">  
     <link resource_type="#entry" rel="self"/>  
    </param>  
   <representation href="#entry"/>  
 </response>   

Does anyone have a clue how to integrate this kind of informations into the generation of a WADL file with Jersey/ JAX-RS?

1

There are 1 answers

0
Sir Geek On

You'll need to create an @Provider block for the code.

It looks pretty well documented here 6.6 - Jersey User Guide

See Example 6.6