public static List<SwaggerOperation> documentOperations(SwaggerModel models, Method method) { List<SwaggerOperation> ops = new ArrayList<SwaggerOperation>(); Annotation[] annotations = method.getAnnotations(); if (annotationPresent(GET.class, annotations)) { ops.add(createOperation(models, GET, method, annotations)); } if (annotationPresent(PUT.class, annotations)) { ops.add(createOperation(models, PUT, method, annotations)); } if (annotationPresent(POST.class, annotations)) { ops.add(createOperation(models, POST, method, annotations)); } if (annotationPresent(DELETE.class, annotations)) { ops.add(createOperation(models, DELETE, method, annotations)); } if (annotationPresent(HEAD.class, annotations)) { ops.add(createOperation(models, HEAD, method, annotations)); } if (annotationPresent(OPTIONS.class, annotations)) { ops.add(createOperation(models, OPTIONS, method, annotations)); } return ops; }
private String verb(Method m) { if (m.getAnnotation(DELETE.class) != null) { return "DELETE "; } else if (m.getAnnotation(GET.class) != null) { return "GET "; } else if (m.getAnnotation(HEAD.class) != null) { return "HEAD "; } else if (m.getAnnotation(OPTIONS.class) != null) { return "OPTIONS "; } else if (m.getAnnotation(POST.class) != null) { return "POST "; } else if (m.getAnnotation(PUT.class) != null) { return "PUT "; } else { return null; } }
@HEAD @Path("/assets") public Response countAssets(@Context UriInfo info, @Context SecurityContext sc) throws InvalidParameterException { if (logger.isLoggable(Level.FINE)) { logger.fine("countAssets called with query parameters: " + info.getRequestUri().getRawQuery()); } AssetQueryParameters params = AssetQueryParameters.create(info); Collection<AssetFilter> filters = params.getFilters(); if (!sc.isUserInRole(ADMIN_ROLE)) { filters.add(ASSET_IS_PUBLISHED); } int count = assetService.countAllAssets(filters, params.getSearchTerm()); return Response.noContent().header("count", count).build(); }
public static String getHttpMethod(Method method){ if (method.getAnnotation(GET.class)!=null){ return HttpMethod.GET; } if (method.getAnnotation(POST.class)!=null){ return HttpMethod.POST; } if (method.getAnnotation(DELETE.class)!=null){ return HttpMethod.DELETE; } if (method.getAnnotation(PUT.class)!=null){ return HttpMethod.PUT; } if (method.getAnnotation(OPTIONS.class)!=null){ return HttpMethod.OPTIONS; } if (method.getAnnotation(HEAD.class)!=null){ return HttpMethod.HEAD; } return null; }
@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(); }
private HTTPMethod getHttpMethod(Method m) { if (m.isAnnotationPresent(GET.class)) { return HTTPMethod.GET; } if (m.isAnnotationPresent(POST.class)) { return HTTPMethod.POST; } if (m.isAnnotationPresent(PUT.class)) { return HTTPMethod.PUT; } if (m.isAnnotationPresent(DELETE.class)) { return HTTPMethod.DELETE; } if (m.isAnnotationPresent(HEAD.class)) { return HTTPMethod.HEAD; } return HTTPMethod.OPTIONS; }
/** * add value of the HTTPMethod to the jaxrs-method model. axis2 only supports POST,GET,PUT,DELETE. * it doesnt support HEAD. if HEAD is given it resolves to the default method (POST) * @param annotation * @param methodModel */ private static void addHTTPMethodToMethodModel(Annotation annotation,JAXRSModel methodModel){ if (annotation instanceof POST) { methodModel.setHTTPMethod(Constants.Configuration.HTTP_METHOD_POST); } else if (annotation instanceof GET) { methodModel.setHTTPMethod(Constants.Configuration.HTTP_METHOD_GET); } else if (annotation instanceof PUT) { methodModel.setHTTPMethod(Constants.Configuration.HTTP_METHOD_PUT); } else if (annotation instanceof DELETE) { methodModel.setHTTPMethod(Constants.Configuration.HTTP_METHOD_DELETE); } else if (annotation instanceof HEAD) { log.warn("HTTP Method HEAD is not supported by AXIS2"); } }
/** * LDP 1.0 - 4.2.6.1 LDP servers must support the HTTP HEAD method. * @param uriInfo the full URL details of the resource * @param path the path of the resource * @param headers the headers included in the request * @param request the request itself * @return an LDP compliant response to the HEAD request */ @HEAD @Path(ENDPOINT_PATH) public Response head( @Context UriInfo uriInfo, @PathParam(ENDPOINT_PATH_PARAM) String path, @Context HttpHeaders headers, @Context Request request) { OperationContext context = newOperationBuilder(HttpMethod.HEAD). withEndpointPath(path). withUriInfo(uriInfo). withHeaders(headers). withRequest(request). build(); return EndpointControllerFactory. newController(). head(context); }
@HEAD @Path("/repository/{repo}") public Response repositoryExists(@HeaderParam(HttpHeaders.AUTHORIZATION) final String authorization, @NotNull @PathParam("repo") String repository) { Identity identity = identities.getGitHubIdentity(authorization); GitHubService gitHubService = gitHubServiceFactory.create(identity); if (gitHubService.repositoryExists(gitHubService.getLoggedUser().getLogin() + "/" + repository)) { return Response.ok().build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } }
@HEAD @Path("/project/{project}") public Response openShiftProjectExists(@HeaderParam(HttpHeaders.AUTHORIZATION) final String authorization, @NotNull @PathParam("project") String project, @QueryParam("cluster") String cluster) { Identity identity = identities.getOpenShiftIdentity(authorization, cluster); OpenShiftCluster openShiftCluster = clusterRegistry.findClusterById(cluster) .orElseThrow(() -> new IllegalStateException("Cluster not found")); OpenShiftService openShiftService = openShiftServiceFactory.create(openShiftCluster, identity); if (openShiftService.projectExists(project)) { return Response.ok().build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } }
@HEAD @Path("/token/openshift") public Response openShiftTokenExists(@HeaderParam(HttpHeaders.AUTHORIZATION) final String authorization, @QueryParam("cluster") String cluster) { Identity identity = identities.getOpenShiftIdentity(authorization, cluster); boolean tokenExists = (identity != null); if (tokenExists) { return Response.ok().build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } }
@HEAD @Path("/token/github") public Response gitHubTokenExists(@HeaderParam(HttpHeaders.AUTHORIZATION) final String authorization) { Identity identity = identities.getGitHubIdentity(authorization); boolean tokenExists = (identity != null); if (tokenExists) { return Response.ok().build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } }
/** * Retrieve the resource headers * * @return response */ @HEAD @Produces({TURTLE_WITH_CHARSET + ";qs=1.0", JSON_LD + ";qs=0.8", N3_WITH_CHARSET, N3_ALT2_WITH_CHARSET, RDF_XML, NTRIPLES, TEXT_PLAIN_WITH_CHARSET, TURTLE_X, TEXT_HTML_WITH_CHARSET}) public Response head() throws UnsupportedAlgorithmException { LOGGER.info("HEAD for: {}", externalPath); final URI internalUri = createFromPath(externalPath); final Container container = getContainerService().find(internalUri); if (container == null) { if (!isRoot(internalUri)) { return Response.status(Response.Status.NOT_FOUND).build(); } } return ok().build(); }
@HEAD @Produces( { MediaType.APPLICATION_JSON, "application/javascript", MediaType.APPLICATION_XML }) public Response existsZNode(@PathParam("path") String path, @Context UriInfo ui) throws InterruptedException, KeeperException { Stat stat = zk.exists(path, false); if (stat == null) { throwNotFound(path, ui); } return Response.status(Response.Status.OK).build(); }
@HEAD @Produces( { MediaType.APPLICATION_OCTET_STREAM }) public Response existsZNodeAsOctet(@PathParam("path") String path, @Context UriInfo ui) throws InterruptedException, KeeperException { Stat stat = zk.exists(path, false); if (stat == null) { throwNotFound(path, ui); } return Response.status(Response.Status.NO_CONTENT).build(); }
@HEAD @Path("/{uuid}/{version}/file/{path:(.*)}") @ApiOperation(value = "Get file metadata") @Produces(MediaType.WILDCARD) public Response headFile(@Context HttpHeaders headers, // @formatter:off @ApiParam(APIDOC_ITEMUUID) @PathParam("uuid") String uuid, @ApiParam(APIDOC_ITEMVERSION) @PathParam("version") int version, @ApiParam("File path") @PathParam("path") String path);
@HEAD @Produces({ MediaType.APPLICATION_JSON }) @Path("{listEntryId}/ecrfpdf/{ecrfId}") public ECRFPDFVO renderEcrfHead(@PathParam("listEntryId") Long listEntryId, @PathParam("ecrfId") Long ecrfId, @QueryParam("blank") Boolean blank) throws AuthenticationException, AuthorisationException, ServiceException { ECRFPDFVO result = WebUtil.getServiceLocator().getTrialService().renderEcrf(auth, ecrfId, null, listEntryId, blank); result.setDocumentDatas(null); return result; }
@HEAD @Produces({ MediaType.APPLICATION_JSON }) @Path("{listEntryId}/ecrfpdf") public ECRFPDFVO renderEcrfsHead(@PathParam("listEntryId") Long listEntryId, @QueryParam("blank") Boolean blank) throws AuthenticationException, AuthorisationException, ServiceException { ECRFPDFVO result = WebUtil.getServiceLocator().getTrialService().renderEcrfs(auth, null, listEntryId, null, blank); result.setDocumentDatas(null); return result; }
@HEAD @Produces({ MediaType.APPLICATION_JSON }) @Path("{id}/probandletterpdf") public ProbandLetterPDFVO renderProbandLetterPDFHead(@PathParam("id") Long id) throws AuthenticationException, AuthorisationException, ServiceException { ProbandLetterPDFVO result = WebUtil.getServiceLocator().getProbandService().renderProbandLetterPDF(auth, id); result.setDocumentDatas(null); return result; }
@Override public Request controllerRequestMapping() { if (controllerClass.isAnnotationPresent(Request.class) || controllerClass.isAnnotationPresent(Path.class) || controllerClass.isAnnotationPresent(GET.class) || controllerClass.isAnnotationPresent(POST.class) || controllerClass.isAnnotationPresent(PUT.class) || controllerClass.isAnnotationPresent(DELETE.class) || controllerClass.isAnnotationPresent(HEAD.class) || controllerClass.isAnnotationPresent(OPTIONS.class)) { return injector.getInstance(Annotations.class).requestMapping(controllerClass); } return null; }
@Override public Request handlerRequestMapping() { if (method.isAnnotationPresent(Request.class) || method.isAnnotationPresent(Path.class) || method.isAnnotationPresent(GET.class) || method.isAnnotationPresent(POST.class) || method.isAnnotationPresent(PUT.class) || method.isAnnotationPresent(DELETE.class) || method.isAnnotationPresent(HEAD.class) || method.isAnnotationPresent(OPTIONS.class)) { return injector.getInstance(Annotations.class).requestMapping(method); } return null; }
protected Request requestMapping(Class<?> controllerClass) { if (controllerClass.isAnnotationPresent(Request.class)) { return controllerClass.getAnnotation(Request.class); } else if (controllerClass.isAnnotationPresent(Path.class) || controllerClass.isAnnotationPresent(GET.class) || controllerClass.isAnnotationPresent(POST.class) || controllerClass.isAnnotationPresent(PUT.class) || controllerClass.isAnnotationPresent(DELETE.class) || controllerClass.isAnnotationPresent(HEAD.class) || controllerClass.isAnnotationPresent(OPTIONS.class)) { return injector.getInstance(Annotations.class).requestMapping(controllerClass); } return null; }
protected Request requestMapping(Method method) { if (method.isAnnotationPresent(Request.class)) { return method.getAnnotation(Request.class); } else if (method.isAnnotationPresent(Path.class) || method.isAnnotationPresent(GET.class) || method.isAnnotationPresent(POST.class) || method.isAnnotationPresent(PUT.class) || method.isAnnotationPresent(DELETE.class) || method.isAnnotationPresent(HEAD.class) || method.isAnnotationPresent(OPTIONS.class)) { return injector.getInstance(Annotations.class).requestMapping(method); } return null; }
/** * Simple HEAD method to check whether a particular pid is registered. * * @param identifier * an identifier string * @return either 200 or 404, indicating whether the PID is registered or * not registered * @throws IOException */ @HEAD @Path("/pid/{identifier}") @ApiOperation(value = "Identifier registered?", notes = "Check to see if identifier is registered") @ApiResponses(value = { @ApiResponse(code = 200, message = "Found"), @ApiResponse(code = 404, message = "Not found") }) public Response isPidRegistered(@PathParam("identifier") String identifier) throws IOException { boolean b = typingService.isIdentifierRegistered(identifier); if (b) return Response.status(200).build(); else return Response.status(404).build(); }
/** * Similar to {@link #isPidRegistered(String)} but supports native slashes * in the identifier path. * * @see #isPidRegistered(String) */ @HEAD @Path("/pid/{prefix}/{suffix}") @ApiOperation(value = "Identifier registered?", notes = "Check to see if identifier is registered") @ApiResponses(value = { @ApiResponse(code = 200, message = "Found"), @ApiResponse(code = 404, message = "Not found") }) public Response isPidRegistered(@PathParam("prefix") String prefix, @PathParam("suffix") String suffix) throws IOException { return isPidRegistered(prefix + "/" + suffix); }
@HEAD @Path("test:table/blob1") public Response getBlobMetadata(@HeaderParam("X-BV-API-Key") String apiKey) { assertEquals(apiKey, API_KEY); return Response.ok() .type(MediaType.APPLICATION_OCTET_STREAM) .header(HttpHeaders.CONTENT_LENGTH, 12) .header(HttpHeaders.ETAG, "etag") .header("X-BV-Length", 12) .header("X-BVA-size", "medium") .lastModified(new Date(1444937753000L)) .build(); }
/** * Retrieve metainformation about the entity implied by the request. * curl -i -X HEAD http://localhost:9090/stockquote/IBM * * @return Response */ @HEAD @Path("/{symbol}") @Produces({"application/json", "text/xml"}) @ApiOperation( value = "Returns headers of corresponding GET request ", notes = "Returns metainformation contained in the HTTP header identical to the corresponding GET Request") public Response getMetaInformationForQuote(@ApiParam(value = "Symbol", required = true) @PathParam("symbol") String symbol) throws SymbolNotFoundException { Stock stock = stockQuotes.get(symbol); if (stock == null) { throw new SymbolNotFoundException(); } return Response.ok().build(); }
@HEAD @Path("/repository/{repo}") public Response repositoryExists(@HeaderParam(HttpHeaders.AUTHORIZATION) final String authorization, @NotNull @PathParam("repo") String repository) { Identity githubIdentity = getGitHubIdentity(authorization); GitHubService gitHubService = gitHubServiceFactory.create(githubIdentity); if (gitHubService.repositoryExists(gitHubService.getLoggedUser().getLogin() + "/" + repository)) { return Response.ok().build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } }
@HEAD @Path("/project/{project}") public Response projectExists(@HeaderParam(HttpHeaders.AUTHORIZATION) final String authorization, @NotNull @PathParam("project") String project, @QueryParam("cluster") String cluster) { Identity openShiftIdentity = getOpenShiftIdentity(authorization, cluster); Optional<OpenShiftCluster> openShiftCluster = clusterRegistry.findClusterById(cluster); assert openShiftCluster.isPresent() : "Cluster not found: " + cluster; OpenShiftService openShiftService = openShiftServiceFactory.create(openShiftCluster.get(), openShiftIdentity); if (openShiftService.projectExists(project)) { return Response.ok().build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } }
@HEAD @Path("/token/openshift") public Response openShiftTokenExists(@HeaderParam(HttpHeaders.AUTHORIZATION) final String authorization, @QueryParam("cluster") String cluster) { boolean tokenExists; try { tokenExists = getOpenShiftIdentity(authorization, cluster) != null; } catch (IllegalArgumentException | IllegalStateException e) { tokenExists = false; } if (tokenExists) { return Response.ok().build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } }