Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
REST
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Implementing a Restful Service with JAX-RS==== * implement an empty class with annoation like @javax.ws.rs.ApplicationPath("/rest") public class JaxRsActivator extends javax.ws.rs.Application { } * reuse BaseEntityService as base class of project uweheuer_new and define subclass like @javax.ws.rs.Path("/notes") @javax.ejb.Stateless // This is a stateless service, so a single shared instance can be used in this case. public class NotesService extends BaseEntityService<Note> The return type obviously depends on the purpose of the API. The procudure to set the return value depends of the outcome of API: #Http codes: 404 requested resource does not exist, 400 the request is semantically incorrect, 401 the user is not authorized, 500 there is a problem with the database connection) via e.g. return Response.status(Response.Status.NOT_FOUND).entity("...").build(); #Http code 201 created * annotate changing services like and return response applying the following patterns @javax.ws.rs.POST @javax.ws.rs.Consumes(MediaType.APPLICATION_JSON) public Response saveNote(Note note) { return Response.ok(); // creates a response with a status of 200 and an empty entity body. return Response.ok(entity).build(); // creates a response with a status of 200, stores the supplied object in the // responses entity body, and determines the entities media type by introspecting the object return Response.noContent().build(); // reating a response with a 204 status (no content) }
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width