Resteasy JAX-RS
Total Page:16
File Type:pdf, Size:1020Kb
RESTEasy JAX-RS RESTFul Web Services for Java 3.1.0.Final Preface ............................................................................................................................. ix 1. Overview ...................................................................................................................... 1 2. License ........................................................................................................................ 3 3. Installation/Configuration ............................................................................................ 5 3.1. Resteasy modules in WildFly ............................................................................... 5 3.1.1. Other Resteasy modules .......................................................................... 6 3.1.2. Upgrading Resteasy within WildFly ........................................................... 7 3.2. Deploying a Resteasy application to WildFly ......................................................... 7 3.3. Deploying to other servlet containers ................................................................... 8 3.3.1. Servlet 3.0 containers .............................................................................. 8 3.3.2. Older servlet containers ............................................................................ 9 3.4. Configuration switches ........................................................................................ 9 3.5. javax.ws.rs.core.Application ............................................................................... 13 3.6. Resteasy as a ServletContextListener ................................................................ 14 3.7. Resteasy as a Servlet Filter .............................................................................. 15 3.8. Client side ........................................................................................................ 16 4. Using @Path and @GET, @POST, etc. ...................................................................... 17 4.1. @Path and regular expression mappings ........................................................... 18 5. @PathParam .............................................................................................................. 21 5.1. Advanced @PathParam and Regular Expressions .............................................. 22 5.2. @PathParam and PathSegment ........................................................................ 22 6. @QueryParam ............................................................................................................ 25 7. @HeaderParam .......................................................................................................... 27 8. Linking resources ...................................................................................................... 29 8.1. Link Headers .................................................................................................... 29 8.2. Atom links in the resource representations ......................................................... 29 8.2.1. Configuration .......................................................................................... 29 8.2.2. Your first links injected ........................................................................... 29 8.2.3. Customising how the Atom links are serialised ......................................... 32 8.2.4. Specifying which JAX-RS methods are tied to which resources .................. 32 8.2.5. Specifying path parameter values for URI templates ................................. 33 8.2.6. Securing entities .................................................................................... 36 8.2.7. Extending the UEL context ..................................................................... 36 8.2.8. Resource facades .................................................................................. 38 9. @MatrixParam ............................................................................................................ 41 10. @CookieParam ........................................................................................................ 43 11. @FormParam ........................................................................................................... 45 12. @Form ..................................................................................................................... 47 13. @DefaultValue .......................................................................................................... 51 14. @Encoded and encoding ......................................................................................... 53 15. @Context ................................................................................................................. 55 16. JAX-RS Resource Locators and Sub Resources ..................................................... 57 17. JAX-RS Content Negotiation .................................................................................... 61 17.1. URL-based negotiation .................................................................................... 62 iii RESTEasy JAX-RS 17.2. Query String Parameter-based negotiation ........................................................ 64 18. Content Marshalling/Providers ................................................................................. 65 18.1. Default Providers and default JAX-RS Content Marshalling ................................ 65 18.2. Content Marshalling with @Provider classes ..................................................... 65 18.3. Providers Utility Class ..................................................................................... 67 18.4. Configuring Document Marshalling ................................................................... 69 19. JAXB providers ........................................................................................................ 71 19.1. JAXB Decorators ............................................................................................ 72 19.2. Pluggable JAXBContext's with ContextResolvers .............................................. 73 19.3. JAXB + XML provider ...................................................................................... 74 19.3.1. @XmlHeader and @Stylesheet ............................................................. 74 19.4. JAXB + JSON provider .................................................................................... 76 19.5. JAXB + FastinfoSet provider ............................................................................ 80 19.6. Arrays and Collections of JAXB Objects ........................................................... 81 19.6.1. JSON and JAXB Collections/arrays ....................................................... 83 19.7. Maps of JAXB Objects .................................................................................... 84 19.7.1. JSON and JAXB maps ......................................................................... 87 19.7.2. Possible Problems with Jettison Provider ............................................... 87 19.8. Interfaces, Abstract Classes, and JAXB ............................................................ 88 19.9. Configurating JAXB Marshalling ....................................................................... 88 20. Resteasy Atom Support ........................................................................................... 91 20.1. Resteasy Atom API and Provider ..................................................................... 91 20.2. Using JAXB with the Atom Provider ................................................................. 92 21. JSON Support via Jackson ...................................................................................... 95 21.1. Using Jackson 1.9.x Outside of WildFly ............................................................ 95 21.2. Using Jackson 1.9.x Inside WildFly 8 ............................................................... 95 21.3. Using Jackson 2 Outside of WildFly ................................................................. 95 21.4. Using Jackson 2 Inside WildFly 9 and above .................................................... 96 21.5. Additional Resteasy Specifics .......................................................................... 96 21.6. Possible Conflict With JAXB Provider ............................................................... 97 21.7. JSONP Support .............................................................................................. 97 21.8. Jackson JSON Decorator ................................................................................ 99 21.9. JSON Filter Support ........................................................................................ 99 22. JSON Support via Java EE 7 JSON-P API .............................................................. 103 23. Multipart Providers ................................................................................................. 105 23.1. Input with multipart/mixed .............................................................................. 105 23.2. java.util.List with multipart data ....................................................................... 107 23.3. Input with multipart/form-data ......................................................................... 107 23.4. java.util.Map with multipart/form-data .............................................................. 108 23.5. Input with multipart/related ............................................................................