[json] Added error representation for 405 Unsupported Media Type
Change-Id: Ic3a81d74110237d80dcb73b1c5dc502530a2e5b9
Signed-off-by: Michael Ochmann <michael.ochmann@sap.com>
diff --git a/org.eclipse.skalli.api/src/main/java/org/eclipse/skalli/services/extension/rest/ResourceBase.java b/org.eclipse.skalli.api/src/main/java/org/eclipse/skalli/services/extension/rest/ResourceBase.java
index 55faf97..30c60f4 100644
--- a/org.eclipse.skalli.api/src/main/java/org/eclipse/skalli/services/extension/rest/ResourceBase.java
+++ b/org.eclipse.skalli.api/src/main/java/org/eclipse/skalli/services/extension/rest/ResourceBase.java
@@ -40,6 +40,10 @@
private static final Logger LOG = LoggerFactory.getLogger(ResourceBase.class);
private static final String ERROR_ID_MISSING_AUTHORIZATION = "rest:permit({0}):00"; //$NON-NLS-1$
+ private static final String ERROR_ID_UNSUPPORTED_MEDIA_TYPE = "rest:mediaType({0}):00"; //$NON-NLS-1$
+
+ private static final String ERROS_MSG_UNSUPPORTED_MEDIA_TYPE =
+ "Unsupported media type {0}. Supported media types are 'text/xml' and 'application/json'."; //$NON-NLS-1$
private RequestContext context;
@@ -176,6 +180,16 @@
}
/**
+ * Creates an {@link ErrorRepresentation error representation} for unsupported media types.
+ * Sets the response status to <tt>415 Unsupported Media Type</tt>.
+ */
+ protected Representation createUnsupportedMediaTypeRepresentation() {
+ return createErrorRepresentation(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE,
+ MessageFormat.format(ERROR_ID_UNSUPPORTED_MEDIA_TYPE, context.getMediaType()),
+ MessageFormat.format(ERROS_MSG_UNSUPPORTED_MEDIA_TYPE, context.getMediaType()));
+ }
+
+ /**
* Creates an {@link ErrorRepresentation error representation} for i/o errors
* and writes a corresponding log entry (severity ERROR). Sets the response status to
* <tt>500 Internal Server Error</tt>.