Search in sources :

Example 1 with BadRequestException

use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.

the class RuntimeExceptionMapperTest method jbossBadRequestException.

@Test
public void jbossBadRequestException() {
    String foo = "foo";
    BadRequestException bre = new BadRequestException(foo);
    Response r = rem.toResponse(bre);
    assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
    verifyMessage(r, "Runtime Error");
}
Also used : Response(javax.ws.rs.core.Response) BadRequestException(org.jboss.resteasy.spi.BadRequestException) Test(org.junit.Test)

Example 2 with BadRequestException

use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.

the class RoleResource method updateRole.

@ApiOperation(notes = "Updates a Role.  To avoid race conditions, we do not support " + "updating the user or permission collections. Currently this call will only update " + "the role name. See the specific nested POST/DELETE calls for modifying users and" + " permissions.", value = "updateRole")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@PUT
@Path("{role_id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Role updateRole(@PathParam("role_id") String roleId, @ApiParam(name = "role", required = true) Role role) {
    // and that ID is NOT equal to what the ID in the URL is, then throw an error
    if (role.getId() != null && !roleId.equals(role.getId())) {
        throw new BadRequestException(i18n.tr("Role ID does not match path."));
    }
    Role existingRole = lookupRole(roleId);
    existingRole.setName(role.getName());
    return this.userService.updateRole(existingRole);
}
Also used : Role(org.candlepin.model.Role) BadRequestException(org.jboss.resteasy.spi.BadRequestException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 3 with BadRequestException

use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.

the class RoleResource method addRolePermission.

@ApiOperation(notes = "Adds a Permission to a Role. Returns the updated Role.", value = "addRolePermission")
@ApiResponses({ @ApiResponse(code = 404, message = ""), @ApiResponse(code = 400, message = "") })
@POST
@Path("{role_id}/permissions")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Role addRolePermission(@PathParam("role_id") String roleId, @ApiParam(name = "permissionBlueprint", required = true) PermissionBlueprint permission) {
    Role existingRole = lookupRole(roleId);
    // internal use:
    if (permission.getAccess().equals(Access.NONE)) {
        throw new BadRequestException(i18n.tr("Access type NONE not supported."));
    }
    // Attach actual owner objects to each incoming permission:
    Owner temp = permission.getOwner();
    Owner real = ownerCurator.lookupByKey(temp.getKey());
    permission.setOwner(real);
    existingRole.addPermission(permission);
    Role r = this.userService.updateRole(existingRole);
    return r;
}
Also used : Role(org.candlepin.model.Role) Owner(org.candlepin.model.Owner) BadRequestException(org.jboss.resteasy.spi.BadRequestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with BadRequestException

use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.

the class BadRequestExceptionMapperTest method emptyMessage.

@Test
public void emptyMessage() {
    rem = injector.getInstance(BadRequestExceptionMapper.class);
    BadRequestException bre = new BadRequestException("");
    Response r = rem.toResponse(bre);
    assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
    verifyMessage(r, "Bad Request");
}
Also used : Response(javax.ws.rs.core.Response) BadRequestException(org.jboss.resteasy.spi.BadRequestException) Test(org.junit.Test)

Example 5 with BadRequestException

use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.

the class BadRequestExceptionMapperTest method extractIllegalValue.

@Test
public void extractIllegalValue() {
    rem = injector.getInstance(BadRequestExceptionMapper.class);
    String foo = "javax.ws.rs.SomeThing(\"paramName\") value is 'strVal' for";
    BadRequestException bre = new BadRequestException(foo);
    Response r = rem.toResponse(bre);
    assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
    verifyMessage(r, "strVal is not a valid value for paramName");
}
Also used : Response(javax.ws.rs.core.Response) BadRequestException(org.jboss.resteasy.spi.BadRequestException) Test(org.junit.Test)

Aggregations

BadRequestException (org.jboss.resteasy.spi.BadRequestException)6 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Owner (org.candlepin.model.Owner)2 Role (org.candlepin.model.Role)2 Date (java.util.Date)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 AutobindDisabledForOwnerException (org.candlepin.controller.AutobindDisabledForOwnerException)1 Consumer (org.candlepin.model.Consumer)1 JobDataMap (org.quartz.JobDataMap)1 JobExecutionException (org.quartz.JobExecutionException)1