Search in sources :

Example 61 with PUT

use of javax.ws.rs.PUT in project opennms by OpenNMS.

the class SnmpTrapNorthbounderConfigurationResource method updateSnmpTrapSink.

/**
     * Update a specific SNMP trap sink.
     *
     * @param trapSinkName the trap sink name
     * @param params the parameters map
     * @return the response
     */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("trapsinks/{trapsinkName}")
public Response updateSnmpTrapSink(@PathParam("trapsinkName") final String trapSinkName, final MultivaluedMapImpl params) {
    writeLock();
    try {
        boolean modified = false;
        SnmpTrapSink trapSink = getSnmpTrapSink(trapSinkName);
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(trapSink);
        for (final String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                final String stringValue = params.getFirst(key);
                final Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            saveConfiguration();
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) SnmpTrapSink(org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 62 with PUT

use of javax.ws.rs.PUT in project opennms by OpenNMS.

the class AbstractDaoRestService method updateProperties.

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{id}")
public Response updateProperties(@Context final UriInfo uriInfo, @PathParam("id") final K id, final MultivaluedMapImpl params) {
    writeLock();
    try {
        final T object = getDao().get(id);
        if (object == null) {
            return Response.status(Status.NOT_FOUND).build();
        }
        LOG.debug("update: updating object {}", object);
        RestUtils.setBeanProperties(object, params);
        LOG.debug("update: object {} updated", object);
        getDao().saveOrUpdate(object);
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : GET(javax.ws.rs.GET) POST(javax.ws.rs.POST) PUT(javax.ws.rs.PUT) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 63 with PUT

use of javax.ws.rs.PUT in project OpenAM by OpenRock.

the class CoreTokenResource method updateToken.

/**
     * Updates a token.
     *
     * @param headers HTTPHeaders object of the request.
     * @param request HTTPServletRequest object of the request.
     * @param tokenId value of token.id in the request path parameter.
     * @param eTag value of the If-Match header in the request.
     * @param msgBody Message body containing the JSON-encoded token attributes.
     */
@PUT
@Consumes("application/json")
@Path("{token.id}")
public void updateToken(@Context HttpHeaders headers, @Context HttpServletRequest request, @PathParam("token.id") String tokenId, @HeaderParam("If-Match") String eTag, String msgBody) {
    try {
        JSONObject jObj = new JSONObject(msgBody);
        CoreTokenStoreFactory.getInstance().updateToken(CoreTokenUtils.getAdminSubject(), tokenId, eTag, jObj);
        // logging
        String[] data = new String[] { jObj.names().toString() };
        TokenLogUtils.access(Level.INFO, TokenLogUtils.TOKEN_UPDATE_SUCCESS, data, null, tokenId);
    } catch (CoreTokenException ce) {
        CoreTokenUtils.debug.error("CoreTokenResource.updateToken", ce);
        String[] data = new String[] { ce.getLocalizedMessage() };
        TokenLogUtils.error(Level.INFO, TokenLogUtils.UNABLE_TO_UPDATE_TOKEN, data, null, tokenId);
        throw getWebApplicationException(headers, ce);
    } catch (JSONException je) {
        CoreTokenUtils.debug.error("CoreTokenResource.updateToken", je);
        String[] data = new String[] { je.getLocalizedMessage() };
        TokenLogUtils.error(Level.INFO, TokenLogUtils.UNABLE_TO_UPDATE_TOKEN, data, null, tokenId);
        throw getWebApplicationException(je, MimeType.PLAIN);
    }
}
Also used : JSONObject(org.json.JSONObject) CoreTokenException(com.sun.identity.coretoken.CoreTokenException) JSONException(org.json.JSONException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 64 with PUT

use of javax.ws.rs.PUT in project OpenAM by OpenRock.

the class PrivilegeResource method modifyPrivilege.

@PUT
@Produces("application/json")
@Path("/{name}")
public String modifyPrivilege(@Context HttpHeaders headers, @Context HttpServletRequest request, @FormParam("realm") @DefaultValue("/") String realm, @FormParam("privilege.json") String jsonString, @PathParam("name") String name) {
    try {
        Subject caller = getCaller(request);
        PrivilegeManager pm = PrivilegeManager.getInstance(realm, caller);
        Privilege privilege = Privilege.getNewInstance(jsonString);
        pm.modify(privilege);
        return createResponseJSONString(200, headers, "OK");
    } catch (JSONException e) {
        PrivilegeManager.debug.error("PrivilegeResource.modify", e);
        throw getWebApplicationException(e, MimeType.JSON);
    } catch (RestException e) {
        PrivilegeManager.debug.error("PrivilegeResource.modify", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    } catch (EntitlementException e) {
        PrivilegeManager.debug.error("PrivilegeResource.modify", e);
        throw getWebApplicationException(headers, e, MimeType.JSON);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) RestException(com.sun.identity.rest.RestException) JSONException(org.json.JSONException) Privilege(com.sun.identity.entitlement.Privilege) Subject(javax.security.auth.Subject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 65 with PUT

use of javax.ws.rs.PUT in project graylog2-server by Graylog2.

the class RolesResource method update.

@PUT
@Path("{rolename}")
@ApiOperation("Update an existing role")
@AuditEvent(type = AuditEventTypes.ROLE_UPDATE)
public RoleResponse update(@ApiParam(name = "rolename", required = true) @PathParam("rolename") String name, @ApiParam(name = "JSON Body", value = "The new representation of the role", required = true) RoleResponse role) throws NotFoundException {
    final Role roleToUpdate = roleService.load(name);
    if (roleToUpdate.isReadOnly()) {
        throw new BadRequestException("Cannot update read only role " + name);
    }
    roleToUpdate.setName(role.name());
    roleToUpdate.setDescription(role.description().orNull());
    roleToUpdate.setPermissions(role.permissions());
    try {
        roleService.save(roleToUpdate);
    } catch (ValidationException e) {
        throw new BadRequestException(e);
    }
    return RoleResponse.create(roleToUpdate.getName(), Optional.fromNullable(roleToUpdate.getDescription()), roleToUpdate.getPermissions(), role.readOnly());
}
Also used : Role(org.graylog2.shared.users.Role) ValidationException(org.graylog2.plugin.database.ValidationException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Aggregations

PUT (javax.ws.rs.PUT)203 Path (javax.ws.rs.Path)172 Consumes (javax.ws.rs.Consumes)108 Produces (javax.ws.rs.Produces)72 ApiOperation (io.swagger.annotations.ApiOperation)70 ApiResponses (io.swagger.annotations.ApiResponses)53 Timed (com.codahale.metrics.annotation.Timed)36 AuditEvent (org.graylog2.audit.jersey.AuditEvent)36 URI (java.net.URI)24 Response (javax.ws.rs.core.Response)23 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)19 IOException (java.io.IOException)18 BeanWrapper (org.springframework.beans.BeanWrapper)16 BadRequestException (javax.ws.rs.BadRequestException)14 NotFoundException (javax.ws.rs.NotFoundException)14 WebApplicationException (javax.ws.rs.WebApplicationException)12 UriBuilder (javax.ws.rs.core.UriBuilder)12 UUID (java.util.UUID)11 GET (javax.ws.rs.GET)11 POST (javax.ws.rs.POST)11