summaryrefslogtreecommitdiffstats
path: root/base/server/cms/src/com/netscape/cms/servlet/base
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2014-04-15 11:10:13 -0400
committerEndi S. Dewata <edewata@redhat.com>2014-04-15 14:52:20 -0400
commit420609c6f746906453977f51a77f3ea9e9cf1935 (patch)
treedf5bd8a10a8f26a923a6db88e8659ba382c1eccd /base/server/cms/src/com/netscape/cms/servlet/base
parent149b9b9a0c7c3db5bf59e7b8ab104df6fa30e784 (diff)
downloadpki-420609c6f746906453977f51a77f3ea9e9cf1935.tar.gz
pki-420609c6f746906453977f51a77f3ea9e9cf1935.tar.xz
pki-420609c6f746906453977f51a77f3ea9e9cf1935.zip
Fixed missing Accept header handling.
Some clients might not send the Accept header when invoking the REST services. To handle this the REST services have been modified to use the Content-type if the Accept header is missing, or use a default message format if Content-type is not specified.
Diffstat (limited to 'base/server/cms/src/com/netscape/cms/servlet/base')
-rw-r--r--base/server/cms/src/com/netscape/cms/servlet/base/PKIService.java21
1 files changed, 20 insertions, 1 deletions
diff --git a/base/server/cms/src/com/netscape/cms/servlet/base/PKIService.java b/base/server/cms/src/com/netscape/cms/servlet/base/PKIService.java
index 2b8a4ada3..9338b9645 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/base/PKIService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/base/PKIService.java
@@ -66,6 +66,8 @@ public class PKIService {
public static MediaType resolveFormat(MediaType format) {
+ if (format == null) return null;
+
for (MediaType supportedFormat : MESSAGE_FORMATS) {
if (format.isCompatible(supportedFormat)) return supportedFormat;
}
@@ -75,6 +77,8 @@ public class PKIService {
public static MediaType resolveFormat(List<MediaType> formats) {
+ if (formats == null) return null;
+
for (MediaType acceptableFormat : formats) {
MediaType supportedFormat = resolveFormat(acceptableFormat);
if (supportedFormat != null) return supportedFormat;
@@ -84,7 +88,22 @@ public class PKIService {
}
public MediaType getResponseFormat() {
- MediaType responseFormat = resolveFormat(headers.getAcceptableMediaTypes());
+ MediaType contentType = headers.getMediaType();
+ List<MediaType> acceptableFormats = headers.getAcceptableMediaTypes();
+
+ MediaType responseFormat;
+ if (acceptableFormats == null || acceptableFormats.isEmpty()) {
+ // if the Accept header is missing
+ if (contentType == null) {
+ // and if the Content-type header is missing, use the default format
+ responseFormat = PKIService.MESSAGE_FORMATS.get(0);
+ } else {
+ // otherwise, use the Content-type header
+ responseFormat = resolveFormat(contentType);
+ }
+ } else {
+ responseFormat = resolveFormat(acceptableFormats);
+ }
if (responseFormat == null) throw new PKIException(Response.Status.NOT_ACCEPTABLE);
return responseFormat;
}