javax.ws.rs.OPTIONS Java Examples

The following examples show how to use javax.ws.rs.OPTIONS. 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: AnnotationProcessor.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
private boolean isHttpMethodAvailable(Annotation[] annotations) {
    for (Annotation annotation : annotations) {
        if (annotation.annotationType().getName().equals(GET.class.getName())) {
            return true;
        } else if (annotation.annotationType().getName().equals(POST.class.getName())) {
            return true;
        } else if (annotation.annotationType().getName().equals(OPTIONS.class.getName())) {
            return true;
        } else if (annotation.annotationType().getName().equals(DELETE.class.getName())) {
            return true;
        } else if (annotation.annotationType().getName().equals(PUT.class.getName())) {
            return true;
        }
    }
    return false;
}
 
Example #2
Source File: DavCollectionResource.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * OPTIONSメソッド.
 * @return JAX-RS Response
 */
@OPTIONS
public Response options() {
    // アクセス制御
    this.davRsCmp.checkAccessContext(this.davRsCmp.getAccessContext(), BoxPrivilege.READ);

    return DcCoreUtils.responseBuilderForOptions(
            HttpMethod.GET,
            HttpMethod.PUT,
            HttpMethod.DELETE,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MKCOL,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MOVE,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPFIND,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPPATCH,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.ACL
            ).build();
}
 
Example #3
Source File: AnnotationProcessor.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
/**
 * Read Method annotations indicating HTTP Methods
 *
 * @param resource
 * @param annotation
 */
private void processHTTPMethodAnnotation(APIResource resource, Annotation annotation) {
    if (annotation.annotationType().getName().equals(GET.class.getName())) {
        resource.setHttpVerb(HttpMethod.GET);
    }
    if (annotation.annotationType().getName().equals(POST.class.getName())) {
        resource.setHttpVerb(HttpMethod.POST);
    }
    if (annotation.annotationType().getName().equals(OPTIONS.class.getName())) {
        resource.setHttpVerb(HttpMethod.OPTIONS);
    }
    if (annotation.annotationType().getName().equals(DELETE.class.getName())) {
        resource.setHttpVerb(HttpMethod.DELETE);
    }
    if (annotation.annotationType().getName().equals(PUT.class.getName())) {
        resource.setHttpVerb(HttpMethod.PUT);
    }
}
 
Example #4
Source File: AnnotationProcessor.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
private boolean isHttpMethodAvailable(Annotation[] annotations) {
    for (Annotation annotation : annotations) {
        if (annotation.annotationType().getName().equals(GET.class.getName())) {
            return true;
        } else if (annotation.annotationType().getName().equals(POST.class.getName())) {
            return true;
        } else if (annotation.annotationType().getName().equals(OPTIONS.class.getName())) {
            return true;
        } else if (annotation.annotationType().getName().equals(DELETE.class.getName())) {
            return true;
        } else if (annotation.annotationType().getName().equals(PUT.class.getName())) {
            return true;
        }
    }
    return false;
}
 
Example #5
Source File: DavRsCmp.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * OPTIONSメソッド.
 * @return JAX-RS Response
 */
@OPTIONS
public Response options() {
    // アクセス制御
    this.checkAccessContext(this.getAccessContext(), BoxPrivilege.READ);

    return DcCoreUtils.responseBuilderForOptions(
            HttpMethod.GET,
            HttpMethod.PUT,
            HttpMethod.DELETE,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MKCOL,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPFIND,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPPATCH,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.ACL
            ).build();
}
 
Example #6
Source File: RestRsRouteInitializer.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static void initHttpOptions(
        VxmsShared vxmsShared,
        Router router,
        Object service,
        Method restMethod,
        Path path,
        Stream<Method> errorMethodStream,
        Optional<Consumes> consumes) {
    final Route route = router.options(URIUtil.cleanPath(path.value()));
    final Context context = getContext(vxmsShared);
    final String methodId =
            path.value()
                    + OPTIONS.class.getName()
                    + ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
    initHttpOperation(
            methodId,
            vxmsShared,
            service,
            restMethod,
            route,
            errorMethodStream,
            consumes,
            OPTIONS.class);
}
 
