Java Code Examples for javax.ws.rs.core.Response#noContent()

The following examples show how to use javax.ws.rs.core.Response#noContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsumersResource.java    From activemq-artemis with Apache License 2.0 8 votes vote down vote up
@Path("attributes-{attributes}/{consumer-id}")
@HEAD
public Response headConsumer(@PathParam("attributes") int attributes,
                             @PathParam("consumer-id") String consumerId,
                             @Context UriInfo uriInfo) throws Exception {
   ActiveMQRestLogger.LOGGER.debug("Handling HEAD request for \"" + uriInfo.getPath() + "\"");

   QueueConsumer consumer = findConsumer(attributes, consumerId, uriInfo);
   Response.ResponseBuilder builder = Response.noContent();
   // we synchronize just in case a failed request is still processing
   synchronized (consumer) {
      if ((attributes & ACKNOWLEDGED) > 0) {
         AcknowledgedQueueConsumer ackedConsumer = (AcknowledgedQueueConsumer) consumer;
         Acknowledgement ack = ackedConsumer.getAck();
         if (ack == null || ack.wasSet()) {
            AcknowledgedQueueConsumer.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/attributes-" + attributes + "/" + consumer.getId(), Long.toString(consumer.getConsumeIndex()));
         } else {
            ackedConsumer.setAcknowledgementLink(builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/attributes-" + attributes + "/" + consumer.getId());
         }

      } else {
         QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/attributes-" + attributes + "/" + consumer.getId(), Long.toString(consumer.getConsumeIndex()));
      }
   }
   return builder.build();
}
 
Example 2
Source File: AbstractServiceImpl.java    From syncope with Apache License 2.0 7 votes vote down vote up
/**
 * Builds response to successful modification request, taking into account any {@code Prefer} header.
 *
 * @param entity the entity just modified
 * @return response to successful modification request
 */
protected Response modificationResponse(final Object entity) {
    Response.ResponseBuilder builder;
    switch (getPreference()) {
        case RETURN_NO_CONTENT:
            builder = Response.noContent();
            break;

        case RETURN_CONTENT:
        case NONE:
        default:
            builder = Response.ok(entity);
            break;
    }
    if (getPreference() == Preference.RETURN_CONTENT || getPreference() == Preference.RETURN_NO_CONTENT) {
        builder.header(RESTHeaders.PREFERENCE_APPLIED, getPreference().toString());
    }

    return builder.build();
}
 
Example 3
Source File: Invoker.java    From greenbeans with Apache License 2.0 6 votes vote down vote up
public WebResponse invoke(WebRequest request, MatchResult match, Handler handler) {
	try {
		Map<String, Object> parameters = createParameters(request, match, handler);
		Object value = handler.invoke(parameters);
		ResponseBuilder builder = value == null ? Response.noContent() : Response.ok(value);
		return toWebResponse(builder.build());
	} catch (Exception e) {
		logInvocationException(e);
		return toWebResponse(e);
	}
}
 
Example 4
Source File: CustomerResource.java    From resteasy-examples with Apache License 2.0 5 votes vote down vote up
@Path("{id}")
@PUT
@Consumes("application/xml")
public Response updateCustomer(@PathParam("id") int id,
                               @Context Request request,
                               Customer update)
{
   Customer cust = customerDB.get(id);
   if (cust == null) throw new WebApplicationException(Response.Status.NOT_FOUND);
   EntityTag tag = new EntityTag(Integer.toString(cust.hashCode()));

   Response.ResponseBuilder builder =
           request.evaluatePreconditions(tag);

   if (builder != null)
   {
      // Preconditions not met!
      return builder.build();
   }

   // Preconditions met, perform update

   cust.setFirstName(update.getFirstName());
   cust.setLastName(update.getLastName());
   cust.setStreet(update.getStreet());
   cust.setState(update.getState());
   cust.setZip(update.getZip());
   cust.setCountry(update.getCountry());


   builder = Response.noContent();
   return builder.build();
}
 
Example 5
Source File: TestClass19.java    From jaxrs-analyzer with Apache License 2.0 5 votes vote down vote up
@javax.ws.rs.GET public Response method() {
    Response.ResponseBuilder responseBuilder = Response.accepted();
    responseBuilder = Response.created(URI.create(""));
    responseBuilder = Response.noContent();
    responseBuilder = Response.notAcceptable(new LinkedList<>());
    responseBuilder = Response.notModified();
    responseBuilder = Response.ok();
    responseBuilder = Response.ok(1L, new Variant(MediaType.TEXT_PLAIN_TYPE, Locale.ENGLISH, "UTF-8"));
    responseBuilder = Response.seeOther(URI.create(""));
    responseBuilder = Response.serverError();
    responseBuilder = Response.temporaryRedirect(URI.create(""));

    return responseBuilder.build();
}
 
Example 6
Source File: SubscriptionsResource.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private Response internalHeadAutoAckSubscription(UriInfo uriInfo, String consumerId) {
   QueueConsumer consumer = findAutoAckSubscription(consumerId);
   Response.ResponseBuilder builder = Response.noContent();
   String pathToPullSubscriptions = uriInfo.getMatchedURIs().get(1);
   headAutoAckSubscriptionResponse(uriInfo, consumer, builder, pathToPullSubscriptions);

   return builder.build();
}
 
Example 7
Source File: MessageRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Response createResponse(List<MessageCorrelationResultDto> resultDtos, CorrelationMessageDto messageDto) {
  Response.ResponseBuilder response = Response.noContent();
  if (messageDto.isResultEnabled()) {
    response = Response.ok(resultDtos, MediaType.APPLICATION_JSON);
  }
  return response.build();
}
 
Example 8
Source File: ShowIbisstoreSummary.java    From iaf with Apache License 2.0 4 votes vote down vote up
@POST
@RolesAllowed({"IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester"})
@Path("/jdbc/summary")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response execute(LinkedHashMap<String, Object> json) throws ApiException {

	Response.ResponseBuilder response = Response.noContent(); //PUT defaults to no content

	String query = null;
	String datasource = null;

	for (Entry<String, Object> entry : json.entrySet()) {
		String key = entry.getKey();
		if(key.equalsIgnoreCase("datasource")) {
			datasource = entry.getValue().toString();
		}
		if(key.equalsIgnoreCase("query")) {
			query = entry.getValue().toString();
		}
	}

	if(datasource == null)
		return response.status(Response.Status.BAD_REQUEST).build();

	String result = "";
	try {
		IbisstoreSummaryQuerySender qs;
		qs = (IbisstoreSummaryQuerySender) getIbisContext().createBeanAutowireByName(IbisstoreSummaryQuerySender.class);
		qs.setSlotmap(getSlotmap());
		try {
			qs.setName("QuerySender");
			qs.setDatasourceName(datasource);
			qs.setQueryType("select");
			qs.setBlobSmartGet(true);
			qs.configure(true);
			qs.open();
			result = qs.sendMessage(new Message(query!=null?query:qs.getDbmsSupport().getIbisStoreSummaryQuery()), null).asString();
		} catch (Throwable t) {
			throw new ApiException("An error occured on executing jdbc query", t);
		} finally {
			qs.close();
		}
	} catch (Exception e) {
		throw new ApiException("An error occured on creating or closing the connection", e);
	}

	String resultObject = "{ \"result\":"+result+"}";
	
	return Response.status(Response.Status.CREATED).entity(resultObject).build();
}
 
Example 9
Source File: BaseAuthApi.java    From ezScrum with GNU General Public License v2.0 4 votes vote down vote up
protected Response response(int statusCode, String entity) {
	ResponseBuilder resBuilder = Response.noContent();
	resBuilder.status(200).entity(entity);
	return resBuilder.build();
}