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

The following examples show how to use javax.ws.rs.core.Response#created() . 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: SitemapResource.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates a subscription for the stream of sitemap events.
 *
 * @return a subscription id
 */
@POST
@Path(SEGMENT_EVENTS + "/subscribe")
@ApiOperation(value = "Creates a sitemap event subscription.")
@ApiResponses(value = { @ApiResponse(code = 201, message = "Subscription created."),
        @ApiResponse(code = 503, message = "Subscriptions limit reached.") })
public Object createEventSubscription() {
    String subscriptionId = subscriptions.createSubscription(this);
    if (subscriptionId == null) {
        return JSONResponse.createResponse(Status.SERVICE_UNAVAILABLE, null,
                "Max number of subscriptions is reached.");
    }
    final EventOutput eventOutput = new SitemapEventOutput(subscriptions, subscriptionId);
    broadcaster.add(eventOutput);
    eventOutputs.put(subscriptionId, eventOutput);
    URI uri = uriInfo.getBaseUriBuilder().path(PATH_SITEMAPS).path(SEGMENT_EVENTS).path(subscriptionId).build();
    logger.debug("Client from IP {} requested new subscription => got id {}.", request.getRemoteAddr(),
            subscriptionId);
    return Response.created(uri);
}
 
Example 2
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 3
Source File: ConsumersResource.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@POST
public Response createSubscription(@FormParam("autoAck") @DefaultValue("true") boolean autoAck,
                                   @FormParam("selector") String selector,
                                   @Context UriInfo uriInfo) {
   ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");

   try {
      QueueConsumer consumer = null;
      int attributes = 0;
      if (selector != null) {
         attributes = attributes | SELECTOR_SET;
      }

      if (autoAck) {
         consumer = createConsumer(selector);
      } else {
         attributes |= ACKNOWLEDGED;
         consumer = createAcknowledgedConsumer(selector);
      }

      String attributesSegment = "attributes-" + attributes;
      UriBuilder location = uriInfo.getAbsolutePathBuilder();
      location.path(attributesSegment);
      location.path(consumer.getId());
      Response.ResponseBuilder builder = Response.created(location.build());

      if (autoAck) {
         QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/" + attributesSegment + "/" + consumer.getId(), "-1");
      } else {
         AcknowledgedQueueConsumer.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/" + attributesSegment + "/" + consumer.getId(), "-1");

      }
      return builder.build();

   } catch (ActiveMQException e) {
      throw new RuntimeException(e);
   } finally {
   }
}
 
Example 4
Source File: MatchService.java    From render with GNU General Public License v2.0 5 votes vote down vote up
@Path("v1/owner/{owner}/matchCollection/{matchCollection}/matches")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Save a set of matches",
        notes = "Inserts or updates matches for the specified collection.")
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "matches successfully saved"),
        @ApiResponse(code = 400, message = "If no matches are provided")
})
public Response saveMatches(@PathParam("owner") final String owner,
                            @PathParam("matchCollection") final String matchCollection,
                            @Context final UriInfo uriInfo,
                            final List<CanvasMatches> canvasMatchesList) {

    LOG.info("saveMatches: entry, owner={}, matchCollection={}",
             owner, matchCollection);

    final MatchCollectionId collectionId = getCollectionId(owner, matchCollection);

    if (canvasMatchesList == null) {
        throw new IllegalServiceArgumentException("no matches provided");
    }

    try {
        matchDao.saveMatches(collectionId, canvasMatchesList);
    } catch (final Throwable t) {
        RenderServiceUtil.throwServiceException(t);
    }

    final Response.ResponseBuilder responseBuilder = Response.created(uriInfo.getRequestUri());

    LOG.info("saveMatches: exit");

    return responseBuilder.build();
}
 
Example 5
Source File: MatchService.java    From render with GNU General Public License v2.0 5 votes vote down vote up
@Path("v1/owner/{owner}/matchCollection/{matchCollection}/pGroup/{pGroupId}/matchCounts")
@PUT
@ApiOperation(
        value = "Update match counts for all pairs with specified pGroup")
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "match counts successfully updated"),
        @ApiResponse(code = 404, message = "Match collection not found")
})
public Response updateMatchCountsForPGroup(@PathParam("owner") final String owner,
                                           @PathParam("matchCollection") final String matchCollection,
                                           @PathParam("pGroupId") final String pGroupId,
                                           @Context final UriInfo uriInfo) {

    LOG.info("updateMatchCountsForPGroup: entry, owner={}, matchCollection={}, pGroupId={}",
             owner, matchCollection, pGroupId);

    final MatchCollectionId collectionId = getCollectionId(owner, matchCollection);
    try {
        matchDao.updateMatchCountsForPGroup(collectionId, pGroupId);
    } catch (final Throwable t) {
        RenderServiceUtil.throwServiceException(t);
    }

    final Response.ResponseBuilder responseBuilder = Response.created(uriInfo.getRequestUri());

    LOG.info("updateMatchCountsForPGroup: exit, pGroupId={}", pGroupId);

    return responseBuilder.build();
}
 
