Search in sources :

Example 16 with PUT

use of javax.ws.rs.PUT in project OpenAttestation by OpenAttestation.

the class AbstractJsonapiResource method storeJsonapiCollection.

/**
     * Replace an item in the collection. Input Content-Type is
     * application/vnd.api+json Output Content-Type is application/vnd.api+json
     *
     * The input item must be wrapped in a collection. The output item is always
     * wrapped in a collection.
     *
     * @param locator
     * @param collection
     * @return
     */
@Path("/{id}")
@PUT
@Consumes(DataMediaType.APPLICATION_VND_API_JSON)
@Produces(DataMediaType.APPLICATION_VND_API_JSON)
public C storeJsonapiCollection(@BeanParam L locator, C collection) {
    // misnomer, what we really mean is "store one but wrapped ina  collection for jsonapi"
    log.debug("storeCollection");
    ValidationUtil.validate(collection);
    List<T> list = collection.getDocuments();
    if (list == null || list.isEmpty()) {
        throw new WebApplicationException(Response.Status.BAD_REQUEST);
    }
    T item = list.get(0);
    locator.copyTo(item);
    if (item == null) {
        getRepository().create(item);
    } else {
        getRepository().store(item);
    }
    return collection;
}
Also used : POST(javax.ws.rs.POST) GET(javax.ws.rs.GET) PUT(javax.ws.rs.PUT) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 17 with PUT

use of javax.ws.rs.PUT in project OpenAttestation by OpenAttestation.

the class AssetTagCert method revokeAssetTagCertificate.

/**
     * This REST API would be called by tag provisioning service whenever a valid asset tag certificate is revoked.
     * @param atagObj
     * @return 
     */
//@RolesAllowed({"AssetTagManagement"})
//    @RequiresPermissions({"tag_certificates:store"})
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String revokeAssetTagCertificate(AssetTagCertRevokeRequest atagObj) {
    boolean result;
    AssetTagCertBO object = new AssetTagCertBO();
    result = object.revokeAssetTagCertificate(atagObj, null);
    return Boolean.toString(result);
}
Also used : AssetTagCertBO(com.intel.mtwilson.as.business.AssetTagCertBO) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 18 with PUT

use of javax.ws.rs.PUT in project jersey by jersey.

the class MultiPartResource method ten.

@Path("ten")
@PUT
@Consumes("multipart/mixed")
@Produces("text/plain")
public Response ten(MultiPart mp) {
    if (!(mp.getBodyParts().size() == 2)) {
        return Response.ok("FAILED:  Body part count is " + mp.getBodyParts().size() + " instead of 2").build();
    } else if (!(mp.getBodyParts().get(1).getEntity() instanceof BodyPartEntity)) {
        return Response.ok("FAILED:  Second body part is " + mp.getBodyParts().get(1).getClass().getName() + " instead of BodyPartEntity").build();
    }
    BodyPartEntity bpe = (BodyPartEntity) mp.getBodyParts().get(1).getEntity();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        InputStream stream = bpe.getInputStream();
        byte[] buffer = new byte[2048];
        while (true) {
            int n = stream.read(buffer);
            if (n < 0) {
                break;
            }
            baos.write(buffer, 0, n);
        }
        if (baos.toByteArray().length > 0) {
            return Response.ok("FAILED:  Second body part had " + baos.toByteArray().length + " bytes instead of 0").build();
        }
        return Response.ok("SUCCESS:  All tests passed").build();
    } catch (IOException e) {
        return Response.ok("FAILED:  Threw IOException").build();
    }
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BodyPartEntity(org.glassfish.jersey.media.multipart.BodyPartEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 19 with PUT

use of javax.ws.rs.PUT in project jersey by jersey.

the class BookmarkResource method putBookmark.

@PUT
@Consumes("application/json")
public void putBookmark(JSONObject jsonEntity) throws JSONException {
    bookmarkEntity.setLdesc(jsonEntity.getString("ldesc"));
    bookmarkEntity.setSdesc(jsonEntity.getString("sdesc"));
    bookmarkEntity.setUpdated(new Date());
    TransactionManager.manage(utx, new Transactional(em) {

        public void transact() {
            em.merge(bookmarkEntity);
        }
    });
}
Also used : Date(java.util.Date) Transactional(org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 20 with PUT

use of javax.ws.rs.PUT in project jersey by jersey.

the class MessageStreamResource method putMessage.

/**
     * Put a new message to the stream.
     *
     * The message will be broadcast to all registered SSE clients.
     *
     * @param message message to be broadcast.
     */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public void putMessage(final Message message) {
    LOGGER.info("--> Message received.");
    final OutboundEvent event = new OutboundEvent.Builder().id(String.valueOf(nextMessageId.getAndIncrement())).mediaType(MediaType.APPLICATION_JSON_TYPE).data(Message.class, message).build();
    broadcaster.broadcast(event);
}
Also used : OutboundEvent(org.glassfish.jersey.media.sse.OutboundEvent) Consumes(javax.ws.rs.Consumes) 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