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/04/10 23:22:17 UTC
[juneau] branch master updated: New RestException subclasses.
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 d4b5941 New RestException subclasses.
d4b5941 is described below
commit d4b59413db39647a3178a7ffff9bec0d3d69b98e
Author: JamesBognar <ja...@apache.org>
AuthorDate: Tue Apr 10 19:22:09 2018 -0400
New RestException subclasses.
---
.../org/apache/juneau/dto/swagger/InfoTest.java | 8 +-
.../java/org/apache/juneau/dto/swagger/Info.java | 2 +-
.../org/apache/juneau/dto/swagger/Swagger.java | 2 +-
.../apache/juneau/dto/swagger/ui/SwaggerUI.java | 12 +--
.../java/org/apache/juneau/BeanPropertyMeta.java | 6 +-
.../org/apache/juneau/BeanRuntimeException.java | 41 +++++----
.../apache/juneau/ClassMetaRuntimeException.java | 39 +++++----
.../java/org/apache/juneau/ConfigException.java | 16 ++--
.../org/apache/juneau/ContextRuntimeException.java | 39 ++-------
.../apache/juneau/FormattedRuntimeException.java | 24 +++++-
.../juneau/InvalidDataConversionException.java | 17 +++-
.../src/main/java/org/apache/juneau/ObjectMap.java | 4 +-
.../remoteable/RemoteableMetadataException.java | 15 +++-
.../org/apache/juneau/utils/PojoRestException.java | 16 +++-
.../apache/juneau/svl/VarResolverException.java | 13 ++-
juneau-doc/src/main/javadoc/overview.html | 41 +++++++++
.../juneau/examples/rest/AtomFeedResource.java | 11 ++-
.../examples/rest/CodeFormatterResource.java | 11 ++-
.../juneau/examples/rest/DirectoryResource.java | 98 ++++++++++++++--------
.../examples/rest/DockerRegistryResource.java | 11 ++-
.../juneau/examples/rest/JsonSchemaResource.java | 11 ++-
.../examples/rest/MethodExampleResource.java | 11 ++-
.../juneau/examples/rest/PhotosResource.java | 19 +++--
.../examples/rest/PredefinedLabelsResource.java | 11 ++-
.../juneau/examples/rest/RequestEchoResource.java | 9 ++
.../examples/rest/SampleRemoteableServlet.java | 12 ++-
.../juneau/examples/rest/SqlQueryResource.java | 21 +++--
.../juneau/examples/rest/StaticFilesResource.java | 9 ++
.../juneau/examples/rest/TempDirResource.java | 34 ++++++--
.../juneau/examples/rest/TumblrParserResource.java | 11 ++-
.../examples/rest/UrlEncodedFormResource.java | 11 ++-
.../rest/addressbook/AddressBookResource.java | 37 ++++----
.../{IdConflictException.java => IdConflict.java} | 8 +-
.../{IdNotFoundException.java => IdNotFound.java} | 8 +-
.../{InvalidIdException.java => InvalidId.java} | 7 +-
.../{LoginException.java => InvalidLogin.java} | 7 +-
.../{InvalidTagException.java => InvalidTag.java} | 7 +-
...UsernameException.java => InvalidUsername.java} | 7 +-
.../juneau/examples/rest/petstore/PetStore.java | 88 +++++++++----------
.../examples/rest/petstore/PetStoreResource.java | 36 ++++----
.../microservice/resources/ConfigResource.java | 19 +++--
.../microservice/resources/DirectoryResource.java | 58 +++++++------
.../microservice/resources/LogsResource.java | 67 +++++++++++----
.../apache/juneau/rest/BasicRestCallHandler.java | 16 ++--
.../java/org/apache/juneau/rest/RequestBody.java | 18 ++--
.../java/org/apache/juneau/rest/RestContext.java | 24 +++---
.../java/org/apache/juneau/rest/RestException.java | 28 +++----
.../java/org/apache/juneau/rest/RestGuard.java | 5 +-
.../org/apache/juneau/rest/RestJavaMethod.java | 19 +++--
.../java/org/apache/juneau/rest/RestRequest.java | 37 +++++---
.../java/org/apache/juneau/rest/RestResponse.java | 21 +++--
.../java/org/apache/juneau/rest/RestServlet.java | 10 ++-
.../juneau/rest/converters/Introspectable.java | 8 +-
.../apache/juneau/rest/converters/Traversable.java | 9 +-
.../apache/juneau/rest/exception/BadRequest.java | 61 ++++++++++----
.../org/apache/juneau/rest/exception/Conflict.java | 63 ++++++++++----
.../juneau/rest/exception/ExpectationFailed.java | 63 ++++++++++----
.../juneau/rest/exception/FailedDependency.java | 63 ++++++++++----
.../apache/juneau/rest/exception/Forbidden.java | 64 ++++++++++----
.../org/apache/juneau/rest/exception/Gone.java | 81 ++++++++++++++++++
.../rest/exception/HttpVersionNotSupported.java | 63 ++++++++++----
.../juneau/rest/exception/InsufficientStorage.java | 63 ++++++++++----
.../juneau/rest/exception/InternalServerError.java | 63 ++++++++++----
.../juneau/rest/exception/LengthRequired.java | 63 ++++++++++----
.../org/apache/juneau/rest/exception/Locked.java | 63 ++++++++++----
.../apache/juneau/rest/exception/LoopDetected.java | 63 ++++++++++----
.../juneau/rest/exception/MethodNotAllowed.java | 63 ++++++++++----
.../juneau/rest/exception/MisdirectedRequest.java | 63 ++++++++++----
.../exception/NetworkAuthenticationRequired.java | 64 ++++++++++----
.../juneau/rest/exception/NotAcceptable.java | 63 ++++++++++----
.../apache/juneau/rest/exception/NotExtended.java | 63 ++++++++++----
.../org/apache/juneau/rest/exception/NotFound.java | 64 ++++++++++----
.../juneau/rest/exception/NotImplemented.java | 64 ++++++++++----
.../juneau/rest/exception/PayloadTooLarge.java | 63 ++++++++++----
.../juneau/rest/exception/PreconditionFailed.java | 63 ++++++++++----
.../rest/exception/PreconditionRequired.java | 64 ++++++++++----
.../juneau/rest/exception/RangeNotSatisfiable.java | 64 ++++++++++----
.../exception/RequestHeaderFieldsTooLarge.java | 63 ++++++++++----
.../juneau/rest/exception/ServiceUnavailable.java | 64 ++++++++++----
.../juneau/rest/exception/TooManyRequests.java | 64 ++++++++++----
.../apache/juneau/rest/exception/Unauthorized.java | 80 ++++++++++++++++++
.../rest/exception/UnavailableForLegalReasons.java | 63 ++++++++++----
.../juneau/rest/exception/UnprocessableEntity.java | 63 ++++++++++----
.../rest/exception/UnsupportedMediaType.java | 64 ++++++++++----
.../juneau/rest/exception/UpgradeRequired.java | 63 ++++++++++----
.../apache/juneau/rest/exception/UriTooLong.java | 64 ++++++++++----
.../rest/exception/VariantAlsoNegotiates.java | 63 ++++++++++----
.../apache/juneau/rest/exception/package-info.java | 18 ++++
.../juneau/rest/remoteable/RemoteableServlet.java | 21 +++--
.../juneau/rest/response/DefaultHandler.java | 9 +-
.../juneau/rest/response/InputStreamHandler.java | 3 +-
.../apache/juneau/rest/response/ReaderHandler.java | 3 +-
.../juneau/rest/response/WritableHandler.java | 3 +-
.../org/apache/juneau/rest/vars/RestInfoVar.java | 7 +-
94 files changed, 2360 insertions(+), 955 deletions(-)
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/InfoTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/InfoTest.java
index 0e92071..508280a 100644
--- a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/InfoTest.java
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/InfoTest.java
@@ -148,7 +148,7 @@ public class InfoTest {
.set("version", "f")
.set("$ref", "ref");
- assertObjectEquals("{title:'e',description:'b',termsOfService:'d',contact:{name:'a'},license:{name:'c'},version:'f','$ref':'ref'}", t);
+ assertObjectEquals("{title:'e',description:'b',version:'f',contact:{name:'a'},license:{name:'c'},termsOfService:'d','$ref':'ref'}", t);
t
.set("contact", "{name:'a'}")
@@ -159,7 +159,7 @@ public class InfoTest {
.set("version", "f")
.set("$ref", "ref");
- assertObjectEquals("{title:'e',description:'b',termsOfService:'d',contact:{name:'a'},license:{name:'c'},version:'f','$ref':'ref'}", t);
+ assertObjectEquals("{title:'e',description:'b',version:'f',contact:{name:'a'},license:{name:'c'},termsOfService:'d','$ref':'ref'}", t);
t
.set("contact", new StringBuilder("{name:'a'}"))
@@ -170,7 +170,7 @@ public class InfoTest {
.set("version", new StringBuilder("f"))
.set("$ref", new StringBuilder("ref"));
- assertObjectEquals("{title:'e',description:'b',termsOfService:'d',contact:{name:'a'},license:{name:'c'},version:'f','$ref':'ref'}", t);
+ assertObjectEquals("{title:'e',description:'b',version:'f',contact:{name:'a'},license:{name:'c'},termsOfService:'d','$ref':'ref'}", t);
assertEquals("{name:'a'}", t.get("contact", String.class));
assertEquals("b", t.get("description", String.class));
@@ -193,7 +193,7 @@ public class InfoTest {
assertNull(t.get(null, Object.class));
assertNull(t.get("foo", Object.class));
- String s = "{title:'e',description:'b',termsOfService:'d',contact:{name:'a'},license:{name:'c'},version:'f','$ref':'ref'}";
+ String s = "{title:'e',description:'b',version:'f',contact:{name:'a'},license:{name:'c'},termsOfService:'d','$ref':'ref'}";
assertObjectEquals(s, JsonParser.DEFAULT.parse(s, Info.class));
}
}
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Info.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Info.java
index 8fca4fa..4868796 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Info.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Info.java
@@ -68,7 +68,7 @@ import org.apache.juneau.utils.*;
* <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="title,description,termsOfService,contact,license,version,*")
+@Bean(properties="title,description,version,contact,license,termsOfService,*")
public class Info extends SwaggerElement {
private String
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
index 209e50d..6bf836d 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
@@ -1358,7 +1358,7 @@ public class Swagger extends SwaggerElement {
try {
return new PojoRest(this).get(ref.substring(1), c);
} catch (Exception e) {
- throw new BeanRuntimeException("Reference ''{0}'' could not be converted to type ''{1}''.", ref, c.getName()).initCause(e);
+ throw new BeanRuntimeException(e, c, "Reference ''{0}'' could not be converted to type ''{1}''.", ref, c.getName());
}
}
}
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ui/SwaggerUI.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ui/SwaggerUI.java
index 4a08001..38d6ef0 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ui/SwaggerUI.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ui/SwaggerUI.java
@@ -130,12 +130,6 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
if (info.hasVersion())
table.child(tr(th("Version:"),td(info.getVersion())));
- if (info.hasTermsOfService()) {
- String tos = info.getTermsOfService();
- Object child = StringUtils.isUri(tos) ? a(tos, tos) : tos;
- table.child(tr(th("Terms of Service:"),td(child)));
- }
-
Contact c = info.getContact();
if (c != null) {
Table t2 = table();
@@ -161,6 +155,12 @@ public class SwaggerUI extends PojoSwap<Swagger,Div> {
Object child = ed.hasUrl() ? a(ed.getUrl(), ed.hasDescription() ? ed.getDescription() : ed.getUrl()) : ed.getDescription();
table.child(tr(th("Docs:"),td(child)));
}
+
+ if (info.hasTermsOfService()) {
+ String tos = info.getTermsOfService();
+ Object child = StringUtils.isUri(tos) ? a(tos, tos) : tos;
+ table.child(tr(th("Terms of Service:"),td(child)));
+ }
}
return table;
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
index 41cb2a9..ea21858 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
@@ -528,7 +528,7 @@ public final class BeanPropertyMeta {
return rawTypeMeta.getPrimitiveDefault();
return null;
}
- throw new BeanRuntimeException(beanMeta.c, "Exception occurred while getting property ''{0}''", name).initCause(e);
+ throw new BeanRuntimeException(e, beanMeta.c, "Exception occurred while getting property ''{0}''", name);
}
}
@@ -554,7 +554,7 @@ public final class BeanPropertyMeta {
return rawTypeMeta.getPrimitiveDefault();
return null;
}
- throw new BeanRuntimeException(beanMeta.c, "Exception occurred while getting property ''{0}''", name).initCause(e);
+ throw new BeanRuntimeException(e, beanMeta.c, "Exception occurred while getting property ''{0}''", name);
}
}
@@ -770,7 +770,7 @@ public final class BeanPropertyMeta {
return rawTypeMeta.getPrimitiveDefault();
return null;
}
- throw new BeanRuntimeException(beanMeta.c, "Error occurred trying to set property ''{0}''", name).initCause(e);
+ throw new BeanRuntimeException(e, beanMeta.c, "Error occurred trying to set property ''{0}''", name);
}
} catch (ParseException e) {
throw new BeanRuntimeException(e);
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRuntimeException.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRuntimeException.java
index 909c997..5bd9f27 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRuntimeException.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRuntimeException.java
@@ -12,6 +12,8 @@
// ***************************************************************************************************************************
package org.apache.juneau;
+import java.text.*;
+
/**
* General bean runtime operation exception.
*/
@@ -22,10 +24,22 @@ public final class BeanRuntimeException extends FormattedRuntimeException {
/**
* Constructor.
*
+ * @param cause The cause of this exception.
+ * @param c The class name of the bean that caused the exception.
+ * @param message The {@link MessageFormat}-style message.
+ * @param args Optional {@link MessageFormat}-style arguments.
+ */
+ public BeanRuntimeException(Throwable cause, Class<?> c, String message, Object... args) {
+ super(cause, getMessage(cause, c, message), args);
+ }
+
+ /**
+ * Constructor.
+ *
* @param message The error message.
*/
public BeanRuntimeException(String message) {
- super(message);
+ this((Throwable)null, null, message);
}
/**
@@ -35,18 +49,18 @@ public final class BeanRuntimeException extends FormattedRuntimeException {
* @param args Arguments passed in to the {@code String.format()} method.
*/
public BeanRuntimeException(String message, Object...args) {
- super(message, args);
+ this(null, null, message, args);
}
/**
- * Shortcut for calling <code><jk>new</jk> BeanRuntimeException(String.format(c.getName() + <js>": "</js> + message, args));</code>
+ * Constructor.
*
* @param c The class name of the bean that caused the exception.
* @param message The error message.
* @param args Arguments passed in to the {@code String.format()} method.
*/
public BeanRuntimeException(Class<?> c, String message, Object... args) {
- super(c.getName() + ": " + message, args);
+ this(null, c, message, args);
}
/**
@@ -55,19 +69,14 @@ public final class BeanRuntimeException extends FormattedRuntimeException {
* @param cause The initial cause of the exception.
*/
public BeanRuntimeException(Throwable cause) {
- super(cause == null ? null : cause.getLocalizedMessage());
- initCause(cause);
+ this(cause, null, null);
}
- /**
- * Sets the inner cause for this exception.
- *
- * @param cause The inner cause.
- * @return This object (for method chaining).
- */
- @Override /* Throwable */
- public synchronized BeanRuntimeException initCause(Throwable cause) {
- super.initCause(cause);
- return this;
+ private static String getMessage(Throwable cause, Class<?> c, String msg) {
+ if (msg != null)
+ return (c == null ? "" : c.getName() + ": ") + msg;
+ if (cause != null)
+ return (c == null ? "" : c.getName() + ": ") + cause.getMessage();
+ return null;
}
}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMetaRuntimeException.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMetaRuntimeException.java
index 1ea6da1..ec53171 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMetaRuntimeException.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMetaRuntimeException.java
@@ -12,6 +12,8 @@
// ***************************************************************************************************************************
package org.apache.juneau;
+import java.text.*;
+
/**
* General class metadata runtime operation exception.
*/
@@ -22,10 +24,22 @@ public final class ClassMetaRuntimeException extends FormattedRuntimeException {
/**
* Constructor.
*
+ * @param cause The cause of this exception.
+ * @param c The class name of the bean that caused the exception.
+ * @param message The {@link MessageFormat}-style message.
+ * @param args Optional {@link MessageFormat}-style arguments.
+ */
+ public ClassMetaRuntimeException(Throwable cause, Class<?> c, String message, Object... args) {
+ super(cause, getMessage(cause, c, message), args);
+ }
+
+ /**
+ * Constructor.
+ *
* @param message The error message.
*/
public ClassMetaRuntimeException(String message) {
- super(message);
+ this((Throwable)null, null, message);
}
/**
@@ -35,7 +49,7 @@ public final class ClassMetaRuntimeException extends FormattedRuntimeException {
* @param args Arguments passed in to the {@code String.format()} method.
*/
public ClassMetaRuntimeException(String message, Object...args) {
- super(message, args);
+ this(null, null, message, args);
}
/**
@@ -46,7 +60,7 @@ public final class ClassMetaRuntimeException extends FormattedRuntimeException {
* @param args Arguments passed in to the {@code String.format()} method.
*/
public ClassMetaRuntimeException(Class<?> c, String message, Object... args) {
- super(c.getName() + ": " + message, args);
+ this(null, c, message, args);
}
/**
@@ -55,19 +69,14 @@ public final class ClassMetaRuntimeException extends FormattedRuntimeException {
* @param cause The initial cause of the exception.
*/
public ClassMetaRuntimeException(Throwable cause) {
- super(cause == null ? null : cause.getLocalizedMessage());
- initCause(cause);
+ this(cause, null, null);
}
- /**
- * Sets the inner cause for this exception.
- *
- * @param cause The inner cause.
- * @return This object (for method chaining).
- */
- @Override /* Throwable */
- public synchronized ClassMetaRuntimeException initCause(Throwable cause) {
- super.initCause(cause);
- return this;
+ private static String getMessage(Throwable cause, Class<?> c, String msg) {
+ if (msg != null)
+ return (c == null ? "" : c.getName() + ": ") + msg;
+ if (cause != null)
+ return (c == null ? "" : c.getName() + ": ") + cause.getMessage();
+ return null;
}
}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ConfigException.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ConfigException.java
index c7b8805..0da30b4 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ConfigException.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ConfigException.java
@@ -21,26 +21,26 @@ public class ConfigException extends FormattedRuntimeException {
private static final long serialVersionUID = 1L;
/**
- * Constructor
+ * Constructor.
*
- * @param message The error message.
+ * @param cause The cause of this exception.
+ * @param message The {@link MessageFormat}-style message.
* @param args Optional {@link MessageFormat}-style arguments.
*/
- public ConfigException(String message, Object...args) {
- super(message, args);
+ public ConfigException(Throwable cause, String message, Object... args) {
+ super(cause, getMessage(cause, message, null), args);
}
/**
* Constructor
*
- * @param t The init cause. Can be <jk>null</jk>.
* @param message The error message.
* @param args Optional {@link MessageFormat}-style arguments.
*/
- public ConfigException(Throwable t, String message, Object...args) {
- super(t, message, args);
+ public ConfigException(String message, Object...args) {
+ this(null, message, args);
}
-
+
@Override
public String getMessage() {
Throwable t = getCause();
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextRuntimeException.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextRuntimeException.java
index 1b92f5f..713f599 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextRuntimeException.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextRuntimeException.java
@@ -12,6 +12,8 @@
// ***************************************************************************************************************************
package org.apache.juneau;
+import java.text.*;
+
/**
* General runtime operation exception that can occur in any of the context classes.
*/
@@ -22,10 +24,12 @@ public final class ContextRuntimeException extends FormattedRuntimeException {
/**
* Constructor.
*
- * @param message The error message.
+ * @param cause The cause of this exception.
+ * @param message The {@link MessageFormat}-style message.
+ * @param args Optional {@link MessageFormat}-style arguments.
*/
- public ContextRuntimeException(String message) {
- super(message);
+ public ContextRuntimeException(Throwable cause, String message, Object... args) {
+ super(cause, getMessage(cause, message, null), args);
}
/**
@@ -35,19 +39,7 @@ public final class ContextRuntimeException extends FormattedRuntimeException {
* @param args Arguments passed in to the {@code String.format()} method.
*/
public ContextRuntimeException(String message, Object...args) {
- super(message, args);
- }
-
- /**
- * Constructor.
- *
- * @param cause The initial cause of the exception.
- * @param message The error message.
- * @param args Arguments passed in to the {@code String.format()} method.
- */
- public ContextRuntimeException(Throwable cause, String message, Object...args) {
- super(message, args);
- initCause(cause);
+ this(null, message, args);
}
/**
@@ -56,19 +48,6 @@ public final class ContextRuntimeException extends FormattedRuntimeException {
* @param cause The initial cause of the exception.
*/
public ContextRuntimeException(Throwable cause) {
- super(cause == null ? null : cause.getLocalizedMessage());
- initCause(cause);
- }
-
- /**
- * Sets the inner cause for this exception.
- *
- * @param cause The inner cause.
- * @return This object (for method chaining).
- */
- @Override /* Throwable */
- public synchronized ContextRuntimeException initCause(Throwable cause) {
- super.initCause(cause);
- return this;
+ this(cause, null);
}
}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/FormattedRuntimeException.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/FormattedRuntimeException.java
index 4b56148..50a1ee3 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/FormattedRuntimeException.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/FormattedRuntimeException.java
@@ -36,12 +36,28 @@ public class FormattedRuntimeException extends RuntimeException {
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
+ * @param cause The cause of this exception.
* @param message The {@link MessageFormat}-style message.
* @param args Optional {@link MessageFormat}-style arguments.
*/
- public FormattedRuntimeException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public FormattedRuntimeException(Throwable cause, String message, Object...args) {
+ this(getMessage(cause, message, null), args);
+ initCause(cause);
+ }
+
+ /**
+ * Finds the message.
+ *
+ * @param cause The cause.
+ * @param msg The message.
+ * @param def The default value if both above are <jk>null</jk>.
+ * @return The resolved message.
+ */
+ protected static final String getMessage(Throwable cause, String msg, String def) {
+ if (msg != null)
+ return msg;
+ if (cause != null)
+ return cause.getMessage();
+ return def;
}
}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/InvalidDataConversionException.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/InvalidDataConversionException.java
index cd5583f..871a371 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/InvalidDataConversionException.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/InvalidDataConversionException.java
@@ -14,6 +14,8 @@ package org.apache.juneau;
import static org.apache.juneau.internal.ClassUtils.*;
+import java.text.*;
+
import org.apache.juneau.json.*;
/**
@@ -28,12 +30,23 @@ public final class InvalidDataConversionException extends FormattedRuntimeExcept
private static final long serialVersionUID = 1L;
/**
+ * Constructor.
+ *
+ * @param cause The cause of this exception.
+ * @param message The {@link MessageFormat}-style message.
+ * @param args Optional {@link MessageFormat}-style arguments.
+ */
+ public InvalidDataConversionException(Throwable cause, String message, Object... args) {
+ super(cause, getMessage(cause, message, null), args);
+ }
+
+ /**
* @param toType Attempting to convert to this class type.
* @param cause The cause.
* @param value The value being converted.
*/
public InvalidDataConversionException(Object value, Class<?> toType, Exception cause) {
- super(cause, "Invalid data conversion from type ''{0}'' to type ''{1}''. Value={2}.",
+ this(cause, "Invalid data conversion from type ''{0}'' to type ''{1}''. Value={2}.",
getReadableClassNameForObject(value), getReadableClassName(toType), getValue(value));
}
@@ -43,7 +56,7 @@ public final class InvalidDataConversionException extends FormattedRuntimeExcept
* @param value The value being converted.
*/
public InvalidDataConversionException(Object value, ClassMeta<?> toType, Exception cause) {
- super(cause, "Invalid data conversion from type ''{0}'' to type ''{1}''. Value={2}.",
+ this(cause, "Invalid data conversion from type ''{0}'' to type ''{1}''. Value={2}.",
getReadableClassNameForObject(value), toType.toString(), getValue(value));
}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ObjectMap.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ObjectMap.java
index a64ca5c..f0484dd 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ObjectMap.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ObjectMap.java
@@ -1489,8 +1489,8 @@ public class ObjectMap extends LinkedHashMap<String,Object> {
}
} catch (Exception e) {
- throw new BeanRuntimeException(cm.innerClass,
- "Error occurred attempting to cast to an object of type ''{0}''", cm.innerClass.getName()).initCause(e);
+ throw new BeanRuntimeException(e, cm.innerClass,
+ "Error occurred attempting to cast to an object of type ''{0}''", cm.innerClass.getName());
}
throw new BeanRuntimeException(cm.innerClass,
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/remoteable/RemoteableMetadataException.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/remoteable/RemoteableMetadataException.java
index 117de01..5456cd9 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/remoteable/RemoteableMetadataException.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/remoteable/RemoteableMetadataException.java
@@ -27,12 +27,23 @@ public class RemoteableMetadataException extends FormattedRuntimeException {
/**
* Constructor.
*
+ * @param cause The cause of this exception.
+ * @param message The {@link MessageFormat}-style message.
+ * @param args Optional {@link MessageFormat}-style arguments.
+ */
+ public RemoteableMetadataException(Throwable cause, String message, Object... args) {
+ super(cause, getMessage(cause, message, null), args);
+ }
+
+ /**
+ * Constructor.
+ *
* @param m The interface method that has an invalid definition.
* @param message The {@link MessageFormat}-style message.
* @param args Optional {@link MessageFormat}-style arguments.
*/
public RemoteableMetadataException(Method m, String message, Object...args) {
- super(getMessage(m.getDeclaringClass(), m, message), args);
+ this((Throwable)null, getMessage(m.getDeclaringClass(), m, message), args);
}
/**
@@ -43,7 +54,7 @@ public class RemoteableMetadataException extends FormattedRuntimeException {
* @param args Optional {@link MessageFormat}-style arguments.
*/
public RemoteableMetadataException(Class<?> c, String message, Object...args) {
- super(getMessage(c, null, message), args);
+ this((Throwable)null, getMessage(c, null, message), args);
}
private static final String getMessage(Class<?> c, Method m, String msg) {
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoRestException.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoRestException.java
index 98b1151..ae28d58 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoRestException.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoRestException.java
@@ -46,13 +46,25 @@ public final class PojoRestException extends FormattedRuntimeException {
/**
* Constructor.
*
+ * @param cause The cause of this exception.
+ * @param status HTTP status code.
+ * @param message The {@link MessageFormat}-style message.
+ * @param args Optional {@link MessageFormat}-style arguments.
+ */
+ public PojoRestException(Throwable cause, int status, String message, Object... args) {
+ super(cause, getMessage(cause, message, null), args);
+ this.status = status;
+ }
+
+ /**
+ * Constructor.
+ *
* @param status The HTTP-equivalent status code.
* @param message The detailed message.
* @param args Optional {@link MessageFormat}-style arguments.
*/
public PojoRestException(int status, String message, Object...args) {
- super(message, args);
- this.status = status;
+ this(null, status, message, args);
}
/**
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
index b11b066..1ad2342 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
@@ -12,8 +12,6 @@
// ***************************************************************************************************************************
package org.apache.juneau.svl;
-import static org.apache.juneau.internal.StringUtils.*;
-
import java.text.*;
import org.apache.juneau.*;
@@ -27,22 +25,21 @@ public class VarResolverException extends FormattedRuntimeException {
/**
* Constructor.
*
+ * @param cause The cause of this exception.
* @param message The {@link MessageFormat}-style message.
* @param args Optional {@link MessageFormat}-style arguments.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public VarResolverException(Throwable cause, String message, Object... args) {
+ super(cause, getMessage(cause, message, null), args);
}
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
* @param message The {@link MessageFormat}-style message.
* @param args Optional {@link MessageFormat}-style arguments.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public VarResolverException(String message, Object...args) {
+ this(null, message, args);
}
}
diff --git a/juneau-doc/src/main/javadoc/overview.html b/juneau-doc/src/main/javadoc/overview.html
index 21fb2a4..7c5878c 100644
--- a/juneau-doc/src/main/javadoc/overview.html
+++ b/juneau-doc/src/main/javadoc/overview.html
@@ -21398,6 +21398,47 @@
<li class='jc'>{@link org.apache.juneau.rest.helper.StreamResourceBuilder}
</ul>
</ul>
+ <li>
+ Predefined HTTP error throwables.
+ <br>When added to REST Java methods, reflected in generated Swagger documentation.
+ <ul class='doctree'>
+ <li class='jp'>{@link org.apache.juneau.rest.exception}
+ <ul>
+ <li class='jc'>{@link org.apache.juneau.rest.exception.BadRequest}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.Conflict}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.ExpectationFailed}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.FailedDependency}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.Forbidden}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.Gone}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.HttpVersionNotSupported}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.InsufficientStorage}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.InternalServerError}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.LengthRequired}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.Locked}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.LoopDetected}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.MethodNotAllowed}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.MisdirectedRequest}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.NetworkAuthenticationRequired}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.NotAcceptable}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.NotExtended}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.NotFound}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.NotImplemented}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.PayloadTooLarge}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.PreconditionFailed}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.PreconditionRequired}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.RangeNotSatisfiable}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.RequestHeaderFieldsTooLarge}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.ServiceUnavailable}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.TooManyRequests}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.Unauthorized}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.UnavailableForLegalReasons}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.UnprocessableEntity}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.UnsupportedMediaType}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.UpgradeRequired}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.UriTooLong}
+ <li class='jc'>{@link org.apache.juneau.rest.exception.VariantAlsoNegotiates}
+ </ul>
+ </ul>
</ul>
<h5 class='topic w800'>juneau-rest-client</h5>
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/AtomFeedResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/AtomFeedResource.java
index 8b7f365..cd9b509 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/AtomFeedResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/AtomFeedResource.java
@@ -50,7 +50,16 @@ import org.apache.juneau.rest.widget.*;
@Property(name=RDF_rdfxml_tab, value="5"),
@Property(name=RDF_addRootProperty, value="true")
},
- encoders=GzipEncoder.class
+ encoders=GzipEncoder.class,
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
+ }
)
public class AtomFeedResource extends BasicRestServletJena {
private static final long serialVersionUID = 1L;
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/CodeFormatterResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/CodeFormatterResource.java
index 61fe830..cb44fbe 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/CodeFormatterResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/CodeFormatterResource.java
@@ -41,7 +41,16 @@ import org.apache.juneau.rest.annotation.*;
"</div>"
},
style="aside {display:table-caption;}"
- )
+ ),
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
+ }
)
@SuppressWarnings({"serial"})
public class CodeFormatterResource extends BasicRestServlet {
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java
index ca7a2e2..7e676c3 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java
@@ -13,7 +13,6 @@
package org.apache.juneau.examples.rest;
import static java.util.logging.Level.*;
-import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.juneau.html.HtmlSerializer.*;
import static org.apache.juneau.http.HttpMethodName.*;
import static org.apache.juneau.rest.annotation.HookEvent.*;
@@ -26,6 +25,7 @@ import java.util.logging.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.converters.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.rest.helper.*;
import org.apache.juneau.rest.widget.*;
import org.apache.juneau.utils.*;
@@ -55,6 +55,15 @@ import org.apache.juneau.utils.*;
@Property(name="allowViews", value="false"),
@Property(name="allowDeletes", value="false"),
@Property(name="allowPuts", value="false")
+ },
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
}
)
public class DirectoryResource extends BasicRestServlet {
@@ -87,39 +96,52 @@ public class DirectoryResource extends BasicRestServlet {
return rootDir;
}
- /** GET request handler */
- @RestMethod(name=GET, path="/*", converters={Queryable.class})
- public Object doGet(RestRequest req, RequestProperties properties) throws Exception {
+ @RestMethod(
+ name=GET,
+ path="/*",
+ summary="Get file or directory information",
+ description="Returns information about a file or directory.",
+ converters={Queryable.class}
+ )
+ public Object doGet(RestRequest req, RequestProperties properties) throws NotFound, InternalServerError {
String pathInfo = req.getPathInfo();
File f = pathInfo == null ? rootDir : new File(rootDir.getAbsolutePath() + pathInfo);
if (!f.exists())
- throw new RestException(SC_NOT_FOUND, "File not found");
+ throw new NotFound("File not found");
properties.put("path", f.getAbsolutePath());
- if (f.isDirectory()) {
- List<FileResource> l = new LinkedList<>();
- File[] lfc = f.listFiles();
- if (lfc != null) {
- for (File fc : lfc) {
- URL fUrl = new URL(req.getRequestURL().append("/").append(fc.getName()).toString());
- l.add(new FileResource(fc, fUrl));
+ try {
+ if (f.isDirectory()) {
+ List<FileResource> l = new LinkedList<>();
+ File[] lfc = f.listFiles();
+ if (lfc != null) {
+ for (File fc : lfc) {
+ URL fUrl = new URL(req.getRequestURL().append("/").append(fc.getName()).toString());
+ l.add(new FileResource(fc, fUrl));
+ }
}
+ return l;
}
- return l;
- }
- return new FileResource(f, new URL(req.getRequestURL().toString()));
+ return new FileResource(f, new URL(req.getRequestURL().toString()));
+
+ } catch (MalformedURLException e) {
+ throw new InternalServerError(e);
+ }
}
- /** DELETE request handler */
- @RestMethod(name=DELETE, path="/*", guards=AdminGuard.class)
- public Object doDelete(RestRequest req) throws Exception {
+ @RestMethod(
+ name=DELETE,
+ path="/*",
+ guards=AdminGuard.class
+ )
+ public Object doDelete(RestRequest req) throws MethodNotAllowed {
if (! allowDeletes)
- throw new RestException(SC_METHOD_NOT_ALLOWED, "DELETE not enabled");
+ throw new MethodNotAllowed("DELETE not enabled");
File f = new File(rootDir.getAbsolutePath() + req.getPathInfo());
deleteFile(f);
@@ -131,16 +153,20 @@ public class DirectoryResource extends BasicRestServlet {
/** PUT request handler */
@RestMethod(name=PUT, path="/*", guards=AdminGuard.class)
- public Object doPut(RestRequest req) throws Exception {
+ public Object doPut(RestRequest req) throws MethodNotAllowed, InternalServerError {
if (! allowPuts)
- throw new RestException(SC_METHOD_NOT_ALLOWED, "PUT not enabled");
+ throw new MethodNotAllowed("PUT not enabled");
File f = new File(rootDir.getAbsolutePath() + req.getPathInfo());
String parentSubPath = f.getParentFile().getAbsolutePath().substring(rootDir.getAbsolutePath().length());
+
try (InputStream is = req.getInputStream(); OutputStream os = new BufferedOutputStream(new FileOutputStream(f))) {
IOPipe.create(is, os).run();
+ } catch (IOException e) {
+ throw new InternalServerError(e);
}
+
if (req.getContentType().contains("html"))
return new Redirect(parentSubPath);
return "File added";
@@ -149,39 +175,41 @@ public class DirectoryResource extends BasicRestServlet {
/** VIEW request handler (overloaded GET for viewing file contents) */
@SuppressWarnings("resource")
@RestMethod(name="VIEW", path="/*")
- public void doView(RestRequest req, RestResponse res) throws Exception {
+ public void doView(RestRequest req, RestResponse res) throws MethodNotAllowed, NotFound {
if (! allowViews)
- throw new RestException(SC_METHOD_NOT_ALLOWED, "VIEW not enabled");
+ throw new MethodNotAllowed("VIEW not enabled");
File f = new File(rootDir.getAbsolutePath() + req.getPathInfo());
- if (!f.exists())
- throw new RestException(SC_NOT_FOUND, "File not found");
-
if (f.isDirectory())
- throw new RestException(SC_METHOD_NOT_ALLOWED, "VIEW not available on directories");
+ throw new MethodNotAllowed("VIEW not available on directories");
- res.setOutput(new FileReader(f)).setContentType("text/plain");
+ try {
+ res.setOutput(new FileReader(f)).setContentType("text/plain");
+ } catch (FileNotFoundException e) {
+ throw new NotFound("File not found");
+ }
}
/** DOWNLOAD request handler (overloaded GET for downloading file contents) */
@SuppressWarnings("resource")
@RestMethod(name="DOWNLOAD")
- public void doDownload(RestRequest req, RestResponse res) throws Exception {
+ public void doDownload(RestRequest req, RestResponse res) throws MethodNotAllowed, NotFound {
if (! allowViews)
- throw new RestException(SC_METHOD_NOT_ALLOWED, "DOWNLOAD not enabled");
+ throw new MethodNotAllowed("DOWNLOAD not enabled");
File f = new File(rootDir.getAbsolutePath() + req.getPathInfo());
- if (!f.exists())
- throw new RestException(SC_NOT_FOUND, "File not found");
-
if (f.isDirectory())
- throw new RestException(SC_METHOD_NOT_ALLOWED, "DOWNLOAD not available on directories");
+ throw new MethodNotAllowed("DOWNLOAD not available on directories");
- res.setOutput(new FileReader(f)).setContentType("application");
+ try {
+ res.setOutput(new FileReader(f)).setContentType("application");
+ } catch (FileNotFoundException e) {
+ throw new NotFound("File not found");
+ }
}
/** File POJO */
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DockerRegistryResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DockerRegistryResource.java
index b167a76..a8e5461 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DockerRegistryResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DockerRegistryResource.java
@@ -38,7 +38,16 @@ import org.apache.juneau.rest.helper.*;
},
// Pull in aside contents from file.
aside="$F{resources/DockerRegistryResourceAside.html}"
- )
+ ),
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
+ }
)
public class DockerRegistryResource extends BasicRestServlet {
private static final long serialVersionUID = 1L;
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java
index 1190b7a..1a385a4 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java
@@ -44,7 +44,16 @@ import org.apache.juneau.rest.widget.*;
" <p>Shows how to produce JSON-Schema documents in a variety of languages using the JSON-Schema DTOs.</p>",
"</div>"
}
- )
+ ),
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
+ }
)
public class JsonSchemaResource extends BasicRestServletJena {
private static final long serialVersionUID = 1L;
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java
index ecbcb63..b9f6e4d 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java
@@ -40,7 +40,16 @@ import org.apache.juneau.utils.*;
" <p>Each method is functionally equivalent but demonstrate different ways to accomplish the same tasks.</p>",
"</div>"
}
- )
+ ),
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
+ }
)
public class MethodExampleResource extends BasicRestServlet {
private static final long serialVersionUID = 1L;
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java
index cd4f61d..6c6bc3e 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java
@@ -12,7 +12,6 @@
// ***************************************************************************************************************************
package org.apache.juneau.examples.rest;
-import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.juneau.html.HtmlSerializer.*;
import static org.apache.juneau.http.HttpMethodName.*;
@@ -27,6 +26,7 @@ import org.apache.juneau.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.serializer.*;
/**
@@ -53,6 +53,15 @@ import org.apache.juneau.serializer.*;
properties={
// Make the anchor text on URLs be just the path relative to the servlet.
@Property(name=HTML_uriAnchorText, value="SERVLET_RELATIVE")
+ },
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
}
)
public class PhotosResource extends BasicRestServlet {
@@ -95,10 +104,10 @@ public class PhotosResource extends BasicRestServlet {
/** GET request handler for single photo */
@RestMethod(name=GET, path="/{id}", serializers=ImageSerializer.class, summary="Get a photo by ID")
- public BufferedImage getPhoto(@Path String id) throws Exception {
+ public BufferedImage getPhoto(@Path String id) throws NotFound {
Photo p = photos.get(id);
if (p == null)
- throw new RestException(SC_NOT_FOUND, "Photo not found");
+ throw new NotFound("Photo not found");
return p.image;
}
@@ -119,10 +128,10 @@ public class PhotosResource extends BasicRestServlet {
/** DELETE request handler */
@RestMethod(name=DELETE, path="/{id}", summary="Delete a photo by ID")
- public String deletePhoto(@Path String id) throws Exception {
+ public String deletePhoto(@Path String id) throws NotFound {
Photo p = photos.remove(id);
if (p == null)
- throw new RestException(SC_NOT_FOUND, "Photo not found");
+ throw new NotFound("Photo not found");
return "OK";
}
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PredefinedLabelsResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PredefinedLabelsResource.java
index 73fdd69..14d3559 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PredefinedLabelsResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PredefinedLabelsResource.java
@@ -40,7 +40,16 @@ import org.apache.juneau.rest.widget.*;
"$W{StyleMenuItem}",
"source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java"
}
- )
+ ),
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
+ }
)
public class PredefinedLabelsResource extends BasicRestServlet {
private static final long serialVersionUID = 1L;
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java
index 1f4b9c0..f12cf49 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java
@@ -61,6 +61,15 @@ import org.apache.juneau.transforms.*;
pojoSwaps={
// Add a special filter for Enumerations
EnumerationSwap.class
+ },
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
}
)
public class RequestEchoResource extends BasicRestServlet {
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java
index f84cf6b..7418523 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java
@@ -41,7 +41,17 @@ import org.apache.juneau.rest.remoteable.*;
}
),
// Allow us to use method=POST from a browser.
- allowedMethodParams="*"
+ allowedMethodParams="*",
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
+ }
+
)
public class SampleRemoteableServlet extends RemoteableServlet {
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java
index 2da3fe1..ad05a25 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java
@@ -12,7 +12,6 @@
// ***************************************************************************************************************************
package org.apache.juneau.examples.rest;
-import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.juneau.dto.html5.HtmlBuilder.*;
import static org.apache.juneau.http.HttpMethodName.*;
import static org.apache.juneau.internal.StringUtils.*;
@@ -27,6 +26,7 @@ import org.apache.juneau.dto.html5.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.annotation.Body;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.rest.widget.*;
/**
@@ -53,7 +53,16 @@ import org.apache.juneau.rest.widget.*;
" <p><a class='link' href='?sql=select+*+from sys.systables'>try me</a></p>",
"</div>"
}
- )
+ ),
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
+ }
)
public class SqlQueryResource extends BasicRestServlet {
private static final long serialVersionUID = 1L;
@@ -129,7 +138,7 @@ public class SqlQueryResource extends BasicRestServlet {
/** POST request handler - Execute the query. */
@RestMethod(name=POST, path="/", summary="Execute one or more queries")
- public List<Object> doPost(@Body PostInput in) throws Exception {
+ public List<Object> doPost(@Body PostInput in) throws BadRequest {
List<Object> results = new LinkedList<>();
@@ -138,9 +147,9 @@ public class SqlQueryResource extends BasicRestServlet {
return results;
if (in.pos < 1 || in.pos > 10000)
- throw new RestException(SC_BAD_REQUEST, "Invalid value for position. Must be between 1-10000");
+ throw new BadRequest("Invalid value for position. Must be between 1-10000");
if (in.limit < 1 || in.limit > 10000)
- throw new RestException(SC_BAD_REQUEST, "Invalid value for limit. Must be between 1-10000");
+ throw new BadRequest("Invalid value for limit. Must be between 1-10000");
String sql = null;
@@ -175,7 +184,7 @@ public class SqlQueryResource extends BasicRestServlet {
else if (allowTempUpdates)
c.rollback();
} catch (SQLException e) {
- throw new RestException(SC_BAD_REQUEST, "Invalid query: {0}", sql).initCause(e);
+ throw new BadRequest(e, "Invalid query: {0}", sql);
}
return results;
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/StaticFilesResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/StaticFilesResource.java
index 330c262..15c2f08 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/StaticFilesResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/StaticFilesResource.java
@@ -45,6 +45,15 @@ import org.apache.juneau.rest.widget.*;
staticFiles= {
// Serve up files in /files under the child URI /static
"static:files"
+ },
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
}
)
public class StaticFilesResource extends BasicRestServletJena {
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java
index 03cc272..1bf8a5e 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java
@@ -60,6 +60,15 @@ import org.apache.juneau.utils.*;
@Property(name="allowViews", value="true"),
@Property(name="allowDeletes", value="true"),
@Property(name="allowPuts", value="false")
+ },
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
}
)
public class TempDirResource extends DirectoryResource {
@@ -80,10 +89,12 @@ public class TempDirResource extends DirectoryResource {
}
}
- /**
- * [GET /upload] - Display the form entry page for uploading a file to the temp directory.
- */
- @RestMethod(name=GET, path="/upload")
+ @RestMethod(
+ name=GET,
+ path="/upload",
+ summary="Upload file form entry page",
+ description="Renders an example form page for uploading a file in multipart/form-data format to the temp directory."
+ )
public Form getUploadForm() {
return
form().id("form").action("servlet:/upload").method(POST).enctype("multipart/form-data")
@@ -94,11 +105,16 @@ public class TempDirResource extends DirectoryResource {
;
}
- /**
- * [POST /upload] - Upload a file as a multipart form post.
- * Shows how to use the Apache Commons ServletFileUpload class for handling multi-part form posts.
- */
- @RestMethod(name=POST, path="/upload", matchers=TempDirResource.MultipartFormDataMatcher.class)
+ @RestMethod(
+ name=POST,
+ path="/upload",
+ summary="Upload a file as a multipart form post",
+ description= {
+ "Shows how to use the Apache Commons ServletFileUpload class for handling multi-part form posts.\n",
+ "Matcher ensures Java method is called only when Content-Type is multipart/form-data."
+ },
+ matchers=TempDirResource.MultipartFormDataMatcher.class
+ )
public Redirect uploadFile(RestRequest req) throws Exception {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(req);
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TumblrParserResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TumblrParserResource.java
index b796cd9..a39bef7 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TumblrParserResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TumblrParserResource.java
@@ -38,7 +38,16 @@ import org.apache.juneau.rest.client.*;
" <p><a class='link' href='$U{servlet:/ibmblr}'>try me</a></p>",
"</div>"
}
- )
+ ),
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
+ }
)
public class TumblrParserResource extends BasicRestServlet {
private static final long serialVersionUID = 1L;
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java
index 75360c2..c08f764 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java
@@ -47,7 +47,16 @@ import org.apache.juneau.transforms.*;
" <p>Submitting the form post will simply echo the bean back on the response.</p>",
"</div>"
}
- )
+ ),
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
+ }
)
public class UrlEncodedFormResource extends BasicRestServlet {
private static final long serialVersionUID = 1L;
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java
index 87da92b..2f272a7 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java
@@ -12,7 +12,6 @@
// ***************************************************************************************************************************
package org.apache.juneau.examples.rest.addressbook;
-import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.juneau.html.HtmlDocSerializer.*;
import static org.apache.juneau.jena.RdfCommon.*;
import static org.apache.juneau.jena.RdfSerializer.*;
@@ -30,6 +29,7 @@ import org.apache.juneau.microservice.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.converters.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.rest.helper.*;
import org.apache.juneau.rest.widget.*;
import org.apache.juneau.transform.*;
@@ -115,13 +115,14 @@ import org.apache.juneau.utils.*;
encoders=GzipEncoder.class,
// Swagger info.
- swagger= {
- "contact:{name:'John Smith',email:'john@smith.com'},",
- "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
- "version:'2.0',",
- "termsOfService:'You\\'re on your own.',",
- "tags:[{name:'Java',description:'Java utility',externalDocs:{description:'Home page',url:'http://juneau.apache.org'}}],",
- "externalDocs:{description:'Home page',url:'http://juneau.apache.org'}"
+ swagger={
+ "info: {",
+ "contact:{name:'Juneau Developer',email:'dev@juneau.apache.org'},",
+ "license:{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'},",
+ "version:'2.0',",
+ "termsOfService:'You are on your own.'",
+ "},",
+ "externalDocs:{description:'Apache Juneau',url:'http://juneau.apache.org'}"
}
)
public class AddressBookResource extends BasicRestServletJena {
@@ -262,10 +263,10 @@ public class AddressBookResource extends BasicRestServletJena {
@RestMethod(name=DELETE, path="/addresses/{id}",
guards=AdminGuard.class
)
- public String deleteAddress(@Path int addressId) throws Exception {
+ public String deleteAddress(@Path int addressId) throws NotFound {
Person p = addressBook.findPersonWithAddress(addressId);
if (p == null)
- throw new RestException(SC_NOT_FOUND, "Person not found");
+ throw new NotFound("Person not found");
Address a = findAddress(addressId);
p.addresses.remove(a);
return "DELETE successful";
@@ -278,7 +279,7 @@ public class AddressBookResource extends BasicRestServletJena {
@RestMethod(name=PUT, path="/people/{id}/*",
guards=AdminGuard.class
)
- public String updatePerson(RequestBody body, @Path int id, @PathRemainder String remainder) throws Exception {
+ public String updatePerson(RequestBody body, @Path int id, @PathRemainder String remainder) throws BadRequest {
try {
Person p = findPerson(id);
PojoRest r = new PojoRest(p);
@@ -287,7 +288,7 @@ public class AddressBookResource extends BasicRestServletJena {
r.put(remainder, in);
return "PUT successful";
} catch (Exception e) {
- throw new RestException(SC_BAD_REQUEST, "PUT unsuccessful").initCause(e);
+ throw new BadRequest(e, "PUT unsuccessful");
}
}
@@ -298,7 +299,7 @@ public class AddressBookResource extends BasicRestServletJena {
@RestMethod(name=PUT, path="/addresses/{id}/*",
guards=AdminGuard.class
)
- public String updateAddress(RestRequest req, @Path int id, @PathRemainder String remainder) throws Exception {
+ public String updateAddress(RestRequest req, @Path int id, @PathRemainder String remainder) throws BadRequest {
try {
Address a = findAddress(id);
PojoRest r = new PojoRest(a);
@@ -307,7 +308,7 @@ public class AddressBookResource extends BasicRestServletJena {
r.put(remainder, in);
return "PUT successful";
} catch (Exception e) {
- throw new RestException(SC_BAD_REQUEST, "PUT unsuccessful").initCause(e);
+ throw new BadRequest(e, "PUT unsuccessful");
}
}
@@ -358,18 +359,18 @@ public class AddressBookResource extends BasicRestServletJena {
}
/** Convenience method - Find a person by ID */
- private Person findPerson(int id) throws RestException {
+ private Person findPerson(int id) throws NotFound {
Person p = addressBook.findPerson(id);
if (p == null)
- throw new RestException(SC_NOT_FOUND, "Person not found");
+ throw new NotFound("Person not found");
return p;
}
/** Convenience method - Find an address by ID */
- private Address findAddress(int id) throws RestException {
+ private Address findAddress(int id) throws NotFound {
Address a = addressBook.findAddress(id);
if (a == null)
- throw new RestException(SC_NOT_FOUND, "Address not found");
+ throw new NotFound("Address not found");
return a;
}
}
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdConflictException.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdConflict.java
similarity index 90%
rename from juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdConflictException.java
rename to juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdConflict.java
index e425cfb..7b1f07b 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdConflictException.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdConflict.java
@@ -12,15 +12,15 @@
// ***************************************************************************************************************************
package org.apache.juneau.examples.rest.petstore;
-import org.apache.juneau.*;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
/**
* Exception thrown when trying to add an entry where the ID is already in use.
*/
@SuppressWarnings("serial")
-@ResponseInfo(code=409, description="ID already in use")
-public class IdConflictException extends FormattedException {
+@ResponseInfo(description="ID already in use")
+public class IdConflict extends Conflict {
/**
* Constructor.
@@ -28,7 +28,7 @@ public class IdConflictException extends FormattedException {
* @param id The duplicate ID.
* @param c The object type..
*/
- public IdConflictException(Object id, Class<?> c) {
+ public IdConflict(Object id, Class<?> c) {
super("ID ''{0}'' already in use for type ''{1}''", id, c.getSimpleName());
}
}
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdNotFoundException.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdNotFound.java
similarity index 90%
rename from juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdNotFoundException.java
rename to juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdNotFound.java
index 9040425..6fd2e43 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdNotFoundException.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/IdNotFound.java
@@ -12,15 +12,15 @@
// ***************************************************************************************************************************
package org.apache.juneau.examples.rest.petstore;
-import org.apache.juneau.*;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
/**
* Exception thrown when trying to add an entry where the ID is already in use.
*/
@SuppressWarnings("serial")
-@ResponseInfo(code=404, description="ID not found")
-public class IdNotFoundException extends FormattedException {
+@ResponseInfo(description="ID not found")
+public class IdNotFound extends NotFound {
/**
* Constructor.
@@ -28,7 +28,7 @@ public class IdNotFoundException extends FormattedException {
* @param id The duplicate ID.
* @param c The object type..
*/
- public IdNotFoundException(Object id, Class<?> c) {
+ public IdNotFound(Object id, Class<?> c) {
super("ID ''{0}'' not found for type ''{1}''", id, c.getSimpleName());
}
}
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidIdException.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidId.java
similarity index 91%
rename from juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidIdException.java
rename to juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidId.java
index c87bc46..88848dd 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidIdException.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidId.java
@@ -13,18 +13,19 @@
package org.apache.juneau.examples.rest.petstore;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
/**
* Exception thrown when trying to add an entry where the ID is already in use.
*/
@SuppressWarnings("serial")
-@ResponseInfo(code=400, description="Invalid ID provided")
-public class InvalidIdException extends Exception {
+@ResponseInfo(description="Invalid ID provided")
+public class InvalidId extends BadRequest {
/**
* Constructor.
*/
- public InvalidIdException() {
+ public InvalidId() {
super("Invalid ID provided.");
}
}
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/LoginException.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidLogin.java
similarity index 90%
rename from juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/LoginException.java
rename to juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidLogin.java
index b6f2bf4..4fc42e4 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/LoginException.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidLogin.java
@@ -13,18 +13,19 @@
package org.apache.juneau.examples.rest.petstore;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
/**
* Exception thrown when an invalid username or password is provided.
*/
@SuppressWarnings("serial")
-@ResponseInfo(code=401, description="Invalid username or password provided")
-public class LoginException extends Exception {
+@ResponseInfo(description="Invalid username or password provided")
+public class InvalidLogin extends Unauthorized {
/**
* Constructor.
*/
- public LoginException() {
+ public InvalidLogin() {
super("Invalid username or password.");
}
}
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidTagException.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidTag.java
similarity index 91%
rename from juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidTagException.java
rename to juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidTag.java
index 400c09b..3d1e4b2 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidTagException.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidTag.java
@@ -13,18 +13,19 @@
package org.apache.juneau.examples.rest.petstore;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
/**
* Exception thrown when trying to add an entry where the ID is already in use.
*/
@SuppressWarnings("serial")
-@ResponseInfo(code=400, description="Invalid tag provided")
-public class InvalidTagException extends Exception {
+@ResponseInfo(description="Invalid tag provided")
+public class InvalidTag extends BadRequest {
/**
* Constructor.
*/
- public InvalidTagException() {
+ public InvalidTag() {
super("Invalid tag provided. Must be at most 8 characters or digits.");
}
}
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidUsernameException.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidUsername.java
similarity index 91%
rename from juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidUsernameException.java
rename to juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidUsername.java
index 0dec4c2..d830f82 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidUsernameException.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/InvalidUsername.java
@@ -13,18 +13,19 @@
package org.apache.juneau.examples.rest.petstore;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
/**
* Exception thrown when trying to add an entry where the ID is already in use.
*/
@SuppressWarnings("serial")
-@ResponseInfo(code=400, description="Invalid username provided")
-public class InvalidUsernameException extends Exception {
+@ResponseInfo(description="Invalid username provided")
+public class InvalidUsername extends BadRequest {
/**
* Constructor.
*/
- public InvalidUsernameException() {
+ public InvalidUsername() {
super("Invalid username provided. Must be 8 or more characters or digits.");
}
}
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStore.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStore.java
index 39a6750..958bca9 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStore.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStore.java
@@ -29,54 +29,54 @@ public class PetStore {
private IdMap<Long,User> userDb = IdMap.createLongMap(User.class);
- public Pet getPet(long id) throws IdNotFoundException {
+ public Pet getPet(long id) throws IdNotFound {
Pet value = petDb.get(id);
if (value == null)
- throw new IdNotFoundException(id, Pet.class);
+ throw new IdNotFound(id, Pet.class);
return value;
}
- public Category getCategory(long id) throws IdNotFoundException {
+ public Category getCategory(long id) throws IdNotFound {
Category value = categoryDb.get(id);
if (value == null)
- throw new IdNotFoundException(id, Pet.class);
+ throw new IdNotFound(id, Pet.class);
return value;
}
- public Order getOrder(long id) throws IdNotFoundException {
+ public Order getOrder(long id) throws IdNotFound {
Order value = orderDb.get(id);
if (value == null)
- throw new IdNotFoundException(id, Pet.class);
+ throw new IdNotFound(id, Pet.class);
return value;
}
- public Tag getTag(long id) throws IdNotFoundException {
+ public Tag getTag(long id) throws IdNotFound {
Tag value = tagDb.get(id);
if (value == null)
- throw new IdNotFoundException(id, Pet.class);
+ throw new IdNotFound(id, Pet.class);
return value;
}
- public Tag getTag(String name) throws InvalidTagException {
+ public Tag getTag(String name) throws InvalidTag {
for (Tag value : tagDb.values())
if (value.getName().equals(name))
return value;
- throw new InvalidTagException();
+ throw new InvalidTag();
}
- public User getUser(long id) throws IdNotFoundException {
+ public User getUser(long id) throws IdNotFound {
User value = userDb.get(id);
if (value == null)
- throw new IdNotFoundException(id, Pet.class);
+ throw new IdNotFound(id, Pet.class);
return value;
}
- public User getUser(String username) throws InvalidUsernameException, IdNotFoundException {
+ public User getUser(String username) throws InvalidUsername, IdNotFound {
assertValidUsername(username);
for (User user : userDb.values())
if (user.getUsername().equals(username))
return user;
- throw new IdNotFoundException(username, User.class);
+ throw new IdNotFound(username, User.class);
}
public boolean isValid(String username, String password) {
@@ -106,117 +106,117 @@ public class PetStore {
return userDb.values();
}
- public Pet add(Pet value) throws IdConflictException {
+ public Pet add(Pet value) throws IdConflict {
if (value.getId() == 0)
value.id(petDb.nextId());
Pet old = petDb.putIfAbsent(value.getId(), value);
if (old != null)
- throw new IdConflictException(value.getId(), Pet.class);
+ throw new IdConflict(value.getId(), Pet.class);
return value;
}
- public Category add(Category value) throws IdConflictException {
+ public Category add(Category value) throws IdConflict {
if (value.getId() == 0)
value.id(categoryDb.nextId());
Category old = categoryDb.putIfAbsent(value.getId(), value);
if (old != null)
- throw new IdConflictException(value.getId(), Category.class);
+ throw new IdConflict(value.getId(), Category.class);
return value;
}
- public Order add(Order value) throws IdConflictException {
+ public Order add(Order value) throws IdConflict {
if (value.getId() == 0)
value.id(orderDb.nextId());
Order old = orderDb.putIfAbsent(value.getId(), value);
if (old != null)
- throw new IdConflictException(value.getId(), Order.class);
+ throw new IdConflict(value.getId(), Order.class);
return value;
}
- public Tag add(Tag value) throws IdConflictException {
+ public Tag add(Tag value) throws IdConflict {
if (value.getId() == 0)
value.id(tagDb.nextId());
Tag old = tagDb.putIfAbsent(value.getId(), value);
if (old != null)
- throw new IdConflictException(value.getId(), Tag.class);
+ throw new IdConflict(value.getId(), Tag.class);
return value;
}
- public User add(User value) throws IdConflictException, InvalidUsernameException {
+ public User add(User value) throws IdConflict, InvalidUsername {
assertValidUsername(value.getUsername());
if (value.getId() == 0)
value.id(userDb.nextId());
User old = userDb.putIfAbsent(value.getId(), value);
if (old != null)
- throw new IdConflictException(value.getId(), User.class);
+ throw new IdConflict(value.getId(), User.class);
return value;
}
- public Pet update(Pet value) throws IdNotFoundException {
+ public Pet update(Pet value) throws IdNotFound {
Pet old = petDb.replace(value.getId(), value);
if (old == null)
- throw new IdNotFoundException(value.getId(), Pet.class);
+ throw new IdNotFound(value.getId(), Pet.class);
return value;
}
- public Category update(Category value) throws IdNotFoundException {
+ public Category update(Category value) throws IdNotFound {
Category old = categoryDb.replace(value.getId(), value);
if (old == null)
- throw new IdNotFoundException(value.getId(), Category.class);
+ throw new IdNotFound(value.getId(), Category.class);
return value;
}
- public Order update(Order value) throws IdNotFoundException {
+ public Order update(Order value) throws IdNotFound {
Order old = orderDb.replace(value.getId(), value);
if (old == null)
- throw new IdNotFoundException(value.getId(), Order.class);
+ throw new IdNotFound(value.getId(), Order.class);
return value;
}
- public Tag update(Tag value) throws IdNotFoundException, InvalidTagException {
+ public Tag update(Tag value) throws IdNotFound, InvalidTag {
assertValidTag(value.getName());
Tag old = tagDb.replace(value.getId(), value);
if (old == null)
- throw new IdNotFoundException(value.getId(), Tag.class);
+ throw new IdNotFound(value.getId(), Tag.class);
return value;
}
- public User update(User value) throws IdNotFoundException, InvalidUsernameException {
+ public User update(User value) throws IdNotFound, InvalidUsername {
assertValidUsername(value.getUsername());
User old = userDb.replace(value.getId(), value);
if (old == null)
- throw new IdNotFoundException(value.getId(), User.class);
+ throw new IdNotFound(value.getId(), User.class);
return value;
}
- public void removePet(long id) throws IdNotFoundException {
+ public void removePet(long id) throws IdNotFound {
petDb.remove(getPet(id).getId());
}
- public void removeCategory(long id) throws IdNotFoundException {
+ public void removeCategory(long id) throws IdNotFound {
categoryDb.remove(getCategory(id).getId());
}
- public void removeOrder(long id) throws IdNotFoundException {
+ public void removeOrder(long id) throws IdNotFound {
orderDb.remove(getOrder(id).getId());
}
- public void removeTag(long id) throws IdNotFoundException {
+ public void removeTag(long id) throws IdNotFound {
tagDb.remove(getTag(id).getId());
}
- public void removeUser(long id) throws IdNotFoundException {
+ public void removeUser(long id) throws IdNotFound {
userDb.remove(getUser(id).getId());
}
- private void assertValidUsername(String username) throws InvalidUsernameException {
+ private void assertValidUsername(String username) throws InvalidUsername {
if (username == null || ! username.matches("[\\w\\d]{8,}"))
- throw new InvalidUsernameException();
+ throw new InvalidUsername();
}
- private void assertValidTag(String tag) throws InvalidTagException {
+ private void assertValidTag(String tag) throws InvalidTag {
if (tag == null || ! tag.matches("[\\w\\d]{1,8}"))
- throw new InvalidTagException();
+ throw new InvalidTag();
}
public Collection<Pet> getPetsByStatus(PetStatus[] status) {
@@ -227,7 +227,7 @@ public class PetStore {
return list;
}
- public Collection<Pet> getPetsByTags(String[] tags) throws InvalidTagException {
+ public Collection<Pet> getPetsByTags(String[] tags) throws InvalidTag {
for (String tag : tags)
assertValidTag(tag);
List<Pet> list = new ArrayList<>();
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStoreResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStoreResource.java
index 18f927d..6e913f6 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStoreResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/petstore/PetStoreResource.java
@@ -98,7 +98,7 @@ public class PetStoreResource extends BasicRestServletJena {
)
public Pet getPet(
@Path(description="ID of pet to return", example="123") long petId
- ) throws IdNotFoundException {
+ ) throws IdNotFound {
return db.getPet(petId);
}
@@ -114,7 +114,7 @@ public class PetStoreResource extends BasicRestServletJena {
)
public Ok addPet(
@Body(description="Pet object that needs to be added to the store") Pet pet
- ) throws IdConflictException {
+ ) throws IdConflict {
db.add(pet);
return OK;
@@ -131,7 +131,7 @@ public class PetStoreResource extends BasicRestServletJena {
)
public Ok updatePet(
@Body(description="Pet object that needs to be added to the store") Pet pet
- ) throws IdNotFoundException {
+ ) throws IdNotFound {
db.update(pet);
return OK;
@@ -179,7 +179,7 @@ public class PetStoreResource extends BasicRestServletJena {
example="['tag1','tag2']"
)
String[] tags
- ) throws InvalidTagException {
+ ) throws InvalidTag {
return db.getPetsByTags(tags);
}
@@ -197,7 +197,7 @@ public class PetStoreResource extends BasicRestServletJena {
@Path(description="ID of pet that needs to be updated", example="123") long petId,
@FormData(name="name", description="Updated name of the pet", example="'Scruffy'") String name,
@FormData(name="status", description="Updated status of the pet", example="'AVAILABLE'") PetStatus status
- ) throws IdNotFoundException {
+ ) throws IdNotFound {
Pet pet = db.getPet(petId);
pet.name(name);
@@ -218,7 +218,7 @@ public class PetStoreResource extends BasicRestServletJena {
public Ok deletePet(
@Header(name="api_key", example="foobar") String apiKey,
@Path(description="Pet id to delete", example="123") long petId
- ) throws IdNotFoundException {
+ ) throws IdNotFound {
db.removePet(petId);
return OK;
@@ -269,10 +269,10 @@ public class PetStoreResource extends BasicRestServletJena {
)
public Order getOrder(
@Path(description="ID of order to fetch", maximum="10", minimum="1", example="5") long orderId
- ) throws InvalidIdException, IdNotFoundException {
+ ) throws InvalidId, IdNotFound {
if (orderId < 0 || orderId > 10)
- throw new InvalidIdException();
+ throw new InvalidId();
return db.getOrder(orderId);
}
@@ -286,7 +286,7 @@ public class PetStoreResource extends BasicRestServletJena {
)
public Order placeOrder(
@Body(description="Order placed for purchasing the pet", example="{petId:456,quantity:100}") Order order
- ) throws IdConflictException {
+ ) throws IdConflict {
return db.add(order);
}
@@ -302,10 +302,10 @@ public class PetStoreResource extends BasicRestServletJena {
)
public Ok deletePurchaseOrder(
@Path(description="ID of the order that needs to be deleted", minimum="1", example="5") long orderId
- ) throws InvalidIdException, IdNotFoundException {
+ ) throws InvalidId, IdNotFound {
if (orderId < 0)
- throw new InvalidIdException();
+ throw new InvalidId();
db.removeOrder(orderId);
return OK;
}
@@ -353,7 +353,7 @@ public class PetStoreResource extends BasicRestServletJena {
)
public User getUser(
@Path(description="The name that needs to be fetched. Use user1 for testing.") String username
- ) throws InvalidUsernameException, IdNotFoundException {
+ ) throws InvalidUsername, IdNotFound {
return db.getUser(username);
}
@@ -369,7 +369,7 @@ public class PetStoreResource extends BasicRestServletJena {
)
public Ok createUser(
@Body(description="Created user object") User user
- ) throws InvalidUsernameException, IdConflictException {
+ ) throws InvalidUsername, IdConflict {
db.add(user);
return OK;
@@ -385,7 +385,7 @@ public class PetStoreResource extends BasicRestServletJena {
)
public Ok createUsers(
@Body(description="List of user objects") User[] users
- ) throws InvalidUsernameException, IdConflictException {
+ ) throws InvalidUsername, IdConflict {
for (User user : users)
db.add(user);
@@ -404,7 +404,7 @@ public class PetStoreResource extends BasicRestServletJena {
public Ok updateUser(
@Path(description="Name that need to be updated") String username,
@Body(description="Updated user object") User user
- ) throws InvalidUsernameException, IdNotFoundException {
+ ) throws InvalidUsername, IdNotFound {
User oldUser = db.getUser(username);
user.id(oldUser.getId());
@@ -423,7 +423,7 @@ public class PetStoreResource extends BasicRestServletJena {
)
public Ok deleteUser(
@Path(description="The name that needs to be deleted") String username
- ) throws InvalidUsernameException, IdNotFoundException {
+ ) throws InvalidUsername, IdNotFound {
User oldUser = db.getUser(username);
db.removeUser(oldUser.getId());
@@ -451,10 +451,10 @@ public class PetStoreResource extends BasicRestServletJena {
@Query(name="password", description="The password for login in clear text", required="true", example="abc123") String password,
RestRequest req,
RestResponse res
- ) throws LoginException {
+ ) throws InvalidLogin {
if (! db.isValid(username, password))
- throw new LoginException();
+ throw new InvalidLogin();
Date d = new Date(System.currentTimeMillis() + 30 * 60 * 1000);
req.getSession().setAttribute("login-expires", d);
diff --git a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java
index f9967f7..0803bab 100755
--- a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java
+++ b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java
@@ -12,7 +12,6 @@
// ***************************************************************************************************************************
package org.apache.juneau.microservice.resources;
-import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.juneau.dto.html5.HtmlBuilder.*;
import static org.apache.juneau.http.HttpMethodName.*;
@@ -21,9 +20,11 @@ import java.util.Map;
import org.apache.juneau.*;
import org.apache.juneau.dto.html5.*;
+import org.apache.juneau.parser.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.annotation.Body;
+import org.apache.juneau.rest.exception.*;
/**
* Shows contents of the microservice configuration file.
@@ -184,7 +185,8 @@ public class ConfigResource extends BasicRestServlet {
* @param key The section key.
* @param value The new value.
* @return The new value.
- * @throws Exception
+ * @throws NotFound Thrown if config section not found.
+ * @throws BadRequest Thrown if contents are not valid.
*/
@RestMethod(name=PUT, path="/{section}/{key}",
description="Add or overwrite a config file entry.",
@@ -196,15 +198,20 @@ public class ConfigResource extends BasicRestServlet {
"]"
}
)
- public String setConfigSection(@Path("section") String section, @Path("key") String key, @Body String value) throws Exception {
+ public String setConfigSection(@Path("section") String section, @Path("key") String key, @Body String value) throws NotFound, BadRequest {
getServletConfig().getConfig().set(section + '/' + key, value);
return getSection(section).getString(key);
}
- private ObjectMap getSection(String name) throws Exception {
- ObjectMap m = getServletConfig().getConfig().getSectionAsMap(name);
+ private ObjectMap getSection(String name) throws NotFound, BadRequest {
+ ObjectMap m;
+ try {
+ m = getServletConfig().getConfig().getSectionAsMap(name);
+ } catch (ParseException e) {
+ throw new BadRequest(e, "Invalid input");
+ }
if (m == null)
- throw new RestException(SC_NOT_FOUND, "Section not found.");
+ throw new NotFound("Section not found.");
return m;
}
}
diff --git a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/DirectoryResource.java b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/DirectoryResource.java
index 44e2b7f..679b50d 100755
--- a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/DirectoryResource.java
+++ b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/DirectoryResource.java
@@ -13,7 +13,6 @@
package org.apache.juneau.microservice.resources;
import static java.util.logging.Level.*;
-import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.juneau.html.HtmlDocSerializer.*;
import static org.apache.juneau.http.HttpMethodName.*;
@@ -28,6 +27,7 @@ import org.apache.juneau.annotation.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.converters.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.rest.helper.*;
import org.apache.juneau.transforms.*;
import org.apache.juneau.utils.*;
@@ -117,20 +117,21 @@ public class DirectoryResource extends BasicRestServlet {
* @param req The HTTP request.
* @return Either a FileResource or list of FileResources depending on whether it's a
* file or directory.
- * @throws Exception If file could not be read or access was not granted.
+ * @throws NotFound If file was not found.
+ * @throws MalformedURLException
*/
@RestMethod(name=GET, path="/*",
description="On directories, returns a directory listing.\nOn files, returns information about the file.",
converters={Queryable.class}
)
- public Object doGet(RestRequest req) throws Exception {
+ public Object doGet(RestRequest req) throws NotFound, MalformedURLException {
checkAccess(req);
String pathInfo = req.getPathInfo();
File f = pathInfo == null ? rootDir : new File(rootDir.getAbsolutePath() + pathInfo);
if (!f.exists())
- throw new RestException(SC_NOT_FOUND, "File not found");
+ throw new NotFound("File not found");
req.setAttribute("path", f.getAbsolutePath());
@@ -175,18 +176,20 @@ public class DirectoryResource extends BasicRestServlet {
*
* @param req The HTTP request.
* @return The message <js>"File added"</js> if successful.
- * @throws Exception If file could not be read or access was not granted.
+ * @throws InternalServerError If file could not be read or access was not granted.
*/
@RestMethod(name=PUT, path="/*",
description="Add or overwrite a file on the file system."
)
- public Object doPut(RestRequest req) throws Exception {
+ public Object doPut(RestRequest req) throws InternalServerError {
checkAccess(req);
File f = new File(rootDir.getAbsolutePath() + req.getPathInfo());
String parentSubPath = f.getParentFile().getAbsolutePath().substring(rootDir.getAbsolutePath().length());
try (InputStream is = req.getInputStream(); OutputStream os = new BufferedOutputStream(new FileOutputStream(f))) {
IOPipe.create(is, os).run();
+ } catch (IOException e) {
+ throw new InternalServerError(e);
}
if (req.getContentType().contains("html"))
return new Redirect(parentSubPath);
@@ -202,24 +205,26 @@ public class DirectoryResource extends BasicRestServlet {
* @param req The HTTP request.
* @param res The HTTP response.
* @return A Reader containing the contents of the file.
- * @throws Exception If file could not be read or access was not granted.
+ * @throws NotFound File not found.
+ * @throws MethodNotAllowed Method not allowed on directories.
*/
@RestMethod(name="VIEW", path="/*",
description="View the contents of a file.\nApplies to files only."
)
- public Reader doView(RestRequest req, RestResponse res) throws Exception {
+ public Reader doView(RestRequest req, RestResponse res) throws NotFound, MethodNotAllowed {
checkAccess(req);
File f = new File(rootDir.getAbsolutePath() + req.getPathInfo());
- if (!f.exists())
- throw new RestException(SC_NOT_FOUND, "File not found");
-
if (f.isDirectory())
- throw new RestException(SC_METHOD_NOT_ALLOWED, "VIEW not available on directories");
+ throw new MethodNotAllowed("VIEW not available on directories");
res.setContentType("text/plain");
- return new FileReader(f);
+ try {
+ return new FileReader(f);
+ } catch (FileNotFoundException e) {
+ throw new NotFound("File not found");
+ }
}
/**
@@ -231,24 +236,26 @@ public class DirectoryResource extends BasicRestServlet {
* @param req The HTTP request.
* @param res The HTTP response.
* @return A Reader containing the contents of the file.
- * @throws Exception If file could not be read or access was not granted.
+ * @throws NotFound Found could not be found.
+ * @throws MethodNotAllowed Cannot call on a directory.
*/
@RestMethod(name="DOWNLOAD", path="/*",
description="Download the contents of a file.\nApplies to files only."
)
- public Reader doDownload(RestRequest req, RestResponse res) throws Exception {
+ public Reader doDownload(RestRequest req, RestResponse res) throws NotFound, MethodNotAllowed {
checkAccess(req);
File f = new File(rootDir.getAbsolutePath() + req.getPathInfo());
- if (!f.exists())
- throw new RestException(SC_NOT_FOUND, "File not found");
-
if (f.isDirectory())
- throw new RestException(SC_METHOD_NOT_ALLOWED, "DOWNLOAD not available on directories");
+ throw new MethodNotAllowed("DOWNLOAD not available on directories");
res.setContentType("application");
- return new FileReader(f);
+ try {
+ return new FileReader(f);
+ } catch (FileNotFoundException e) {
+ throw new NotFound("File not found");
+ }
}
/**
@@ -259,17 +266,18 @@ public class DirectoryResource extends BasicRestServlet {
* Method should throw a {@link RestException} if the request should be disallowed.
*
* @param req The HTTP request.
+ * @throws MethodNotAllowed Thrown if specified method is not allowed.
*/
- protected void checkAccess(RestRequest req) {
+ protected void checkAccess(RestRequest req) throws MethodNotAllowed {
String method = req.getMethod();
if (method.equals("VIEW") && ! allowViews)
- throw new RestException(SC_METHOD_NOT_ALLOWED, "VIEW not enabled");
+ throw new MethodNotAllowed("VIEW not enabled");
if (method.equals("PUT") && ! allowPuts)
- throw new RestException(SC_METHOD_NOT_ALLOWED, "PUT not enabled");
+ throw new MethodNotAllowed("PUT not enabled");
if (method.equals("DELETE") && ! allowDeletes)
- throw new RestException(SC_METHOD_NOT_ALLOWED, "DELETE not enabled");
+ throw new MethodNotAllowed("DELETE not enabled");
if (method.equals("DOWNLOAD") && ! allowViews)
- throw new RestException(SC_METHOD_NOT_ALLOWED, "DOWNLOAD not enabled");
+ throw new MethodNotAllowed("DOWNLOAD not enabled");
}
/** File POJO */
diff --git a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
index aff8328..1446dfe 100755
--- a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
+++ b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
@@ -12,7 +12,6 @@
// ***************************************************************************************************************************
package org.apache.juneau.microservice.resources;
-import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.juneau.html.HtmlDocSerializer.*;
import static org.apache.juneau.rest.annotation.HookEvent.*;
import static org.apache.juneau.internal.StringUtils.*;
@@ -29,6 +28,7 @@ import org.apache.juneau.dto.LinkString;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.converters.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.rest.helper.*;
import org.apache.juneau.transforms.*;
@@ -131,7 +131,9 @@ public class LogsResource extends BasicRestServlet {
* @param thread Optional thread name filter. Only show log entries with the specified thread name. Example: "&thread=pool-33-thread-1".
* @param loggers Optional logger filter. Only show log entries if they were produced by one of the specified loggers (simple class name). Example: "&loggers=(LinkIndexService,LinkIndexRestService)".
* @param severity Optional severity filter. Only show log entries with the specified severity. Example: "&severity=(ERROR,WARN)".
- * @throws Exception
+ * @throws NotFound File not found.
+ * @throws MethodNotAllowed View not available on directories.
+ * @throws IOException Could not write file.
*/
@RestMethod(
name="VIEW",
@@ -143,11 +145,22 @@ public class LogsResource extends BasicRestServlet {
"}"
}
)
- public void viewFile(RestRequest req, RestResponse res, @PathRemainder String path, RequestProperties properties, @Query("highlight") boolean highlight, @Query("start") String start, @Query("end") String end, @Query("thread") String thread, @Query("loggers") String[] loggers, @Query("severity") String[] severity) throws Exception {
+ public void viewFile(
+ RestRequest req,
+ RestResponse res,
+ @PathRemainder String path,
+ RequestProperties properties,
+ @Query("highlight") boolean highlight,
+ @Query("start") String start,
+ @Query("end") String end,
+ @Query("thread") String thread,
+ @Query("loggers") String[] loggers,
+ @Query("severity") String[] severity
+ ) throws NotFound, MethodNotAllowed, IOException {
File f = getFile(path);
if (f.isDirectory())
- throw new RestException(SC_METHOD_NOT_ALLOWED, "View not available on directories");
+ throw new MethodNotAllowed("View not available on directories");
Date startDate = parseISO8601Date(start), endDate = parseISO8601Date(end);
@@ -201,7 +214,9 @@ public class LogsResource extends BasicRestServlet {
* @param loggers Optional logger filter. Only show log entries if they were produced by one of the specified loggers (simple class name). Example: "&loggers=(LinkIndexService,LinkIndexRestService)".
* @param severity Optional severity filter. Only show log entries with the specified severity. Example: "&severity=(ERROR,WARN)".
* @return The parsed contents of the log file.
- * @throws Exception
+ * @throws NotFound File not found.
+ * @throws MethodNotAllowed View not available on directories.
+ * @throws IOException Could not read file.
*/
@RestMethod(
name="PARSE",
@@ -214,13 +229,21 @@ public class LogsResource extends BasicRestServlet {
"}"
}
)
- public LogParser viewParsedEntries(RestRequest req, @PathRemainder String path, @Query("start") String start, @Query("end") String end, @Query("thread") String thread, @Query("loggers") String[] loggers, @Query("severity") String[] severity) throws Exception {
+ public LogParser viewParsedEntries(
+ RestRequest req,
+ @PathRemainder String path,
+ @Query("start") String start,
+ @Query("end") String end,
+ @Query("thread") String thread,
+ @Query("loggers") String[] loggers,
+ @Query("severity") String[] severity
+ ) throws NotFound, MethodNotAllowed, IOException {
File f = getFile(path);
Date startDate = parseISO8601Date(start), endDate = parseISO8601Date(end);
if (f.isDirectory())
- throw new RestException(SC_METHOD_NOT_ALLOWED, "View not available on directories");
+ throw new MethodNotAllowed("View not available on directories");
return getLogParser(f, startDate, endDate, thread, loggers, severity);
}
@@ -231,7 +254,8 @@ public class LogsResource extends BasicRestServlet {
* @param res The HTTP response.
* @param path The log file path.
* @return The contents of the log file.
- * @throws Exception
+ * @throws NotFound File not found.
+ * @throws MethodNotAllowed Download not available on directories.
*/
@RestMethod(
name="DOWNLOAD",
@@ -243,16 +267,21 @@ public class LogsResource extends BasicRestServlet {
"}"
}
)
- public Object downloadFile(RestResponse res, @PathRemainder String path) throws Exception {
+ public Object downloadFile(RestResponse res, @PathRemainder String path) throws NotFound, MethodNotAllowed {
File f = getFile(path);
if (f.isDirectory())
- throw new RestException(SC_METHOD_NOT_ALLOWED, "Download not available on directories");
+ throw new MethodNotAllowed("Download not available on directories");
res.setContentType("application/octet-stream");
res.setContentLength((int)f.length());
- return new FileInputStream(f);
+
+ try {
+ return new FileInputStream(f);
+ } catch (FileNotFoundException e) {
+ throw new NotFound("File not found");
+ }
}
/**
@@ -260,7 +289,9 @@ public class LogsResource extends BasicRestServlet {
*
* @param path The log file path.
* @return A redirect object to the root.
- * @throws Exception
+ * @throws NotFound File not found.
+ * @throws BadRequest Delete not available on directories.
+ * @throws Forbidden Could not delete file.
*/
@RestMethod(
name=DELETE,
@@ -272,16 +303,16 @@ public class LogsResource extends BasicRestServlet {
"}"
}
)
- public Object deleteFile(@PathRemainder String path) throws Exception {
+ public Object deleteFile(@PathRemainder String path) throws NotFound, BadRequest, Forbidden {
File f = getFile(path);
if (f.isDirectory())
- throw new RestException(SC_BAD_REQUEST, "Delete not available on directories.");
+ throw new BadRequest("Delete not available on directories.");
if (f.canWrite())
if (! f.delete())
- throw new RestException(SC_FORBIDDEN, "Could not delete file.");
+ throw new Forbidden("Could not delete file.");
return new Redirect(path + "/..");
}
@@ -290,13 +321,13 @@ public class LogsResource extends BasicRestServlet {
return new BufferedReader(new InputStreamReader(new FileInputStream(f), Charset.defaultCharset()));
}
- private File getFile(String path) {
+ private File getFile(String path) throws NotFound {
if (path != null && path.indexOf("..") != -1)
- throw new RestException(SC_NOT_FOUND, "File not found.");
+ throw new NotFound("File not found.");
File f = (path == null ? logDir : new File(logDir.getAbsolutePath() + '/' + path));
if (filter.accept(f))
return f;
- throw new RestException(SC_NOT_FOUND, "File not found.");
+ throw new NotFound("File not found.");
}
/**
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestCallHandler.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestCallHandler.java
index ed09093..fc07d68 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestCallHandler.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestCallHandler.java
@@ -24,6 +24,7 @@ import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.rest.helper.*;
import org.apache.juneau.rest.vars.*;
@@ -192,7 +193,7 @@ public class BasicRestCallHandler implements RestCallHandler {
handleError(r1, r2, e);
} catch (Throwable e) {
ResponseInfo ri = e.getClass().getAnnotation(ResponseInfo.class);
- RestException e2 = new RestException(ri == null || ri.code() == 0 ? SC_INTERNAL_SERVER_ERROR : ri.code(), e);
+ RestException e2 = new RestException(e, ri == null || ri.code() == 0 ? SC_INTERNAL_SERVER_ERROR : ri.code());
r1.setAttribute("Exception", e);
r1.setAttribute("ExecTime", System.currentTimeMillis() - startTime);
handleError(r1, r2, e2);
@@ -223,12 +224,12 @@ public class BasicRestCallHandler implements RestCallHandler {
* @throws RestException
*/
@Override /* RestCallHandler */
- public void handleResponse(RestRequest req, RestResponse res, Object output) throws IOException, RestException {
+ public void handleResponse(RestRequest req, RestResponse res, Object output) throws IOException, RestException, NotImplemented {
// Loop until we find the correct handler for the POJO.
for (ResponseHandler h : context.getResponseHandlers())
if (h.handle(req, res, output))
return;
- throw new RestException(SC_NOT_IMPLEMENTED, "No response handlers found to process output of type '"+(output == null ? null : output.getClass().getName())+"'");
+ throw new NotImplemented("No response handlers found to process output of type '"+(output == null ? null : output.getClass().getName())+"'");
}
/**
@@ -241,19 +242,18 @@ public class BasicRestCallHandler implements RestCallHandler {
* @param rc The HTTP response code.
* @param req The HTTP request.
* @param res The HTTP response.
- * @throws Exception
*/
@Override /* RestCallHandler */
- public void handleNotFound(int rc, RestRequest req, RestResponse res) throws Exception {
+ public void handleNotFound(int rc, RestRequest req, RestResponse res) throws NotFound, PreconditionFailed, MethodNotAllowed, ServletException {
String pathInfo = req.getPathInfo();
String methodUC = req.getMethod();
String onPath = pathInfo == null ? " on no pathInfo" : String.format(" on path '%s'", pathInfo);
if (rc == SC_NOT_FOUND)
- throw new RestException(rc, "Method ''{0}'' not found on resource with matching pattern{1}.", methodUC, onPath);
+ throw new NotFound("Method ''{0}'' not found on resource with matching pattern{1}.", methodUC, onPath);
else if (rc == SC_PRECONDITION_FAILED)
- throw new RestException(rc, "Method ''{0}'' not found on resource{1} with matching matcher.", methodUC, onPath);
+ throw new PreconditionFailed("Method ''{0}'' not found on resource{1} with matching matcher.", methodUC, onPath);
else if (rc == SC_METHOD_NOT_ALLOWED)
- throw new RestException(rc, "Method ''{0}'' not found on resource.", methodUC);
+ throw new MethodNotAllowed("Method ''{0}'' not found on resource.", methodUC);
else
throw new ServletException("Invalid method response: " + rc);
}
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 fd5aead..dfddced 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
@@ -12,7 +12,6 @@
// ***************************************************************************************************************************
package org.apache.juneau.rest;
-import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.juneau.internal.IOUtils.*;
import static org.apache.juneau.internal.StringUtils.*;
@@ -27,6 +26,7 @@ import org.apache.juneau.encoders.*;
import org.apache.juneau.http.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.parser.*;
+import org.apache.juneau.rest.exception.*;
/**
* Contains the body of the HTTP request.
@@ -373,7 +373,7 @@ public class RequestBody {
}
/* Workhorse method */
- private <T> T parse(ClassMeta<T> cm) throws RestException {
+ private <T> T parse(ClassMeta<T> cm) throws BadRequest, UnsupportedMediaType, InternalServerError {
try {
if (cm.isReader())
@@ -396,34 +396,34 @@ public class RequestBody {
return session.parse(in, cm);
}
} catch (ParseException e) {
- throw new RestException(SC_BAD_REQUEST,
+ throw new BadRequest(e,
"Could not convert request body content to class type ''{0}'' using parser ''{1}''.",
cm, p.getClass().getName()
- ).initCause(e);
+ );
}
}
- throw new RestException(SC_UNSUPPORTED_MEDIA_TYPE,
+ throw new UnsupportedMediaType(
"Unsupported media-type in request header ''Content-Type'': ''{0}''\n\tSupported media-types: {1}",
headers.getContentType(), req.getParsers().getSupportedMediaTypes()
);
} catch (IOException e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR,
+ throw new InternalServerError(e,
"I/O exception occurred while attempting to handle request ''{0}''.",
req.getDescription()
- ).initCause(e);
+ );
}
}
- private Encoder getEncoder() {
+ private Encoder getEncoder() throws UnsupportedMediaType {
if (encoder == null) {
String ce = req.getHeader("content-encoding");
if (! isEmpty(ce)) {
ce = ce.trim();
encoder = encoders.getEncoder(ce);
if (encoder == null)
- throw new RestException(SC_UNSUPPORTED_MEDIA_TYPE,
+ throw new UnsupportedMediaType(
"Unsupported encoding in request header ''Content-Encoding'': ''{0}''\n\tSupported codings: {1}",
req.getHeader("content-encoding"), encoders.getSupportedEncodings()
);
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 3d212b1..41ea56b 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
@@ -46,6 +46,7 @@ import org.apache.juneau.parser.*;
import org.apache.juneau.plaintext.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.converters.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.rest.helper.*;
import org.apache.juneau.rest.response.*;
import org.apache.juneau.rest.vars.*;
@@ -2983,7 +2984,7 @@ public final class RestContext extends BeanContext {
sm = new RestJavaMethod(resource, method, this) {
@Override
- int invoke(String pathInfo, RestRequest req, RestResponse res) throws RestException {
+ int invoke(String pathInfo, RestRequest req, RestResponse res) throws InternalServerError {
int rc = super.invoke(pathInfo, req, res);
if (rc != SC_OK)
@@ -3010,7 +3011,7 @@ public final class RestContext extends BeanContext {
}
return SC_OK;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
}
}
@@ -3172,7 +3173,7 @@ public final class RestContext extends BeanContext {
_initException = e;
throw e;
} catch (Exception e) {
- _initException = new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ _initException = new RestException(e, SC_INTERNAL_SERVER_ERROR);
throw e;
} finally {
initException = _initException;
@@ -3290,13 +3291,14 @@ public final class RestContext extends BeanContext {
*
* @param pathInfo The unencoded path info.
* @return The resource, or <jk>null</jk> if the resource could not be resolved.
+ * @throws NotFound Invalid path.
* @throws IOException
*/
- public StreamResource resolveStaticFile(String pathInfo) throws IOException {
+ public StreamResource resolveStaticFile(String pathInfo) throws NotFound, IOException {
if (! staticFilesCache.containsKey(pathInfo)) {
String p = urlDecode(trimSlashes(pathInfo));
if (p.indexOf("..") != -1)
- throw new RestException(SC_NOT_FOUND, "Invalid path");
+ throw new NotFound("Invalid path");
for (StaticFileMapping sfm : staticFiles) {
String path = sfm.path;
if (p.startsWith(path)) {
@@ -4315,10 +4317,10 @@ public final class RestContext extends BeanContext {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_BAD_REQUEST,
+ throw new BadRequest(e,
"Invalid data conversion. Could not convert {0} ''{1}'' to type ''{2}'' on method ''{3}.{4}''.",
mp[i].getParamType().name(), mp[i].getName(), mp[i].getType(), m.getDeclaringClass().getName(), m.getName()
- ).initCause(e);
+ );
}
}
try {
@@ -4326,7 +4328,7 @@ public final class RestContext extends BeanContext {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage()).initCause(e);
+ throw new InternalServerError(e);
}
}
}
@@ -4347,7 +4349,7 @@ public final class RestContext extends BeanContext {
startOrFinish(resource, endCallMethods[i], endCallMethodParams[i], req, res);
}
- private static void startOrFinish(Object resource, Method m, Class<?>[] p, HttpServletRequest req, HttpServletResponse res) {
+ private static void startOrFinish(Object resource, Method m, Class<?>[] p, HttpServletRequest req, HttpServletResponse res) throws RestException, InternalServerError {
if (m != null) {
Object[] args = new Object[p.length];
for (int i = 0; i < p.length; i++) {
@@ -4361,7 +4363,7 @@ public final class RestContext extends BeanContext {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage()).initCause(e);
+ throw new InternalServerError(e);
}
}
}
@@ -4402,7 +4404,7 @@ public final class RestContext extends BeanContext {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage()).initCause(e);
+ throw new InternalServerError(e);
}
}
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestException.java
index bdf453b..336ca51 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestException.java
@@ -36,38 +36,34 @@ public class RestException extends FormattedRuntimeException {
/**
* Constructor.
- *
+ * @param cause The cause of this exception.
* @param status The HTTP status code.
* @param msg The status message.
* @param args Optional {@link MessageFormat}-style arguments.
*/
- public RestException(int status, String msg, Object...args) {
- super(msg, args);
+ public RestException(Throwable cause, int status, String msg, Object...args) {
+ super(cause, msg, args);
this.status = status;
}
/**
* Constructor.
- *
- * @param status The HTTP status code.
* @param cause The root exception.
+ * @param status The HTTP status code.
*/
- public RestException(int status, Throwable cause) {
- this(status, cause.getLocalizedMessage());
- initCause(cause);
+ public RestException(Throwable cause, int status) {
+ this(cause, status, null);
}
-
/**
- * Sets the inner cause for this exception.
+ * Constructor.
*
- * @param cause The inner cause.
- * @return This object (for method chaining).
+ * @param status The HTTP status code.
+ * @param msg The status message.
+ * @param args Optional {@link MessageFormat}-style arguments.
*/
- @Override /* Throwable */
- public synchronized RestException initCause(Throwable cause) {
- super.initCause(cause);
- return this;
+ public RestException(int status, String msg, Object...args) {
+ this(null, status, msg, args);
}
/**
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestGuard.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestGuard.java
index e385dd2..da89c08 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestGuard.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestGuard.java
@@ -12,9 +12,8 @@
// ***************************************************************************************************************************
package org.apache.juneau.rest;
-import static javax.servlet.http.HttpServletResponse.*;
-
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
/**
* REST method guard.
@@ -92,7 +91,7 @@ public abstract class RestGuard {
*/
public boolean guard(RestRequest req, RestResponse res) throws RestException {
if (! isRequestAllowed(req))
- throw new RestException(SC_FORBIDDEN, "Access denied by guard");
+ throw new Forbidden("Access denied by guard");
return true;
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestJavaMethod.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestJavaMethod.java
index 41f21cf..4fea1a6 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestJavaMethod.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestJavaMethod.java
@@ -33,6 +33,7 @@ import org.apache.juneau.httppart.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.rest.widget.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.svl.*;
@@ -452,7 +453,7 @@ public class RestJavaMethod implements Comparable<RestJavaMethod> {
* @param pathInfo The value of {@link HttpServletRequest#getPathInfo()} (sorta)
* @return The HTTP response code.
*/
- int invoke(String pathInfo, RestRequest req, RestResponse res) throws RestException {
+ int invoke(String pathInfo, RestRequest req, RestResponse res) throws RestException, BadRequest, InternalServerError {
String[] patternVals = pathPattern.match(pathInfo);
if (patternVals == null)
@@ -496,10 +497,10 @@ public class RestJavaMethod implements Comparable<RestJavaMethod> {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_BAD_REQUEST,
+ throw new BadRequest(e,
"Invalid data conversion. Could not convert {0} ''{1}'' to type ''{2}'' on method ''{3}.{4}''.",
methodParams[i].getParamType().name(), methodParams[i].getName(), methodParams[i].getType(), method.getDeclaringClass().getName(), method.getName()
- ).initCause(e);
+ );
}
}
@@ -523,23 +524,23 @@ public class RestJavaMethod implements Comparable<RestJavaMethod> {
res.setOutput(output);
}
} catch (IllegalArgumentException e) {
- throw new RestException(SC_BAD_REQUEST,
+ throw new BadRequest(e,
"Invalid argument type passed to the following method: ''{0}''.\n\tArgument types: {1}",
method.toString(), getReadableClassNames(args)
- ).initCause(e);
+ );
} catch (InvocationTargetException e) {
Throwable e2 = e.getTargetException(); // Get the throwable thrown from the doX() method.
if (e2 instanceof RestException)
throw (RestException)e2;
if (e2 instanceof ParseException)
- throw new RestException(SC_BAD_REQUEST, e2);
+ throw new BadRequest(e2);
if (e2 instanceof InvalidDataConversionException)
- throw new RestException(SC_BAD_REQUEST, e2);
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e2);
+ throw new BadRequest(e2);
+ throw new InternalServerError(e2);
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
return SC_OK;
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
index c4c9928..f992917 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
@@ -14,7 +14,6 @@ package org.apache.juneau.rest;
import static java.util.Collections.*;
import static java.util.logging.Level.*;
-import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.juneau.html.HtmlDocSerializer.*;
import static org.apache.juneau.internal.IOUtils.*;
import static org.apache.juneau.serializer.Serializer.*;
@@ -38,6 +37,7 @@ import org.apache.juneau.httppart.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.rest.helper.*;
import org.apache.juneau.rest.widget.*;
import org.apache.juneau.serializer.*;
@@ -392,7 +392,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
* Returns the charset specified on the <code>Content-Type</code> header, or <js>"UTF-8"</js> if not specified.
*/
@Override /* ServletRequest */
- public String getCharacterEncoding() {
+ public String getCharacterEncoding() throws UnsupportedMediaType {
if (charset == null) {
// Determine charset
// NOTE: Don't use super.getCharacterEncoding() because the spec is implemented inconsistently.
@@ -406,7 +406,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
if (charset == null)
charset = restJavaMethod.defaultCharset;
if (! Charset.isSupported(charset))
- throw new RestException(SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported charset in header ''Content-Type'': ''{0}''", h);
+ throw new UnsupportedMediaType("Unsupported charset in header ''Content-Type'': ''{0}''", h);
}
return charset;
}
@@ -552,9 +552,10 @@ public final class RestRequest extends HttpServletRequestWrapper {
* @return
* The URL-encoded form data from the request.
* <br>Never <jk>null</jk>.
+ * @throws InternalServerError If query parameters could not be parsed.
* @see org.apache.juneau.rest.annotation.FormData
*/
- public RequestFormData getFormData() {
+ public RequestFormData getFormData() throws InternalServerError {
try {
if (formData == null) {
formData = new RequestFormData();
@@ -572,7 +573,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
formData.addDefault(restJavaMethod.defaultFormData);
return formData;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
}
@@ -900,6 +901,8 @@ public final class RestRequest extends HttpServletRequestWrapper {
* @return
* The swagger associated with the resource.
* <br>Never <jk>null</jk>.
+ * @throws RestException
+ * @throws InternalServerError
*/
public Swagger getSwagger() {
try {
@@ -909,7 +912,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
}
@@ -935,6 +938,8 @@ public final class RestRequest extends HttpServletRequestWrapper {
* Equivalent to calling {@link RestInfoProvider#getSiteName(RestRequest)} with this object.
*
* @return The localized site name.
+ * @throws RestException
+ * @throws InternalServerError
*/
public String getSiteName() {
try {
@@ -942,7 +947,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
}
@@ -953,6 +958,8 @@ public final class RestRequest extends HttpServletRequestWrapper {
* Equivalent to calling {@link RestInfoProvider#getTitle(RestRequest)} with this object.
*
* @return The localized resource title.
+ * @throws RestException
+ * @throws InternalServerError
*/
public String getResourceTitle() {
try {
@@ -960,7 +967,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
}
@@ -971,6 +978,8 @@ public final class RestRequest extends HttpServletRequestWrapper {
* Equivalent to calling {@link RestInfoProvider#getDescription(RestRequest)} with this object.
*
* @return The localized resource description.
+ * @throws RestException
+ * @throws InternalServerError
*/
public String getResourceDescription() {
try {
@@ -978,7 +987,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
}
@@ -989,6 +998,8 @@ public final class RestRequest extends HttpServletRequestWrapper {
* Equivalent to calling {@link RestInfoProvider#getMethodSummary(Method, RestRequest)} with this object.
*
* @return The localized method description.
+ * @throws RestException
+ * @throws InternalServerError
*/
public String getMethodSummary() {
try {
@@ -996,7 +1007,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
}
@@ -1007,14 +1018,16 @@ public final class RestRequest extends HttpServletRequestWrapper {
* Equivalent to calling {@link RestInfoProvider#getMethodDescription(Method, RestRequest)} with this object.
*
* @return The localized method description.
+ * @throws RestException
+ * @throws InternalServerError
*/
- public String getMethodDescription() {
+ public String getMethodDescription() throws RestException, InternalServerError {
try {
return context.getInfoProvider().getMethodDescription(javaMethod, this);
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
index fcdc854..03af644 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
@@ -26,6 +26,7 @@ import org.apache.juneau.encoders.*;
import org.apache.juneau.http.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.serializer.*;
/**
@@ -67,7 +68,7 @@ public final class RestResponse extends HttpServletResponseWrapper {
/**
* Constructor.
*/
- RestResponse(RestContext context, RestRequest req, HttpServletResponse res) {
+ RestResponse(RestContext context, RestRequest req, HttpServletResponse res) throws BadRequest {
super(res);
this.request = req;
@@ -83,14 +84,14 @@ public final class RestResponse extends HttpServletResponseWrapper {
setHeader(e.getKey(), e.getValue().toString());
}
} catch (Exception e1) {
- throw new RestException(SC_BAD_REQUEST, "Invalid format for header 'x-response-headers'. Must be in URL-encoded format.").initCause(e1);
+ throw new BadRequest(e1, "Invalid format for header 'x-response-headers'. Must be in URL-encoded format.");
}
}
/*
* Called from RestServlet after a match has been made but before the guard or method invocation.
*/
- final void init(RestJavaMethod rjm, RequestProperties properties) {
+ final void init(RestJavaMethod rjm, RequestProperties properties) throws NotAcceptable {
this.restJavaMethod = rjm;
this.properties = properties;
@@ -112,7 +113,7 @@ public final class RestResponse extends HttpServletResponseWrapper {
}
if (charset == null)
- throw new RestException(SC_NOT_ACCEPTABLE, "No supported charsets in header ''Accept-Charset'': ''{0}''", request.getHeader("Accept-Charset"));
+ throw new NotAcceptable("No supported charsets in header ''Accept-Charset'': ''{0}''", request.getHeader("Accept-Charset"));
super.setCharacterEncoding(charset);
}
@@ -347,9 +348,10 @@ public final class RestResponse extends HttpServletResponseWrapper {
* was found that matched the <code>Accept-Encoding</code> header.
*
* @return A negotiated output stream.
+ * @throws NotAcceptable If unsupported Accept-Encoding value specified.
* @throws IOException
*/
- public FinishableServletOutputStream getNegotiatedOutputStream() throws IOException {
+ public FinishableServletOutputStream getNegotiatedOutputStream() throws NotAcceptable, IOException {
if (os == null) {
Encoder encoder = null;
EncoderGroup encoders = restJavaMethod.encoders;
@@ -360,7 +362,7 @@ public final class RestResponse extends HttpServletResponseWrapper {
if (match == null) {
// Identity should always match unless "identity;q=0" or "*;q=0" is specified.
if (ae.matches(".*(identity|\\*)\\s*;\\s*q\\s*=\\s*(0(?!\\.)|0\\.0).*")) {
- throw new RestException(SC_NOT_ACCEPTABLE,
+ throw new NotAcceptable(
"Unsupported encoding in request header ''Accept-Encoding'': ''{0}''\n\tSupported codings: {1}",
ae, encoders.getSupportedEncodings()
);
@@ -435,14 +437,15 @@ public final class RestResponse extends HttpServletResponseWrapper {
* header to the appropriate value.
*
* @return The negotiated writer.
+ * @throws NotAcceptable If unsupported charset in request header Accept-Charset.
* @throws IOException
*/
- public FinishablePrintWriter getNegotiatedWriter() throws IOException {
+ public FinishablePrintWriter getNegotiatedWriter() throws NotAcceptable, IOException {
return getWriter(false);
}
@SuppressWarnings("resource")
- private FinishablePrintWriter getWriter(boolean raw) throws IOException {
+ private FinishablePrintWriter getWriter(boolean raw) throws NotAcceptable, IOException {
if (w != null)
return w;
@@ -457,7 +460,7 @@ public final class RestResponse extends HttpServletResponseWrapper {
} catch (UnsupportedEncodingException e) {
String ce = getCharacterEncoding();
setCharacterEncoding("UTF-8");
- throw new RestException(SC_NOT_ACCEPTABLE, "Unsupported charset in request header ''Accept-Charset'': ''{0}''", ce);
+ throw new NotAcceptable("Unsupported charset in request header ''Accept-Charset'': ''{0}''", ce);
}
}
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 c726a6a..67333c8 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
@@ -23,6 +23,8 @@ import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
+import org.apache.juneau.rest.exception.*;
+
/**
* Servlet implementation of a REST resource.
*
@@ -129,17 +131,17 @@ public abstract class RestServlet extends HttpServlet {
* 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, IOException {
+ public void service(HttpServletRequest r1, HttpServletResponse r2) throws ServletException, InternalServerError, IOException {
try {
if (initException != null) {
if (initException instanceof RestException)
throw (RestException)initException;
- throw new RestException(SC_INTERNAL_SERVER_ERROR, initException);
+ throw new InternalServerError(initException);
}
if (context == null)
- throw new RestException(SC_INTERNAL_SERVER_ERROR, "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());
+ 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());
if (! isInitialized)
- throw new RestException(SC_INTERNAL_SERVER_ERROR, "Servlet {0} has not been initialized", getClass().getName());
+ throw new InternalServerError("Servlet {0} has not been initialized", getClass().getName());
context.getCallHandler().service(r1, r2);
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converters/Introspectable.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converters/Introspectable.java
index 0f72e6a..ad6c018 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converters/Introspectable.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converters/Introspectable.java
@@ -12,11 +12,10 @@
// ***************************************************************************************************************************
package org.apache.juneau.rest.converters;
-import static javax.servlet.http.HttpServletResponse.*;
-
import org.apache.juneau.*;
import org.apache.juneau.json.*;
import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.transform.*;
import org.apache.juneau.utils.*;
@@ -53,7 +52,7 @@ public final class Introspectable implements RestConverter {
@Override /* RestConverter */
@SuppressWarnings({"unchecked", "rawtypes"})
- public Object convert(RestRequest req, Object o) throws RestException {
+ public Object convert(RestRequest req, Object o) throws InternalServerError {
String method = req.getQuery().getString("invokeMethod");
String args = req.getQuery().getString("invokeArgs");
if (method == null)
@@ -65,8 +64,7 @@ public final class Introspectable implements RestConverter {
o = swap.swap(bs, o);
return new PojoIntrospector(o, JsonParser.DEFAULT).invokeMethod(method, args);
} catch (Exception e) {
- e.printStackTrace();
- return new RestException(SC_INTERNAL_SERVER_ERROR,
+ return new InternalServerError(
"Error occurred trying to invoke method: {0}",
e.getLocalizedMessage()
).initCause(e);
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converters/Traversable.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converters/Traversable.java
index 63134c4..a13ee6b 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converters/Traversable.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converters/Traversable.java
@@ -12,10 +12,9 @@
// ***************************************************************************************************************************
package org.apache.juneau.rest.converters;
-import javax.servlet.http.*;
-
import org.apache.juneau.*;
import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.transform.*;
import org.apache.juneau.utils.*;
@@ -52,7 +51,7 @@ public final class Traversable implements RestConverter {
@Override /* RestConverter */
@SuppressWarnings({"rawtypes", "unchecked"})
- public Object convert(RestRequest req, Object o) throws RestException {
+ public Object convert(RestRequest req, Object o) throws RestException, InternalServerError {
if (o == null)
return null;
@@ -67,9 +66,9 @@ public final class Traversable implements RestConverter {
PojoRest p = new PojoRest(o, req.getBody().getReaderParser());
o = p.get(pathRemainder);
} catch (PojoRestException e) {
- throw new RestException(e.getStatus(), e);
+ throw new RestException(e, e.getStatus());
} catch (Exception e) {
- throw new RestException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
}
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/BadRequest.java
similarity index 53%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/BadRequest.java
index b11b066..0c2a0c1 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/BadRequest.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.BadRequest.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 400 (Bad Request).
+ *
+ * <p>
+ * The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class BadRequest extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Bad Request";
+
+ /** HTTP status code */
+ public static final int CODE = 400;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public BadRequest(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public BadRequest() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public BadRequest(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public BadRequest(Throwable cause) {
+ this(cause, null);
}
}
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Conflict.java
similarity index 55%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Conflict.java
index b11b066..2fc9528 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Conflict.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.Conflict.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 409 (Conflict).
+ *
+ * <p>
+ * Indicates that the request could not be processed because of conflict in the request, such as an edit conflict between multiple simultaneous updates.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class Conflict extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Conflict";
+
+ /** HTTP status code */
+ public static final int CODE = 409;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public Conflict(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public Conflict() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public Conflict(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public Conflict(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/ExpectationFailed.java
similarity index 55%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/ExpectationFailed.java
index b11b066..ba5f1f0 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/ExpectationFailed.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.ExpectationFailed.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 417 (Expectation Failed).
+ *
+ * <p>
+ * The server cannot meet the requirements of the Expect request-header field.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class ExpectationFailed extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Expectation Failed";
+
+ /** HTTP status code */
+ public static final int CODE = 417;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public ExpectationFailed(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public ExpectationFailed() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public ExpectationFailed(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public ExpectationFailed(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/FailedDependency.java
similarity index 54%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/FailedDependency.java
index b11b066..97242a7 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/FailedDependency.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.FailedDependency.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 424 (Failed Dependency).
+ *
+ * <p>
+ * The request failed because it depended on another request and that request failed (e.g., a PROPPATCH).
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class FailedDependency extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Failed Dependency";
+
+ /** HTTP status code */
+ public static final int CODE = 424;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public FailedDependency(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public FailedDependency() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public FailedDependency(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public FailedDependency(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Forbidden.java
similarity index 54%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Forbidden.java
index b11b066..d019699 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Forbidden.java
@@ -10,39 +10,69 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.Forbidden.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 403 (Forbidden).
+ *
+ * <p>
+ * The request was valid, but the server is refusing action.
+ * <br>The user might not have the necessary permissions for a resource, or may need an account of some sort.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class Forbidden extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Forbidden";
+
+ /** HTTP status code */
+ public static final int CODE = 403;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public Forbidden(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public Forbidden() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public Forbidden(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public Forbidden(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Gone.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Gone.java
new file mode 100644
index 0000000..beca699
--- /dev/null
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Gone.java
@@ -0,0 +1,81 @@
+// ***************************************************************************************************************************
+// * 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.exception;
+
+import static org.apache.juneau.rest.exception.Gone.*;
+
+import java.text.*;
+
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
+
+/**
+ * Exception representing an HTTP 410 ().
+ *
+ * <p>
+ * Indicates that the resource requested is no longer available and will not be available again.
+ * <br>This should be used when a resource has been intentionally removed and the resource should be purged.
+ * <br>Upon receiving a 410 status code, the client should not request the resource in the future.
+ * <br>Clients such as search engines should remove the resource from their indices.
+ * <br>Most use cases do not require clients and search engines to purge the resource, and a <js>"404 Not Found"</js> may be used instead.
+ */
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class Gone extends RestException {
+ private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Gone";
+
+ /** HTTP status code */
+ public static final int CODE = 410;
+
+ /**
+ * Constructor.
+ *
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public Gone(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
+ }
+
+ /**
+ * Constructor.
+ */
+ public Gone() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public Gone(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause The cause. Can be <jk>null</jk>.
+ */
+ public Gone(Throwable cause) {
+ this(cause, null);
+ }
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/HttpVersionNotSupported.java
similarity index 54%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/HttpVersionNotSupported.java
index b11b066..31c4319 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/HttpVersionNotSupported.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.HttpVersionNotSupported.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 505 ().
+ *
+ * <p>
+ * The server does not support the HTTP protocol version used in the request.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class HttpVersionNotSupported extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "HTTP Version Not Supported";
+
+ /** HTTP status code */
+ public static final int CODE = 505;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public HttpVersionNotSupported(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public HttpVersionNotSupported() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public HttpVersionNotSupported(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public HttpVersionNotSupported(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/InsufficientStorage.java
similarity index 55%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/InsufficientStorage.java
index b11b066..fd919ef 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/InsufficientStorage.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.InsufficientStorage.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 507 ().
+ *
+ * <p>
+ * The server is unable to store the representation needed to complete the request.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class InsufficientStorage extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Insufficient Storage";
+
+ /** HTTP status code */
+ public static final int CODE = 507;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public InsufficientStorage(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public InsufficientStorage() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public InsufficientStorage(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public InsufficientStorage(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/InternalServerError.java
similarity index 53%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/InternalServerError.java
index b11b066..9d53925 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/InternalServerError.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.InternalServerError.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 500 (Internal Server Error).
+ *
+ * <p>
+ * A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class InternalServerError extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Internal Server Error";
+
+ /** HTTP status code */
+ public static final int CODE = 500;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public InternalServerError(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public InternalServerError() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public InternalServerError(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public InternalServerError(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/LengthRequired.java
similarity index 55%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/LengthRequired.java
index b11b066..be37718 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/LengthRequired.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.LengthRequired.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 411 ().
+ *
+ * <p>
+ * The request did not specify the length of its content, which is required by the requested resource.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class LengthRequired extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Length Required";
+
+ /** HTTP status code */
+ public static final int CODE = 411;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public LengthRequired(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public LengthRequired() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public LengthRequired(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public LengthRequired(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Locked.java
similarity index 57%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Locked.java
index b11b066..65df3d3 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Locked.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.Locked.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 423 (Locked).
+ *
+ * <p>
+ * The resource that is being accessed is locked.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class Locked extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Locked";
+
+ /** HTTP status code */
+ public static final int CODE = 423;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public Locked(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public Locked() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public Locked(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public Locked(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/LoopDetected.java
similarity index 55%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/LoopDetected.java
index b11b066..2f0c88d 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/LoopDetected.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.LoopDetected.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 508 (Loop Detected).
+ *
+ * <p>
+ * The server detected an infinite loop while processing the request (sent in lieu of 208 Already Reported).
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class LoopDetected extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Loop Detected";
+
+ /** HTTP status code */
+ public static final int CODE = 508;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public LoopDetected(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public LoopDetected() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public LoopDetected(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public LoopDetected(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/MethodNotAllowed.java
similarity index 53%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/MethodNotAllowed.java
index b11b066..f3c54f4 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/MethodNotAllowed.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.MethodNotAllowed.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 405 (Method Not Allowed).
+ *
+ * <p>
+ * A request method is not supported for the requested resource; for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class MethodNotAllowed extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Method Not Allowed";
+
+ /** HTTP status code */
+ public static final int CODE = 405;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public MethodNotAllowed(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public MethodNotAllowed() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public MethodNotAllowed(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public MethodNotAllowed(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/MisdirectedRequest.java
similarity index 54%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/MisdirectedRequest.java
index b11b066..174a3c6 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/MisdirectedRequest.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.MisdirectedRequest.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 421 (Misdirected Request).
+ *
+ * <p>
+ * The request was directed at a server that is not able to produce a response (for example because of connection reuse).
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class MisdirectedRequest extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Misdirected Request";
+
+ /** HTTP status code */
+ public static final int CODE = 421;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public MisdirectedRequest(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public MisdirectedRequest() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public MisdirectedRequest(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public MisdirectedRequest(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NetworkAuthenticationRequired.java
similarity index 50%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NetworkAuthenticationRequired.java
index b11b066..cd1a77a 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NetworkAuthenticationRequired.java
@@ -10,39 +10,69 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.NetworkAuthenticationRequired.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 511 (Network Authentication Required).
+ *
+ * <p>
+ * The client needs to authenticate to gain network access.
+ * <br>Intended for use by intercepting proxies used to control access to the network (e.g., "captive portals" used to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot).
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class NetworkAuthenticationRequired extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Network Authentication Required";
+
+ /** HTTP status code */
+ public static final int CODE = 511;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public NetworkAuthenticationRequired(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public NetworkAuthenticationRequired() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public NetworkAuthenticationRequired(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public NetworkAuthenticationRequired(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotAcceptable.java
similarity index 54%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotAcceptable.java
index b11b066..44dd802 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotAcceptable.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.NotAcceptable.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 406 (Not Acceptable).
+ *
+ * <br>
+ * The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class NotAcceptable extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Not Acceptable";
+
+ /** HTTP status code */
+ public static final int CODE = 406;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public NotAcceptable(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public NotAcceptable() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public NotAcceptable(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public NotAcceptable(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotExtended.java
similarity index 55%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotExtended.java
index b11b066..834f609 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotExtended.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.NotExtended.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 510 (Not Extended).
+ *
+ * <p>
+ * Further extensions to the request are required for the server to fulfill it.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class NotExtended extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Not Extended";
+
+ /** HTTP status code */
+ public static final int CODE = 510;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public NotExtended(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public NotExtended() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public NotExtended(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public NotExtended(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotFound.java
similarity index 55%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotFound.java
index b11b066..42aefab 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotFound.java
@@ -10,39 +10,69 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.NotFound.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 404 (Not Found).
+ *
+ * <p>
+ * The requested resource could not be found but may be available in the future.
+ * <br>Subsequent requests by the client are permissible.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class NotFound extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Not Found";
+
+ /** HTTP status code */
+ public static final int CODE = 404;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public NotFound(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public NotFound() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public NotFound(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public NotFound(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotImplemented.java
similarity index 53%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotImplemented.java
index b11b066..184d117 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/NotImplemented.java
@@ -10,39 +10,69 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.NotImplemented.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 501 (Not Implemented).
+ *
+ * <p>
+ * The server either does not recognize the request method, or it lacks the ability to fulfill the request.
+ * <br>Usually this implies future availability (e.g., a new feature of a web-service API).
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class NotImplemented extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Not Implemented";
+
+ /** HTTP status code */
+ public static final int CODE = 501;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public NotImplemented(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public NotImplemented() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public NotImplemented(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public NotImplemented(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/PayloadTooLarge.java
similarity index 55%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/PayloadTooLarge.java
index b11b066..90f5855 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/PayloadTooLarge.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.PayloadTooLarge.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 413 (Payload Too Large).
+ *
+ * <p>
+ * The request is larger than the server is willing or able to process.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class PayloadTooLarge extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Payload Too Large";
+
+ /** HTTP status code */
+ public static final int CODE = 413;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public PayloadTooLarge(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public PayloadTooLarge() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public PayloadTooLarge(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public PayloadTooLarge(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/PreconditionFailed.java
similarity index 54%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/PreconditionFailed.java
index b11b066..a9e806c 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/PreconditionFailed.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.PreconditionFailed.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 412 (Precondition Failed).
+ *
+ * <p>
+ * The server does not meet one of the preconditions that the requester put on the request.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class PreconditionFailed extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Precondition Failed";
+
+ /** HTTP status code */
+ public static final int CODE = 412;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public PreconditionFailed(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public PreconditionFailed() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public PreconditionFailed(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public PreconditionFailed(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/PreconditionRequired.java
similarity index 51%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/PreconditionRequired.java
index b11b066..00f90df 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/PreconditionRequired.java
@@ -10,39 +10,69 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.PreconditionRequired.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 428 (Precondition Required).
+ *
+ * <p>
+ * The origin server requires the request to be conditional.
+ * <br>Intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class PreconditionRequired extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Precondition Required";
+
+ /** HTTP status code */
+ public static final int CODE = 428;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public PreconditionRequired(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public PreconditionRequired() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public PreconditionRequired(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public PreconditionRequired(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/RangeNotSatisfiable.java
similarity index 52%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/RangeNotSatisfiable.java
index b11b066..953fdef 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/RangeNotSatisfiable.java
@@ -10,39 +10,69 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.RangeNotSatisfiable.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 416 (Range Not Satisfiable).
+ *
+ * <p>
+ * The client has asked for a portion of the file (byte serving), but the server cannot supply that portion.
+ * <br>For example, if the client asked for a part of the file that lies beyond the end of the file.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class RangeNotSatisfiable extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Range Not Satisfiable";
+
+ /** HTTP status code */
+ public static final int CODE = 416;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public RangeNotSatisfiable(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public RangeNotSatisfiable() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public RangeNotSatisfiable(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public RangeNotSatisfiable(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/RequestHeaderFieldsTooLarge.java
similarity index 52%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/RequestHeaderFieldsTooLarge.java
index b11b066..398a63c 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/RequestHeaderFieldsTooLarge.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.RequestHeaderFieldsTooLarge.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 431 (Request Header Fields Too Large).
+ *
+ * <p>
+ * The server is unwilling to process the request because either an individual header field, or all the header fields collectively, are too large.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class RequestHeaderFieldsTooLarge extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Request Header Fields Too Large";
+
+ /** HTTP status code */
+ public static final int CODE = 431;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public RequestHeaderFieldsTooLarge(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public RequestHeaderFieldsTooLarge() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public RequestHeaderFieldsTooLarge(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public RequestHeaderFieldsTooLarge(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/ServiceUnavailable.java
similarity index 53%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/ServiceUnavailable.java
index b11b066..2628e37 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/ServiceUnavailable.java
@@ -10,39 +10,69 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.ServiceUnavailable.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 503 (Service Unavailable).
+ *
+ * <p>
+ * The server is currently unavailable (because it is overloaded or down for maintenance).
+ * <br>Generally, this is a temporary state.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class ServiceUnavailable extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Service Unavailable";
+
+ /** HTTP status code */
+ public static final int CODE = 503;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public ServiceUnavailable(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public ServiceUnavailable() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public ServiceUnavailable(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public ServiceUnavailable(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/TooManyRequests.java
similarity index 54%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/TooManyRequests.java
index b11b066..275067c 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/TooManyRequests.java
@@ -10,39 +10,69 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.TooManyRequests.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 429 (Too Many Requests).
+ *
+ * <p>
+ * The user has sent too many requests in a given amount of time.
+ * <br>Intended for use with rate-limiting schemes.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class TooManyRequests extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Too Many Requests";
+
+ /** HTTP status code */
+ public static final int CODE = 429;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public TooManyRequests(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public TooManyRequests() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public TooManyRequests(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public TooManyRequests(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Unauthorized.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Unauthorized.java
new file mode 100644
index 0000000..fecbc8a
--- /dev/null
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/Unauthorized.java
@@ -0,0 +1,80 @@
+// ***************************************************************************************************************************
+// * 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.exception;
+
+import static org.apache.juneau.rest.exception.Unauthorized.*;
+
+import java.text.*;
+
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
+
+/**
+ * Exception representing an HTTP 401 (Unauthorized).
+ *
+ * <p>
+ * Similar to <code>403 Forbidden</code>, but specifically for use when authentication is required and has failed or has not yet been provided.
+ * <br>The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource.
+ * <br>401 semantically means "unauthenticated",i.e. the user does not have the necessary credentials.
+ * <br>Note: Some sites issue HTTP 401 when an IP address is banned from the website (usually the website domain) and that specific address is refused permission to access a website.
+ */
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class Unauthorized extends RestException {
+ private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Unauthorized";
+
+ /** HTTP status code */
+ public static final int CODE = 401;
+
+ /**
+ * Constructor.
+ *
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public Unauthorized(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
+ }
+
+ /**
+ * Constructor.
+ */
+ public Unauthorized() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public Unauthorized(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause The cause. Can be <jk>null</jk>.
+ */
+ public Unauthorized(Throwable cause) {
+ this(cause, null);
+ }
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UnavailableForLegalReasons.java
similarity index 52%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UnavailableForLegalReasons.java
index b11b066..d84de7e 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UnavailableForLegalReasons.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.UnavailableForLegalReasons.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 451 (Unavailable For Legal Reasons).
+ *
+ * <p>
+ * A server operator has received a legal demand to deny access to a resource or to a set of resources that includes the requested resource.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class UnavailableForLegalReasons extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Unavailable For Legal Reasons";
+
+ /** HTTP status code */
+ public static final int CODE = 451;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public UnavailableForLegalReasons(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public UnavailableForLegalReasons() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public UnavailableForLegalReasons(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public UnavailableForLegalReasons(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UnprocessableEntity.java
similarity index 54%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UnprocessableEntity.java
index b11b066..8e81565 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UnprocessableEntity.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.UnprocessableEntity.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 422 (Unprocessable Entity).
+ *
+ * <p>
+ * The request was well-formed but was unable to be followed due to semantic errors.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class UnprocessableEntity extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Unprocessable Entity";
+
+ /** HTTP status code */
+ public static final int CODE = 422;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public UnprocessableEntity(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public UnprocessableEntity() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public UnprocessableEntity(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public UnprocessableEntity(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UnsupportedMediaType.java
similarity index 52%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UnsupportedMediaType.java
index b11b066..2074e5c 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UnsupportedMediaType.java
@@ -10,39 +10,69 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.UnsupportedMediaType.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 415 (Unsupported Media Type).
+ *
+ * <p>
+ * The request entity has a media type which the server or resource does not support.
+ * <br>For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class UnsupportedMediaType extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Unsupported Media Type";
+
+ /** HTTP status code */
+ public static final int CODE = 415;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public UnsupportedMediaType(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public UnsupportedMediaType() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public UnsupportedMediaType(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public UnsupportedMediaType(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UpgradeRequired.java
similarity index 54%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UpgradeRequired.java
index b11b066..b047ab8 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UpgradeRequired.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.UpgradeRequired.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 426 (Upgrade Required).
+ *
+ * <p>
+ * The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class UpgradeRequired extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Upgrade Required";
+
+ /** HTTP status code */
+ public static final int CODE = 426;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public UpgradeRequired(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public UpgradeRequired() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public UpgradeRequired(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public UpgradeRequired(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UriTooLong.java
similarity index 53%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UriTooLong.java
index b11b066..5edee8b 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/UriTooLong.java
@@ -10,39 +10,69 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.UriTooLong.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 414 (URI Too Long).
+ *
+ * <p>
+ * The URI provided was too long for the server to process.
+ * <br>Often the result of too much data being encoded as a query-string of a GET request, in which case it should be converted to a POST request.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class UriTooLong extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "URI Too Long";
+
+ /** HTTP status code */
+ public static final int CODE = 414;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public UriTooLong(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public UriTooLong() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public UriTooLong(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public UriTooLong(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/VariantAlsoNegotiates.java
similarity index 54%
copy from juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
copy to juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/VariantAlsoNegotiates.java
index b11b066..d413cd8 100644
--- a/juneau-core/juneau-svl/src/main/java/org/apache/juneau/svl/VarResolverException.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/VariantAlsoNegotiates.java
@@ -10,39 +10,68 @@
// * "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.svl;
+package org.apache.juneau.rest.exception;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.exception.VariantAlsoNegotiates.*;
import java.text.*;
-import org.apache.juneau.*;
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
/**
- * Exception that occurs during a var resolver session.
+ * Exception representing an HTTP 506 (Variant Also Negotiate).
+ *
+ * <p>
+ * Transparent content negotiation for the request results in a circular reference.
*/
-public class VarResolverException extends FormattedRuntimeException {
+@ResponseInfo(
+ code=CODE,
+ description=MESSAGE
+)
+public class VariantAlsoNegotiates extends RestException {
private static final long serialVersionUID = 1L;
+
+ /** Default message */
+ public static final String MESSAGE = "Variant Also Negotiate";
+
+ /** HTTP status code */
+ public static final int CODE = 506;
/**
* Constructor.
*
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
*/
- public VarResolverException(String message, Object...args) {
- super(format(message, args));
+ public VariantAlsoNegotiates(Throwable cause, String msg, Object...args) {
+ super(cause, CODE, getMessage(cause, msg, MESSAGE), args);
}
-
+
+ /**
+ * Constructor.
+ */
+ public VariantAlsoNegotiates() {
+ this((Throwable)null, MESSAGE);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param msg The message. Can be <jk>null</jk>.
+ * @param args Optional {@link MessageFormat}-style arguments in the message.
+ */
+ public VariantAlsoNegotiates(String msg, Object...args) {
+ this(null, msg, args);
+ }
+
/**
* Constructor.
*
- * @param causedBy The cause of this exception.
- * @param message The {@link MessageFormat}-style message.
- * @param args Optional {@link MessageFormat}-style arguments.
+ * @param cause The cause. Can be <jk>null</jk>.
*/
- public VarResolverException(Throwable causedBy, String message, Object...args) {
- this(message, args);
- initCause(causedBy);
+ public VariantAlsoNegotiates(Throwable cause) {
+ this(cause, null);
}
-}
+}
\ No newline at end of file
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/package-info.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/package-info.java
new file mode 100644
index 0000000..b7d5678
--- /dev/null
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/exception/package-info.java
@@ -0,0 +1,18 @@
+/***************************************************************************************************************************
+ * 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.
+ *
+ ***************************************************************************************************************************/
+
+/**
+ * REST Interface Exception Classes
+ */
+package org.apache.juneau.rest.exception;
\ No newline at end of file
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/remoteable/RemoteableServlet.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/remoteable/RemoteableServlet.java
index 42b26da..04209d4 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/remoteable/RemoteableServlet.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/remoteable/RemoteableServlet.java
@@ -12,7 +12,6 @@
// ***************************************************************************************************************************
package org.apache.juneau.rest.remoteable;
-import static javax.servlet.http.HttpServletResponse.*;
import static org.apache.juneau.dto.html5.HtmlBuilder.*;
import static org.apache.juneau.http.HttpMethodName.*;
import static org.apache.juneau.internal.StringUtils.*;
@@ -29,6 +28,7 @@ import org.apache.juneau.internal.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.exception.*;
/**
* Abstract class for defining Remoteable services.
@@ -111,15 +111,16 @@ public abstract class RemoteableServlet extends BasicRestServlet {
* @param javaInterface The Java interface name.
* @param javaMethod The Java method name or signature.
* @return A simple form entry page for invoking a remoteable method.
+ * @throws NotFound
* @throws Exception
*/
@RestMethod(name=GET, path="/{javaInterface}/{javaMethod}", summary="Form entry for method $RP{javaMethod} on interface $RP{javaInterface}")
- public Div showEntryForm(RestRequest req, @Path("javaInterface") String javaInterface, @Path("javaMethod") String javaMethod) throws Exception {
+ public Div showEntryForm(RestRequest req, @Path("javaInterface") String javaInterface, @Path("javaMethod") String javaMethod) throws NotFound, Exception {
// Find the method.
java.lang.reflect.Method m = getMethods(javaInterface).get(javaMethod);
if (m == null)
- throw new RestException(SC_NOT_FOUND, "Method not found");
+ throw new NotFound("Method not found");
Table t = table();
@@ -154,26 +155,28 @@ public abstract class RemoteableServlet extends BasicRestServlet {
* @param javaInterface The Java interface name.
* @param javaMethod The Java method name or signature.
* @return The results from invoking the specified Java method.
+ * @throws UnsupportedMediaType
+ * @throws NotFound
* @throws Exception
*/
@RestMethod(name=POST, path="/{javaInterface}/{javaMethod}")
- public Object invoke(RestRequest req, @Path String javaInterface, @Path String javaMethod) throws Exception {
+ public Object invoke(RestRequest req, @Path String javaInterface, @Path String javaMethod) throws UnsupportedMediaType, NotFound, Exception {
// Find the parser.
ReaderParser p = req.getBody().getReaderParser();
if (p == null)
- throw new RestException(SC_UNSUPPORTED_MEDIA_TYPE, "Could not find parser for media type ''{0}''", req.getHeaders().getContentType());
+ throw new UnsupportedMediaType("Could not find parser for media type ''{0}''", req.getHeaders().getContentType());
Class<?> c = getInterfaceClass(javaInterface);
// Find the service.
Object service = getServiceMap().get(c);
if (service == null)
- throw new RestException(SC_NOT_FOUND, "Service not found");
+ throw new NotFound("Service not found");
// Find the method.
java.lang.reflect.Method m = getMethods(javaInterface).get(javaMethod);
if (m == null)
- throw new RestException(SC_NOT_FOUND, "Method not found");
+ throw new NotFound("Method not found");
// Parse the args and invoke the method.
Object[] params = p.parseArgs(req.getReader(), m.getGenericParameterTypes());
@@ -198,7 +201,7 @@ public abstract class RemoteableServlet extends BasicRestServlet {
/**
* Return the <code>Class</code> given it's name if it exists in the services map.
*/
- private Class<?> getInterfaceClass(String javaInterface) throws Exception {
+ private Class<?> getInterfaceClass(String javaInterface) throws NotFound, Exception {
Class<?> c = classNameMap.get(javaInterface);
if (c == null) {
for (Class<?> c2 : getServiceMap().keySet())
@@ -206,7 +209,7 @@ public abstract class RemoteableServlet extends BasicRestServlet {
classNameMap.put(javaInterface, c2);
return c2;
}
- throw new RestException(SC_NOT_FOUND, "Interface class not found");
+ throw new NotFound("Interface class not found");
}
return c;
}
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java
index 6d31c83..0a5245c 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java
@@ -12,14 +12,13 @@
// ***************************************************************************************************************************
package org.apache.juneau.rest.response;
-import static javax.servlet.http.HttpServletResponse.*;
-
import java.io.*;
import java.util.*;
import org.apache.juneau.http.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.serializer.*;
/**
@@ -44,7 +43,7 @@ public class DefaultHandler implements ResponseHandler {
@SuppressWarnings("resource")
@Override /* ResponseHandler */
- public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, RestException {
+ public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, InternalServerError, NotAcceptable {
SerializerGroup g = res.getSerializers();
String accept = req.getHeaders().getString("Accept", "");
SerializerMatch sm = g.getSerializerMatch(accept);
@@ -93,10 +92,10 @@ public class DefaultHandler implements ResponseHandler {
w.finish();
}
} catch (SerializeException e) {
- throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
} else {
- throw new RestException(SC_NOT_ACCEPTABLE,
+ throw new NotAcceptable(
"Unsupported media-type in request header ''Accept'': ''{0}''\n\tSupported media-types: {1}",
req.getHeaders().getString("Accept", ""), g.getSupportedMediaTypes()
);
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/InputStreamHandler.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/InputStreamHandler.java
index 9a6edfb..bfbf3d0 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/InputStreamHandler.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/InputStreamHandler.java
@@ -15,6 +15,7 @@ package org.apache.juneau.rest.response;
import java.io.*;
import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.utils.*;
/**
@@ -34,7 +35,7 @@ import org.apache.juneau.utils.*;
public final class InputStreamHandler implements ResponseHandler {
@Override /* ResponseHandler */
- public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, RestException {
+ public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, NotAcceptable, RestException {
if (output instanceof InputStream) {
res.setHeader("Content-Type", res.getContentType());
try (OutputStream os = res.getNegotiatedOutputStream()) {
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/ReaderHandler.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/ReaderHandler.java
index 8629c4c..1a7621b 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/ReaderHandler.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/ReaderHandler.java
@@ -15,6 +15,7 @@ package org.apache.juneau.rest.response;
import java.io.*;
import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.utils.*;
/**
@@ -31,7 +32,7 @@ import org.apache.juneau.utils.*;
public final class ReaderHandler implements ResponseHandler {
@Override /* ResponseHandler */
- public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, RestException {
+ public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, NotAcceptable, RestException {
if (output instanceof Reader) {
try (Writer w = res.getNegotiatedWriter()) {
IOPipe.create(output, w).run();
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/WritableHandler.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/WritableHandler.java
index b5f37b8..3fa6da8 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/WritableHandler.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/response/WritableHandler.java
@@ -20,6 +20,7 @@ import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.http.*;
import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.rest.helper.*;
/**
@@ -36,7 +37,7 @@ import org.apache.juneau.rest.helper.*;
public final class WritableHandler implements ResponseHandler {
@Override /* ResponseHandler */
- public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, RestException {
+ public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, NotAcceptable, RestException {
if (output instanceof Writable) {
if (output instanceof ReaderResource) {
ReaderResource r = (ReaderResource)output;
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/RestInfoVar.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/RestInfoVar.java
index 78b96e2..df357d2 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/RestInfoVar.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/RestInfoVar.java
@@ -15,12 +15,11 @@ package org.apache.juneau.rest.vars;
import java.lang.reflect.*;
import java.util.*;
-import javax.servlet.http.*;
-
import org.apache.juneau.dto.swagger.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.json.*;
import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.exception.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.svl.*;
@@ -99,7 +98,7 @@ public class RestInfoVar extends MultipartResolvingVar {
}
@Override /* Parameter */
- public String resolve(VarResolverSession session, String key) {
+ public String resolve(VarResolverSession session, String key) throws RestException, InternalServerError {
try {
RestRequest req = session.getSessionObject(RestRequest.class, SESSION_req);
Swagger swagger = req.getSwagger();
@@ -149,7 +148,7 @@ public class RestInfoVar extends MultipartResolvingVar {
} catch (RestException e) {
throw e;
} catch (Exception e) {
- throw new RestException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
+ throw new InternalServerError(e);
}
}
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
jamesbognar@apache.org.