org.springframework.web.bind.annotation.RequestMethod#OPTIONS源码实例Demo

下面列出了org.springframework.web.bind.annotation.RequestMethod#OPTIONS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: arctic-sea   文件: Service.java
@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);
    }
}
 
@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);
}
 
源代码3 项目: steady   文件: BugController.java
/**
 * <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);
	}
}
 
@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));
}
 
源代码5 项目: yshopmall   文件: Knife4jController.java
@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();
}
 
源代码6 项目: steady   文件: LibraryController.java
/**
 * 
 * @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);		
}
 
源代码7 项目: steady   文件: TenantController.java
/**
 * 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);
	}
}
 
源代码8 项目: spring-openapi   文件: DummyController.java
@RequestMapping(path = "/{id}", method = RequestMethod.OPTIONS)
public ResponseEntity<OptionsClass> getOptions(@PathVariable("id") Integer id) {
	return null;
}
 
源代码9 项目: spring-openapi   文件: DummyController.java
@RequestMapping(path = "/{id}", method = RequestMethod.OPTIONS)
public ResponseEntity<OptionsClass> getOptions(@PathVariable("id") Integer id) {
	return null;
}
 
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
/**
 * 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() {
}
 
源代码12 项目: spring-analysis-note   文件: HttpOptionsTests.java
@RequestMapping(value = "/myUrl", method = RequestMethod.OPTIONS)
@ResponseBody
public void handle() {
	counter.incrementAndGet();
}
 
源代码13 项目: brave   文件: Servlet25TestController.java
@RequestMapping(method = RequestMethod.OPTIONS, value = "/")
public ResponseEntity<Void> root() {
  return new ResponseEntity<>(HttpStatus.OK);
}
 
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
@RequestMapping(value = "/myPath.do", method = RequestMethod.OPTIONS)
public void options() {
}
 
@RequestMapping(value = "/something", method = RequestMethod.OPTIONS)
public HttpHeaders fooOptions() {
	HttpHeaders headers = new HttpHeaders();
	headers.add("Allow", "PUT,POST");
	return headers;
}
 
/**
 * 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() {
}
 
源代码19 项目: Moss   文件: MossInstancesProxyController.java
/**
 * 所以端点的请求代理入口:/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);
}
 
/**
 * 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));
}