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 8b65e13 REST refactoring.
8b65e13 is described below
commit 8b65e13fed87f222c2970bedca326677e9dd2c58
Author: JamesBognar <[email protected]>
AuthorDate: Mon Jan 11 09:15:19 2021 -0500
REST refactoring.
---
.../rest/springboot/BasicSpringRestServlet.java | 2 +-
.../org/apache/juneau/rest/BasicRestObject.java | 2 +-
.../org/apache/juneau/rest/BasicRestServlet.java | 2 +-
.../java/org/apache/juneau/rest/RestContext.java | 10 --
.../java/org/apache/juneau/rest/RestObject.java | 93 +-----------
.../java/org/apache/juneau/rest/RestServlet.java | 165 +++++----------------
6 files changed, 41 insertions(+), 233 deletions(-)
diff --git
a/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/BasicSpringRestServlet.java
b/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/BasicSpringRestServlet.java
index 587538a..d7dbc0d 100644
---
a/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/BasicSpringRestServlet.java
+++
b/juneau-rest/juneau-rest-server-springboot/src/main/java/org/apache/juneau/rest/springboot/BasicSpringRestServlet.java
@@ -165,7 +165,7 @@ public abstract class BasicSpringRestServlet extends
SpringRestServlet implement
@Override /* BasicRestConfig */
public Swagger getApi(RestRequest req) {
try {
- return getSwagger(req);
+ return req.getSwagger();
} catch (Exception e) {
throw new InternalServerError(e);
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestObject.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestObject.java
index d94bb90..027683d 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestObject.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestObject.java
@@ -44,7 +44,7 @@ public abstract class BasicRestObject extends RestObject
implements BasicUnivers
@Override /* BasicRestConfig */
public Swagger getApi(RestRequest req) {
try {
- return getSwagger(req);
+ return req.getSwagger();
} catch (Exception e) {
throw new InternalServerError(e);
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestServlet.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestServlet.java
index 70c5623..b837269 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestServlet.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestServlet.java
@@ -164,7 +164,7 @@ public abstract class BasicRestServlet extends RestServlet
implements BasicUnive
@Override /* BasicRestConfig */
public Swagger getApi(RestRequest req) {
try {
- return getSwagger(req);
+ return req.getSwagger();
} catch (Exception e) {
throw new InternalServerError(e);
}
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 5932161..42aac79 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
@@ -1077,8 +1077,6 @@ public class RestContext extends BeanContext {
* <li class='jm'>{@link
org.apache.juneau.rest.RestContextBuilder#fileFinder(Class)}
* <li class='jm'>{@link
org.apache.juneau.rest.RestContextBuilder#fileFinder(FileFinder)}
* <li class='jm'>{@link
org.apache.juneau.rest.RestContext#createFileFinder(BeanFactory)}
- * <li class='jm'>{@link
org.apache.juneau.rest.BasicRestObject#createFileFinder()}
- * <li class='jm'>{@link
org.apache.juneau.rest.BasicRestServlet#createFileFinder()}
* </ul>
* </ul>
*
@@ -1103,9 +1101,6 @@ public class RestContext extends BeanContext {
* <li>Returns the resource class itself if it's an instance of
{@link FileFinder}.
* <li>Looks for {@link #REST_fileFinder} setting.
* <li>Looks for a public <c>createFileFinder()</> method on the
resource class with an optional {@link RestContext} argument.
- * <br>Note that the {@link RestObject#createFileFinder()}
and {@link RestServlet#createFileFinder()} methods are implemented
- * to automatically look for injected beans of type {@link
FileFinder} allowing preconfigured file finders to be
- * defined in a Spring configuration class.
* <li>Instantiates the default file finder as specified via
{@link #REST_fileFinderDefault}.
* <li>Instantiates a {@link BasicFileFinder} which provides basic
support for finding localized
* resources on the classpath and JVM working directory.
@@ -2562,8 +2557,6 @@ public class RestContext extends BeanContext {
* <li class='jm'>{@link
org.apache.juneau.rest.RestContextBuilder#staticFiles(Class)}
* <li class='jm'>{@link
org.apache.juneau.rest.RestContextBuilder#staticFiles(StaticFiles)}
* <li class='jm'>{@link
org.apache.juneau.rest.RestContext#createStaticFiles(BeanFactory)}
- * <li class='jm'>{@link
org.apache.juneau.rest.BasicRestObject#createStaticFiles()}
- * <li class='jm'>{@link
org.apache.juneau.rest.BasicRestServlet#createStaticFiles()}
* </ul>
* </ul>
*
@@ -2590,9 +2583,6 @@ public class RestContext extends BeanContext {
* <li>Returns the resource class itself is an instance of {@link
StaticFiles}.
* <li>Looks in {@link #REST_staticFiles} setting.
* <li>Looks for a public <c>createStaticFiles()</> method on the
resource class with an optional {@link RestContext} argument.
- * <br>Note that the {@link
RestObject#createStaticFiles()} and {@link RestServlet#createStaticFiles()}
methhods are implemented
- * to automatically look for injected beans of type {@link
StaticFiles} allowing preconfigured static file finders to be
- * defined in a Spring configuration class.
* <li>Instantiates a {@link BasicStaticFiles} which provides
basic support for finding localized
* resources on the classpath and JVM working directory..
* </ul>
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestObject.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestObject.java
index 9b4f9e5..5d25abe 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestObject.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestObject.java
@@ -14,7 +14,6 @@ package org.apache.juneau.rest;
import static org.apache.juneau.rest.annotation.HookEvent.*;
-import java.lang.reflect.Method;
import java.text.*;
import java.util.function.*;
import java.util.logging.*;
@@ -22,12 +21,9 @@ import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
-import org.apache.juneau.cp.*;
-import org.apache.juneau.dto.swagger.*;
import org.apache.juneau.http.exception.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.rest.logging.*;
/**
* Identical to {@link RestServlet} but doesn't extend from {@link
HttpServlet}.
@@ -40,11 +36,10 @@ import org.apache.juneau.rest.logging.*;
* <li class='link'>{@doc BasicRest}
* </ul>
*/
-public abstract class RestObject implements RestInfoProvider {
+public abstract class RestObject {
private Logger logger = Logger.getLogger(getClass().getName());
private volatile RestContext context;
- private RestInfoProvider infoProvider;
//-----------------------------------------------------------------------------------------------------------------
// Context methods.
@@ -61,57 +56,6 @@ public abstract class RestObject implements RestInfoProvider
{
return context;
}
- /**
- * Instantiates the file finder to use for this REST resource.
- *
- * <p>
- * Default implementation returns <jk>null</jk>
- * which results in the default lookup logic as defined in {@link
RestContext#createFileFinder(BeanFactory)}.
- *
- * <ul class='seealso'>
- * <li class='link'>{@link RestContext#REST_fileFinder}.
- * </ul>
- *
- * @return The file finder to use for this REST resource, or
<jk>null</jk> if default logic should be used.
- */
- public FileFinder createFileFinder() {
- return null;
- }
-
- /**
- * Instantiates the static file finder to use for this REST resource.
- *
- * <p>
- * Default implementation returns <jk>null</jk>
- * which results in the default lookup logic as defined in {@link
RestContext#createStaticFiles(BeanFactory)}.
- *
- * <ul class='seealso'>
- * <li class='link'>{@link RestContext#REST_staticFiles}.
- * </ul>
- *
- * @return The static file finder to use for this REST resource, or
<jk>null</jk> if default logic should be used.
- */
- public StaticFiles createStaticFiles() {
- return null;
- }
-
- /**
- * Instantiates the call logger to use for this REST resource.
- *
- * <p>
- * Default implementation returns <jk>null</jk>
- * which results in the default lookup logic as defined in {@link
RestContext#createCallLogger(BeanFactory)}.
- *
- * <ul class='seealso'>
- * <li class='link'>{@link RestContext#REST_callLogger}.
- * </ul>
- *
- * @return The call logger to use for this REST resource, or
<jk>null</jk> if default logic should be used.
- */
- public RestLogger createCallLogger() {
- return null;
- }
-
//-----------------------------------------------------------------------------------------------------------------
// Convenience logger methods
//-----------------------------------------------------------------------------------------------------------------
@@ -260,7 +204,6 @@ public abstract class RestObject implements
RestInfoProvider {
@RestHook(POST_INIT)
public void onPostInit(RestContext context) throws Exception {
this.context = context;
- this.infoProvider = new BasicRestInfoProvider(context);
}
/**
@@ -484,38 +427,4 @@ public abstract class RestObject implements
RestInfoProvider {
public synchronized RestResponse getResponse() {
return getContext().getResponse();
}
-
-
//-----------------------------------------------------------------------------------------------------------------
- // RestInfoProvider
-
//-----------------------------------------------------------------------------------------------------------------
-
- @Override /* RestInfoProvider */
- public Swagger getSwagger(RestRequest req) throws Exception {
- return infoProvider.getSwagger(req);
- }
-
- @Override /* RestInfoProvider */
- public String getSiteName(RestRequest req) throws Exception {
- return infoProvider.getSiteName(req);
- }
-
- @Override /* RestInfoProvider */
- public String getTitle(RestRequest req) throws Exception {
- return infoProvider.getTitle(req);
- }
-
- @Override /* RestInfoProvider */
- public String getDescription(RestRequest req) throws Exception {
- return infoProvider.getDescription(req);
- }
-
- @Override /* RestInfoProvider */
- public String getMethodSummary(Method method, RestRequest req) throws
Exception {
- return infoProvider.getMethodSummary(method, req);
- }
-
- @Override /* RestInfoProvider */
- public String getMethodDescription(Method method, RestRequest req)
throws Exception {
- return infoProvider.getMethodDescription(method, req);
- }
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServlet.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServlet.java
index 1d6a115..2dde88b 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServlet.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServlet.java
@@ -19,7 +19,6 @@ import static org.apache.juneau.rest.HttpRuntimeException.*;
import static org.apache.juneau.rest.annotation.HookEvent.*;
import java.io.*;
-import java.lang.reflect.Method;
import java.text.*;
import java.util.function.*;
import java.util.logging.*;
@@ -30,9 +29,7 @@ import javax.servlet.http.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.reflect.*;
import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.rest.logging.*;
import org.apache.juneau.cp.*;
-import org.apache.juneau.dto.swagger.*;
import org.apache.juneau.http.exception.*;
/**
@@ -42,7 +39,7 @@ import org.apache.juneau.http.exception.*;
* <li class='link'>{@doc RestServlet}
* </ul>
*/
-public abstract class RestServlet extends HttpServlet implements
RestInfoProvider {
+public abstract class RestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -51,7 +48,6 @@ public abstract class RestServlet extends HttpServlet
implements RestInfoProvide
private volatile Exception initException;
private boolean isInitialized = false; // Should not be volatile.
private Logger logger = Logger.getLogger(getClass().getName());
- private RestInfoProvider infoProvider;
@Override /* Servlet */
public synchronized void init(ServletConfig servletConfig) throws
ServletException {
@@ -102,7 +98,6 @@ public abstract class RestServlet extends HttpServlet
implements RestInfoProvide
this.builder = context.builder;
this.context = context;
isInitialized = true;
- infoProvider = new BasicRestInfoProvider(context);
context.postInit();
}
@@ -139,6 +134,42 @@ public abstract class RestServlet extends HttpServlet
implements RestInfoProvide
}
//-----------------------------------------------------------------------------------------------------------------
+ // Lifecycle methods
+
//-----------------------------------------------------------------------------------------------------------------
+
+ /**
+ * The main service method.
+ *
+ * <p>
+ * Subclasses can optionally override this method if they want to
tailor the behavior of requests.
+ */
+ @Override /* Servlet */
+ public void service(HttpServletRequest r1, HttpServletResponse r2)
throws ServletException, InternalServerError, IOException {
+ try {
+ // To avoid checking the volatile field context on
every call, use the non-volatile isInitialized field as a first-check check.
+ if (! isInitialized) {
+ if (initException != null)
+ throw initException;
+ if (context == null)
+ throw new InternalServerError("Servlet
{0} not initialized. init(ServletConfig) was not called. This can occur if
you've overridden this method but didn't call super.init(RestConfig).",
getClass().getName());
+ isInitialized = true;
+ }
+
+ context.execute(r1, r2);
+
+ } catch (Throwable e) {
+ r2.sendError(SC_INTERNAL_SERVER_ERROR,
e.getLocalizedMessage());
+ }
+ }
+
+ @Override /* GenericServlet */
+ public synchronized void destroy() {
+ if (context != null)
+ context.destroy();
+ super.destroy();
+ }
+
+
//-----------------------------------------------------------------------------------------------------------------
// Context methods.
//-----------------------------------------------------------------------------------------------------------------
@@ -164,57 +195,6 @@ public abstract class RestServlet extends HttpServlet
implements RestInfoProvide
return context;
}
- /**
- * Instantiates the file finder to use for this REST resource.
- *
- * <p>
- * Default implementation returns <jk>null</jk>
- * which results in the default lookup logic as defined in {@link
RestContext#createFileFinder(BeanFactory)}.
- *
- * <ul class='seealso'>
- * <li class='link'>{@link RestContext#REST_fileFinder}.
- * </ul>
- *
- * @return The file finder to use for this REST resource, or
<jk>null</jk> if default logic should be used.
- */
- public FileFinder createFileFinder() {
- return null;
- }
-
- /**
- * Instantiates the static file finder to use for this REST resource.
- *
- * <p>
- * Default implementation returns <jk>null</jk>
- * which results in the default lookup logic as defined in {@link
RestContext#createStaticFiles(BeanFactory)}.
- *
- * <ul class='seealso'>
- * <li class='link'>{@link RestContext#REST_staticFiles}.
- * </ul>
- *
- * @return The static file finder to use for this REST resource, or
<jk>null</jk> if default logic should be used.
- */
- public StaticFiles createStaticFiles() {
- return null;
- }
-
- /**
- * Instantiates the call logger to use for this REST resource.
- *
- * <p>
- * Default implementation returns <jk>null</jk>
- * which results in the default lookup logic as defined in {@link
RestContext#createCallLogger(BeanFactory)}.
- *
- * <ul class='seealso'>
- * <li class='link'>{@link RestContext#REST_callLogger}.
- * </ul>
- *
- * @return The call logger to use for this REST resource, or
<jk>null</jk> if default logic should be used.
- */
- public RestLogger createCallLogger() {
- return null;
- }
-
//-----------------------------------------------------------------------------------------------------------------
// Convenience logger methods
//-----------------------------------------------------------------------------------------------------------------
@@ -293,42 +273,6 @@ public abstract class RestServlet extends HttpServlet
implements RestInfoProvide
}
//-----------------------------------------------------------------------------------------------------------------
- // Lifecycle methods
-
//-----------------------------------------------------------------------------------------------------------------
-
- /**
- * The main service method.
- *
- * <p>
- * Subclasses can optionally override this method if they want to
tailor the behavior of requests.
- */
- @Override /* Servlet */
- public void service(HttpServletRequest r1, HttpServletResponse r2)
throws ServletException, InternalServerError, IOException {
- try {
- // To avoid checking the volatile field context on
every call, use the non-volatile isInitialized field as a first-check check.
- if (! isInitialized) {
- if (initException != null)
- throw initException;
- if (context == null)
- throw new InternalServerError("Servlet
{0} not initialized. init(ServletConfig) was not called. This can occur if
you've overridden this method but didn't call super.init(RestConfig).",
getClass().getName());
- isInitialized = true;
- }
-
- context.execute(r1, r2);
-
- } catch (Throwable e) {
- r2.sendError(SC_INTERNAL_SERVER_ERROR,
e.getLocalizedMessage());
- }
- }
-
- @Override /* GenericServlet */
- public synchronized void destroy() {
- if (context != null)
- context.destroy();
- super.destroy();
- }
-
-
//-----------------------------------------------------------------------------------------------------------------
// Hook events
//-----------------------------------------------------------------------------------------------------------------
@@ -622,39 +566,4 @@ public abstract class RestServlet extends HttpServlet
implements RestInfoProvide
public synchronized RestResponse getResponse() {
return getContext().getResponse();
}
-
-
-
//-----------------------------------------------------------------------------------------------------------------
- // RestInfoProvider
-
//-----------------------------------------------------------------------------------------------------------------
-
- @Override /* RestInfoProvider */
- public Swagger getSwagger(RestRequest req) throws Exception {
- return infoProvider.getSwagger(req);
- }
-
- @Override /* RestInfoProvider */
- public String getSiteName(RestRequest req) throws Exception {
- return infoProvider.getSiteName(req);
- }
-
- @Override /* RestInfoProvider */
- public String getTitle(RestRequest req) throws Exception {
- return infoProvider.getTitle(req);
- }
-
- @Override /* RestInfoProvider */
- public String getDescription(RestRequest req) throws Exception {
- return infoProvider.getDescription(req);
- }
-
- @Override /* RestInfoProvider */
- public String getMethodSummary(Method method, RestRequest req) throws
Exception {
- return infoProvider.getMethodSummary(method, req);
- }
-
- @Override /* RestInfoProvider */
- public String getMethodDescription(Method method, RestRequest req)
throws Exception {
- return infoProvider.getMethodDescription(method, req);
- }
}