Skip to content

Instantly share code, notes, and snippets.

@ggtools
Created June 4, 2014 21:46
Show Gist options
  • Save ggtools/4f618850ad8edfbd1516 to your computer and use it in GitHub Desktop.
Save ggtools/4f618850ad8edfbd1516 to your computer and use it in GitHub Desktop.
Restx Router to handle PUT of a video stream
public class PutVideoRoute extends StdEntityRoute<InputStream, String> {
private final VideoResource videoResource;
public PutVideoRoute(EntityResponseWriterRegistry writerRegistry, VideoResource videoResource) {
super("Put Video Route",
new EntityRequestBodyReader<InputStream>() {
@Override
public Type getType() {
return InputStream.class;
}
@Override
public InputStream readBody(RestxRequest req, RestxContext ctx) throws IOException {
return req.getContentStream();
}
},
writerRegistry.<String>build(String.class, Optional.<String>absent()),
new StdRestxRequestMatcher("PUT", "/videos"),
HttpStatus.CREATED, RestxLogLevel.DEFAULT
);
this.videoResource = videoResource;
}
@Override
protected Optional<String> doRoute(RestxRequest restxRequest, RestxRequestMatch match, InputStream inputStream) throws IOException {
return Optional.of(videoResource.addVideo(inputStream));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment