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 . These examples are extracted from open source projects. 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 Project: arctic-sea   File: Service.java    License: 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 2
@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 3
Source Project: steady   File: BugController.java    License: 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 4
@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 5
Source Project: yshopmall   File: Knife4jController.java    License: 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 6
Source Project: steady   File: LibraryController.java    License: 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 Project: steady   File: TenantController.java    License: 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 8
Source Project: spring-openapi   File: DummyController.java    License: 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 9
Source Project: spring-openapi   File: DummyController.java    License: 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 10
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
Example 11
/**
 * 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 12
Source Project: spring-analysis-note   File: HttpOptionsTests.java    License: MIT License 4 votes vote down vote up
@RequestMapping(value = "/myUrl", method = RequestMethod.OPTIONS)
@ResponseBody
public void handle() {
	counter.incrementAndGet();
}
 
Example 13
Source Project: brave   File: Servlet25TestController.java    License: 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 14
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
Example 15
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
Example 16
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
Example 17
@RequestMapping(value = "/something", method = RequestMethod.OPTIONS)
public HttpHeaders fooOptions() {
	HttpHeaders headers = new HttpHeaders();
	headers.add("Allow", "PUT,POST");
	return headers;
}
 
Example 18
/**
 * 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 19
/**
 * 所以端点的请求代理入口:/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
/**
 * 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));
}