Example #7
Source File: CorsFilterIntTest.java    From jrestless with Apache License 2.0 6 votes vote down vote up
@Override
protected Application configure() {
	CorsFilter corsFilter = new CorsFilter.Builder()
			.allowMethod(HttpMethod.DELETE)
			.allowMethod(HttpMethod.OPTIONS)
			.allowHeader("ah0")
			.allowHeader("ah1")
			.allowOrigin(DEFAULT_ORIGIN)
			.allowOrigin("http://test.com")
			.exposeHeader("eh0")
			.exposeHeader("eh1")
			.build();
	ResourceConfig application = new ResourceConfig();
	application.register(corsFilter);
	application.register(TestResource.class);
	return application;
}
 
Example #8
Source File: GetBufferedAIDRData.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@OPTIONS
@Produces(MediaType.APPLICATION_JSON)
@Path("/channel/filter/{crisisCode}")
public Response getBufferedAIDRDataPostFilter(@PathParam("crisisCode") String channelCode,
		@QueryParam("callback") String callbackName,
		@DefaultValue("1000") @QueryParam("count") int count) {
	return Response.ok()
			.allow("POST", "GET", "PUT", "UPDATE", "OPTIONS", "HEAD")
			.header("Access-Control-Allow-Origin", "*")
			.header("Access-Control-Allow-Credentials", "true")
			.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS, HEAD")
			.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
			.build();
}
 
Example #9
Source File: RealmsResource.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@OPTIONS
@Path("{realm}/.well-known/{provider}")
@Produces(MediaType.APPLICATION_JSON)
public Response getVersionPreflight(final @PathParam("realm") String name,
                                    final @PathParam("provider") String providerName) {
    return Cors.add(request, Response.ok()).allowedMethods("GET").preflight().auth().build();
}
 
Example #10
Source File: AccountRestService.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * CORS preflight
 *
 * @return
 */
@Path("/")
@OPTIONS
@NoCache
public Response preflight() {
    return Cors.add(request, Response.ok()).auth().preflight().build();
}
 
Example #11
Source File: CorsPreflightService.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * CORS preflight
 *
 * @return
 */
@Path("{any:.*}")
@OPTIONS
public Response preflight() {
    Cors cors = Cors.add(request, Response.ok()).auth().allowedMethods("GET", "POST", "HEAD", "OPTIONS").preflight();
    return cors.build();
}
 
Example #12
Source File: TokenEndpoint.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@OPTIONS
public Response preflight() {
    if (logger.isDebugEnabled()) {
        logger.debugv("CORS preflight from: {0}", headers.getRequestHeaders().getFirst("Origin"));
    }
    return Cors.add(request, Response.ok()).auth().preflight().allowedMethods("POST", "OPTIONS").build();
}
 
Example #13
Source File: BookStore.java    From cxf with Apache License 2.0 5 votes vote down vote up
@OPTIONS
@Path("/options")
public Response getOptions() throws Exception {
    return Response.ok().header("Allow", "POST")
                        .header("Allow", "PUT")
                        .header("Allow", "GET")
                        .header("Allow", "DELETE")
                        .build();
}
 
Example #14
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@Deprecated
@OPTIONS
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/getClassifiedTweets")
public Response get_N_LatestClassifiedTweetsFiltered(@QueryParam("collectionCode") String collectionCode, 
		@QueryParam("exportLimit") int exportLimit, 
		@QueryParam("callback") String callback) throws UnknownHostException {
	return Response.ok()
			.allow("POST", "OPTIONS", "HEAD")
			.header("Access-Control-Allow-Origin", "*")
			.header("Access-Control-Allow-Credentials", "true")
			.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
			.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
			.build();
}
 
Example #15
Source File: HttpMethodAnnotationHandlerTest.java    From minnal with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleOPTIONSAnnotation() throws Exception {
	OPTIONSAnnotationHandler handler = new OPTIONSAnnotationHandler();
	handler.handle(metaData, mock(OPTIONS.class), DummyResource.class.getMethod("options"));
	assertTrue(! metaData.getResourceMethods().isEmpty());
	assertEquals(metaData.getResourceMethods().iterator().next(), new ResourceMethodMetaData("/dummy", HttpMethod.OPTIONS, DummyResource.class.getMethod("options")));
}
 
Example #16
Source File: AnnotatedCorsServer.java    From cxf with Apache License 2.0 5 votes vote down vote up
@OPTIONS
@Path("/delete")
@LocalPreflight
public Response deleteOptions() {
    String origin = headers.getRequestHeader("Origin").get(0);
    if ("http://area51.mil:3333".equals(origin)) {
        return Response.ok().header(CorsHeaderConstants.HEADER_AC_ALLOW_METHODS, "DELETE PUT")
            .header(CorsHeaderConstants.HEADER_AC_ALLOW_CREDENTIALS, "false")
            .header(CorsHeaderConstants.HEADER_AC_ALLOW_ORIGIN, "http://area51.mil:3333").build();
    }
    return Response.ok().build();
}
 
Example #17
Source File: AnnotatedCorsServer2.java    From cxf with Apache License 2.0 5 votes vote down vote up
@OPTIONS
@Path("/delete")
@LocalPreflight
public Response deleteOptions() {
    String origin = headers.getRequestHeader("Origin").get(0);
    if ("http://area51.mil:3333".equals(origin)) {
        return Response.ok().header(CorsHeaderConstants.HEADER_AC_ALLOW_METHODS, "DELETE PUT")
            .header(CorsHeaderConstants.HEADER_AC_ALLOW_CREDENTIALS, "false")
            .header(CorsHeaderConstants.HEADER_AC_ALLOW_ORIGIN, "http://area51.mil:3333").build();
    }
    return Response.ok().build();
}
 
Example #18
Source File: ApiPermissionInfoGenerator.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private static String getMethodType(Method method) {
    Set<String> httpAnnotations = Lists.newArrayList(GET.class, DELETE.class, PUT.class, POST.class, HEAD.class, OPTIONS.class, PATCH.class)
            .stream()
            .filter(httpAnnotation -> method.isAnnotationPresent(httpAnnotation))
            .map(httpAnnotation -> httpAnnotation.getSimpleName())
            .collect(Collectors.toSet());
    return Joiner.on(" ").join(httpAnnotations);
}
 
Example #19
Source File: DcEngineSourceCollection.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * OPTIONSメソッドの処理.
 * @return JAX-RS応答オブジェクト
 */
@OPTIONS
public Response options() {
    // 移動元に対するアクセス制御
    this.davRsCmp.checkAccessContext(this.davRsCmp.getAccessContext(), BoxPrivilege.READ);
    return DcCoreUtils.responseBuilderForOptions(
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPFIND
            ).build();
}
 
Example #20
Source File: Persister4TaggerAPI.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@OPTIONS
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genTweetIds")
public Response generateTweetsIDSCSVFromAllJSONFiltered(@QueryParam("collectionCode") String collectionCode,
		@DefaultValue("true") @QueryParam("downloadLimited") Boolean downloadLimited) 
				throws UnknownHostException {
	return Response.ok()
			.allow("POST", "OPTIONS", "HEAD")
			.header("Access-Control-Allow-Origin", "*")
			.header("Access-Control-Allow-Credentials", "true")
			.header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD")
			.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
			.build();
}
 
Example #21
Source File: CorsResource.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@OPTIONS
public Response options(@Context HttpServletRequest httpServletRequest) {
    if ((Boolean) httpServletRequest.getAttribute("cors.isCorsRequest"))
        return Response.ok().build();
    else
        return Response.serverError().build();
}
 
Example #22
Source File: ODataSubLocator.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@OPTIONS
public Response handleOptions() throws ODataException {
  // RFC 2616, 5.1.1: "An origin server SHOULD return the status code [...]
  // 501 (Not Implemented) if the method is unrecognized or not implemented
  // by the origin server."
  return returnNotImplementedResponse(ODataNotImplementedException.COMMON);
}
 
Example #23
Source File: ODataSubLocator.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@POST
public Response handlePost(@HeaderParam("X-HTTP-Method") final String xHttpMethod) throws ODataException {
  Response response;

  if (xHttpMethod == null) {
    response = handle(ODataHttpMethod.POST);
  } else {
    /* tunneling */
    if ("MERGE".equals(xHttpMethod)) {
      response = handle(ODataHttpMethod.MERGE);
    } else if ("PATCH".equals(xHttpMethod)) {
      response = handle(ODataHttpMethod.PATCH);
    } else if (HttpMethod.DELETE.equals(xHttpMethod)) {
      response = handle(ODataHttpMethod.DELETE);
    } else if (HttpMethod.PUT.equals(xHttpMethod)) {
      response = handle(ODataHttpMethod.PUT);
    } else if (HttpMethod.GET.equals(xHttpMethod)) {
      response = handle(ODataHttpMethod.GET);
    } else if (HttpMethod.POST.equals(xHttpMethod)) {
      response = handle(ODataHttpMethod.POST);
    } else if (HttpMethod.HEAD.equals(xHttpMethod)) {
      response = handleHead();
    } else if (HttpMethod.OPTIONS.equals(xHttpMethod)) {
      response = handleOptions();
    } else {
      response = returnNotImplementedResponse(ODataNotImplementedException.TUNNELING);
    }
  }
  return response;
}
 
