Search in sources :

Example 1 with SchoolDataBridgeException

use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeException in project muikku by otavanopisto.

the class PyramusRestClient method delete.

public void delete(Client client, String accssToken, String path) {
    WebTarget target = client.target(url + path);
    Builder request = target.request();
    request.header("Authorization", "Bearer " + accssToken);
    Response response = request.delete();
    try {
        switch(response.getStatus()) {
            case 200:
            case 204:
            case 404:
                break;
            case 403:
                logger.warning(String.format("Pyramus DELETE for path %s unauthorized (%d)", path, response.getStatus()));
                throw new SchoolDataBridgeUnauthorizedException(String.format("Received http error %d when requesting %s", response.getStatus(), path));
            default:
                logger.warning(String.format("Pyramus DELETE for path %s failed (%d)", path, response.getStatus()));
                throw new SchoolDataBridgeException(response.getStatus(), String.format("Received http error %d (%s) when requesting %s", response.getStatus(), response.getEntity(), path));
        }
    } finally {
        response.close();
    }
}
Also used : Response(javax.ws.rs.core.Response) SchoolDataBridgeException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeException) Builder(javax.ws.rs.client.Invocation.Builder) SchoolDataBridgeUnauthorizedException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException) WebTarget(javax.ws.rs.client.WebTarget)

Aggregations

SchoolDataBridgeException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeException)1 SchoolDataBridgeUnauthorizedException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException)1 Builder (javax.ws.rs.client.Invocation.Builder)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1