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 d3d8fe9 Context API refactoring.
d3d8fe9 is described below
commit d3d8fe9a814e87b425b894428671786ebdf7497b
Author: JamesBognar <[email protected]>
AuthorDate: Sun Sep 19 17:24:35 2021 -0400
Context API refactoring.
---
.../java/org/apache/juneau/rest/RestOpContext.java | 59 +---------------------
.../apache/juneau/rest/RestOpContextBuilder.java | 59 +++++++++++++++-------
2 files changed, 42 insertions(+), 76 deletions(-)
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
index 957fb69..8ff1f87 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
@@ -48,7 +48,6 @@ import org.apache.juneau.httppart.*;
import org.apache.juneau.httppart.bean.*;
import org.apache.juneau.internal.HttpUtils;
import org.apache.juneau.jsonschema.*;
-import org.apache.juneau.oapi.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.reflect.*;
import org.apache.juneau.rest.annotation.*;
@@ -152,10 +151,7 @@ public class RestOpContext extends Context implements
Comparable<RestOpContext>
serializers = bs.add(SerializerGroup.class,
builder.getSerializers().orElse(context.getSerializers()));
parsers = bs.add(ParserGroup.class,
builder.getParsers().orElse(context.getParsers()));
partSerializer = bs.add(HttpPartSerializer.class,
builder.getPartSerializer().orElse(context.getPartSerializer()));
-
- partParser = createPartParser(r, builder, bs);
- bs.addBean(HttpPartParser.class, partParser);
-
+ partParser = bs.add(HttpPartParser.class,
builder.getPartParser().orElse(context.getPartParser()));
converters = bs.add(RestConverter[].class,
builder.converters().build().asArray());
guards = createGuards(r, builder, bs).asArray();
@@ -325,59 +321,6 @@ public class RestOpContext extends Context implements
Comparable<RestOpContext>
}
/**
- * Instantiates the HTTP part parser for this REST resource.
- *
- * <p>
- * Instantiates based on the following logic:
- * <ul>
- * <li>Returns the resource class itself is an instance of {@link
HttpPartParser}.
- * <li>Looks for part parser set via any of the following:
- * <ul>
- * <li>{@link RestContextBuilder#partParser()}
- * <li>{@link Rest#partParser()}.
- * </ul>
- * <li>Looks for a static or non-static <c>createPartParser()</>
method that returns <c>{@link HttpPartParser}</c> on the
- * resource class with any of the following arguments:
- * <ul>
- * <li>{@link RestContext}
- * <li>{@link BeanStore}
- * <li>Any {@doc RestInjection injected beans}.
- * </ul>
- * <li>Resolves it via the bean store registered in this context.
- * <li>Instantiates an {@link OpenApiSerializer}.
- * </ul>
- *
- * @param resource The REST resource object.
- * @param builder The builder for this object.
- * @param beanStore The bean store to use for retrieving and creating
beans.
- * @return The HTTP part parser for this REST resource.
- * @throws Exception If parser could not be instantiated.
- */
- protected HttpPartParser createPartParser(Object resource,
RestOpContextBuilder builder, BeanStore beanStore) throws Exception {
-
- HttpPartParser g =
beanStore.getBean(HttpPartParser.class).orElse(null);
-
- if (g != null)
- return g;
-
- HttpPartParser.Creator x = builder.partParser;
-
- if (x == null)
- x = builder.restContext.builder.partParser();
-
- x = BeanStore
- .of(beanStore, resource)
- .addBean(HttpPartParser.Creator.class, x)
- .createMethodFinder(HttpPartParser.Creator.class,
resource)
- .find("createPartParser", Method.class)
- .thenFind("createPartParser")
- .withDefault(x)
- .run();
-
- return x.create();
- }
-
- /**
* Instantiates the path matchers for this method.
*
* @param resource The REST resource object.
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContextBuilder.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContextBuilder.java
index 35c5b04..1aec019 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContextBuilder.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContextBuilder.java
@@ -32,7 +32,6 @@ import org.apache.juneau.http.remote.*;
import org.apache.juneau.http.response.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.internal.*;
-import org.apache.juneau.oapi.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.reflect.*;
import org.apache.juneau.rest.annotation.*;
@@ -136,7 +135,7 @@ public class RestOpContextBuilder extends ContextBuilder {
if (context.builder.partSerializer().canApply(al))
partSerializer().apply(al);
if (context.builder.partParser().canApply(al))
- getPartParser().apply(al);
+ partParser().apply(al);
} catch (Exception e) {
throw toHttpException(e, InternalServerError.class);
@@ -389,6 +388,46 @@ public class RestOpContextBuilder extends ContextBuilder {
}
//-----------------------------------------------------------------------------------------------------------------
+ // partParser
+
//-----------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Returns the builder for the {@link HttpPartParser} object in the
REST context.
+ *
+ * @return The builder for the {@link HttpPartParser} object in the
REST context.
+ */
+ public final HttpPartParser.Creator partParser() {
+ if (partParser == null)
+ partParser = createPartParser(beanStore(), parent,
resource());
+ return partParser;
+ }
+
+ /**
+ * Constructs the part parser builder for this REST method.
+ *
+ * @param beanStore
+ * The factory used for creating beans and retrieving injected
beans.
+ * @param parent
+ * The builder for the REST resource class.
+ * @param resource
+ * The REST servlet/bean instance that this context is defined
against.
+ * @return The part serializer builder for this REST resource.
+ */
+ protected HttpPartParser.Creator createPartParser(BeanStore beanStore,
RestContextBuilder parent, Supplier<?> resource) {
+
+ // Default value.
+ Value<HttpPartParser.Creator> v = Value.of(
+ parent.partParser().copy()
+ );
+
+ return v.get();
+ }
+
+ final Optional<HttpPartParser> getPartParser() {
+ return partParser == null ? empty() : of(partParser.create());
+ }
+
+
//-----------------------------------------------------------------------------------------------------------------
// converters
//-----------------------------------------------------------------------------------------------------------------
@@ -543,22 +582,6 @@ public class RestOpContextBuilder extends ContextBuilder {
return this;
}
- /**
- * Returns the HTTP part parser creator containing the part parser for
parsing HTTP parts into POJOs.
- *
- * <p>
- * The default value is {@link OpenApiParser} which allows for both
plain-text and URL-Encoded-Object-Notation values.
- * <br>If your parts contain text that can be confused with UON (e.g.
<js>"(foo)"</js>), you can switch to
- * {@link SimplePartParser} which treats everything as plain text.
- *
- * @return The HTTP part parser creator.
- */
- public HttpPartParser.Creator getPartParser() {
- if (partParser == null)
- partParser = restContext.builder.partParser().copy();
- return partParser;
- }
-
//----------------------------------------------------------------------------------------------------
// Properties
//----------------------------------------------------------------------------------------------------