This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 86c97bea27 refactor: inline RestContext Args and remove RestContextInit
86c97bea27 is described below
commit 86c97bea27d2d1cf3452928e751ccf88da321a10
Author: James Bognar <[email protected]>
AuthorDate: Mon May 4 17:11:46 2026 -0400
refactor: inline RestContext Args and remove RestContextInit
---
.../juneau/ng/rest/mock/NgMockRestClient.java | 2 +-
.../apache/juneau/rest/mock/MockRestClient.java | 2 +-
.../java/org/apache/juneau/rest/RestChild.java | 66 ---------
.../java/org/apache/juneau/rest/RestContext.java | 146 ++++++++++--------
.../org/apache/juneau/rest/RestContextInit.java | 164 ---------------------
.../apache/juneau/rest/servlet/RestServlet.java | 2 +-
.../src/test/java/org/apache/juneau/TestUtils.java | 2 +-
.../org/apache/juneau/rest/NoInherit_Test.java | 10 +-
.../RestOpContext_HttpMethodResolution_Test.java | 2 +-
.../rest/RestOpContext_OpLevelOverrides_Test.java | 2 +-
.../java/org/apache/juneau/rest/Swagger_Test.java | 4 +-
.../annotation/Rest_BeanCreatorOverrides_Test.java | 2 +-
12 files changed, 98 insertions(+), 306 deletions(-)
diff --git
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/ng/rest/mock/NgMockRestClient.java
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/ng/rest/mock/NgMockRestClient.java
index 7456f6e954..91f532ca37 100644
---
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/ng/rest/mock/NgMockRestClient.java
+++
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/ng/rest/mock/NgMockRestClient.java
@@ -218,7 +218,7 @@ public final class NgMockRestClient implements Closeable {
if (!restContextCache.containsKey(c)) {
var isClass = impl instanceof Class<?>;
var o = isClass ?
((Class<?>)impl).getDeclaredConstructor().newInstance() : impl;
- RestContext rc = new RestContext(new
RestContextInit(o.getClass(), () -> o, bs -> {
+ RestContext rc = new RestContext(new
RestContext.Args(o.getClass(), null, null, () -> o, "", bs -> {
bs.addBean(Enablement.class,
CONDITIONAL);
bs.addBeanType(CallLogger.class, BasicTestCallLogger.class);
})).postInit().postInitChildFirst();
diff --git
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
index 25267ec984..10c7158ad0 100644
---
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
+++
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
@@ -1886,7 +1886,7 @@ public class MockRestClient extends RestClient implements
HttpClientConnection {
if (! restContexts.containsKey(c)) {
var isClass = restBean instanceof Class;
var o = isClass ?
((Class<?>)restBean).getDeclaredConstructor().newInstance() : restBean;
- RestContext rc = new RestContext(new
RestContextInit(o.getClass(), () -> o, bs -> {
+ RestContext rc = new RestContext(new
RestContext.Args(o.getClass(), null, null, () -> o, "", bs -> {
bs.addBean(Enablement.class,
CONDITIONAL);
bs.addBeanType(CallLogger.class,
BasicTestCallLogger.class);
})).postInit().postInitChildFirst();
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestChild.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestChild.java
deleted file mode 100644
index ddf4aead43..0000000000
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestChild.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.juneau.rest;
-
-import org.apache.juneau.cp.*;
-import org.apache.juneau.rest.annotation.*;
-
-/**
- * Represents a simple child REST resource / path mapping.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Parent resource declares its children declaratively via the
@Rest annotation.</jc>
- * <ja>@Rest</ja>(children = { MyChildResource.<jk>class</jk>,
OtherChildResource.<jk>class</jk> })
- * <jk>public class</jk> MyResource { ... }
- *
- * <jc>// Or programmatically via RestContextInit when constructing the
context directly:</jc>
- * <jk>new</jk> RestContext(<jk>new</jk> RestContextInit(
- * MyResource.<jk>class</jk>, <jk>null</jk>, <jk>null</jk>, ()
-> <jk>new</jk> MyResource(),
- * <js>""</js>, List.<jsm>of</jsm>(<jk>new</jk>
RestChild(<js>"/child"</js>, <jk>new</jk> MyChildResource()))));
- * </p>
- *
- * <h5 class='section'>Note (9.5):</h5>
- * <p>
- * The legacy {@code public MyResource(RestContext.Builder builder)}
constructor pattern (where the resource class
- * imperatively registered children inside its own ctor) is removed in 9.5
along with {@code RestContext.Builder}.
- * Resource classes now declare children either via the {@link Rest#children()
@Rest(children=...)} annotation or
- * by passing them through {@link RestContextInit#children()
RestContextInit.children}.
- *
- * <h5 class='section'>See Also:</h5><ul>
- * <li class='link'><a class="doclink"
href="https://juneau.apache.org/docs/topics/RestAnnotatedClassBasics">@Rest-Annotated
Class Basics</a>
- * </ul>
- */
-public class RestChild {
-
- final String path;
- final Object resource;
-
- /**
- * Constructor.
- *
- * @param path The child resource path relative to the parent resource
URI.
- * @param resource
- * The child resource.
- * <br>Can either be a Class (which will be instantiated using the
registered {@link BasicBeanStore})
- * or an already-instantiated object.
- */
- public RestChild(String path, Object resource) {
- this.path = path;
- this.resource = resource;
- }
-}
\ No newline at end of file
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index 1b9c08cc0d..76f8e7f6a5 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -99,7 +99,7 @@ import jakarta.servlet.http.*;
* (and inherited from any parent classes), and programmatically through
{@link RestInject @RestInject}-annotated
* methods/fields that contribute named beans (e.g. <c>encoders</c>,
<c>parsers</c>, <c>callLogger</c>) to the REST
* resource's bean store. Where direct construction is needed (test rigs, mock
clients, embedded usage),
- * the public constructor takes a {@link RestContextInit} record carrying the
bootstrap state.
+ * the public constructor takes a {@link RestContext.Args} record carrying the
bootstrap state.
*
* <h5 class='section'>Example:</h5>
* <p class='bjava'>
@@ -160,12 +160,69 @@ public class RestContext extends Context {
private static final String ARG_resource = "resource";
private static final String ARG_restContext = "restContext";
+ /**
+ * Bootstrap arguments for {@link RestContext}.
+ *
+ * <p>
+ * Bundles the small, fixed set of inputs needed to construct a {@link
RestContext} into a single immutable record.
+ *
+ * <p>
+ * All non-required values default sensibly:
+ * <ul>
+ * <li>{@code parentContext}, {@code servletConfig} — {@code null}
(top-level resource, no servlet container)
+ * <li>{@code path} — {@code ""} (no path prefix)
+ * <li>{@code beanStoreConfigurer} — no-op (no pre-build
bean-store mutation)
+ * </ul>
+ *
+ * <p>
+ * The {@code beanStoreConfigurer} hook gives test fixtures and
integration code a chance to register beans on
+ * the {@link BasicBeanStore} after the resource has been wired in but
before the
+ * {@code findXxx()} memoizers fire.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bjava'>
+ * <jk>var</jk> <jv>ctx</jv> = <jk>new</jk>
RestContext(<jk>new</jk> RestContext.Args(MyResource.<jk>class</jk>, () ->
<jk>new</jk> MyResource()));
+ * </p>
+ *
+ * @param resourceClass The {@link Rest @Rest}-annotated REST resource
class. Must not be {@code null}.
+ * @param parentContext The parent {@link RestContext}, or {@code null}
if this is a top-level resource.
+ * @param servletConfig The {@link ServletConfig} from the servlet
container, or {@code null} when none is available.
+ * @param resource The supplier that provides the resource instance
during initialization. Must not be {@code null}.
+ * @param path The path prefix relative to the parent. Defaults to
{@code ""}.
+ * @param beanStoreConfigurer A pre-build hook that runs against the
resolved {@link BasicBeanStore}
+ * after the resource has been wired in but before any {@code
findXxx()} memoizer fires. Defaults to a no-op.
+ *
+ * @since 9.5.0
+ */
+ public static record Args(
+ Class<?> resourceClass,
+ RestContext parentContext,
+ ServletConfig servletConfig,
+ Supplier<?> resource,
+ String path,
+ Consumer<BasicBeanStore> beanStoreConfigurer
+ ) {
+
+ /**
+ * Compact canonical constructor — null-coalesces optional
fields and validates required ones.
+ */
+ public Args {
+ assertArgNotNull("resourceClass", resourceClass);
+ assertArgNotNull(ARG_resource, resource);
+ if (path == null)
+ path = "";
+ if (beanStoreConfigurer == null)
+ beanStoreConfigurer = bs -> {};
+ }
+
+ }
+
/**
* Builder class.
*
* <p>
* Demoted to package-private in the April 2026 refactor (2026-04-19).
User code should construct a
- * {@link RestContext} via the public {@link
#RestContext(RestContextInit)} constructor; this Builder
+ * {@link RestContext} via the public {@link #RestContext(Args)}
constructor; this Builder
* exists only as internal bootstrap state for the framework and is
slated for inlining in a later phase.
*/
static class Builder extends Context.Builder implements ServletConfig {
@@ -253,7 +310,6 @@ public class RestContext extends Context {
private BeanContext.Builder beanContext;
private BasicBeanStore beanStore;
private BasicBeanStore bootstrapBeanStore;
- private boolean initialized;
private final Class<?> resourceClass;
private Config config;
private EncoderSet.Builder encoders;
@@ -281,21 +337,25 @@ public class RestContext extends Context {
*
* <p>
* Demoted from {@code protected} to package-private in the
April 2026 refactor (2026-04-19). Only
- * {@link RestContext#toBuilder(RestContextInit)} instantiates
this type now.
+ * {@link RestContext#RestContext(Args)} instantiates this type
now.
*
- * @param resourceClass
- * The REST servlet/bean type that this context is defined
against.
- * @param parentContext The parent context if this is a child
of another resource.
- * @param servletConfig The servlet config if available.
+ * @param rci The bootstrap arguments. Must not be {@code null}.
+ * @throws ServletException If hook method calls failed.
*/
- Builder(Class<?> resourceClass, RestContext parentContext,
ServletConfig servletConfig) {
+ Builder(Args rci) throws ServletException {
- this.resourceClass = resourceClass;
- this.inner = servletConfig;
- this.parentContext = parentContext;
+ this.resourceClass = rci.resourceClass();
+ this.inner = rci.servletConfig();
+ this.parentContext = rci.parentContext();
if (nn(parentContext))
bootstrapBeanStore =
parentContext.bootstrapBeanStore;
+
+ init(rci.resource());
+
+ if (! rci.path().isEmpty())
+ path(rci.path());
+ rci.beanStoreConfigurer().accept(beanStore());
}
@Override /* Context.Builder is abstract - copy() is not
meaningful for the transient RestContext bootstrap state. */
@@ -369,7 +429,7 @@ public class RestContext extends Context {
*
* <p>
* Child resources must specify a value for {@link Rest#path()
@Rest(path)} that identifies the subpath of the child resource
- * relative to the ascendant path unless registered as explicit
{@link RestChild} instances.
+ * relative to the ascendant path.
*
* <p>
* Child resources can be nested arbitrarily deep using this
technique (i.e. children can also have children).
@@ -411,7 +471,7 @@ public class RestContext extends Context {
*
* <p>
* For programmatic registration of pre-instantiated child
resources, supply them via
- * {@link RestContextInit#children()} when constructing the
context directly.
+ * {@link Rest#children() @Rest(children)} when constructing
the context directly.
*
* <h5 class='section'>Notes:</h5><ul>
* <li class='note'>
@@ -430,7 +490,6 @@ public class RestContext extends Context {
* <ul>
* <li>A class that has a constructor described
above.
* <li>An instantiated resource object (such as a
servlet object instantiated by a servlet container).
- * <li>An instance of {@link RestChild} containing
an instantiated resource object and a subpath.
* </ul>
* @return This object.
*/
@@ -687,20 +746,7 @@ public class RestContext extends Context {
@Override /* Overridden from ServletConfig */
public String getServletName() { return inner == null ? null :
inner.getServletName(); }
- /**
- * Performs initialization on this builder against the
specified REST servlet/bean instance.
- *
- * @param resource
- * The REST servlet/bean instance that this context is
defined against.
- * <br>Cannot be <jk>null</jk>.
- * @return This object.
- * @throws ServletException If hook method calls failed.
- */
- public Builder init(Supplier<?> resource) throws
ServletException {
-
- if (initialized)
- return this;
- initialized = true;
+ private Builder init(Supplier<?> resource) throws
ServletException {
this.resource = new ResourceSupplier(resourceClass,
assertArgNotNull(ARG_resource, resource));
var r = this.resource;
@@ -921,7 +967,7 @@ public class RestContext extends Context {
* </p>
*
* <p>
- * For programmatic construction, supply the path via {@link
RestContextInit} when building a {@link RestContext}
+ * For programmatic construction, supply the path via {@link
RestContext.Args} when building a {@link RestContext}
* directly.
*
* <p>
@@ -1757,16 +1803,10 @@ public class RestContext extends Context {
// Initialize our child resources.
for (var o : children) {
- String path2 = null;
Supplier<?> so;
Class<?> rc2;
- if (o instanceof RestChild o2) {
- path2 = o2.path;
- var o3 = o2.resource;
- so = () -> o3;
- rc2 = o3.getClass();
- } else if (o instanceof Class<?> oc) {
+ if (o instanceof Class<?> oc) {
// Don't allow specifying yourself as a
child. Causes an infinite loop.
if (oc == resourceClass)
continue;
@@ -1785,8 +1825,7 @@ public class RestContext extends Context {
so = () -> o;
}
- var cc = new RestContext(new
RestContextInit(rc2, restContext, inner, so,
- path2 == null ? "" : path2,
java.util.List.of()));
+ var cc = new RestContext(new Args(rc2, restContext,
inner, so, "", null));
var mi = ClassInfo.of(so.get()).getMethod(x ->
x.hasName("setContext") && x.hasParameterTypes(RestContext.class)).orElse(null);
if (nn(mi))
@@ -2531,30 +2570,14 @@ public class RestContext extends Context {
});
/**
- * Constructor — record-based entry point.
- *
- * <p>
- * Wires {@link RestContextInit#resourceClass()}, {@link
RestContextInit#parentContext()},
- * {@link RestContextInit#servletConfig()}, {@link
RestContextInit#resource()}, {@link RestContextInit#path()},
- * {@link RestContextInit#children()}, and {@link
RestContextInit#beanStoreConfigurer()} into the resolved
- * {@code RestContext}. Replaces the deleted {@code
RestContext.create(...)} fluent factory.
+ * Constructor.
*
- * @param init The bootstrap arguments. Must not be <jk>null</jk>.
+ * @param args The bootstrap arguments. Must not be <jk>null</jk>.
* @throws Exception If any initialization problems were encountered.
- * @since 9.2.1
+ * @since 9.5.0
*/
- public RestContext(RestContextInit init) throws Exception {
- this(toBuilder(init));
- }
-
- private static Builder toBuilder(RestContextInit init) throws
ServletException {
- var b = new Builder(init.resourceClass(), init.parentContext(),
init.servletConfig()).init(init.resource());
- if (! init.path().isEmpty())
- b.path(init.path());
- if (! init.children().isEmpty())
- b.children(init.children().toArray());
- init.beanStoreConfigurer().accept(b.beanStore());
- return b;
+ public RestContext(Args args) throws Exception {
+ this(new Builder(args));
}
/**
@@ -2562,8 +2585,7 @@ public class RestContext extends Context {
*
* <p>
* Privatized in the April 2026 refactor (2026-04-19). External callers
must use
- * {@link #RestContext(RestContextInit)} instead; this constructor only
services the internal
- * {@link #toBuilder(RestContextInit)} helper.
+ * {@link #RestContext(Args)} instead.
*
* @param builder The builder containing the settings for this bean.
* @throws Exception If any initialization problems were encountered.
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextInit.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextInit.java
deleted file mode 100644
index cc91ea11a1..0000000000
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextInit.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.juneau.rest;
-
-import static java.util.Collections.emptyList;
-import static org.apache.juneau.commons.utils.AssertionUtils.assertArgNotNull;
-
-import java.util.List;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
-
-import jakarta.servlet.ServletConfig;
-
-import org.apache.juneau.cp.BasicBeanStore;
-import org.apache.juneau.rest.annotation.Rest;
-
-/**
- * Bootstrap arguments for {@link RestContext}.
- *
- * <p>
- * Bundles the small, fixed set of inputs needed to construct a {@link
RestContext} into a single immutable record,
- * replacing the chained {@code RestContext.Builder.init(Supplier)} / {@code
RestContext.Builder.path(String)} /
- * {@code RestContext.Builder.children(Object...)} fluent calls of the legacy
builder factory.
- *
- * <p>
- * All non-required values default sensibly:
- * <ul>
- * <li>{@code parentContext}, {@code servletConfig} — {@code null}
(top-level resource, no servlet container)
- * <li>{@code path} — {@code ""} (no path prefix)
- * <li>{@code children} — empty list (no programmatic child resources)
- * <li>{@code beanStoreConfigurer} — no-op (no pre-build bean-store
mutation)
- * </ul>
- *
- * <p>
- * The {@code beanStoreConfigurer} hook gives test fixtures and integration
code (mock REST clients, etc.) a chance
- * to register beans on the {@link BasicBeanStore} *after* the resource has
been wired in but *before* the
- * {@code findXxx()} memoizers fire. This is the post-builder replacement for
the legacy pattern
- * {@code RestContext.create(...).init(...).beanStore(X.class,
x).beanStore().addBeanType(Y.class, Yimpl.class)
- * .build()}.
- *
- * <p>
- * Required values:
- * <ul>
- * <li>{@code resourceClass} — the {@link Rest @Rest}-annotated REST
resource type
- * <li>{@code resource} — the supplier that yields the resource instance
during {@code init()}
- * </ul>
- *
- * <h5 class='section'>Note on naming:</h5>
- * <p>
- * Decision #27 in the RestContext refactor plan originally settled on the
{@code XArgs} suffix for
- * ctor-arg-bundle records, but
- * {@code RestContextArgs} is already taken by the {@link
org.apache.juneau.rest.arg.RestContextArgs} parameter
- * resolver in the {@link org.apache.juneau.rest.arg} package (one of an
entire family of {@code *Args}
- * {@link org.apache.juneau.rest.annotation.RestOp @RestOp}-method
arg-resolver classes:
- * {@link org.apache.juneau.rest.arg.RestSessionArgs RestSessionArgs},
- * {@link org.apache.juneau.rest.arg.RestOpContextArgs RestOpContextArgs},
etc.). The {@code Init} suffix avoids the
- * collision and reads naturally — this record consolidates the legacy {@code
RestContext.Builder.init(Supplier)}
- * fluent method.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bjava'>
- * <jc>// Top-level resource, no servlet config, no children, no path
prefix.</jc>
- * <jk>var</jk> <jv>ctx</jv> = <jk>new</jk> RestContext(<jk>new</jk>
RestContextInit(MyResource.<jk>class</jk>, () -> <jk>new</jk> MyResource()));
- *
- * <jc>// Child resource registered against a parent context with a path
prefix.</jc>
- * <jk>var</jk> <jv>child</jv> = <jk>new</jk> RestContext(<jk>new</jk>
RestContextInit(
- * MyChild.<jk>class</jk>, <jv>parent</jv>, <jk>null</jk>, ()
-> <jk>new</jk> MyChild(), <js>"/child"</js>, List.<jsm>of</jsm>()));
- * </p>
- *
- * @param resourceClass The {@link Rest @Rest}-annotated REST resource class.
Must not be {@code null}.
- * @param parentContext The parent {@link RestContext}, or {@code null} if
this is a top-level resource.
- * @param servletConfig The {@link ServletConfig} from the servlet container,
or {@code null} when none is available.
- * @param resource The supplier that provides the resource instance during
initialization. Must not be {@code null}.
- * @param path The path prefix relative to the parent. Defaults to {@code ""}.
- * @param children Programmatically-registered child resources. Defaults to an
empty list.
- * @param beanStoreConfigurer A pre-build hook that runs against the resolved
{@link BasicBeanStore} after the
- * resource has been wired in but before any {@code findXxx()} memoizer
fires. Defaults to a no-op. Use this to
- * register typed-class bindings (via {@link
BasicBeanStore#addBeanType(Class, Class) addBeanType}) or instance
- * beans (via {@link BasicBeanStore#addBean(Class, Object) addBean}) that
need to be visible to the memoizers.
- *
- * @since 9.2.1
- */
-public record RestContextInit(
- Class<?> resourceClass,
- RestContext parentContext,
- ServletConfig servletConfig,
- Supplier<?> resource,
- String path,
- List<Object> children,
- Consumer<BasicBeanStore> beanStoreConfigurer
-) {
-
- /**
- * Compact canonical constructor — null-coalesces optional fields and
validates the required ones.
- *
- * @param resourceClass The REST resource class. Must not be
<jk>null</jk>.
- * @param parentContext Optional parent context.
- * @param servletConfig Optional servlet config.
- * @param resource The resource supplier. Must not be <jk>null</jk>.
- * @param path Optional path prefix. {@code null} is normalized to
{@code ""}.
- * @param children Optional child list. {@code null} is normalized to
an empty list.
- * @param beanStoreConfigurer Optional pre-build bean-store hook.
{@code null} is normalized to a no-op.
- */
- public RestContextInit {
- assertArgNotNull("resourceClass", resourceClass);
- assertArgNotNull("resource", resource);
- if (path == null)
- path = "";
- if (children == null)
- children = emptyList();
- if (beanStoreConfigurer == null)
- beanStoreConfigurer = bs -> {};
- }
-
- /**
- * Backward-compat constructor — same as the canonical constructor but
without the {@code beanStoreConfigurer} hook.
- *
- * @param resourceClass The REST resource class. Must not be
<jk>null</jk>.
- * @param parentContext Optional parent context.
- * @param servletConfig Optional servlet config.
- * @param resource The resource supplier. Must not be <jk>null</jk>.
- * @param path Optional path prefix. {@code null} is normalized to
{@code ""}.
- * @param children Optional child list. {@code null} is normalized to
an empty list.
- */
- public RestContextInit(Class<?> resourceClass, RestContext
parentContext, ServletConfig servletConfig,
- Supplier<?> resource, String path, List<Object>
children) {
- this(resourceClass, parentContext, servletConfig, resource,
path, children, null);
- }
-
- /**
- * Convenience constructor for a top-level resource with no servlet
config, no path prefix, and no programmatic children.
- *
- * @param resourceClass The REST resource class. Must not be
<jk>null</jk>.
- * @param resource The resource supplier. Must not be <jk>null</jk>.
- */
- public RestContextInit(Class<?> resourceClass, Supplier<?> resource) {
- this(resourceClass, null, null, resource, "", emptyList(),
null);
- }
-
- /**
- * Convenience constructor for a top-level resource with a pre-build
bean-store configurer.
- *
- * @param resourceClass The REST resource class. Must not be
<jk>null</jk>.
- * @param resource The resource supplier. Must not be <jk>null</jk>.
- * @param beanStoreConfigurer Pre-build bean-store hook.
- */
- public RestContextInit(Class<?> resourceClass, Supplier<?> resource,
Consumer<BasicBeanStore> beanStoreConfigurer) {
- this(resourceClass, null, null, resource, "", emptyList(),
beanStoreConfigurer);
- }
-}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/servlet/RestServlet.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/servlet/RestServlet.java
index 3ad82d4be6..9e5f17bab1 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/servlet/RestServlet.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/servlet/RestServlet.java
@@ -149,7 +149,7 @@ public abstract class RestServlet extends HttpServlet {
if (nn(context.get()))
return;
super.init(servletConfig);
- context.set(new RestContext(new
RestContextInit(this.getClass(), null, servletConfig, () -> this, "",
java.util.List.of())));
+ context.set(new RestContext(new
RestContext.Args(this.getClass(), null, servletConfig, () -> this, "", null)));
context.get().postInit();
context.get().postInitChildFirst();
} catch (ServletException e) {
diff --git a/juneau-utest/src/test/java/org/apache/juneau/TestUtils.java
b/juneau-utest/src/test/java/org/apache/juneau/TestUtils.java
index 7e384e23d7..b26800278c 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/TestUtils.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/TestUtils.java
@@ -331,7 +331,7 @@ public class TestUtils extends Utils {
public static Swagger getSwagger(Class<?> c) {
try {
var r = c.getDeclaredConstructor().newInstance();
- var rc = new RestContext(new
RestContextInit(r.getClass(), () -> r));
+ var rc = new RestContext(new
RestContext.Args(r.getClass(), null, null, () -> r, "", null));
var ctx = new
RestOpContext(TestUtils.class.getMethod("getSwagger", Class.class), rc);
var session =
RestSession.create(rc).resource(r).req(new MockServletRequest()).res(new
MockServletResponse()).build();
var req = ctx.createRequest(session);
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/NoInherit_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/NoInherit_Test.java
index 739f32f175..2dc2b219e0 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/NoInherit_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/NoInherit_Test.java
@@ -43,7 +43,7 @@ class NoInherit_Test extends TestBase {
parentContext = restContext(parentClass);
}
- return new RestContext(new RestContextInit(c, parentContext,
null, () -> o, "", java.util.List.of())).postInit().postInitChildFirst();
+ return new RestContext(new RestContext.Args(c, parentContext,
null, () -> o, "", null)).postInit().postInitChildFirst();
}
@Rest(allowedSerializerOptions = "parentSer")
@@ -195,7 +195,7 @@ class NoInherit_Test extends TestBase {
@Test
void a06_restOp_noInherit_defaultCharset_skipsContextCharset() throws
Exception {
var o = new CharsetNoInheritPlain();
- var ctx = new RestContext(new
RestContextInit(CharsetNoInheritPlain.class, () ->
o)).postInit().postInitChildFirst();
+ var ctx = new RestContext(new
RestContext.Args(CharsetNoInheritPlain.class, null, null, () -> o, "",
null)).postInit().postInitChildFirst();
var op = ctx.getRestOperations().getOpContexts().get(0);
assertFalse(op.getRestOpAnnotations().isEmpty(), "Expected
@RestGet on method for noInherit aggregation");
assertFalse(op.isInherited("defaultCharset"),
"noInherit=defaultCharset should block @Rest charset fallback");
@@ -207,7 +207,7 @@ class NoInherit_Test extends TestBase {
@Test
void a07_restOp_withoutNoInherit_defaultCharset_inheritsContext()
throws Exception {
var o = new CharsetInheritPlain();
- var ctx = new RestContext(new
RestContextInit(CharsetInheritPlain.class, () ->
o)).postInit().postInitChildFirst();
+ var ctx = new RestContext(new
RestContext.Args(CharsetInheritPlain.class, null, null, () -> o, "",
null)).postInit().postInitChildFirst();
var op = ctx.getRestOperations().getOpContexts().get(0);
assertEquals(StandardCharsets.ISO_8859_1,
op.getDefaultCharset());
}
@@ -231,7 +231,7 @@ class NoInherit_Test extends TestBase {
@Test
void a08_restOp_noInherit_maxInput_skipsContextMaxInput() throws
Exception {
var o = new MaxNoInheritPlain();
- var ctx = new RestContext(new
RestContextInit(MaxNoInheritPlain.class, () ->
o)).postInit().postInitChildFirst();
+ var ctx = new RestContext(new
RestContext.Args(MaxNoInheritPlain.class, null, null, () -> o, "",
null)).postInit().postInitChildFirst();
var op = ctx.getRestOperations().getOpContexts().get(0);
var expected = env("RestContext.maxInput").map(x ->
parseLongWithSuffix(x)).orElse(100_000_000L);
assertEquals(expected, op.getMaxInput());
@@ -241,7 +241,7 @@ class NoInherit_Test extends TestBase {
@Test
void a09_restOp_withoutNoInherit_maxInput_inheritsContext() throws
Exception {
var o = new MaxInheritPlain();
- var ctx = new RestContext(new
RestContextInit(MaxInheritPlain.class, () ->
o)).postInit().postInitChildFirst();
+ var ctx = new RestContext(new
RestContext.Args(MaxInheritPlain.class, null, null, () -> o, "",
null)).postInit().postInitChildFirst();
var op = ctx.getRestOperations().getOpContexts().get(0);
assertEquals(parseLongWithSuffix("7M"), op.getMaxInput());
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/RestOpContext_HttpMethodResolution_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/RestOpContext_HttpMethodResolution_Test.java
index 9b1800c833..22646528e4 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/RestOpContext_HttpMethodResolution_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/RestOpContext_HttpMethodResolution_Test.java
@@ -40,7 +40,7 @@ class RestOpContext_HttpMethodResolution_Test extends
TestBase {
private static RestContext build(Class<?> c) throws Exception {
var o = c.getDeclaredConstructor().newInstance();
- return new RestContext(new RestContextInit(c, () ->
o)).postInit().postInitChildFirst();
+ return new RestContext(new RestContext.Args(c, null, null, ()
-> o, "", null)).postInit().postInitChildFirst();
}
private static String verbOf(RestContext ctx, String javaMethodName) {
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/RestOpContext_OpLevelOverrides_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/RestOpContext_OpLevelOverrides_Test.java
index 3121e0ce62..bbce72d9a8 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/RestOpContext_OpLevelOverrides_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/RestOpContext_OpLevelOverrides_Test.java
@@ -43,7 +43,7 @@ class RestOpContext_OpLevelOverrides_Test extends TestBase {
private static RestContext build(Class<?> c) throws Exception {
var o = c.getDeclaredConstructor().newInstance();
- return new RestContext(new RestContextInit(c, () ->
o)).postInit().postInitChildFirst();
+ return new RestContext(new RestContext.Args(c, null, null, ()
-> o, "", null)).postInit().postInitChildFirst();
}
private static RestOpContext op(RestContext ctx) {
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/Swagger_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/Swagger_Test.java
index f24e5052ef..3949337233 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/Swagger_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/Swagger_Test.java
@@ -52,7 +52,7 @@ class Swagger_Test extends TestBase {
public void testMethod() { /* no-op */ }
private static org.apache.juneau.bean.swagger.Swagger
getSwaggerWithFile(Object resource) throws Exception {
- var rc = new RestContext(new
RestContextInit(resource.getClass(), () -> resource,
+ var rc = new RestContext(new
RestContext.Args(resource.getClass(), null, null, () -> resource, "",
bs -> bs.addBeanType(StaticFiles.class,
TestClasspathFileFinder.class)));
var roc = new
RestOpContext(Swagger_Test.class.getMethod("testMethod"), rc);
var call = RestSession.create(rc).resource(resource).req(new
MockServletRequest()).res(new MockServletResponse()).build();
@@ -62,7 +62,7 @@ class Swagger_Test extends TestBase {
}
private static org.apache.juneau.bean.swagger.Swagger getSwagger(Object
resource) throws Exception {
- var rc = new RestContext(new
RestContextInit(resource.getClass(), () -> resource));
+ var rc = new RestContext(new
RestContext.Args(resource.getClass(), null, null, () -> resource, "", null));
var roc = new
RestOpContext(Swagger_Test.class.getMethod("testMethod"), rc);
var call = RestSession.create(rc).resource(resource).req(new
MockServletRequest()).res(new MockServletResponse()).build();
var req = roc.createRequest(call);
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_BeanCreatorOverrides_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_BeanCreatorOverrides_Test.java
index 35b0e9ef75..03d54d08a5 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_BeanCreatorOverrides_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_BeanCreatorOverrides_Test.java
@@ -44,7 +44,7 @@ class Rest_BeanCreatorOverrides_Test extends TestBase {
private static RestContext build(Class<?> resourceClass) throws
Exception {
var resource =
resourceClass.getDeclaredConstructor().newInstance();
- return new RestContext(new RestContextInit(resourceClass, () ->
resource));
+ return new RestContext(new RestContext.Args(resourceClass,
null, null, () -> resource, "", null));
}
//------------------------------------------------------------------------------------------------------------------