Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.yammer.dropwizard.jersey;
 
    private static class OptionalResourceMethodDispatchProvider implements ResourceMethodDispatchProvider {
        private final ResourceMethodDispatchProvider provider;
            this. = provider;
        }
        @Override
        public RequestDispatcher create(AbstractResourceMethod abstractResourceMethod) {
            return new OptionalRequestDispatcher(.create(abstractResourceMethod));
        }
    }
    private static class OptionalRequestDispatcher implements RequestDispatcher {
        private final RequestDispatcher dispatcher;
        private OptionalRequestDispatcher(RequestDispatcher dispatcher) {
            this. = dispatcher;
        }
        @Override
        public void dispatch(Object resourceHttpContext context) {
            .dispatch(resourcecontext);
            final Object entity = context.getResponse().getEntity();
            if (entity instanceof Optional) {
                final Optional<?> optional = (Optional<?>) entity;
                if (optional.isPresent()) {
                    context.getResponse().setEntity(optional.get());
                } else {
                    throw new NotFoundException();
                }
            }
        }
    }
    @Override
        return new OptionalResourceMethodDispatchProvider(provider);
    }
New to GrepCode? Check out our FAQ X