@@ -122,3 +122,40 @@ private class PostConstructDataBoundMethod extends Method {
122122 this .getAnAnnotation ( ) instanceof PostConstructAnnotation
123123 }
124124}
125+
126+ /**
127+ * A method intended for Stapler request routing.
128+ *
129+ * From: https://www.jenkins.io/doc/developer/handling-requests/actions/
130+ * Web methods need to provide some indication that they are intended for Stapler routing:
131+ * - Any applicable annotation recognized by Stapler, e.g., @RequirePOST.
132+ * - Any inferable parameter type, e.g., StaplerRequest.
133+ * - Any applicable parameter annotation, recognized by Stapler, e.g., @AncestorInPath.
134+ * - Any declared exception type implementing HttpResponse, e.g., HttpResponseException.
135+ * - A return type implementing HttpResponse.
136+ */
137+ class StaplerWebMethod extends Method {
138+ StaplerWebMethod ( ) {
139+ // Any applicable annotation recognized by Stapler, e.g., @RequirePOST.
140+ this .hasAnnotation ( "org.kohsuke.stapler" , "WebMethod" )
141+ or
142+ this .hasAnnotation ( "org.kohsuke.stapler.interceptor" , [ "RequirePOST" , "RespondSuccess" ] )
143+ or
144+ this .hasAnnotation ( "org.kohsuke.stapler.verb" , [ "DELETE" , "GET" , "POST" , "PUT" ] )
145+ or
146+ // Any inferable parameter type, e.g., StaplerRequest.
147+ this .getAParamType ( )
148+ .( RefType )
149+ .hasQualifiedName ( "org.kohsuke.stapler" , [ "StaplerRequest" , "StaplerRequest2" ] )
150+ or
151+ // Any applicable parameter annotation, recognized by Stapler, e.g., @AncestorInPath
152+ this .getAParameter ( )
153+ .hasAnnotation ( "org.kohsuke.stapler" , [ "AncestorInPath" , "QueryParameter" , "Header" ] )
154+ or
155+ // A return type implementing HttpResponse
156+ this .getReturnType ( ) .( RefType ) .getASourceSupertype * ( ) instanceof HttpResponse
157+ or
158+ // Any declared exception type implementing HttpResponse, e.g., HttpResponseException
159+ this .getAThrownExceptionType ( ) .( RefType ) .getASourceSupertype * ( ) instanceof HttpResponse
160+ }
161+ }
0 commit comments