@RestResource(path="/photos", messages="nls/PhotosResource", title="Photo REST service", description="Sample resource that allows images to be uploaded and retrieved.", htmldoc=, properties=@Property(name="HtmlSerializer.uriAnchorText.s",value="SERVLET_RELATIVE"), swagger=) public class PhotosResource extends BasicRestServlet
Modifier and Type | Class and Description |
---|---|
static class |
PhotosResource.ImageParser
Parser for converting byte streams to images
|
static class |
PhotosResource.ImageSerializer
Serializer for converting images to byte streams
|
static class |
PhotosResource.Photo
Our bean class for storing photos
|
Constructor and Description |
---|
PhotosResource() |
Modifier and Type | Method and Description |
---|---|
String |
addPhoto(String id,
BufferedImage image) |
String |
deletePhoto(String id) |
Collection<PhotosResource.Photo> |
getAllPhotos() |
BufferedImage |
getPhoto(String id) |
void |
init() |
PhotosResource.Photo |
setPhoto(BufferedImage image) |
SeeOtherRoot |
uploadFile(RestRequest req) |
getOptions
destroy, getContext, getPath, getProperties, getRequest, getResponse, getServletConfig, init, log, log, log, log, logObjects, service, setContext, setRestResourceResolver
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
public PhotosResource()
public void init()
init
in class javax.servlet.GenericServlet
@RestMethod(name="GET", path="/", summary="Show the list of all currently loaded photos") public Collection<PhotosResource.Photo> getAllPhotos() throws Exception
Exception
@RestMethod(name="GET", path="/{id}", serializers=PhotosResource.ImageSerializer.class, summary="Get a photo by ID", description="Shows how to use a custom serializer to serialize a BufferedImage object to a stream.") @Response(schema=@Schema(type="file")) public BufferedImage getPhoto(@Path(value="id") String id) throws NotFound
NotFound
@RestMethod(name="PUT", path="/{id}", parsers=PhotosResource.ImageParser.class, summary="Add or overwrite a photo", description="Shows how to use a custom parser to parse a stream into a BufferedImage object.") public String addPhoto(@Path(value="id") String id, @Body(description="Binary contents of image.",schema=@Schema(type="file")) BufferedImage image) throws Exception
Exception
@RestMethod(name="POST", path="/", parsers=PhotosResource.ImageParser.class, summary="Add a photo", description="Shows how to use a custom parser to parse a stream into a BufferedImage object.") public PhotosResource.Photo setPhoto(@Body(description="Binary contents of image.",schema=@Schema(type="file")) BufferedImage image) throws Exception
Exception
@RestMethod(name="POST", path="/upload", matchers=MultipartFormDataMatcher.class, summary="Upload a photo from a multipart form post", description="Shows how to parse a multipart form post containing a binary field.", swagger=) public SeeOtherRoot uploadFile(RestRequest req) throws Exception
Exception
Copyright © 2018 Apache. All rights reserved.