You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2018/01/20 18:29:04 UTC
[3/3] juneau git commit: Refactor RestInfoProvider.
Refactor RestInfoProvider.
Project: http://git-wip-us.apache.org/repos/asf/juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/juneau/commit/62b041ab
Tree: http://git-wip-us.apache.org/repos/asf/juneau/tree/62b041ab
Diff: http://git-wip-us.apache.org/repos/asf/juneau/diff/62b041ab
Branch: refs/heads/master
Commit: 62b041abd97ac04d0cb4628ee4dec0bac54d445a
Parents: 3c498b4
Author: JamesBognar <ja...@apache.org>
Authored: Sat Jan 20 13:28:51 2018 -0500
Committer: JamesBognar <ja...@apache.org>
Committed: Sat Jan 20 13:28:51 2018 -0500
----------------------------------------------------------------------
.../juneau/dto/swagger/ParameterInfo.java | 60 +
.../apache/juneau/dto/swagger/ResponseInfo.java | 22 +
.../juneau/internal/BeanPropertyUtils.java | 22 +-
.../org/apache/juneau/internal/StringUtils.java | 28 +
juneau-doc/src/main/javadoc/overview.html | 22 +-
.../juneau/rest/test/InheritanceResource.java | 6 +-
.../java/org/apache/juneau/rest/test/Root.java | 2 +-
.../juneau/rest/test/NlsResource.properties | 89 +-
.../org/apache/juneau/rest/RequestBody.java | 2 +-
.../apache/juneau/rest/RequestPathMatch.java | 22 +-
.../org/apache/juneau/rest/RestContext.java | 244 ++--
.../apache/juneau/rest/RestContextBuilder.java | 36 +-
.../apache/juneau/rest/RestInfoProvider.java | 248 +++-
.../juneau/rest/RestInfoProviderDefault.java | 1258 +++++++++++++++---
.../org/apache/juneau/rest/RestJavaMethod.java | 359 +----
.../org/apache/juneau/rest/RestRequest.java | 90 +-
.../juneau/rest/RestServletGroupDefault.java | 3 +-
.../juneau/rest/annotation/MethodSwagger.java | 119 +-
.../juneau/rest/annotation/ResourceSwagger.java | 141 +-
.../juneau/rest/annotation/RestMethod.java | 8 +-
.../juneau/rest/annotation/RestResource.java | 8 +-
.../rest/labels/ChildResourceDescriptions.java | 6 +-
.../java/org/apache/juneau/rest/package.html | 4 +-
.../apache/juneau/rest/vars/RestInfoVar.java | 97 +-
.../rest/vars/SerializedRequestAttrVar.java | 2 +-
.../juneau/rest/widget/ContentTypeMenuItem.java | 2 +-
26 files changed, 1991 insertions(+), 909 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
index 3129f8d..cc3965e 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
@@ -130,6 +130,66 @@ public class ParameterInfo extends SwaggerElement {
}
/**
+ * Copies any non-null fields from the specified object to this object.
+ *
+ * @param p
+ * The object to copy fields from.
+ * <br>Can be <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo copyFrom(ParameterInfo p) {
+ if (p != null) {
+ if (p.name != null)
+ name = p.name;
+ if (p.in != null)
+ in = p.in;
+ if (p.description != null)
+ description = p.description;
+ if (p.type != null)
+ type = p.type;
+ if (p.format != null)
+ format = p.format;
+ if (p.pattern != null)
+ pattern = p.pattern;
+ if (p.collectionFormat != null)
+ collectionFormat = p.collectionFormat;
+ if (p.maximum != null)
+ maximum = p.maximum;
+ if (p.minimum != null)
+ minimum = p.minimum;
+ if (p.multipleOf != null)
+ multipleOf = p.multipleOf;
+ if (p.maxLength != null)
+ maxLength = p.maxLength;
+ if (p.minLength != null)
+ minLength = p.minLength;
+ if (p.maxItems != null)
+ maxItems = p.maxItems;
+ if (p.minItems != null)
+ minItems = p.minItems;
+ if (p.required != null)
+ required = p.required;
+ if (p.allowEmptyValue != null)
+ allowEmptyValue = p.allowEmptyValue;
+ if (p.exclusiveMaximum != null)
+ exclusiveMaximum = p.exclusiveMaximum;
+ if (p.exclusiveMinimum != null)
+ exclusiveMinimum = p.exclusiveMinimum;
+ if (p.uniqueItems != null)
+ uniqueItems = p.uniqueItems;
+ if (p.schema != null)
+ schema = p.schema;
+ if (p.items != null)
+ items = p.items;
+ if (p._default != null)
+ _default = p._default;
+ if (p._enum != null)
+ _enum = p._enum;
+ }
+ return this;
+ }
+
+ /**
* Bean property getter: <property>name</property>.
*
* <p>
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
index ead018d..6a7f9d5 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
@@ -66,6 +66,28 @@ public class ResponseInfo extends SwaggerElement {
private Map<String,Object> examples;
/**
+ * Copies any non-null fields from the specified object to this object.
+ *
+ * @param r
+ * The object to copy fields from.
+ * <br>Can be <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public ResponseInfo copyFrom(ResponseInfo r) {
+ if (r != null) {
+ if (r.description != null)
+ description = r.description;
+ if (r.schema != null)
+ schema = r.schema;
+ if (r.headers != null)
+ headers = r.headers;
+ if (r.examples != null)
+ examples = r.examples;
+ }
+ return this;
+ }
+
+ /**
* Bean property getter: <property>description</property>.
*
* <p>
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/BeanPropertyUtils.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/BeanPropertyUtils.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/BeanPropertyUtils.java
index 8a01323..63b481c 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/BeanPropertyUtils.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/BeanPropertyUtils.java
@@ -12,6 +12,8 @@
// ***************************************************************************************************************************
package org.apache.juneau.internal;
+import static org.apache.juneau.internal.StringUtils.*;
+
import java.lang.reflect.*;
import java.util.*;
@@ -105,7 +107,7 @@ public final class BeanPropertyUtils {
}
}
}
- return l;
+ return l.isEmpty() ? null : l;
} catch (ParseException e) {
throw new RuntimeException(e);
}
@@ -142,28 +144,12 @@ public final class BeanPropertyUtils {
}
}
}
- return m;
+ return m.isEmpty() ? null : m;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
- private static boolean isObjectList(Object o) {
- if (o instanceof CharSequence) {
- String s = o.toString();
- return (s.startsWith("[") && s.endsWith("]") && BeanContext.DEFAULT != null);
- }
- return false;
- }
-
- private static boolean isObjectMap(Object o) {
- if (o instanceof CharSequence) {
- String s = o.toString();
- return (s.startsWith("{") && s.endsWith("}") && BeanContext.DEFAULT != null);
- }
- return false;
- }
-
/**
* Converts an object to the specified type.
*
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
index e5b2b45..3dea15d 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
@@ -1893,4 +1893,32 @@ public final class StringUtils {
public static boolean contains(String value, CharSequence substring) {
return value == null ? false : value.contains(substring);
}
+
+ /**
+ * Returns <jk>true</jk> if the specified string appears to be an JSON array.
+ *
+ * @param o The object to test.
+ * @return <jk>true</jk> if the specified string appears to be a JSON array.
+ */
+ public static boolean isObjectList(Object o) {
+ if (o instanceof CharSequence) {
+ String s = o.toString();
+ return (s.startsWith("[") && s.endsWith("]") && BeanContext.DEFAULT != null);
+ }
+ return false;
+ }
+
+ /**
+ * Returns <jk>true</jk> if the specified string appears to be a JSON object.
+ *
+ * @param o The object to test.
+ * @return <jk>true</jk> if the specified string appears to be a JSON object.
+ */
+ public static boolean isObjectMap(Object o) {
+ if (o instanceof CharSequence) {
+ String s = o.toString();
+ return (s.startsWith("{") && s.endsWith("}") && BeanContext.DEFAULT != null);
+ }
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-doc/src/main/javadoc/overview.html
----------------------------------------------------------------------
diff --git a/juneau-doc/src/main/javadoc/overview.html b/juneau-doc/src/main/javadoc/overview.html
index 797c40b..39a4410 100644
--- a/juneau-doc/src/main/javadoc/overview.html
+++ b/juneau-doc/src/main/javadoc/overview.html
@@ -9211,8 +9211,8 @@
<li><js>"description"</js> - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getDescription(RestRequest)}
<li><js>"externalDocs"</js> - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getExternalDocs(RestRequest)}
<li><js>"license"</js> - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getLicense(RestRequest)}
- <li><js>"methodDescription"</js> - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getMethodDescription(RestRequest)}
- <li><js>"methodSummary"</js> - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getMethodSummary(RestRequest)}
+ <li><js>"methodDescription"</js> - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getMethodDescription(Method,RestRequest)}
+ <li><js>"methodSummary"</js> - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getMethodSummary(Method,RestRequest)}
<li><js>"siteName"</js> - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getSiteName(RestRequest)}
<li><js>"tags"</js> - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getTags(RestRequest)}
<li><js>"termsOfService"</js> - Value returned by {@link org.apache.juneau.rest.RestInfoProvider#getTermsOfService(RestRequest)}
@@ -9257,8 +9257,8 @@
<li>{@link org.apache.juneau.rest.RestContext#REST_responseHandlers REST_responseHandlers}
<li>{@link org.apache.juneau.rest.RestContext#REST_defaultRequestHeaders REST_defaultRequestHeaders}
<li>{@link org.apache.juneau.rest.RestContext#REST_defaultResponseHeaders REST_defaultResponseHeaders}
- <li>{@link org.apache.juneau.rest.RestContext#REST_supportedAcceptTypes REST_supportedAcceptTypes}
- <li>{@link org.apache.juneau.rest.RestContext#REST_supportedContentTypes REST_supportedContentTypes}
+ <li>{@link org.apache.juneau.rest.RestContext#REST_produces REST_produces}
+ <li>{@link org.apache.juneau.rest.RestContext#REST_consumes REST_consumes}
<li>{@link org.apache.juneau.rest.RestContext#REST_clientVersionHeader REST_clientVersionHeader}
<li>{@link org.apache.juneau.rest.RestContext#REST_resourceResolver REST_resourceResolver}
<li>{@link org.apache.juneau.rest.RestContext#REST_logger REST_logger}
@@ -9330,8 +9330,8 @@
Changes to {@link org.apache.juneau.rest.RestRequest}:
<ul>
<li><code>getSupportedMediaTypes()</code> replaced with
- {@link org.apache.juneau.rest.RestRequest#getSupportedAcceptTypes() getSupportedAcceptTypes()} and
- {@link org.apache.juneau.rest.RestRequest#getSupportedContentTypes() getSupportedContentTypes()}.
+ {@link org.apache.juneau.rest.RestRequest#getConsumes() getConsumes()} and
+ {@link org.apache.juneau.rest.RestRequest#getProduces() getProduces()}.
<li><code>getReaderResource(String,boolean,MediaType)</code> renamed to
{@link org.apache.juneau.rest.RestRequest#getClasspathReaderResource(String,boolean,MediaType) getClasspathReaderResource(String,boolean,MediaType)}
<li><code>getReaderResource(String,boolean)</code> renamed to
@@ -9347,8 +9347,8 @@
<li>
Changes to {@link org.apache.juneau.rest.annotation.RestMethod @RestMethod}:
<ul>
- <li>New {@link org.apache.juneau.rest.annotation.RestMethod#supportedAcceptTypes() supportedAcceptTypes()} and
- {@link org.apache.juneau.rest.annotation.RestMethod#supportedContentTypes() supportedContentTypes()}
+ <li>New {@link org.apache.juneau.rest.annotation.RestMethod#consumes() consumes()} and
+ {@link org.apache.juneau.rest.annotation.RestMethod#produces() produces()}
for overriding the supported media types inferred from the serializers and parsers.
</ul>
<li>
@@ -9374,6 +9374,8 @@
annotations.
<br>These aren't needed anymore since you can just pass in <code>MessageBundle</code> and
<code>RestRequestProperties</code> as unannotated parameters.
+ <li>
+ Revamped the {@link org.apache.juneau.rest.RestInfoProvider} class.
</ul>
<h6 class='topic'>juneau-rest-client</h6>
@@ -11404,8 +11406,8 @@
<li><code><del>@RestResource.version()</del></code> / {@link org.apache.juneau.rest.RestInfoProvider#getVersion(RestRequest)}
<li><code><del>@RestResource.tags()</del></code> / {@link org.apache.juneau.rest.RestInfoProvider#getTags(RestRequest)}
<li><code><del>@RestResource.externalDocs()</del></code> / {@link org.apache.juneau.rest.RestInfoProvider#getExternalDocs(RestRequest)}
- <li>{@link org.apache.juneau.rest.annotation.RestMethod#summary() @RestMethod.summary()} / {@link org.apache.juneau.rest.RestInfoProvider#getMethodSummary(String,RestRequest)}
- <li>{@link org.apache.juneau.rest.annotation.RestMethod#description() @RestMethod.description()} / {@link org.apache.juneau.rest.RestInfoProvider#getMethodDescription(String,RestRequest)}
+ <li>{@link org.apache.juneau.rest.annotation.RestMethod#summary() @RestMethod.summary()} / <code><del>RestInfoProvider.getMethodSummary(String,RestRequest)</del></code>
+ <li>{@link org.apache.juneau.rest.annotation.RestMethod#description() @RestMethod.description()} /<code><del>RestInfoProvider.getMethodDescription(String,RestRequest)</del></code>
<li><code><del>@RestMethod.externalDocs()</del></code>
<li><code><del>@RestMethod.tags()</del></code>
<li><code><del>@RestMethod.deprecated()</del></code>
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/InheritanceResource.java
----------------------------------------------------------------------
diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/InheritanceResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/InheritanceResource.java
index 863c7cb..2ba85e5 100644
--- a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/InheritanceResource.java
+++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/InheritanceResource.java
@@ -102,7 +102,7 @@ public class InheritanceResource extends RestServlet {
path="/test1"
)
public Reader test1(RestRequest req) {
- return new StringReader(new ObjectList(req.getSupportedContentTypes()).toString());
+ return new StringReader(new ObjectList(req.getConsumes()).toString());
}
// Should show ['text/p5']
@@ -112,7 +112,7 @@ public class InheritanceResource extends RestServlet {
parsers=P5.class
)
public Reader test2(RestRequest req) {
- return new StringReader(new ObjectList(req.getSupportedContentTypes()).toString());
+ return new StringReader(new ObjectList(req.getConsumes()).toString());
}
// Should show ['text/p5','text/p3','text/p4','text/p1','text/p2']
@@ -123,7 +123,7 @@ public class InheritanceResource extends RestServlet {
inherit="PARSERS"
)
public Reader test3(RestRequest req) {
- return new StringReader(new ObjectList(req.getSupportedContentTypes()).toString());
+ return new StringReader(new ObjectList(req.getConsumes()).toString());
}
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
----------------------------------------------------------------------
diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
index 43c1181..6acd2e8 100644
--- a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
+++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
@@ -82,7 +82,7 @@ public class Root extends RestServletDefault {
private static final long serialVersionUID = 1L;
@RestMethod(name=GET, path="/")
- public ChildResourceDescriptions doGet(RestRequest req) {
+ public ChildResourceDescriptions doGet(RestRequest req) throws Exception {
return new ChildResourceDescriptions(getContext(), req);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties
----------------------------------------------------------------------
diff --git a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties
index d461923..1c820fd 100644
--- a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties
+++ b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties
@@ -15,41 +15,52 @@
title = Test2.a
description = Test2.b
test2.summary = Test2.c
-test2.req.path.a.description = Test2.d
-test2.req.query.b.description = Test2.e
-test2.req.body.description = Test2.f
-test2.req.header.D.description = Test2.g
-test2.req.path.a2.description = Test2.h
-test2.req.query.b2.description = Test2.i
-test2.req.header.D2.description = Test2.j
-test2.res.200.description = OK2
-test2.res.201.description = Test2.l
+test2.parameters = [\
+ {in:"path",name:"a",description:"Test2.d"},\
+ {in:"query",name:"b",description:"Test2.e"},\
+ {in:"body",description:"Test2.f"},\
+ {in:"header",name:"D",description:"Test2.g"},\
+ {in:"path",name:"a2",description:"Test2.h"},\
+ {in:"query",name:"b2",description:"Test2.i"},\
+ {in:"header",name:"D2",description:"Test2.j"}\
+ ]
+test2.responses = {\
+ 200:{description:"OK2"},\
+ 201:{description:"Test2.l"}\
+ }
Test3.title = Test3.a
Test3.description = Test3.b
Test3.test3.summary = Test3.c
-Test3.test3.req.path.a.description = Test3.d
-Test3.test3.req.query.b.description = Test3.e
-Test3.test3.req.body.description = Test3.f
-Test3.test3.req.header.D.description = Test3.g
-Test3.test3.req.path.a2.description = Test3.h
-Test3.test3.req.query.b2.description = Test3.i
-Test3.test3.req.header.D2.description = Test3.j
-Test3.test3.res.200.description = OK3
-Test3.test3.res.201.description = Test3.l
+test3.parameters = [\
+ {in:"path",name:"a",description:"Test3.d"},\
+ {in:"query",name:"b",description:"Test3.e"},\
+ {in:"body",description:"Test3.f"},\
+ {in:"header",name:"D",description:"Test3.g"},\
+ {in:"path",name:"a2",description:"Test3.h"},\
+ {in:"query",name:"b2",description:"Test3.i"},\
+ {in:"header",name:"D2",description:"Test3.j"}\
+ ]
+test3.responses = {\
+ 200:{description:"OK3"},\
+ 201:{description:"Test3.l"}\
+ }
Test4.title = $L{foo}
Test4.description = $L{foo}
-Test4.test4.summary = $L{foo}
-Test4.test4.req.path.a.description = $L{foo}
-Test4.test4.req.query.b.description = $L{foo}
-Test4.test4.req.body.description = $L{foo}
-Test4.test4.req.header.D.description = $L{foo}
-Test4.test4.req.path.a2.description = $L{foo}
-Test4.test4.req.query.b2.description = $L{foo}
-Test4.test4.req.header.D2.description = $L{foo}
-Test4.test4.res.200.description = foo$L{foo}foo$L{foo}foo
-Test4.test4.res.201.description = $L{foo}
+test4.parameters = [\
+ {in:"path",name:"a",description:"$L{foo}"},\
+ {in:"query",name:"b",description:"$L{foo}"},\
+ {in:"body",description:"$L{foo}"},\
+ {in:"header",name:"D",description:"$L{foo}"},\
+ {in:"path",name:"a2",description:"$L{foo}"},\
+ {in:"query",name:"b2",description:"$L{foo}"},\
+ {in:"header",name:"D2",description:"$L{foo}"}\
+ ]
+test4.responses = {\
+ 200:{description:"foo$L{foo}foo$L{foo}foo"},\
+ 201:{description:"$L{foo}"}\
+ }
foo = $L{bar}
bar = baz
@@ -57,15 +68,19 @@ bar = baz
Test5.title = $L{foo2}
Test5.description = $R{servletTitle}
Test5.test5.summary = $R{servletTitle}
-Test5.test5.req.path.a.description = $R{servletTitle}
-Test5.test5.req.query.b.description = $R{servletTitle}
-Test5.test5.req.body.description = $R{servletTitle}
-Test5.test5.req.header.D.description = $R{servletTitle}
-Test5.test5.req.path.a2.description = $R{servletTitle}
-Test5.test5.req.query.b2.description = $R{servletTitle}
-Test5.test5.req.header.D2.description = $R{servletTitle}
-Test5.test5.res.200.description = foo$R{servletTitle}foo$R{servletTitle}foo
-Test5.test5.res.201.description = $R{servletTitle}
+test5.parameters = [\
+ {in:"path",name:"a",description:"$R{servletTitle}"},\
+ {in:"query",name:"b",description:"$R{servletTitle}"},\
+ {in:"body",description:"$R{servletTitle}"},\
+ {in:"header",name:"D",description:"$R{servletTitle}"},\
+ {in:"path",name:"a2",description:"$R{servletTitle}"},\
+ {in:"query",name:"b2",description:"$R{servletTitle}"},\
+ {in:"header",name:"D2",description:"$R{servletTitle}"}\
+ ]
+test5.responses = {\
+ 200:{description:"foo$R{servletTitle}foo$R{servletTitle}foo"},\
+ 201:{description:"$R{servletTitle}"}\
+ }
Test5.foo2 = $L{bar2}
Test5.bar2 = baz2
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
index 51117b0..b804e75 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
@@ -374,7 +374,7 @@ public class RequestBody {
throw new RestException(SC_UNSUPPORTED_MEDIA_TYPE,
"Unsupported media-type in request header ''Content-Type'': ''{0}''\n\tSupported media-types: {1}",
- headers.getContentType(), req.getParserGroup().getSupportedMediaTypes()
+ headers.getContentType(), req.getParsers().getSupportedMediaTypes()
);
} catch (IOException e) {
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathMatch.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathMatch.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathMatch.java
index ea30efa..49e4eda 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathMatch.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestPathMatch.java
@@ -33,27 +33,32 @@ public class RequestPathMatch extends TreeMap<String,String> {
private HttpPartParser parser;
private BeanSession beanSession;
- private String remainder;
+ private String remainder, pattern;
RequestPathMatch() {
super(String.CASE_INSENSITIVE_ORDER);
}
- RequestPathMatch setParser(HttpPartParser parser) {
+ RequestPathMatch parser(HttpPartParser parser) {
this.parser = parser;
return this;
}
- RequestPathMatch setBeanSession(BeanSession beanSession) {
+ RequestPathMatch beanSession(BeanSession beanSession) {
this.beanSession = beanSession;
return this;
}
- RequestPathMatch setRemainder(String remainder) {
+ RequestPathMatch remainder(String remainder) {
this.remainder = remainder;
return this;
}
+ RequestPathMatch pattern(String pattern) {
+ this.pattern = pattern;
+ return this;
+ }
+
/**
* Sets a request query parameter value.
*
@@ -219,4 +224,13 @@ public class RequestPathMatch extends TreeMap<String,String> {
public String getRemainderUndecoded() {
return remainder;
}
+
+ /**
+ * Returns the path pattern that matched this request.
+ *
+ * @return The path pattern that matched this request.
+ */
+ public String getPattern() {
+ return pattern;
+ }
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
----------------------------------------------------------------------
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 7230156..eedf655 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
@@ -339,6 +339,17 @@ public final class RestContext extends BeanContext {
* }
* }
* </p>
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * <li>When defined as a class, the implementation must have one of the following constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(RestContext)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * <li>Inner classes of the REST resource class are allowed.
+ * </ul>
*/
public static final String REST_callHandler = PREFIX + "callHandler.o";
@@ -406,17 +417,6 @@ public final class RestContext extends BeanContext {
* </dd>
* </dl>
*
- * <h5 class='section'>Notes:</h5>
- * <ul class='spaced-list'>
- * <li>When defined as classes, instances are resolved using the registered {@link #REST_resourceResolver} which
- * by default is {@link RestResourceResolverDefault} which requires the class have one of the following
- * constructors:
- * <ul>
- * <li><code><jk>public</jk> T(RestContextBuilder)</code>
- * <li><code><jk>public</jk> T()</code>
- * </ul>
- * </ul>
- *
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
* <jc>// Our child resource.</jc>
@@ -450,6 +450,17 @@ public final class RestContext extends BeanContext {
* }
* }
*
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>When defined as classes, instances are resolved using the registered {@link #REST_resourceResolver} which
+ * by default is {@link RestResourceResolverDefault} which requires the class have one of the following
+ * constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(RestContextBuilder)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * </ul>
+ *
* <h5 class='section'>Documentation:</h5>
* <ul>
* <li><a class="doclink" href="package-summary.html#RestResources.Children">org.apache.juneau.rest > Children</a>
@@ -550,6 +561,13 @@ public final class RestContext extends BeanContext {
* <br>The {@link ClasspathResourceFinderRecursive} is another option that also recursively searches for resources
* up the parent class hierarchy.
* <br>Each of these classes can be extended to provide customized handling of resource retrieval.
+ * <li>When defined as a class, the implementation must have one of the following constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(RestContext)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * <li>Inner classes of the REST resource class are allowed.
+ * </ul>
* </ul>
*/
public static final String REST_classpathResourceFinder = PREFIX + "classpathResourceFinder.o";
@@ -779,6 +797,17 @@ public final class RestContext extends BeanContext {
* <ul>
* <li><a class="doclink" href="package-summary.html#RestResources.Converters">org.apache.juneau.rest > Converters</a>
* </ul>
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * <li>When defined as a class, the implementation must have one of the following constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(BeanContext)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * <li>Inner classes of the REST resource class are allowed.
+ * </ul>
*/
public static final String REST_converters = PREFIX + "converters.lo";
@@ -1000,16 +1029,6 @@ public final class RestContext extends BeanContext {
* <p>
* These can be used to enable various kinds of compression (e.g. <js>"gzip"</js>) on requests and responses.
*
- * <h5 class='section'>Notes:</h5>
- * <ul class='spaced-list'>
- * <li>When defined as classes, the class must provide one of the following constructors:
- * <ul>
- * <li><code><jk>public</jk> T(PropertyStore)</code>
- * <li><code><jk>public</jk> T()</code>
- * </ul>
- * <li>Instance class can be defined as an inner class of the REST resource class.
- * </ul>
- *
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
* <jc>// Registered via annotation.</jc>
@@ -1042,6 +1061,17 @@ public final class RestContext extends BeanContext {
* }
* </p>
*
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * <li>When defined as a class, the implementation must have one of the following constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(BeanContext)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * <li>Inner classes of the REST resource class are allowed.
+ * </ul>
+ *
* <h5 class='section'>Documentation:</h5>
* <ul>
* <li><a class="doclink" href="package-summary.html#RestResources.Encoders">org.apache.juneau.rest > Encoders</a>
@@ -1076,19 +1106,8 @@ public final class RestContext extends BeanContext {
* <br>These guards get called immediately before execution of any REST method in this class.
*
* <p>
- * Typically, guards will be used for permissions checking on the user making the request, but it can also be used
- * for other purposes like pre-call validation of a request.
- *
- * <h5 class='section'>Notes:</h5>
- * <ul class='spaced-list'>
- * <li>When defined as classes, the class must provide one of the following constructors:
- * <ul>
- * <li><code><jk>public</jk> T(PropertyStore)</code>
- * <li><code><jk>public</jk> T()</code>
- * </ul>
- * <li>Instance class can be defined as an inner class of the REST resource class.
- * <li>If multiple guards are specified, <b>ALL</b> guards must pass.
- * </ul>
+ * If multiple guards are specified, <b>ALL</b> guards must pass.
+ * <br>Note that this is different than matchers were only ONE matcher needs to pass.
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
@@ -1130,6 +1149,17 @@ public final class RestContext extends BeanContext {
* }
* </p>
*
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * <li>When defined as a class, the implementation must have one of the following constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(BeanContext)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * <li>Inner classes of the REST resource class are allowed.
+ * </ul>
+ *
* <h5 class='section'>Documentation:</h5>
* <ul>
* <li><a class="doclink" href="package-summary.html#RestResources.Guards">org.apache.juneau.rest > Guards</a>
@@ -1213,6 +1243,17 @@ public final class RestContext extends BeanContext {
* }
* }
* </p>
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * <li>When defined as a class, the implementation must have one of the following constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(BeanContext)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * <li>Inner classes of the REST resource class are allowed.
+ * </ul>
*/
public static final String REST_infoProvider = PREFIX + "infoProvider.o";
@@ -1361,6 +1402,17 @@ public final class RestContext extends BeanContext {
* }
* }
* </p>
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul class='spaced-list'>
+ * <li>
+ * <li>When defined as a class, the implementation must have one of the following constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(BeanContext)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * <li>Inner classes of the REST resource class are allowed.
+ * </ul>
*/
public static final String REST_maxInput = PREFIX + "maxInput.s";
@@ -1527,7 +1579,13 @@ public final class RestContext extends BeanContext {
*
* <h5 class='section'>Notes:</h5>
* <ul class='spaced-list'>
- * <li>{@link RestParam} classes must have either a no-arg or {@link PropertyStore} argument constructors.
+ * <li>
+ * <li>When defined as a class, the implementation must have one of the following constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(BeanContext)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * <li>Inner classes of the REST resource class are allowed.
* </ul>
*/
public static final String REST_paramResolvers = PREFIX + "paramResolvers.lo";
@@ -1729,10 +1787,15 @@ public final class RestContext extends BeanContext {
* <p>
* Can be used to provide customized resolution of REST resource class instances (e.g. resources retrieve from Spring).
*
- * <p>
* <h5 class='section'>Notes:</h5>
* <ul class='spaced-list'>
* <li>Unless overridden, resource resolvers are inherited from parent resources.
+ * <li>When defined as a class, the implementation must have one of the following constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(BeanContext)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * <li>Inner classes of the REST resource class are allowed.
* </ul>
*/
public static final String REST_resourceResolver = PREFIX + "resourceResolver.o";
@@ -1772,11 +1835,16 @@ public final class RestContext extends BeanContext {
* <li>{@link RedirectHandler}
* <li>{@link DefaultHandler}
* </ul>
-
- * <p>
+ *
* <h5 class='section'>Notes:</h5>
* <ul class='spaced-list'>
- * <li>{@link ResponseHandler} classes must have either a no-arg or {@link PropertyStore} argument constructors.
+ * <li>Unless overridden, resource resolvers are inherited from parent resources.
+ * <li>When defined as a class, the implementation must have one of the following constructors:
+ * <ul>
+ * <li><code><jk>public</jk> T(BeanContext)</code>
+ * <li><code><jk>public</jk> T()</code>
+ * </ul>
+ * <li>Inner classes of the REST resource class are allowed.
* </ul>
*/
public static final String REST_responseHandlers = PREFIX + "responseHandlers.lo";
@@ -1917,19 +1985,19 @@ public final class RestContext extends BeanContext {
*
* <h5 class='section'>Property:</h5>
* <ul>
- * <li><b>Name:</b> <js>"RestContext.supportedAcceptTypes.ls"</js>
+ * <li><b>Name:</b> <js>"RestContext.produces.ls"</js>
* <li><b>Data type:</b> <code>List<String></code>
* <li><b>Default:</b> empty list
* <li><b>Session-overridable:</b> <jk>false</jk>
* <li><b>Annotations:</b>
* <ul>
- * <li class='ja'>{@link RestResource#supportedAcceptTypes()}
- * <li class='ja'>{@link RestMethod#supportedAcceptTypes()}
+ * <li class='ja'>{@link RestResource#produces()}
+ * <li class='ja'>{@link RestMethod#produces()}
* </ul>
* <li><b>Methods:</b>
* <ul>
- * <li class='jm'>{@link RestContextBuilder#supportedAcceptTypes(boolean,String...)}
- * <li class='jm'>{@link RestContextBuilder#supportedAcceptTypes(boolean,MediaType...)}
+ * <li class='jm'>{@link RestContextBuilder#produces(boolean,String...)}
+ * <li class='jm'>{@link RestContextBuilder#produces(boolean,MediaType...)}
* </ul>
* </ul>
*
@@ -1938,29 +2006,29 @@ public final class RestContext extends BeanContext {
* Overrides the media types inferred from the serializers that identify what media types can be produced by the resource.
*
* <p>
- * This affects the values returned by {@link RestRequest#getSupportedAcceptTypes()} and the supported accept
+ * This affects the values returned by {@link RestRequest#getProduces()} and the supported accept
* types shown in {@link RestInfoProvider#getSwagger(RestRequest)}.
*/
- public static final String REST_supportedAcceptTypes = PREFIX + "supportedAcceptTypes.ls";
+ public static final String REST_produces = PREFIX + "produces.ls";
/**
* Configuration property: Supported content media types.
*
* <h5 class='section'>Property:</h5>
* <ul>
- * <li><b>Name:</b> <js>"RestContext.supportedContentTypes.ls"</js>
+ * <li><b>Name:</b> <js>"RestContext.consumes.ls"</js>
* <li><b>Data type:</b> <code>List<String></code>
* <li><b>Default:</b> empty list
* <li><b>Session-overridable:</b> <jk>false</jk>
* <li><b>Annotations:</b>
* <ul>
- * <li class='ja'>{@link RestResource#supportedContentTypes()}
- * <li class='ja'>{@link RestMethod#supportedContentTypes()}
+ * <li class='ja'>{@link RestResource#consumes()}
+ * <li class='ja'>{@link RestMethod#consumes()}
* </ul>
* <li><b>Methods:</b>
* <ul>
- * <li class='jm'>{@link RestContextBuilder#supportedContentTypes(boolean,String...)}
- * <li class='jm'>{@link RestContextBuilder#supportedContentTypes(boolean,MediaType...)}
+ * <li class='jm'>{@link RestContextBuilder#consumes(boolean,String...)}
+ * <li class='jm'>{@link RestContextBuilder#consumes(boolean,MediaType...)}
* </ul>
* </ul>
*
@@ -1969,10 +2037,10 @@ public final class RestContext extends BeanContext {
* Overrides the media types inferred from the parsers that identify what media types can be consumed by the resource.
*
* <p>
- * This affects the values returned by {@link RestRequest#getSupportedContentTypes()} and the supported content
+ * This affects the values returned by {@link RestRequest#getConsumes()} and the supported content
* types shown in {@link RestInfoProvider#getSwagger(RestRequest)}.
*/
- public static final String REST_supportedContentTypes = PREFIX + "supportedContentTypes.ls";
+ public static final String REST_consumes = PREFIX + "consumes.ls";
/**
* Configuration property: Use classpath resource caching.
@@ -2123,8 +2191,8 @@ public final class RestContext extends BeanContext {
private final HttpPartParser partParser;
private final EncoderGroup encoders;
private final List<MediaType>
- supportedContentTypes,
- supportedAcceptTypes;
+ consumes,
+ produces;
private final Map<String,Object>
defaultRequestHeaders,
defaultResponseHeaders,
@@ -2206,12 +2274,12 @@ public final class RestContext extends BeanContext {
maxInput = getProperty(REST_maxInput, long.class, 100_000_000l);
clientVersionHeader = getProperty(REST_clientVersionHeader, String.class, "X-Client-Version");
- converters = getInstanceArrayProperty(REST_converters, resource, RestConverter.class, new RestConverter[0], true, ps);
- guards = getInstanceArrayProperty(REST_guards, resource, RestGuard.class, new RestGuard[0], true, ps);
- responseHandlers = getInstanceArrayProperty(REST_responseHandlers, resource, ResponseHandler.class, new ResponseHandler[0], true, ps);
+ converters = getInstanceArrayProperty(REST_converters, resource, RestConverter.class, new RestConverter[0], true, this);
+ guards = getInstanceArrayProperty(REST_guards, resource, RestGuard.class, new RestGuard[0], true, this);
+ responseHandlers = getInstanceArrayProperty(REST_responseHandlers, resource, ResponseHandler.class, new ResponseHandler[0], true, this);
Map<Class<?>,RestParam> _paramResolvers = new HashMap<>();
- for (RestParam rp : getInstanceArrayProperty(REST_paramResolvers, RestParam.class, new RestParam[0], true, ps))
+ for (RestParam rp : getInstanceArrayProperty(REST_paramResolvers, RestParam.class, new RestParam[0], true, this))
_paramResolvers.put(rp.forClass(), rp);
paramResolvers = Collections.unmodifiableMap(_paramResolvers);
@@ -2222,7 +2290,7 @@ public final class RestContext extends BeanContext {
defaultResponseHeaders = getMapProperty(REST_defaultResponseHeaders, Object.class);
staticFileResponseHeaders = getMapProperty(REST_staticFileResponseHeaders, Object.class);
- logger = getInstanceProperty(REST_logger, resource, RestLogger.class, RestLoggerNoOp.class, true, ps);
+ logger = getInstanceProperty(REST_logger, resource, RestLogger.class, RestLoggerNoOp.class, true, this);
varResolver = builder.varResolverBuilder
.vars(
@@ -2258,12 +2326,12 @@ public final class RestContext extends BeanContext {
for (String mimeType : getArrayProperty(REST_mimeTypes, String.class))
mimetypesFileTypeMap.addMimeTypes(mimeType);
- ClasspathResourceFinder rf = getInstanceProperty(REST_classpathResourceFinder, ClasspathResourceFinder.class, ClasspathResourceFinderBasic.class);
+ ClasspathResourceFinder rf = getInstanceProperty(REST_classpathResourceFinder, ClasspathResourceFinder.class, ClasspathResourceFinderBasic.class, true, this);
boolean useClasspathResourceCaching = getProperty(REST_useClasspathResourceCaching, boolean.class, true);
staticResourceManager = new ClasspathResourceManager(resourceClass, rf, useClasspathResourceCaching);
- supportedContentTypes = getListProperty(REST_supportedContentTypes, MediaType.class, serializers.getSupportedMediaTypes());
- supportedAcceptTypes = getListProperty(REST_supportedAcceptTypes, MediaType.class, parsers.getSupportedMediaTypes());
+ consumes = getListProperty(REST_consumes, MediaType.class, parsers.getSupportedMediaTypes());
+ produces = getListProperty(REST_produces, MediaType.class, serializers.getSupportedMediaTypes());
staticFiles = ArrayUtils.reverse(getArrayProperty(REST_staticFiles, StaticFileMapping.class));
Set<String> s = new TreeSet<>();
@@ -2480,7 +2548,7 @@ public final class RestContext extends BeanContext {
this.callRouters = Collections.unmodifiableMap(_callRouters);
// Initialize our child resources.
- resourceResolver = getInstanceProperty(REST_resourceResolver, resource, RestResourceResolver.class, parentContext == null ? RestResourceResolverDefault.class : parentContext.resourceResolver, true, this, ps);
+ resourceResolver = getInstanceProperty(REST_resourceResolver, resource, RestResourceResolver.class, parentContext == null ? RestResourceResolverDefault.class : parentContext.resourceResolver, true, this);
for (Object o : getArrayProperty(REST_children, Object.class)) {
String path = null;
Object r = null;
@@ -2520,8 +2588,8 @@ public final class RestContext extends BeanContext {
childResources.put(path, rc2);
}
- callHandler = getInstanceProperty(REST_callHandler, resource, RestCallHandler.class, RestCallHandlerDefault.class, true, this, ps);
- infoProvider = getInstanceProperty(REST_infoProvider, resource, RestInfoProvider.class, RestInfoProviderDefault.class, true, this, ps);
+ callHandler = getInstanceProperty(REST_callHandler, resource, RestCallHandler.class, RestCallHandlerDefault.class, true, this);
+ infoProvider = getInstanceProperty(REST_infoProvider, resource, RestInfoProvider.class, RestInfoProviderDefault.class, true, this);
} catch (RestException e) {
_initException = e;
@@ -3484,13 +3552,20 @@ public final class RestContext extends BeanContext {
*
* <p>
* By default, this is simply the list of accept types supported by the registered parsers, but
- * can be overridden via the {@link RestContextBuilder#supportedAcceptTypes(boolean,MediaType...)}/{@link RestContextBuilder#supportedAcceptTypes(boolean,String...)}
- * methods.
+ * can be overridden via the following:
+ * <ul>
+ * <li class='jf'>{@link RestContext#REST_produces}
+ * <li class='ja'>{@link RestResource#produces()}
+ * <li class='jm'>{@link RestContextBuilder#produces(boolean,MediaType...)}
+ * <li class='jm'>{@link RestContextBuilder#produces(boolean,String...)}
+ * </ul>
*
- * @return The supported <code>Accept</code> header values for this resource. Never <jk>null</jk>.
+ * @return
+ * The supported <code>Accept</code> header values for this resource.
+ * <br>Never <jk>null</jk>.
*/
- protected List<MediaType> getSupportedAcceptTypes() {
- return supportedAcceptTypes;
+ protected List<MediaType> getProduces() {
+ return produces;
}
/**
@@ -3498,13 +3573,20 @@ public final class RestContext extends BeanContext {
*
* <p>
* By default, this is simply the list of content types supported by the registered serializers, but can be
- * overridden via the {@link RestContextBuilder#supportedContentTypes(boolean,MediaType...)}/{@link RestContextBuilder#supportedContentTypes(boolean,String...)}
- * methods.
+ * overridden via the following:
+ * <ul>
+ * <li class='jf'>{@link RestContext#REST_consumes}
+ * <li class='ja'>{@link RestResource#consumes()}
+ * <li class='jm'>{@link RestContextBuilder#consumes(boolean,MediaType...)}
+ * <li class='jm'>{@link RestContextBuilder#consumes(boolean,String...)}
+ * </ul>
*
- * @return The supported <code>Content-Type</code> header values for this resource. Never <jk>null</jk>.
+ * @return
+ * The supported <code>Content-Type</code> header values for this resource.
+ * <br>Never <jk>null</jk>.
*/
- protected List<MediaType> getSupportedContentTypes() {
- return supportedContentTypes;
+ protected List<MediaType> getConsumes() {
+ return consumes;
}
/**
@@ -3701,6 +3783,16 @@ public final class RestContext extends BeanContext {
return null;
}
+ /**
+ * TODO
+ *
+ * @param method
+ * @return TODO
+ */
+ protected RestParam[] getRestParams(Method method) {
+ return callMethods.get(method.getName()).params;
+ }
+
@Override /* BeanContextBuilder */
public BeanSession createSession(BeanSessionArgs args) {
throw new NoSuchMethodError();
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
index 85bbf26..7c24de3 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
@@ -189,10 +189,10 @@ public class RestContextBuilder extends BeanContextBuilder implements ServletCon
serializers(r.serializers());
parsers(r.parsers());
encoders(r.encoders());
- if (r.supportedAcceptTypes().length > 0)
- supportedAcceptTypes(false, resolveVars(vr, r.supportedAcceptTypes()));
- if (r.supportedContentTypes().length > 0)
- supportedContentTypes(false, resolveVars(vr, r.supportedContentTypes()));
+ if (r.produces().length > 0)
+ produces(false, resolveVars(vr, r.produces()));
+ if (r.consumes().length > 0)
+ consumes(false, resolveVars(vr, r.consumes()));
defaultRequestHeaders(resolveVars(vr, r.defaultRequestHeaders()));
defaultResponseHeaders(resolveVars(vr, r.defaultResponseHeaders()));
responseHandlers(r.responseHandlers());
@@ -1766,7 +1766,7 @@ public class RestContextBuilder extends BeanContextBuilder implements ServletCon
*
* <h5 class='section'>See Also:</h5>
* <ul>
- * <li class='jf'>{@link RestContext#REST_supportedAcceptTypes}
+ * <li class='jf'>{@link RestContext#REST_produces}
* </ul>
*
* @param append
@@ -1774,19 +1774,19 @@ public class RestContextBuilder extends BeanContextBuilder implements ServletCon
* @param values The values to add to this setting.
* @return This object (for method chaining).
*/
- public RestContextBuilder supportedAcceptTypes(boolean append, String...values) {
- return set(append, REST_supportedAcceptTypes, values);
+ public RestContextBuilder produces(boolean append, String...values) {
+ return set(append, REST_produces, values);
}
/**
* Configuration property: Supported accept media types.
*
* <p>
- * Same as {@link #supportedAcceptTypes(boolean, String...)} except input is {@link MediaType} instances.
+ * Same as {@link #produces(boolean, String...)} except input is {@link MediaType} instances.
*
* <h5 class='section'>See Also:</h5>
* <ul>
- * <li class='jf'>{@link RestContext#REST_supportedAcceptTypes}
+ * <li class='jf'>{@link RestContext#REST_produces}
* </ul>
*
* @param append
@@ -1794,8 +1794,8 @@ public class RestContextBuilder extends BeanContextBuilder implements ServletCon
* @param values The values to add to this setting.
* @return This object (for method chaining).
*/
- public RestContextBuilder supportedAcceptTypes(boolean append, MediaType...values) {
- return set(append, REST_supportedAcceptTypes, values);
+ public RestContextBuilder produces(boolean append, MediaType...values) {
+ return set(append, REST_produces, values);
}
/**
@@ -1806,7 +1806,7 @@ public class RestContextBuilder extends BeanContextBuilder implements ServletCon
*
* <h5 class='section'>See Also:</h5>
* <ul>
- * <li class='jf'>{@link RestContext#REST_supportedContentTypes}
+ * <li class='jf'>{@link RestContext#REST_consumes}
* </ul>
*
* @param append
@@ -1814,19 +1814,19 @@ public class RestContextBuilder extends BeanContextBuilder implements ServletCon
* @param values The values to add to this setting.
* @return This object (for method chaining).
*/
- public RestContextBuilder supportedContentTypes(boolean append, String...values) {
- return set(append, REST_supportedContentTypes, values);
+ public RestContextBuilder consumes(boolean append, String...values) {
+ return set(append, REST_consumes, values);
}
/**
* Configuration property: Supported content media types.
*
* <p>
- * Same as {@link #supportedContentTypes(boolean, String...)} except input is {@link MediaType} instances.
+ * Same as {@link #consumes(boolean, String...)} except input is {@link MediaType} instances.
*
* <h5 class='section'>See Also:</h5>
* <ul>
- * <li class='jf'>{@link RestContext#REST_supportedContentTypes}
+ * <li class='jf'>{@link RestContext#REST_consumes}
* </ul>
*
* @param append
@@ -1834,8 +1834,8 @@ public class RestContextBuilder extends BeanContextBuilder implements ServletCon
* @param values The values to add to this setting.
* @return This object (for method chaining).
*/
- public RestContextBuilder supportedContentTypes(boolean append, MediaType...values) {
- return set(append, REST_supportedContentTypes, values);
+ public RestContextBuilder consumes(boolean append, MediaType...values) {
+ return set(append, REST_consumes, values);
}
/**
http://git-wip-us.apache.org/repos/asf/juneau/blob/62b041ab/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestInfoProvider.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestInfoProvider.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestInfoProvider.java
index b817fb4..188540e 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestInfoProvider.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestInfoProvider.java
@@ -12,13 +12,18 @@
// ***************************************************************************************************************************
package org.apache.juneau.rest;
+import java.lang.reflect.Method;
import java.util.*;
import org.apache.juneau.dto.swagger.*;
+import org.apache.juneau.http.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Class that provides documentation and other related information about a REST resource.
+ * REST resource information provider.
*
+ * <p>
+ * Provides localized Swagger documentation and other related information about a REST resource.
*
* <h5 class='topic'>Additional Information</h5>
* <ul>
@@ -41,136 +46,277 @@ public interface RestInfoProvider {
*
* @param req The incoming HTTP request.
* @return
- * The contents of the parsed swagger file.
- * Returns <jk>null</jk> if a swagger file could not be found.
- * @throws RestException
+ * The contents of the parsed swagger file, or <jk>null</jk> if a swagger file could not be found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public Swagger getSwaggerFromFile(RestRequest req) throws RestException;
+ public Swagger getSwaggerFromFile(RestRequest req) throws Exception;
/**
- * Returns the localized swagger for this REST resource.
+ * Returns the localized swagger for the REST resource.
*
* <p>
* If {@link #getSwaggerFromFile(RestRequest)} returns a non-<jk>null</jk> value, then
* that swagger is returned by this method.
- * <br>Otherwise, a new swagger object is return with information gathered via various means.
+ * <br>Otherwise, a new swagger object is return with information gathered via the other methods defined on this class.
*
* @param req The incoming HTTP request.
- * @return A new Swagger instance.
- * @throws RestException
+ * @return
+ * A new {@link Swagger} instance.
+ * <br>Never <jk>null</jk>.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public Swagger getSwagger(RestRequest req) throws RestException;
-
+ public Swagger getSwagger(RestRequest req) throws Exception;
/**
- * Returns the localized summary of the specified java method on this servlet.
+ * Returns the localized operation ID of the specified java method.
*
- * @param javaMethodName The name of the Java method whose description we're retrieving.
+ * @param method The Java method annotated with {@link RestMethod @RestMethod}.
* @param req The current request.
- * @return The localized summary of the method, or a blank string if no summary was found.
+ * @return The localized operation ID of the method, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public String getMethodSummary(String javaMethodName, RestRequest req);
+ public String getMethodOperationId(Method method, RestRequest req) throws Exception;
/**
- * Returns the localized summary of the java method invoked on the specified request.
+ * Returns the localized summary of the specified java method.
*
+ * @param method The Java method annotated with {@link RestMethod @RestMethod}.
* @param req The current request.
- * @return The localized summary of the method, or a blank string if no summary was found.
+ * @return The localized summary of the method, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public String getMethodSummary(RestRequest req);
+ public String getMethodSummary(Method method, RestRequest req) throws Exception;
/**
* Returns the localized description of the specified java method on this servlet.
*
- * @param javaMethodName The name of the Java method whose description we're retrieving.
+ * @param method The Java method annotated with {@link RestMethod @RestMethod}.
+ * @param req The current request.
+ * @return The localized description of the method, or <jk>null</jk> if none was was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
+ */
+ public String getMethodDescription(Method method, RestRequest req) throws Exception;
+
+ /**
+ * Returns the localized tags of the specified java method on this servlet.
+ *
+ * @param method The Java method annotated with {@link RestMethod @RestMethod}.
+ * @param req The current request.
+ * @return The localized tags of the method, or <jk>null</jk> if none were found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
+ */
+ public List<String> getMethodTags(Method method, RestRequest req) throws Exception;
+
+ /**
+ * Returns the localized external documentation of the specified java method on this servlet.
+ *
+ * @param method The Java method annotated with {@link RestMethod @RestMethod}.
+ * @param req The current request.
+ * @return The localized external documentation of the method, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
+ */
+ public ExternalDocumentation getMethodExternalDocs(Method method, RestRequest req) throws Exception;
+
+ /**
+ * Returns the localized parameter info for the specified java method.
+ *
+ * @param method The Java method annotated with {@link RestMethod @RestMethod}.
+ * @param req The current request.
+ * @return The localized parameter info of the method, or <jk>null</jk> if none were found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
+ */
+ public List<ParameterInfo> getMethodParameters(Method method, RestRequest req) throws Exception;
+
+ /**
+ * Returns the localized Swagger response information about the specified Java method.
+ *
+ * @param method The Java method annotated with {@link RestMethod @RestMethod}.
* @param req The current request.
- * @return The localized description of the method, or a blank string if no description was found.
+ * @return The localized response information of the method, or <jk>null</jk> if none were found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public String getMethodDescription(String javaMethodName, RestRequest req);
+ public Map<Integer,ResponseInfo> getMethodResponses(Method method, RestRequest req) throws Exception;
+
+ /**
+ * Returns the supported <code>Accept</code> types the specified Java method.
+ *
+ * @param method The Java method annotated with {@link RestMethod @RestMethod}.
+ * @param req The current request.
+ * @return The supported <code>Accept</code> types of the method, or <jk>null</jk> if none were found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
+ */
+ public List<MediaType> getMethodProduces(Method method, RestRequest req) throws Exception;
+
+ /**
+ * Returns the supported <code>Content-Type</code> types the specified Java method.
+ *
+ * @param method The Java method annotated with {@link RestMethod @RestMethod}.
+ * @param req The current request.
+ * @return The supported <code>Content-Type</code> types of the method, or <jk>null</jk> if none were found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
+ */
+ public List<MediaType> getMethodConsumes(Method method, RestRequest req) throws Exception;
/**
- * Returns the localized description of the invoked java method on the specified request.
+ * Returns whether the specified method is deprecated
*
+ * @param method The Java method annotated with {@link RestMethod @RestMethod}.
* @param req The current request.
- * @return The localized description of the method, or a blank string if no description was found.
+ * @return <jk>true</jk> if the method is deprecated.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public String getMethodDescription(RestRequest req);
+ public boolean isDeprecated(Method method, RestRequest req) throws Exception;
/**
- * Returns the localized site name of this REST resource.
+ * Returns the localized site name of the REST resource.
*
* @param req The current request.
- * @return The localized description of this REST resource, or <jk>null</jk> if no resource description was found.
+ * @return The localized site name of the REST resource, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public String getSiteName(RestRequest req);
+ public String getSiteName(RestRequest req) throws Exception;
/**
- * Returns the localized title of this REST resource.
+ * Returns the localized title of the REST resource.
*
* @param req The current request.
- * @return The localized description of this REST resource, or <jk>null</jk> if no resource description was found.
+ * @return The localized title of the REST resource, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public String getTitle(RestRequest req);
+ public String getTitle(RestRequest req) throws Exception;
/**
- * Returns the localized description of this REST resource.
+ * Returns the localized description of the REST resource.
*
* @param req The current request.
- * @return The localized description of this REST resource, or <jk>null</jk> if no resource description was found.
+ * @return The localized description of the REST resource, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public String getDescription(RestRequest req);
+ public String getDescription(RestRequest req) throws Exception;
/**
- * Returns the localized contact information of this REST resource.
+ * Returns the localized contact information of the REST resource.
*
* @param req The current request.
* @return
- * The localized contact information of this REST resource, or <jk>null</jk> if no contact information was found.
+ * The localized contact information of the REST resource, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public Contact getContact(RestRequest req) ;
+ public Contact getContact(RestRequest req) throws Exception;
/**
- * Returns the localized license information of this REST resource.
+ * Returns the localized license information of the REST resource.
*
* @param req The current request.
* @return
- * The localized contact information of this REST resource, or <jk>null</jk> if no contact information was found.
+ * The localized license information of the REST resource, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public License getLicense(RestRequest req);
+ public License getLicense(RestRequest req) throws Exception;
/**
- * Returns the terms-of-service information of this REST resource.
+ * Returns the terms-of-service iof the REST resource.
*
* @param req The current request.
* @return
- * The localized contact information of this REST resource, or <jk>null</jk> if no contact information was found.
+ * The localized terms-of-service of the REST resource, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public String getTermsOfService(RestRequest req);
+ public String getTermsOfService(RestRequest req) throws Exception;
/**
- * Returns the version information of this REST resource.
+ * Returns the localized version of the REST resource.
*
* @param req The current request.
* @return
- * The localized contact information of this REST resource, or <jk>null</jk> if no contact information was found.
+ * The localized version of the REST resource, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public String getVersion(RestRequest req);
+ public String getVersion(RestRequest req) throws Exception;
/**
- * Returns the version information of this REST resource.
+ * Returns the supported <code>Content-Type</code> request headers for the REST resource.
+ *
+ * @param req The current request.
+ * @return
+ * The supported <code>Content-Type</code> request headers of the REST resource, or <jk>null</jk> if none were found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
+ */
+ public List<MediaType> getConsumes(RestRequest req) throws Exception;
+
+ /**
+ * Returns the supported <code>Accept</code> request headers for the REST resource.
+ *
+ * @param req The current request.
+ * @return
+ * The supported <code>Accept</code> request headers of the REST resource, or <jk>null</jk> if none were found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
+ */
+ public List<MediaType> getProduces(RestRequest req) throws Exception;
+
+ /**
+ * Returns the localized tags of the REST resource.
*
* @param req The current request.
* @return
- * The localized contact information of this REST resource, or <jk>null</jk> if no contact information was found.
+ * The localized tags of the REST resource, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public List<Tag> getTags(RestRequest req);
+ public List<Tag> getTags(RestRequest req) throws Exception;
/**
- * Returns the external documentation of this REST resource.
+ * Returns the external documentation of the REST resource.
*
* @param req The current request.
* @return
- * The localized contact information of this REST resource, or <jk>null</jk> if no contact information was found.
+ * The localized external documentation of the REST resource, or <jk>null</jk> if none was found.
+ * @throws Exception
+ * Throw a {@link RestException} with a specific HTTP error status or any other exception
+ * to cause a <jsf>SC_INTERNAL_SERVER_ERROR</jsf>.
*/
- public ExternalDocumentation getExternalDocs(RestRequest req);
+ public ExternalDocumentation getExternalDocs(RestRequest req) throws Exception;
}