001package org.kohsuke.stapler.interceptor;
002
003import org.kohsuke.stapler.HttpResponses;
004import org.kohsuke.stapler.StaplerRequest;
005import org.kohsuke.stapler.StaplerResponse;
006
007import javax.servlet.ServletException;
008import java.lang.annotation.Retention;
009import java.lang.annotation.Target;
010import java.lang.reflect.InvocationTargetException;
011
012import static java.lang.annotation.ElementType.*;
013import static java.lang.annotation.RetentionPolicy.RUNTIME;
014
015/**
016 * Used on the web-bound doXyz method to indicate that the successful return of the method should
017 * result in HTTP 200 Success status.
018 *
019 * @author Kohsuke Kawaguchi
020 * @see HttpResponses#ok()
021 */
022@Retention(RUNTIME)
023@Target({METHOD,FIELD})
024@InterceptorAnnotation(RespondSuccess.Processor.class)
025public @interface RespondSuccess {
026    public static class Processor extends Interceptor {
027        @Override
028        public Object invoke(StaplerRequest request, StaplerResponse response, Object instance, Object[] arguments)
029                throws IllegalAccessException, InvocationTargetException, ServletException {
030            target.invoke(request, response, instance, arguments);
031            // TODO does this actually do anything?
032            // Function.bindAndInvokeAndServeResponse ignores return value if the method is declared to return void.
033            // And it seems Stapler will send a 200 by default anyway.
034            return HttpResponses.ok();
035        }
036    }
037}