Search in sources :

Example 6 with SchoolDataBridgeUnauthorizedException

use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException 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

SchoolDataBridgeUnauthorizedException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException)6 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)3 UserPendingPasswordChange (fi.otavanopisto.muikku.plugins.user.UserPendingPasswordChange)3 PyramusRestClientUnauthorizedException (fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException)2 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)2 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 SchoolDataSource (fi.otavanopisto.muikku.model.base.SchoolDataSource)1 SchoolDataBridgeException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeException)1 UserAddress (fi.otavanopisto.muikku.schooldata.entity.UserAddress)1 Address (fi.otavanopisto.pyramus.rest.model.Address)1 UserCredentials (fi.otavanopisto.pyramus.rest.model.UserCredentials)1 Builder (javax.ws.rs.client.Invocation.Builder)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1