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 d7f29b5 Context API refactoring.
d7f29b5 is described below
commit d7f29b5a88290a1700af639c7859ab1850291f6e
Author: JamesBognar <[email protected]>
AuthorDate: Sun Sep 19 18:18:55 2021 -0400
Context API refactoring.
---
.../java/org/apache/juneau/rest/RestOpContext.java | 60 +---------------------
.../apache/juneau/rest/RestOpContextBuilder.java | 56 ++++++++++++++++++++
2 files changed, 57 insertions(+), 59 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 41c386a..afe723a 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
@@ -158,11 +158,9 @@ public class RestOpContext extends Context implements
Comparable<RestOpContext>
optionalMatchers = matchers.getOptionalEntries();
requiredMatchers = matchers.getRequiredEntries();
- pathMatchers = createPathMatchers(r, builder,
bs).asArray();
- bs.addBean(UrlPathMatcher[].class, pathMatchers);
+ pathMatchers = bs.add(UrlPathMatcher[].class,
builder.getPathMatchers().asArray());
bs.addBean(UrlPathMatcher.class, pathMatchers.length >
0 ? pathMatchers[0] : null);
-
jsonSchemaGenerator = createJsonSchemaGenerator(r,
builder, bs);
bs.addBean(JsonSchemaGenerator.class,
jsonSchemaGenerator);
@@ -215,62 +213,6 @@ public class RestOpContext extends Context implements
Comparable<RestOpContext>
}
/**
- * Instantiates the path matchers for this method.
- *
- * @param resource The REST resource object.
- * @param builder The builder for this bean.
- * @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 UrlPathMatcherList createPathMatchers(Object resource,
RestOpContextBuilder builder, BeanStore beanStore) throws Exception {
-
- UrlPathMatcherList x = UrlPathMatcherList.create();
- boolean dotAll = builder.dotAll;
-
- if (builder.path != null) {
- for (String p : builder.path) {
- if (dotAll && ! p.endsWith("/*"))
- p += "/*";
- x.add(UrlPathMatcher.of(p));
- }
- }
-
- if (x.isEmpty()) {
- MethodInfo mi = MethodInfo.of(method);
- String p = null;
- String httpMethod = null;
- if (mi.hasAnnotation(RestGet.class))
- httpMethod = "get";
- else if (mi.hasAnnotation(RestPut.class))
- httpMethod = "put";
- else if (mi.hasAnnotation(RestPost.class))
- httpMethod = "post";
- else if (mi.hasAnnotation(RestDelete.class))
- httpMethod = "delete";
- else if (mi.hasAnnotation(RestOp.class))
- httpMethod =
mi.getAnnotations(RestOp.class).stream().map(y -> y.method()).filter(y -> !
y.isEmpty()).findFirst().orElse(null);
-
- p = HttpUtils.detectHttpPath(method, httpMethod);
-
- if (dotAll && ! p.endsWith("/*"))
- p += "/*";
-
- x.add(UrlPathMatcher.of(p));
- }
-
- x = BeanStore
- .of(beanStore, resource)
- .addBean(UrlPathMatcherList.class, x)
- .createMethodFinder(UrlPathMatcherList.class, resource)
- .find("createPathMatchers", Method.class)
- .withDefault(x)
- .run();
-
- return x;
- }
-
- /**
* Instantiates the JSON-schema generator 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 35924ef..b5d01b6 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
@@ -37,6 +37,7 @@ import org.apache.juneau.reflect.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.converters.*;
import org.apache.juneau.rest.guards.*;
+import org.apache.juneau.rest.util.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.svl.*;
@@ -786,6 +787,61 @@ public class RestOpContextBuilder extends ContextBuilder {
return b.build();
}
+
//-----------------------------------------------------------------------------------------------------------------
+ // pathMatchers
+
//-----------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Instantiates the path matchers for this method.
+ *
+ * @return The path matchers for this method.
+ */
+ protected UrlPathMatcherList getPathMatchers() {
+
+ Value<UrlPathMatcherList> v = Value.of(
+ UrlPathMatcherList.create()
+ );
+
+ if (path != null) {
+ for (String p : path) {
+ if (dotAll && ! p.endsWith("/*"))
+ p += "/*";
+ v.get().add(UrlPathMatcher.of(p));
+ }
+ }
+
+ if (v.get().isEmpty()) {
+ MethodInfo mi = MethodInfo.of(restMethod);
+ String p = null;
+ String httpMethod = null;
+ if (mi.hasAnnotation(RestGet.class))
+ httpMethod = "get";
+ else if (mi.hasAnnotation(RestPut.class))
+ httpMethod = "put";
+ else if (mi.hasAnnotation(RestPost.class))
+ httpMethod = "post";
+ else if (mi.hasAnnotation(RestDelete.class))
+ httpMethod = "delete";
+ else if (mi.hasAnnotation(RestOp.class))
+ httpMethod =
mi.getAnnotations(RestOp.class).stream().map(y -> y.method()).filter(y -> !
y.isEmpty()).findFirst().orElse(null);
+
+ p = HttpUtils.detectHttpPath(restMethod, httpMethod);
+
+ if (dotAll && ! p.endsWith("/*"))
+ p += "/*";
+
+ v.get().add(UrlPathMatcher.of(p));
+ }
+
+ beanStore
+ .createMethodFinder(UrlPathMatcherList.class,
resource().get())
+ .addBean(UrlPathMatcherList.class, v.get())
+ .find("createPathMatchers", Method.class)
+ .run(x -> v.set(x));
+
+ return v.get();
+ }
+
/**
* When enabled, append <js>"/*"</js> to path patterns if not already
present.
*