Java Code Examples for org.springframework.web.bind.annotation.RequestMethod#OPTIONS

The following examples show how to use org.springframework.web.bind.annotation.RequestMethod#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: InstancesProxyController.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(path = APPLICATION_MAPPED_PATH, method = { RequestMethod.GET, RequestMethod.HEAD,
		RequestMethod.POST, RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.OPTIONS })
public Flux<InstanceWebProxy.InstanceResponse> endpointProxy(
		@PathVariable("applicationName") String applicationName, HttpServletRequest servletRequest) {
	ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
	String endpointLocalPath = this.getEndpointLocalPath(this.adminContextPath + APPLICATION_MAPPED_PATH,
			servletRequest);
	URI uri = UriComponentsBuilder.fromPath(endpointLocalPath).query(request.getURI().getRawQuery()).build(true)
			.toUri();

	Flux<DataBuffer> cachedBody = DataBufferUtils.readInputStream(request::getBody, this.bufferFactory, 4096)
			.cache();

	return this.instanceWebProxy.forward(this.registry.getInstances(applicationName), uri, request.getMethod(),
			this.httpHeadersFilter.filterHeaders(request.getHeaders()), BodyInserters.fromDataBuffers(cachedBody));
}
 
Example 2
Source File: BugController.java    From steady with Apache License 2.0 6 votes vote down vote up
/**
 * <p>isBugExisting.</p>
 *
 * @return 404 {@link HttpStatus#NOT_FOUND} if bug with given bugid does not exist, 200 {@link HttpStatus#OK} if the bug is found
 * @param bugid a {@link java.lang.String} object.
 */
@RequestMapping(value = "/{bugid}", method = RequestMethod.OPTIONS)
public ResponseEntity<Bug> isBugExisting(@PathVariable String bugid) {
	final StopWatch sw = new StopWatch("OPTIONS bug [" + bugid + "]").start();
	try {
		BugRepository.FILTER.findOne(this.bugRepository.findByBugId(bugid));
		sw.stop();
		return new ResponseEntity<Bug>(HttpStatus.OK);
	}
	catch(EntityNotFoundException enfe) {
		sw.stop(enfe);
		return new ResponseEntity<Bug>(HttpStatus.NOT_FOUND);
	}
	catch(Exception e) {
		sw.stop(e);
		return new ResponseEntity<Bug>(HttpStatus.INTERNAL_SERVER_ERROR);
	}
}
 
Example 3
Source File: RequestMappingInfoTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void preFlightRequest() {
	MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/foo");
	request.addHeader(HttpHeaders.ORIGIN, "http://domain.com");
	request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST");

	RequestMappingInfo info = new RequestMappingInfo(
			new PatternsRequestCondition("/foo"), new RequestMethodsRequestCondition(RequestMethod.POST), null,
			null, null, null, null);
	RequestMappingInfo match = info.getMatchingCondition(request);
	assertNotNull(match);

	info = new RequestMappingInfo(
			new PatternsRequestCondition("/foo"), new RequestMethodsRequestCondition(RequestMethod.OPTIONS), null,
			null, null, null, null);
	match = info.getMatchingCondition(request);
	assertNotNull(match);
}
 
Example 4
Source File: Service.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
@RequestMapping(method = RequestMethod.OPTIONS)
private void options(HttpServletRequest request,
                     HttpServletResponse response)
        throws IOException, ServletException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    long currentCount = logRequest(request);
    addVersionHeader(response);
    Binding binding = null;
    try {
        binding = getBinding(request);
        binding.doOptionsOperation(request, response);
    } catch (HTTPException exception) {
        if (exception.getStatus() == HTTPStatus.METHOD_NOT_ALLOWED && binding != null) {
            doDefaultOptions(binding, request, response);
        } else {
            onHttpException(request, response, exception);
        }
    } finally {
        logResponse(request, response, currentCount, stopwatch);
    }
}
 