Example 6
Source File: StackMetaDataService.java    From render with GNU General Public License v2.0 4 votes vote down vote up
@Path("v1/owner/{owner}/project/{fromProject}/stack/{fromStack}/cloneTo/{toStack}")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
        tags = {"Stack Data APIs"},
        value = "Clones one stack to another",
        notes = "This operation copies all fromStack tiles and transformations to a new stack with the specified metadata.  This is a potentially long running operation (depending upon the size of the fromStack).")
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "stack successfully cloned"),
        @ApiResponse(code = 400, message = "toStack is not in LOADING state"),
        @ApiResponse(code = 404, message = "fromStack not found")
})
public Response cloneStackVersion(@PathParam("owner") final String owner,
                                  @PathParam("fromProject") final String fromProject,
                                  @PathParam("fromStack") final String fromStack,
                                  @PathParam("toStack") final String toStack,
                                  @QueryParam("z") final List<Double> zValues,
                                  @QueryParam("toProject") String toProject,
                                  @QueryParam("skipTransforms") final Boolean skipTransforms,
                                  @Context final UriInfo uriInfo,
                                  final StackVersion stackVersion) {

    LOG.info("cloneStackVersion: entry, owner={}, fromProject={}, fromStack={}, toProject={}, toStack={}, zValues={}, stackVersion={}",
             owner, fromProject, fromStack, toProject, toStack, zValues, stackVersion);

    try {
        if (stackVersion == null) {
            throw new IllegalArgumentException("no stack version provided");
        }

        if (toProject == null) {
            toProject = fromProject;
        }

        final StackMetaData fromStackMetaData = getStackMetaData(owner, fromProject, fromStack);
        final StackId toStackId = new StackId(owner, toProject, toStack);

        StackMetaData toStackMetaData = renderDao.getStackMetaData(toStackId);

        if ((toStackMetaData != null) && (! toStackMetaData.isLoading())) {
            throw new IllegalStateException("Tiles cannot be cloned to stack " + toStack +
                                            " because it is " + toStackMetaData.getState() + ".");
        }

        renderDao.cloneStack(fromStackMetaData.getStackId(), toStackId, zValues, skipTransforms);

        toStackMetaData = new StackMetaData(toStackId, stackVersion);
        renderDao.saveStackMetaData(toStackMetaData);

        LOG.info("cloneStackVersion: created {} from {}", toStackId, fromStackMetaData.getStackId());

    } catch (final Throwable t) {
        RenderServiceUtil.throwServiceException(t);
    }

    final Response.ResponseBuilder responseBuilder = Response.created(uriInfo.getRequestUri());

    return responseBuilder.build();
}
 
Example 7
Source File: StackMetaDataService.java    From render with GNU General Public License v2.0 4 votes vote down vote up
@Path("v1/owner/{owner}/project/{project}/stack/{stack}")
@POST  // NOTE: POST method is used because version number is auto-incremented
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
        tags = {"Stack Data APIs"},
        value = "Saves new version of stack metadata")
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "stackVersion successfully created"),
        @ApiResponse(code = 400, message = "stackVersion not specified or stack is READ_ONLY")
})
public Response saveStackVersion(@PathParam("owner") final String owner,
                                 @PathParam("project") final String project,
                                 @PathParam("stack") final String stack,
                                 @Context final UriInfo uriInfo,
                                 final StackVersion stackVersion) {

    LOG.info("saveStackVersion: entry, owner={}, project={}, stack={}, stackVersion={}",
             owner, project, stack, stackVersion);

    try {
        if (stackVersion == null) {
            throw new IllegalArgumentException("no stack version provided");
        }

        final StackId stackId = new StackId(owner, project, stack);

        StackMetaData stackMetaData = renderDao.getStackMetaData(stackId);
        if (stackMetaData == null) {
            stackMetaData = new StackMetaData(stackId, stackVersion);
        } else {
            validateStackIsModifiable(stackMetaData);
            stackMetaData = stackMetaData.getNextVersion(stackVersion);
        }

        renderDao.saveStackMetaData(stackMetaData);

        LOG.info("saveStackVersion: saved version number {}", stackMetaData.getCurrentVersionNumber());

    } catch (final Throwable t) {
        RenderServiceUtil.throwServiceException(t);
    }

    final Response.ResponseBuilder responseBuilder = Response.created(uriInfo.getRequestUri());

    return responseBuilder.build();
}
 
Example 8
Source File: StackMetaDataService.java    From render with GNU General Public License v2.0 4 votes vote down vote up
@Path("v1/owner/{owner}/project/{project}/stack/{stack}/state/{state}")
@PUT
@ApiOperation(
        tags = {"Stack Data APIs"},
        value = "Sets the stack's current state",
        notes = "Normal progression is LOADING to COMPLETE to READ_ONLY to OFFLINE.  " +
                "Transitioning to COMPLETE is a potentially long running operation " +
                "since it creates indexes and aggregates meta data.  " +
                "Transitioning to OFFLINE assumes that the stack data has been persisted elsewhere " +
                "(e.g. a database dump file) and will remove the stack tile and transform collections, " +
                "so BE CAREFUL when transitioning to OFFLINE!")
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "state successfully changed"),
        @ApiResponse(code = 400, message = "stack state cannot be changed because of current state"),
        @ApiResponse(code = 404, message = "stack not found"),
})
public Response setStackState(@PathParam("owner") final String owner,
                              @PathParam("project") final String project,
                              @PathParam("stack") final String stack,
                              @PathParam("state") final StackState state,
                              @Context final UriInfo uriInfo) {

    LOG.info("setStackState: entry, owner={}, project={}, stack={}, state={}",
             owner, project, stack, state);

    try {
        final StackMetaData stackMetaData = getStackMetaData(owner, project, stack);
        final StackState currentState = stackMetaData.getState();

        stackMetaData.validateStateChange(state);

        if (COMPLETE.equals(state)) {

            if (READ_ONLY.equals(currentState)) {
                stackMetaData.setState(state);
                renderDao.saveStackMetaData(stackMetaData);
            } else {
                renderDao.ensureIndexesAndDeriveStats(stackMetaData); // also sets state to COMPLETE
            }

        } else if (OFFLINE.equals(state)) {

            stackMetaData.setState(state);
            renderDao.saveStackMetaData(stackMetaData);
            renderDao.removeStack(stackMetaData.getStackId(), false);

        } else { // LOADING

            stackMetaData.setState(state);
            renderDao.saveStackMetaData(stackMetaData);
        }

    } catch (final Throwable t) {
        RenderServiceUtil.throwServiceException(t);
    }

    final Response.ResponseBuilder responseBuilder = Response.created(uriInfo.getRequestUri());

    return responseBuilder.build();
}
 
Example 9
Source File: RenderDataService.java    From render with GNU General Public License v2.0 4 votes vote down vote up
@Path("v1/owner/{owner}/project/{project}/stack/{stack}/z/{z}/tileIds")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
        tags = "Section Data APIs",
        value = "Set z value for specified tiles (e.g. to split a layer)")
@ApiResponses(value = {
        @ApiResponse(code = 400, message = "stack not in LOADING state"),
        @ApiResponse(code = 404, message = "stack not found"),
})
public Response updateZForTiles(@PathParam("owner") final String owner,
                                @PathParam("project") final String project,
                                @PathParam("stack") final String stack,
                                @PathParam("z") final Double z,
                                @Context final UriInfo uriInfo,
                                final List<String> tileIds) {
    LOG.info("updateZForTiles: entry, owner={}, project={}, stack={}, z={}",
             owner, project, stack, z);

    try {
        final StackId stackId = new StackId(owner, project, stack);
        final StackMetaData stackMetaData = getStackMetaData(stackId);

        if (! stackMetaData.isLoading()) {
            throw new IllegalStateException("Z values can only be updated for stacks in the " +
                                            LOADING + " state, but this stack's state is " +
                                            stackMetaData.getState() + ".");
        }

        renderDao.updateZForTiles(stackId, z, tileIds);

    } catch (final Throwable t) {
        RenderServiceUtil.throwServiceException(t);
    }

    final Response.ResponseBuilder responseBuilder = Response.created(uriInfo.getRequestUri());

    LOG.info("updateZForTiles: exit");

    return responseBuilder.build();
}
 