Example #24
Source File: ODataLinksResource.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * OPTIONSメソッド.
 * @return JAX-RS Response
 */
@OPTIONS
public Response options() {

    // アクセス制御
    this.odataResource.checkAccessContext(this.accessContext,
            this.odataResource.getNecessaryOptionsPrivilege());

    return DcCoreUtils.responseBuilderForOptions(
            HttpMethod.GET,
            HttpMethod.DELETE,
            HttpMethod.PUT,
            HttpMethod.POST
            ).build();
}
 
Example #25
Source File: ODataPropertyResource.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * OPTIONSメソッド.
 * @return JAX-RS Response
 */
@OPTIONS
public Response options() {
    // アクセス制御
    this.odataResource.checkAccessContext(this.accessContext,
            this.odataResource.getNecessaryOptionsPrivilege());
    return DcCoreUtils.responseBuilderForOptions(
            HttpMethod.GET,
            HttpMethod.POST
            ).build();
}
 
Example #26
Source File: ODataResource.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * OPTIONSメソッド.
 * @return JAX-RS Response
 */
@OPTIONS
@Path("")
public Response optionsRoot() {
    // アクセス制御
    this.checkAccessContext(this.getAccessContext(), BoxPrivilege.READ);
    return DcCoreUtils.responseBuilderForOptions(
            HttpMethod.GET
            ).build();
}
 
Example #27
Source File: ODataEntityResource.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * OPTIONSメソッド.
 * @return JAX-RS Response
 */
@OPTIONS
public Response options() {
    // アクセス制御
    this.odataResource.checkAccessContext(this.accessContext,
            this.odataResource.getNecessaryReadPrivilege(getEntitySetName()));

    return DcCoreUtils.responseBuilderForOptions(
            HttpMethod.GET,
            HttpMethod.PUT,
            DcCoreUtils.HttpMethod.MERGE,
            HttpMethod.DELETE
            ).build();
}
 
Example #28
Source File: ODataSvcSchemaResource.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * OPTIONS Method.
 * @return JAX-RS Response
 */
@Override
@OPTIONS
@Path("")
public Response optionsRoot() {
    // アクセス制御
    this.checkAccessContext(this.getAccessContext(), BoxPrivilege.READ);
    return super.doGetOptionsMetadata();
}
 
Example #29
Source File: DcEngineSvcCollectionResource.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * OPTIONSメソッド.
 * @return JAX-RS Response
 */
@OPTIONS
public Response options() {
    // アクセス制御
    this.davRsCmp.checkAccessContext(this.davRsCmp.getAccessContext(), BoxPrivilege.READ);
    return DcCoreUtils.responseBuilderForOptions(
            HttpMethod.DELETE,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MOVE,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPFIND,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPPATCH,
            com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.ACL
            ).build();
}
 
Example #30
Source File: JaxRsAnnotationParser.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
@Override
public void initMethodAnnotationProcessor() {
  super.initMethodAnnotationProcessor();
  methodAnnotationMap.put(Path.class, new PathMethodAnnotationProcessor());

  HttpMethodAnnotationProcessor httpMethodAnnotationProcessor = new HttpMethodAnnotationProcessor();
  methodAnnotationMap.put(GET.class, httpMethodAnnotationProcessor);
  methodAnnotationMap.put(POST.class, httpMethodAnnotationProcessor);
  methodAnnotationMap.put(DELETE.class, httpMethodAnnotationProcessor);
  methodAnnotationMap.put(PATCH.class, httpMethodAnnotationProcessor);
  methodAnnotationMap.put(PUT.class, httpMethodAnnotationProcessor);
  methodAnnotationMap.put(OPTIONS.class, httpMethodAnnotationProcessor);
  methodAnnotationMap.put(HEAD.class, httpMethodAnnotationProcessor);
  methodAnnotationMap.put(Consumes.class, new ConsumesAnnotationProcessor());
}