* Stapler will invoke the designated constructor by using arguments from the corresponding - * {@link JSONObject} (in case of {@link StaplerRequest#bindJSON(Class, JSONObject)}) or request parameters - * (in case of {@link StaplerRequest#bindParameters(Class, String)}). + * {@link JSONObject} (in case of {@link StaplerRequest2#bindJSON(Class, JSONObject)}) or request parameters + * (in case of {@link StaplerRequest2#bindParameters(Class, String)}). * *
* The matching is done by using the constructor parameter name. Since this information is not available diff --git a/core/src/main/java/org/kohsuke/stapler/DataBoundResolvable.java b/core/src/main/java/org/kohsuke/stapler/DataBoundResolvable.java index b0723709e..a86821644 100644 --- a/core/src/main/java/org/kohsuke/stapler/DataBoundResolvable.java +++ b/core/src/main/java/org/kohsuke/stapler/DataBoundResolvable.java @@ -4,12 +4,12 @@ /** * For data-bound class (that has a constructor marked with {@link DataBoundConstructor}, the - * {@link #bindResolve(StaplerRequest, JSONObject)} allows an instance to replace the object + * {@link #bindResolve(StaplerRequest2, JSONObject)} allows an instance to replace the object * bound from submitted JSON object. * *
* This method is automatically invoked by Stapler during databinding method like - * {@link StaplerRequest#bindJSON(Class, JSONObject)}. + * {@link StaplerRequest2#bindJSON(Class, JSONObject)}. * *
* This method definition is inspired by Java serialization's {@code readResolve()} method. @@ -31,5 +31,5 @@ public interface DataBoundResolvable { * Can be any value, including null. Typically, this method would have to return an * instance of a type compatible to the caller's expectation. */ - Object bindResolve(StaplerRequest request, JSONObject src); + Object bindResolve(StaplerRequest2 request, JSONObject src); } diff --git a/core/src/main/java/org/kohsuke/stapler/DataBoundSetter.java b/core/src/main/java/org/kohsuke/stapler/DataBoundSetter.java index 7ed4c5930..7d0d2de03 100644 --- a/core/src/main/java/org/kohsuke/stapler/DataBoundSetter.java +++ b/core/src/main/java/org/kohsuke/stapler/DataBoundSetter.java @@ -11,8 +11,8 @@ /** * Designates a setter method or a field used to databind JSON values into objects in methods like - * {@link StaplerRequest#bindJSON(Class, JSONObject)} and - * {@link StaplerRequest#bindParameters(Class, String)}. + * {@link StaplerRequest2#bindJSON(Class, JSONObject)} and + * {@link StaplerRequest2#bindParameters(Class, String)}. * *
* Stapler will first invoke {@link DataBoundConstructor}-annotated constructor, and if there's any
diff --git a/core/src/main/java/org/kohsuke/stapler/DiagnosticThreadNameFilter.java b/core/src/main/java/org/kohsuke/stapler/DiagnosticThreadNameFilter.java
index 7cef9f850..1b72836b1 100644
--- a/core/src/main/java/org/kohsuke/stapler/DiagnosticThreadNameFilter.java
+++ b/core/src/main/java/org/kohsuke/stapler/DiagnosticThreadNameFilter.java
@@ -1,20 +1,20 @@
package org.kohsuke.stapler;
+import jakarta.servlet.Filter;
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.FilterConfig;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.ServletRequest;
+import jakarta.servlet.ServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
/**
* {@link Filter} that sets the thread name to reflect the current request being processed.
*
* @author Kohsuke Kawaguchi
*/
-public class DiagnosticThreadNameFilter implements Filter {
+public class DiagnosticThreadNameFilter implements CompatibleFilter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {}
diff --git a/core/src/main/java/org/kohsuke/stapler/DirectoryishDispatcher.java b/core/src/main/java/org/kohsuke/stapler/DirectoryishDispatcher.java
index 9970c7088..3e7cd5404 100644
--- a/core/src/main/java/org/kohsuke/stapler/DirectoryishDispatcher.java
+++ b/core/src/main/java/org/kohsuke/stapler/DirectoryishDispatcher.java
@@ -1,10 +1,10 @@
package org.kohsuke.stapler;
+import jakarta.servlet.ServletException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.servlet.ServletException;
/**
* {@link Dispatcher} that tells browsers to append '/' to the request path and try again.
diff --git a/core/src/main/java/org/kohsuke/stapler/DispatchValidator.java b/core/src/main/java/org/kohsuke/stapler/DispatchValidator.java
index e21a84060..e5237cf76 100644
--- a/core/src/main/java/org/kohsuke/stapler/DispatchValidator.java
+++ b/core/src/main/java/org/kohsuke/stapler/DispatchValidator.java
@@ -48,7 +48,7 @@ public interface DispatchValidator {
* @return true if the request should be dispatched, false if not, or null if unknown or neutral
*/
@CheckForNull
- Boolean isDispatchAllowed(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp);
+ Boolean isDispatchAllowed(@NonNull StaplerRequest2 req, @NonNull StaplerResponse2 rsp);
/**
* Checks if the given request and response should be allowed to dispatch a view on an optionally present node
@@ -61,24 +61,24 @@ public interface DispatchValidator {
* @return true if the view should be allowed to dispatch, false if it should not, or null if unknown
*/
default @CheckForNull Boolean isDispatchAllowed(
- @NonNull StaplerRequest req,
- @NonNull StaplerResponse rsp,
+ @NonNull StaplerRequest2 req,
+ @NonNull StaplerResponse2 rsp,
@NonNull String viewName,
@CheckForNull Object node) {
return isDispatchAllowed(req, rsp);
}
/**
- * Allows the given request to be dispatched. Further calls to {@link #isDispatchAllowed(StaplerRequest, StaplerResponse)}
+ * Allows the given request to be dispatched. Further calls to {@link #isDispatchAllowed(StaplerRequest2, StaplerResponse2)}
* should return true for the same request.
*/
- void allowDispatch(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp);
+ void allowDispatch(@NonNull StaplerRequest2 req, @NonNull StaplerResponse2 rsp);
/**
* Throws a {@link CancelRequestHandlingException} if the given request is not
- * {@linkplain #isDispatchAllowed(StaplerRequest, StaplerResponse) allowed}.
+ * {@linkplain #isDispatchAllowed(StaplerRequest2, StaplerResponse2) allowed}.
*/
- default void requireDispatchAllowed(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp)
+ default void requireDispatchAllowed(@NonNull StaplerRequest2 req, @NonNull StaplerResponse2 rsp)
throws CancelRequestHandlingException {
Boolean allowed = isDispatchAllowed(req, rsp);
if (allowed == null || !allowed) {
@@ -91,12 +91,12 @@ default void requireDispatchAllowed(@NonNull StaplerRequest req, @NonNull Staple
*/
DispatchValidator DEFAULT = new DispatchValidator() {
@Override
- public Boolean isDispatchAllowed(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp) {
+ public Boolean isDispatchAllowed(@NonNull StaplerRequest2 req, @NonNull StaplerResponse2 rsp) {
return true;
}
@Override
- public void allowDispatch(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp) {
+ public void allowDispatch(@NonNull StaplerRequest2 req, @NonNull StaplerResponse2 rsp) {
// no-op
}
};
diff --git a/core/src/main/java/org/kohsuke/stapler/Dispatcher.java b/core/src/main/java/org/kohsuke/stapler/Dispatcher.java
index 17e52b5ee..6b5fd1f63 100644
--- a/core/src/main/java/org/kohsuke/stapler/Dispatcher.java
+++ b/core/src/main/java/org/kohsuke/stapler/Dispatcher.java
@@ -24,6 +24,7 @@
package org.kohsuke.stapler;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import jakarta.servlet.ServletException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@@ -31,7 +32,6 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.servlet.ServletException;
/**
* Controls the dispatching of incoming HTTP requests.
@@ -63,7 +63,7 @@ public static boolean traceable() {
return TRACE || TRACE_PER_REQUEST || LOGGER.isLoggable(Level.FINE);
}
- public static void traceEval(StaplerRequest req, StaplerResponse rsp, Object node) {
+ public static void traceEval(StaplerRequest2 req, StaplerResponse2 rsp, Object node) {
trace(
req,
rsp,
@@ -75,14 +75,14 @@ public static void traceEval(StaplerRequest req, StaplerResponse rsp, Object nod
}
public static void anonymizedTraceEval(
- StaplerRequest req, StaplerResponse rsp, Object node, String format, String... args) {
+ StaplerRequest2 req, StaplerResponse2 rsp, Object node, String format, String... args) {
List
+ * For example, if the requested URL is "foo/bar/zot/abc?def=ghi" and
+ * "foo/bar" portion matched {@code bar.jsp}, this method returns
+ * "/zot/abc".
+ *
+ *
+ * If this method is invoked from getters or {@link StaplerProxy#getTarget()}
+ * during the object traversal, this method returns the path portion
+ * that is not yet processed.
+ *
+ * @return
+ * can be empty string, but never null.
+ */
+ String getRestOfPath();
+
+ /**
+ * Returns the same thing as {@link #getRestOfPath()} but in the pre-decoded form,
+ * so all "%HH"s as present in the request URL is intact.
+ */
+ String getOriginalRestOfPath();
+
+ /**
+ * Returns the {@link ServletContext} object given to the stapler
+ * dispatcher servlet.
+ */
+ @Override
+ ServletContext getServletContext();
+
+ /**
+ * {@link #getRequestURI()} plus additional query string part, if it exists.
+ */
+ String getRequestURIWithQueryString();
+
+ /**
+ * {@link #getRequestURL()} plus additional query string part, if it exists.
+ */
+ StringBuffer getRequestURLWithQueryString();
+
+ /**
+ * Gets the {@link RequestDispatcher} that represents a specific view
+ * for the given object.
+ *
+ * This support both JSP and Jelly.
+ *
+ * @param viewName
+ * If this name is relative name like "foo.jsp" or "bar/zot.jelly",
+ * then the corresponding "side file" is searched by this name.
+ *
+ * For Jelly, this also accepts absolute path name that starts
+ * with '/', such as "/foo/bar/zot.jelly". In this case,
+ * {@code it.getClass().getClassLoader()} is searched for this script.
+ *
+ * @return null
+ * if neither JSP nor Jelly is not found by the given name.
+ */
+ RequestDispatcher getView(Object it, String viewName) throws IOException;
+
+ /**
+ * Convenience method to call {@link #getView(Klass, String)} with {@link Class}.
+ */
+ RequestDispatcher getView(Class clazz, String viewName) throws IOException;
+
+ /**
+ * Gets the {@link RequestDispatcher} that represents a specific view
+ * for the given class.
+ *
+ *
+ * Unlike {@link #getView(Object, String)}, calling this request dispatcher
+ * doesn't set the "it" variable, so
+ * {@code getView(it.getClass(),viewName)} and {@code getView(it,viewName)}
+ * aren't the same thing.
+ */
+ RequestDispatcher getView(Klass> clazz, String viewName) throws IOException;
+
+ /**
+ * Gets the part of the request URL from protocol up to the context path.
+ * So typically it's something like {@code http://foobar:8080/something}
+ */
+ String getRootPath();
+
+ /**
+ * Gets the referer header (like "http://foobar.com/zot") or null.
+ *
+ * This is just a convenience method.
+ */
+ String getReferer();
+
+ /**
+ * Returns a list of ancestor objects that lead to the "it" object.
+ * The returned list contains {@link Ancestor} objects sorted in the
+ * order from root to the "it" object.
+ *
+ *
+ * For example, if the URL was "foo/bar/zot" and the "it" object
+ * was determined as
+ *
+ *
+ * @return
+ * list of {@link Ancestor}s. Can be empty, but always non-null.
+ */
+ List
+ * This method can behave in three ways.
+ *
+ *
+ * This method sends out the "Expires" header to force browser
+ * to re-validate all the time.
+ *
+ * @param timestampOfResource
+ * The time stamp of the resource.
+ * @param rsp
+ * This object is updated accordingly to simplify processing.
+ *
+ * @return
+ * false to indicate that the caller has to serve the actual resource.
+ * true to indicate that the caller should just quit processing right there
+ * (and send back {@link HttpServletResponse#SC_NOT_MODIFIED}.
+ */
+ boolean checkIfModified(long timestampOfResource, StaplerResponse2 rsp);
+
+ /**
+ * @see #checkIfModified(long, StaplerResponse2)
+ */
+ boolean checkIfModified(Date timestampOfResource, StaplerResponse2 rsp);
+
+ /**
+ * @see #checkIfModified(long, StaplerResponse2)
+ */
+ boolean checkIfModified(Calendar timestampOfResource, StaplerResponse2 rsp);
+
+ /**
+ * @param expiration
+ * The number of milliseconds until the resource will "expire".
+ * Until it expires the browser will be allowed to cache it
+ * and serve it without checking back with the server.
+ * After it expires, the client will send conditional GET to
+ * check if the resource is actually modified or not.
+ * If 0, it will immediately expire.
+ *
+ * @see #checkIfModified(long, StaplerResponse2)
+ */
+ boolean checkIfModified(long timestampOfResource, StaplerResponse2 rsp, long expiration);
+
+ /**
+ * Binds form parameters to a bean by using introspection.
+ *
+ * For example, if there's a parameter called 'foo' that has value 'abc',
+ * then {@code bean.setFoo('abc')} will be invoked. This will be repeated
+ * for all parameters. Parameters that do not have corresponding setters will
+ * be simply ignored.
+ *
+ *
+ * Values are converted into the right type. See {@link ConvertUtils#convert(String, Class)}.
+ *
+ * @see BeanUtils#setProperty(Object, String, Object)
+ *
+ * @param bean
+ * The object which will be filled out.
+ */
+ void bindParameters(Object bean);
+
+ /**
+ * Binds form parameters to a bean by using introspection.
+ *
+ * This method works like {@link #bindParameters(Object)}, but it performs a
+ * pre-processing on property names. Namely, only property names that start
+ * with the given prefix will be used for binding, and only the portion of the
+ * property name after the prefix is used.
+ *
+ * So for example, if the prefix is "foo.", then property name "foo.bar" with value
+ * "zot" will invoke {@code bean.setBar("zot")}.
+ *
+ *
+ * @deprecated
+ * Instead of using prefix to group object among form parameter names,
+ * use structured form submission and {@link #bindJSON(Class, JSONObject)}.
+ */
+ @Deprecated
+ void bindParameters(Object bean, String prefix);
+
+ /**
+ * Binds collection form parameters to beans by using introspection or
+ * constructor parameters injection.
+ *
+ *
+ * This method works like {@link #bindParameters(Object,String)} and
+ * {@link #bindParameters(Class, String)}, but it assumes
+ * that form parameters have multiple-values, and use individual values to
+ * fill in multiple beans.
+ *
+ *
+ * For example, if {@code getParameterValues("foo")=={"abc","def"}}
+ * and {@code getParameterValues("bar")=={"5","3"}}, then this method will
+ * return two objects (the first with "abc" and "5", the second with
+ * "def" and "3".)
+ *
+ * @param type
+ * Type of the bean to be created. This class must have the default no-arg
+ * constructor.
+ *
+ * @param prefix
+ * See {@link #bindParameters(Object, String)} for details.
+ *
+ * @return
+ * Can be empty but never null.
+ *
+ *
+ * @deprecated
+ * Instead of using prefix to group object among form parameter names,
+ * use structured form submission and {@link #bindJSON(Class, JSONObject)}.
+ */
+ @Deprecated
+
+ * The given class must have a constructor annotated with '@stapler-constructor',
+ * and must be processed by the maven-stapler-plugin, so that the parameter names
+ * of the constructor is available at runtime.
+ *
+ *
+ * The prefix is used to control the form parameter name. For example,
+ * if the prefix is "foo." and if the constructor is define as
+ *
+ * This is useful for creating multiple instances from repeated form fields.
+ *
+ *
+ * @deprecated
+ * Instead of using prefix to group object among form parameter names,
+ * use structured form submission and {@link #bindJSON(Class, JSONObject)}.
+ */
+ @Deprecated
+
+ * For example, if you have a constructor that looks like the following:
+ *
+ * Sub-typing: In the above example,
+ * a new instance of {@code Bar} was created,
+ * but you can also create a subtype of Bar by having the '$class' property in
+ * JSON like this:
+ *
+ *
+ * The type that shows up in the constructor ({@code Bar} in this case)
+ * can be an interface or an abstract class.
+ */
+
+ * This method is bit like {@link #bindJSON(Class, JSONObject)}, except that this method
+ * populates an existing object, instead of creating a new instance.
+ *
+ *
+ * This method is also bit like {@link #bindParameters(Object, String)}, in that it
+ * populates an existing object from a form submission, except that this method
+ * obtains data from {@link JSONObject} thus more structured, whereas {@link #bindParameters(Object, String)}
+ * uses the map structure of the form submission.
+ */
+ void bindJSON(Object bean, JSONObject src);
+
+ /**
+ * Data-bind from either {@link JSONObject} or {@link JSONArray} to a list,
+ * by using {@link #bindJSON(Class, JSONObject)} as the lower-level mechanism.
+ *
+ *
+ * If the source is {@link JSONObject}, the returned list will contain
+ * a single item. If it is {@link JSONArray}, each item will be bound.
+ * If it is null, then the list will be empty.
+ */
+ {
/**
* Executes the given script on the given node and request, rendering output to the given response.
*/
- void execute(@NonNull StaplerRequest req, @NonNull StaplerResponse rsp, @NonNull S script, @CheckForNull Object it)
+ void execute(
+ @NonNull StaplerRequest2 req, @NonNull StaplerResponse2 rsp, @NonNull S script, @CheckForNull Object it)
throws Exception;
}
diff --git a/core/src/main/java/org/kohsuke/stapler/ScriptRequestDispatcher.java b/core/src/main/java/org/kohsuke/stapler/ScriptRequestDispatcher.java
index 803122772..9c63b6562 100644
--- a/core/src/main/java/org/kohsuke/stapler/ScriptRequestDispatcher.java
+++ b/core/src/main/java/org/kohsuke/stapler/ScriptRequestDispatcher.java
@@ -27,13 +27,13 @@
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import jakarta.servlet.RequestDispatcher;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.ServletRequest;
+import jakarta.servlet.ServletResponse;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
/**
* Implements a RequestDispatcher for a given model node and view. Unlike dispatchers created through
@@ -91,8 +91,8 @@ private ScriptRequestDispatcher(
@Override
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException {
- StaplerRequest req = (StaplerRequest) request;
- StaplerResponse rsp = (StaplerResponse) response;
+ StaplerRequest2 req = (StaplerRequest2) request;
+ StaplerResponse2 rsp = (StaplerResponse2) response;
DispatchValidator validator = req.getWebApp().getDispatchValidator();
validator.allowDispatch(req, rsp);
try {
diff --git a/core/src/main/java/org/kohsuke/stapler/SelectionInterceptedFunction.java b/core/src/main/java/org/kohsuke/stapler/SelectionInterceptedFunction.java
index c1426796d..d8c1a6517 100644
--- a/core/src/main/java/org/kohsuke/stapler/SelectionInterceptedFunction.java
+++ b/core/src/main/java/org/kohsuke/stapler/SelectionInterceptedFunction.java
@@ -1,7 +1,7 @@
package org.kohsuke.stapler;
+import jakarta.servlet.ServletException;
import java.lang.reflect.InvocationTargetException;
-import javax.servlet.ServletException;
import org.kohsuke.stapler.interceptor.Interceptor;
import org.kohsuke.stapler.interceptor.InterceptorAnnotation;
@@ -21,7 +21,7 @@
}
@Override
- Object bindAndInvoke(Object o, StaplerRequest req, StaplerResponse rsp, Object... headArgs)
+ Object bindAndInvoke(Object o, StaplerRequest2 req, StaplerResponse2 rsp, Object... headArgs)
throws IllegalAccessException, InvocationTargetException, ServletException {
return interceptor.invoke(req, rsp, o, headArgs);
}
@@ -32,7 +32,7 @@ private static final class Adapter extends ForwardingFunction {
}
@Override
- public Object invoke(StaplerRequest req, StaplerResponse rsp, Object o, Object... args)
+ public Object invoke(StaplerRequest2 req, StaplerResponse2 rsp, Object o, Object... args)
throws IllegalAccessException, InvocationTargetException, ServletException {
return next.bindAndInvoke(o, req, rsp, args);
}
diff --git a/core/src/main/java/org/kohsuke/stapler/Stapler.java b/core/src/main/java/org/kohsuke/stapler/Stapler.java
index 68a2530a2..4dbdc8da2 100644
--- a/core/src/main/java/org/kohsuke/stapler/Stapler.java
+++ b/core/src/main/java/org/kohsuke/stapler/Stapler.java
@@ -24,6 +24,15 @@
package org.kohsuke.stapler;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import jakarta.servlet.RequestDispatcher;
+import jakarta.servlet.ServletConfig;
+import jakarta.servlet.ServletContext;
+import jakarta.servlet.ServletContextEvent;
+import jakarta.servlet.ServletContextListener;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.File;
@@ -59,15 +68,6 @@
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.ConvertUtils;
@@ -462,7 +462,7 @@ OpenConnection selectResourceByLocale(URL url, Locale locale) throws IOException
/**
* Serves the specified {@link URLConnection} as a static resource.
*/
- boolean serveStaticResource(HttpServletRequest req, StaplerResponse rsp, OpenConnection con, long expiration)
+ boolean serveStaticResource(HttpServletRequest req, StaplerResponse2 rsp, OpenConnection con, long expiration)
throws IOException {
if (con == null) {
return false;
@@ -484,7 +484,7 @@ boolean serveStaticResource(HttpServletRequest req, StaplerResponse rsp, OpenCon
/**
* Serves the specified {@link URL} as a static resource.
*/
- boolean serveStaticResource(HttpServletRequest req, StaplerResponse rsp, URL url, long expiration)
+ boolean serveStaticResource(HttpServletRequest req, StaplerResponse2 rsp, URL url, long expiration)
throws IOException {
return serveStaticResource(req, rsp, openURL(url), expiration);
}
@@ -561,7 +561,7 @@ private static URLConnection openConnection(URL url) throws IOException {
*/
boolean serveStaticResource(
HttpServletRequest req,
- StaplerResponse rsp,
+ StaplerResponse2 rsp,
InputStream in,
long lastModified,
long expiration,
@@ -1001,7 +1001,7 @@ void invoke(RequestImpl req, ResponseImpl rsp, Object node) throws IOException,
@SuppressFBWarnings(
value = "REQUESTDISPATCHER_FILE_DISCLOSURE",
justification = "Forwarding the request to be handled correctly.")
- public void forward(RequestDispatcher dispatcher, StaplerRequest req, HttpServletResponse rsp)
+ public void forward(RequestDispatcher dispatcher, StaplerRequest2 req, HttpServletResponse rsp)
throws ServletException, IOException {
dispatcher.forward(req, new ResponseImpl(this, rsp));
}
@@ -1045,7 +1045,7 @@ public static void setRoot(ServletContextEvent event, Object rootApp) {
}
/**
- * Sets the classloader used by {@link StaplerRequest#bindJSON(Class, JSONObject)} and its sibling methods.
+ * Sets the classloader used by {@link StaplerRequest2#bindJSON(Class, JSONObject)} and its sibling methods.
*
* @deprecated
* Use {@link WebApp#setClassLoader(ClassLoader)}
@@ -1074,19 +1074,37 @@ public ClassLoader getClassLoader() {
}
/**
- * Gets the current {@link StaplerRequest} that the calling thread is associated with.
+ * Gets the current {@link StaplerRequest2} that the calling thread is associated with.
*/
- public static StaplerRequest getCurrentRequest() {
+ public static StaplerRequest2 getCurrentRequest2() {
return CURRENT_REQUEST.get();
}
/**
- * Gets the current {@link StaplerResponse} that the calling thread is associated with.
+ * @deprecated use {@link #getCurrentRequest2()}
*/
- public static StaplerResponse getCurrentResponse() {
+ @Deprecated
+ public static StaplerRequest getCurrentRequest() {
+ StaplerRequest2 currentRequest = getCurrentRequest2();
+ return currentRequest != null ? StaplerRequest.fromStaplerRequest2(currentRequest) : null;
+ }
+
+ /**
+ * Gets the current {@link StaplerResponse2} that the calling thread is associated with.
+ */
+ public static StaplerResponse2 getCurrentResponse2() {
return CURRENT_RESPONSE.get();
}
+ /**
+ * @deprecated use {@link #getCurrentResponse2()}
+ */
+ @Deprecated
+ public static StaplerResponse getCurrentResponse() {
+ StaplerResponse2 currentResponse = getCurrentResponse2();
+ return currentResponse != null ? StaplerResponse.fromStaplerResponse2(currentResponse) : null;
+ }
+
/**
* Gets the current {@link Stapler} that the calling thread is associated with.
*/
@@ -1166,7 +1184,7 @@ static String canonicalPath(String path) {
/**
* This is the {@link Converter} registry that Stapler uses, primarily
- * for form-to-JSON binding in {@link StaplerRequest#bindJSON(Class, JSONObject)}
+ * for form-to-JSON binding in {@link StaplerRequest2#bindJSON(Class, JSONObject)}
* and its family of methods.
*/
public static final ConvertUtilsBean CONVERT_UTILS = new ConvertUtilsBean();
@@ -1237,7 +1255,7 @@ public FileItem convert(Class type, Object value) {
return null;
}
try {
- return Stapler.getCurrentRequest().getFileItem2(value.toString());
+ return Stapler.getCurrentRequest2().getFileItem2(value.toString());
} catch (ServletException | IOException e) {
throw new ConversionException(e);
}
@@ -1254,7 +1272,7 @@ public org.apache.commons.fileupload.FileItem convert(Class type, Object value)
}
try {
return org.apache.commons.fileupload.FileItem.fromFileUpload2FileItem(
- Stapler.getCurrentRequest().getFileItem2(value.toString()));
+ Stapler.getCurrentRequest2().getFileItem2(value.toString()));
} catch (ServletException | IOException e) {
throw new ConversionException(e);
}
diff --git a/core/src/main/java/org/kohsuke/stapler/StaplerRequest.java b/core/src/main/java/org/kohsuke/stapler/StaplerRequest.java
index 448627d1b..59e79f1a5 100644
--- a/core/src/main/java/org/kohsuke/stapler/StaplerRequest.java
+++ b/core/src/main/java/org/kohsuke/stapler/StaplerRequest.java
@@ -23,17 +23,38 @@
package org.kohsuke.stapler;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
+import java.security.Principal;
import java.util.Calendar;
+import java.util.Collection;
import java.util.Date;
+import java.util.Enumeration;
import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.servlet.AsyncContext;
+import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpUpgradeHandler;
+import javax.servlet.http.Part;
+import javax.servlet.http.PushBuilder;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.beanutils.BeanUtils;
@@ -48,7 +69,9 @@
*
* @see Stapler#getCurrentRequest()
* @author Kohsuke Kawaguchi
+ * @deprecated use {@link StaplerRequest2}
*/
+@Deprecated
public interface StaplerRequest extends HttpServletRequest {
/**
* Gets the {@link Stapler} instance that this belongs to.
@@ -553,4 +576,1264 @@ public String getUrlNames() {
* {@code makeStaplerProxy}.
*/
RenderOnDemandParameters createJavaScriptProxyParameters(Object toBeExported);
+
+ default StaplerRequest2 toStaplerRequest2() {
+ return new StaplerRequest2() {
+ @Override
+ public Object getAttribute(String name) {
+ return StaplerRequest.this.getAttribute(name);
+ }
+
+ @Override
+ public Enumerationroot.getFoo().getBar("zot")
,
+ * then this list will contain the following 3 objects in this order:
+ *
+ *
+ *
+ *
+ *
+ * Foo(String a, String b)
, then the constructor will be invoked
+ * as new Foo(getParameter("foo.a"),getParameter("foo.b"))
.
+ *
+ * @deprecated
+ * Instead of using prefix to group object among form parameter names,
+ * use structured form submission and {@link #bindJSON(Class, JSONObject)}.
+ */
+ @Deprecated
+
+ * class Foo {
+ * @{@link DataBoundConstructor}
+ * public Foo(Integer x, String y, boolean z, Bar bar) { ... }
+ * }
+ *
+ * class Bar {
+ * @{@link DataBoundConstructor}
+ * public Bar(int x, int y) {}
+ * }
+ *
+ *
+ * ... and if JSONObject looks like
+ *
+ * { y:"text", z:true, bar:{x:1,y:2}}
+ *
+ * then, this method returns
+ *
+ * new Foo(null,"text",true,new Bar(1,2))
+ *
+ *
+ * class BarEx extends Bar {
+ * @{@link DataBoundConstructor}
+ * public BarEx(int a, int b, int c) {}
+ * }
+ *
+ * { y:"text", z:true, bar: { $class:"p.k.g.BarEx", a:1, b:2, c:3 } }
+ *
+ *
+ *