Example 10
Source File: RenderDataService.java    From render with GNU General Public License v2.0 4 votes vote down vote up
@Path("v1/owner/{owner}/project/{project}/stack/{stack}/z/{z}/resolvedTiles")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
        tags = "Section Data APIs",
        value = "Save specified raw tile and transform specs for section")
@ApiResponses(value = {
        @ApiResponse(code = 400, message = "stack not in LOADING state, invalid data provided"),
        @ApiResponse(code = 404, message = "stack not found"),
})
public Response saveResolvedTilesForZ(@PathParam("owner") final String owner,
                                      @PathParam("project") final String project,
                                      @PathParam("stack") final String stack,
                                      @PathParam("z") final Double z,
                                      @QueryParam("deriveData") final Boolean deriveData,
                                      @Context final UriInfo uriInfo,
                                      final ResolvedTileSpecCollection resolvedTiles) {

    LOG.info("saveResolvedTilesForZ: entry, owner={}, project={}, stack={}, z={}",
             owner, project, stack, z);

    try {
        if (resolvedTiles == null) {
            throw new IllegalServiceArgumentException("no resolved tiles provided");
        }

        final StackId stackId = new StackId(owner, project, stack);
        final StackMetaData stackMetaData = getStackMetaData(stackId);

        if (! stackMetaData.isLoading()) {
            throw new IllegalStateException("Resolved tiles can only be saved to stacks in the " +
                                            LOADING + " state, but this stack's state is " +
                                            stackMetaData.getState() + ".");
        }

        if ((deriveData != null) && deriveData) {
            final ProcessTimer timer = new ProcessTimer();
            int tileSpecCount = 0;
            final Collection<TileSpec> tileSpecs = resolvedTiles.getTileSpecs();
            for (final TileSpec tileSpec : tileSpecs) {
                tileSpecCount++;
                tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true);

                if (timer.hasIntervalPassed()) {
                    LOG.info("saveResolvedTilesForZ: derived bounding box for {} out of {} tiles",
                             tileSpecCount, tileSpecs.size());
                }
            }

            LOG.info("saveResolvedTilesForZ: derived bounding box for {} tiles, elapsedSeconds={}",
                     tileSpecCount, timer.getElapsedSeconds());
        }

        resolvedTiles.validateCollection(z);

        renderDao.saveResolvedTiles(stackId, resolvedTiles);

    } catch (final Throwable t) {
        RenderServiceUtil.throwServiceException(t);
    }

    final Response.ResponseBuilder responseBuilder = Response.created(uriInfo.getRequestUri());

    LOG.info("saveResolvedTilesForZ: exit");

    return responseBuilder.build();
}
 
Example 11
Source File: RenderDataService.java    From render with GNU General Public License v2.0 4 votes vote down vote up
@Path("v1/owner/{owner}/project/{project}/stack/{stack}/section/{sectionId}/z")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
        tags = "Section Data APIs",
        value = "Set z value for section")
@ApiResponses(value = {
        @ApiResponse(code = 400, message = "stack not in LOADING state"),
        @ApiResponse(code = 404, message = "stack not found")
})
public Response updateZForSection(@PathParam("owner") final String owner,
                                  @PathParam("project") final String project,
                                  @PathParam("stack") final String stack,
                                  @PathParam("sectionId") final String sectionId,
                                  @Context final UriInfo uriInfo,
                                  final Double z) {
    LOG.info("updateZForSection: entry, owner={}, project={}, stack={}, sectionId={}, z={}",
             owner, project, stack, sectionId, z);

    try {
        final StackId stackId = new StackId(owner, project, stack);
        final StackMetaData stackMetaData = getStackMetaData(stackId);

        if (! stackMetaData.isLoading()) {
            throw new IllegalStateException("Z values can only be updated for stacks in the " +
                                            LOADING + " state, but this stack's state is " +
                                            stackMetaData.getState() + ".");
        }

        renderDao.updateZForSection(stackId, sectionId, z);

    } catch (final Throwable t) {
        RenderServiceUtil.throwServiceException(t);
    }

    final Response.ResponseBuilder responseBuilder = Response.created(uriInfo.getRequestUri());

    LOG.info("updateZForSection: exit");

    return responseBuilder.build();
}