Example 5
Source File: TenantController.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether a {@link Tenant} with the given token exists in the database.
 *
 * @param token a {@link java.lang.String} object.
 * @return 404 {@link HttpStatus#NOT_FOUND} if tenant with given token does not exist, 200 {@link HttpStatus#OK} if the tenant is found
 */
@RequestMapping(value = "/{token:.+}", method = RequestMethod.OPTIONS)
@JsonView(Views.Default.class)
public ResponseEntity<Tenant> isTenantExisting(@PathVariable String token) {
	try {
		TenantRepository.FILTER.findOne(tenantRepository.findBySecondaryKey(token));
		return new ResponseEntity<Tenant>(HttpStatus.OK);
	}
	catch(EntityNotFoundException enfe) {
		return new ResponseEntity<Tenant>(HttpStatus.NOT_FOUND);
	}
}
 
Example 6
Source File: LibraryController.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param digest
 * @return 404 {@link HttpStatus#NOT_FOUND} if the library file needs to be uploaded (not known to Maven central and not already uploaded), 200 otherwise
 */
@RequestMapping(value = "/{digest}/upload", method = RequestMethod.OPTIONS)
ResponseEntity<Library> isJARrequired(@PathVariable String digest, HttpEntity<byte[]> requestEntity) {
	final Library l = LibraryRepository.FILTER.findOne(this.libRepository.findByDigest(digest));
	if(l.getWellknownDigest()==false){
		final File f = new File (VulasConfiguration.getGlobal().getLocalM2Repository().toString()+ File.separator +"uknownJars" + File.separator + digest + ".jar");
		if(!f.exists())
			return new ResponseEntity<Library>(HttpStatus.NOT_FOUND);
	}		
	return new ResponseEntity<Library>(HttpStatus.OK);		
}
 
Example 7
Source File: Knife4jController.java    From yshopmall with Apache License 2.0 5 votes vote down vote up
@Autowired
public Knife4jController(Environment environment, ServiceModelToSwagger2Mapper mapper, DocumentationCache documentationCache, JsonSerializer jsonSerializer, List<RequestHandlerProvider> handlerProviders, ObjectProvider<MarkdownFiles> markdownFilesObjectProvider) {
    this.globalRequestMethods = new RequestMethod[]{RequestMethod.POST, RequestMethod.GET, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.PATCH, RequestMethod.OPTIONS, RequestMethod.HEAD};
    this.mapper = mapper;
    this.documentationCache = documentationCache;
    this.jsonSerializer = jsonSerializer;
    this.hostNameOverride = environment.getProperty("springfox.documentation.swagger.v2.host", "DEFAULT");
    this.handlerProviders = handlerProviders;
    this.markdownFiles = (MarkdownFiles)markdownFilesObjectProvider.getIfAvailable();
}
 
Example 8
Source File: ServletAnnotationControllerHandlerMethodTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
Example 9
Source File: SafeSpringCsrfRequestMappingController.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Mapping to several HTTP request methods is fine as long as all the HTTP request methods used are unprotected.
 */
@RequestMapping(value = "/request-mapping-several-unprotected-methods",
        method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.TRACE, RequestMethod.OPTIONS})
public void requestMappingSeveralUnprotectedMethods() {
}
 
Example 10
Source File: RequestMappingInfoHandlerMappingTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@RequestMapping(value = "/something", method = RequestMethod.OPTIONS)
public HttpHeaders fooOptions() {
	HttpHeaders headers = new HttpHeaders();
	headers.add("Allow", "PUT,POST");
	return headers;
}
 
Example 11
Source File: ServletAnnotationControllerHandlerMethodTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
Example 12
Source File: DummyController.java    From spring-openapi with MIT License 4 votes vote down vote up
@RequestMapping(path = "/{id}", method = RequestMethod.OPTIONS)
public ResponseEntity<OptionsClass> getOptions(@PathVariable("id") Integer id) {
	return null;
}
 
Example 13
Source File: ServletAnnotationControllerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
Example 14
Source File: Servlet25TestController.java    From brave with Apache License 2.0 4 votes vote down vote up
@RequestMapping(method = RequestMethod.OPTIONS, value = "/")
public ResponseEntity<Void> root() {
  return new ResponseEntity<>(HttpStatus.OK);
}
 
Example 15
Source File: HttpOptionsTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@RequestMapping(value = "/myUrl", method = RequestMethod.OPTIONS)
@ResponseBody
public void handle() {
	counter.incrementAndGet();
}
 
Example 16
Source File: UnsafeSpringCsrfRequestMappingController.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Mapping to several HTTP request methods is not OK if it's a mix of unprotected and protected HTTP request methods.
 */
@RequestMapping(value = "/request-mapping-all-unprotected-methods-and-one-protected-method",
        method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.TRACE, RequestMethod.OPTIONS, RequestMethod.PATCH})
public void requestMappingAllUnprotectedMethodsAndOneProtectedMethod() {
}
 
Example 17
Source File: ServletAnnotationControllerHandlerMethodTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
Example 18
Source File: DummyController.java    From spring-openapi with MIT License 4 votes vote down vote up
@RequestMapping(path = "/{id}", method = RequestMethod.OPTIONS)
public ResponseEntity<OptionsClass> getOptions(@PathVariable("id") Integer id) {
	return null;
}
 
Example 19
Source File: MossInstancesProxyController.java    From Moss with Apache License 2.0 3 votes vote down vote up
/**
 * 所以端点的请求代理入口:/admin/instances/{instanceId}/actuator/**
 * @author xujin
 * @param instanceId
 * @param servletRequest
 * @param servletResponse
 * @return
 * @throws IOException
 */
@ResponseBody
@RequestMapping(path = HALO_REQUEST_MAPPING_PATH, method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.OPTIONS})
public Mono<Void> endpointProxy(@PathVariable("instanceId") String instanceId,
                                HttpServletRequest servletRequest,
                                HttpServletResponse servletResponse) throws IOException {
   return super.endpointProxy(instanceId, servletRequest, servletResponse);
}
 
Example 20
Source File: AbstractOpenApiResource.java    From springdoc-openapi with Apache License 2.0 2 votes vote down vote up
/**
 * Gets default allowed http methods.
 *
 * @return the default allowed http methods
 */
protected Set<RequestMethod> getDefaultAllowedHttpMethods() {
	RequestMethod[] allowedRequestMethods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.OPTIONS, RequestMethod.HEAD };
	return new HashSet<>(Arrays.asList(allowedRequestMethods));
}