简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM