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 a36bf4c  REST servlet refactoring
a36bf4c is described below

commit a36bf4cb212edc7c9598ad76652d3c3dff67560b
Author: JamesBognar <[email protected]>
AuthorDate: Mon Jan 3 12:40:26 2022 -0500

    REST servlet refactoring
---
 .../java/org/apache/juneau/rest/RestContext.java   | 24 +++++---
 .../apache/juneau/rest/RestServletException.java   | 69 ----------------------
 .../rest/swagger/BasicSwaggerProviderSession.java  |  4 +-
 3 files changed, 19 insertions(+), 78 deletions(-)

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 8d1c4b3..cd62d1b 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
@@ -387,12 +387,12 @@ public class RestContext extends Context {
 
                                List<ClassInfo> missing = 
beanStore.getMissingParamTypes(params);
                                if (! missing.isEmpty())
-                                       throw new RestServletException("Could 
not call @RestHook(INIT) method {0}.{1}.  Could not find prerequisites: {2}.", 
m.getDeclaringClass().getSimpleName(), m.getSignature(), 
missing.stream().map(x->x.getSimpleName()).collect(Collectors.joining(",")));
+                                       throw servletException("Could not call 
@RestHook(INIT) method {0}.{1}.  Could not find prerequisites: {2}.", 
m.getDeclaringClass().getSimpleName(), m.getSignature(), 
missing.stream().map(x->x.getSimpleName()).collect(Collectors.joining(",")));
 
                                try {
                                        m.invoke(r, 
beanStore.getParams(params));
                                } catch (Exception e) {
-                                       throw new RestServletException(e, 
"Exception thrown from @RestHook(INIT) method {0}.{1}.", 
m.getDeclaringClass().getSimpleName(), m.getSignature());
+                                       throw servletException(e, "Exception 
thrown from @RestHook(INIT) method {0}.{1}.", 
m.getDeclaringClass().getSimpleName(), m.getSignature());
                                }
                        }
                }
@@ -4141,9 +4141,9 @@ public class RestContext extends Context {
                 *
                 * @param restContext The rest context.
                 * @return The REST operations list.
-                * @throws RestServletException If a problem occurred 
instantiating one of the child rest contexts.
+                * @throws ServletException If a problem occurred instantiating 
one of the child rest contexts.
                 */
-               public final RestOperations.Builder restOperations(RestContext 
restContext) throws RestServletException {
+               public final RestOperations.Builder restOperations(RestContext 
restContext) throws ServletException {
                        if (restOperations == null)
                                restOperations = 
createRestOperations(beanStore(), resource(), restContext);
                        return restOperations;
@@ -4161,9 +4161,9 @@ public class RestContext extends Context {
                 * @param resource
                 *      The REST servlet/bean instance that this context is 
defined against.
                 * @return A new REST operations list.
-                * @throws RestServletException If a problem occurred 
instantiating one of the child rest contexts.
+                * @throws ServletException If a problem occurred instantiating 
one of the child rest contexts.
                 */
-               protected RestOperations.Builder createRestOperations(BeanStore 
beanStore, Supplier<?> resource, RestContext restContext) throws 
RestServletException {
+               protected RestOperations.Builder createRestOperations(BeanStore 
beanStore, Supplier<?> resource, RestContext restContext) throws 
ServletException {
 
                        // Default value.
                        Value<RestOperations.Builder> v = Value.of(
@@ -4187,7 +4187,7 @@ public class RestContext extends Context {
                                if (al.size() > 0) {
                                        try {
                                                if (mi.isNotPublic())
-                                                       throw new 
RestServletException("@RestOp method {0}.{1} must be defined as public.", 
rci.inner().getName(), mi.getSimpleName());
+                                                       throw 
servletException("@RestOp method {0}.{1} must be defined as public.", 
rci.inner().getName(), mi.getSimpleName());
 
                                                RestOpContext roc = 
RestOpContext
                                                        .create(mi.inner(), 
restContext)
@@ -4216,7 +4216,7 @@ public class RestContext extends Context {
                                                        v.get().add(roc);
                                                }
                                        } catch (Throwable e) {
-                                               throw new 
RestServletException(e, "Problem occurred trying to initialize methods on class 
{0}", rci.inner().getName());
+                                               throw servletException(e, 
"Problem occurred trying to initialize methods on class {0}", 
rci.inner().getName());
                                        }
                                }
                        }
@@ -7306,6 +7306,14 @@ public class RestContext extends Context {
                return t;
        }
 
+       static ServletException servletException(String msg, Object...args) {
+               return new ServletException(format(msg, args));
+       }
+
+       static ServletException servletException(Throwable t, String msg, 
Object...args) {
+               return new ServletException(format(msg, args), t);
+       }
+
        
//-----------------------------------------------------------------------------------------------------------------
        // Other methods
        
//-----------------------------------------------------------------------------------------------------------------
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServletException.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServletException.java
deleted file mode 100644
index d1383e9..0000000
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServletException.java
+++ /dev/null
@@ -1,69 +0,0 @@
-// 
***************************************************************************************************************************
-// * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements.  See the NOTICE file *
-// * distributed with this work for additional information regarding copyright 
ownership.  The ASF licenses this file        *
-// * to you under the Apache License, Version 2.0 (the "License"); you may not 
use this file except in compliance            *
-// * with the License.  You may obtain a copy of the License at                
                                              *
-// *                                                                           
                                              *
-// *  http://www.apache.org/licenses/LICENSE-2.0                               
                                              *
-// *                                                                           
                                              *
-// * Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an  *
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
express or implied.  See the License for the        *
-// * specific language governing permissions and limitations under the 
License.                                              *
-// 
***************************************************************************************************************************
-package org.apache.juneau.rest;
-
-import static org.apache.juneau.internal.StringUtils.*;
-
-import java.text.*;
-
-import javax.servlet.*;
-
-import org.apache.juneau.internal.*;
-import org.apache.juneau.rest.servlet.*;
-
-/**
- * General exception thrown from {@link RestServlet} during construction or 
initialization.
- *
- * <ul class='seealso'>
- *     <li class='link'>{@doc jrs.Overview}
- *     <li class='extlink'>{@source}
- * </ul>
- *
- * @serial exclude
- */
-public class RestServletException extends ServletException {
-
-       private static final long serialVersionUID = 1L;
-
-       /**
-        * Constructor.
-        *
-        * @param message The detailed message.
-        * @param args Optional {@link MessageFormat}-style arguments.
-        */
-       public RestServletException(String message, Object...args) {
-               super(format(message, args));
-       }
-
-       /**
-        * Constructor.
-        *
-        * @param cause The cause.
-        * @param message The detailed message.
-        * @param args Optional {@link MessageFormat}-style arguments.
-        */
-       public RestServletException(Throwable cause, String message, 
Object...args) {
-               super(format(message, args), cause);
-       }
-
-       /**
-        * Similar to {@link #getCause()} but searches until it finds the 
throwable of the specified type.
-        *
-        * @param <T> The throwable type.
-        * @param c The throwable type.
-        * @return The cause of the specified type, or <jk>null</jk> of not 
found.
-        */
-       public <T extends Throwable> T getCause(Class<T> c) {
-               return ThrowableUtils.getCause(c, this);
-       }
-}
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
index 987b561..99e38ff 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
@@ -22,6 +22,8 @@ import java.lang.reflect.*;
 import java.lang.reflect.Method;
 import java.util.*;
 
+import javax.servlet.*;
+
 import org.apache.juneau.*;
 import org.apache.juneau.collections.*;
 import org.apache.juneau.cp.*;
@@ -545,7 +547,7 @@ public class BasicSwaggerProviderSession {
 //                     System.err.println(swaggerJson);
                        return jp.parse(swaggerJson, Swagger.class);
                } catch (Exception e) {
-                       throw new RestServletException(e, "Error detected in 
swagger.");
+                       throw new ServletException("Error detected in 
swagger.", e);
                }
        }
        
//=================================================================================================================

Reply via email to