/*
 * CWS, Cryptographic Web Store - open source Cryptographic Storage system.
 * Copyright (C) 2016-2019, JavaDog.io
 * mailto: cws AT JavaDog DOT io
 *
 * CWS is free software; you can redistribute it and/or modify it under the
 * terms of the Apache License, as published by the Apache Software Foundation.
 *
 * CWS is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the Apache License for more details.
 *
 * You should have received a copy of the Apache License, version 2, along with
 * this program; If not, you can download a copy of the License
 * here: https://www.apache.org/licenses/
 */
package io.javadog.cws.rest;

import io.javadog.cws.api.common.ReturnCode;
import io.javadog.cws.api.responses.CwsResponse;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * <p>Common REST utilities, for all REST services.</p>
 *
 * @author Kim Jensen
 * @since  CWS 1.0
 */
public final class RestUtils {

    /** REST WebService consummation media type. */
    public static final String CONSUMES = MediaType.APPLICATION_JSON;
    /** REST WebService production media type. */
    public static final String PRODUCES = MediaType.APPLICATION_JSON;

    private RestUtils() {
        // Private Constructor, this is a Utility Class.
    }

    public static Response buildResponse(final CwsResponse cwsResponse) {
        return Response
                .status(ReturnCode.findReturnCode(cwsResponse.getReturnCode()).getHttpCode())
                .type(PRODUCES)
                .entity(cwsResponse)
                .build();
    }
}

@@ -754,53 +754,8 @@
 t;%0A%0A
-import io.javadog.cws.api.common.ReturnCode;%0A
 impo
@@ -799,17 +799,16 @@
 sponse;%0A
-%0A
 import j
@@ -1342,16 +1342,850 @@
 %0A    %7D%0A%0A
+    /**%0A     * %3Cp%3EThis method will build the response to be returned by the REST%0A     * service. Please note, that rather than just taking the existing%0A     * returnCode and use it, the method will always return that the request%0A     * was successful, even it if wasn't.%3C/p%3E%0A     *%0A     * %3Cp%3EThe reason for this, is that it is not possible to set change the%0A     * error message being returned, and as it contains important information%0A     * about what went wrong and how it can be fixed - is is critical that it%0A     * is not lost. Hence, any request coming into CWS, which CWS and not the%0A     * underlying container is responding too, will be replied with a success,%0A     * even if the reply failed.%3C/p%3E%0A     *%0A     * @param cwsResponse The CWS Response Object to convert%0A     * @return The converted REST Response Object%0A     */%0A
     publ
@@ -2295,83 +2295,11 @@
    .
-status(ReturnCode.findReturnCode(cwsResponse.getReturnCode()).getHttpCode()
+ok(
 )%0A  

Change in the REST responses from CWS. Although REST is very close to HTTP and the responses should honor the HTTP thinking. There is a problem with returning error codes, since it is not possible to alter the error message. For this reason, CWS is deliberately breaking with best practices regarding REST return information, so *all* CWS Responses will be with the HTTP Code 200, i.e. SUCCESS. However, the returned Object (JSON) will contain both the internal CWS ReturnCode & ReturnMessage. Which should be used to determine the actual response from, as the ReturnMessage contain useful details about the problem, eg. missing or invalid request parameters, authorization issues, etc.