use of org.springframework.http.HttpMethod in project spring-framework by spring-projects.
the class AsyncRestTemplateIntegrationTests method optionsForAllowCallback.
@Test
public void optionsForAllowCallback() throws Exception {
ListenableFuture<Set<HttpMethod>> allowedFuture = template.optionsForAllow(new URI(baseUrl + "/get"));
allowedFuture.addCallback(new ListenableFutureCallback<Set<HttpMethod>>() {
@Override
public void onSuccess(Set<HttpMethod> result) {
assertEquals("Invalid response", EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS, HttpMethod.HEAD, HttpMethod.TRACE), result);
}
@Override
public void onFailure(Throwable ex) {
fail(ex.getMessage());
}
});
waitTillDone(allowedFuture);
}
use of org.springframework.http.HttpMethod in project spring-framework by spring-projects.
the class DefaultServerRequestTests method method.
@Test
public void method() throws Exception {
HttpMethod method = HttpMethod.HEAD;
when(mockRequest.getMethod()).thenReturn(method);
assertEquals(method, defaultRequest.method());
}
use of org.springframework.http.HttpMethod in project spring-framework by spring-projects.
the class WebContentGenerator method initAllowHeader.
private void initAllowHeader() {
Collection<String> allowedMethods;
if (this.supportedMethods == null) {
allowedMethods = new ArrayList<>(HttpMethod.values().length - 1);
for (HttpMethod method : HttpMethod.values()) {
if (!HttpMethod.TRACE.equals(method)) {
allowedMethods.add(method.name());
}
}
} else if (this.supportedMethods.contains(HttpMethod.OPTIONS.name())) {
allowedMethods = this.supportedMethods;
} else {
allowedMethods = new ArrayList<>(this.supportedMethods);
allowedMethods.add(HttpMethod.OPTIONS.name());
}
this.allowHeader = StringUtils.collectionToCommaDelimitedString(allowedMethods);
}
use of org.springframework.http.HttpMethod in project spring-security-oauth by spring-projects.
the class ServerRunning method createRestTemplate.
public RestOperations createRestTemplate() {
RestTemplate client = new RestTemplate();
client.setRequestFactory(new HttpComponentsClientHttpRequestFactory() {
@Override
protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
HttpClientContext context = HttpClientContext.create();
Builder builder = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).setAuthenticationEnabled(false).setRedirectsEnabled(false);
context.setRequestConfig(builder.build());
return context;
}
});
client.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return false;
}
});
return client;
}
use of org.springframework.http.HttpMethod in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method testNoRetryAccessDeniedExceptionForNoExistingToken.
@Test(expected = AccessTokenRequiredException.class)
public void testNoRetryAccessDeniedExceptionForNoExistingToken() throws Exception {
restTemplate.setAccessTokenProvider(new StubAccessTokenProvider());
restTemplate.setRequestFactory(new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
throw new AccessTokenRequiredException(resource);
}
});
restTemplate.doExecute(new URI("http://foo"), HttpMethod.GET, new NullRequestCallback(), new SimpleResponseExtractor());
}
Aggregations