@@ -122,3 +122,45 @@ 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" , _)
143+ or
144+ this .hasAnnotation ( "org.kohsuke.stapler.verb" , _)
145+ or
146+ // Any inferable parameter type, e.g., StaplerRequest.
147+ this .getAParamType ( )
148+ .( RefType )
149+ .hasQualifiedName ( "org.kohsuke.stapler" ,
150+ [ "StaplerRequest" , "StaplerRequest2" , "StaplerResponse" , "StaplerResponse2" ] )
151+ or
152+ // Any applicable parameter annotation, recognized by Stapler, e.g., @AncestorInPath
153+ this .getAParameter ( )
154+ .hasAnnotation ( "org.kohsuke.stapler" , [ "AncestorInPath" , "QueryParameter" , "Header" ] )
155+ or
156+ // Any declared exception type implementing HttpResponse, e.g., HttpResponseException
157+ this .getAParameter ( ) .hasAnnotation ( "org.kohsuke.stapler" , "HttpResponses.HttpResponseException" )
158+ or
159+ // A return type implementing HttpResponse
160+ exists ( HttpResponse httpResponse |
161+ this .getReturnType ( ) .( RefType ) .extendsOrImplements ( httpResponse )
162+ )
163+ or
164+ this instanceof HudsonWebMethod
165+ }
166+ }
0 commit comments