Search in sources :

Example 21 with HttpMethod

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);
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) URI(java.net.URI) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Example 22 with HttpMethod

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());
}
Also used : HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Example 23 with HttpMethod

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);
}
Also used : ArrayList(java.util.ArrayList) HttpMethod(org.springframework.http.HttpMethod)

Example 24 with HttpMethod

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;
}
Also used : DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) Builder(org.apache.http.client.config.RequestConfig.Builder) RestTemplate(org.springframework.web.client.RestTemplate) HttpContext(org.apache.http.protocol.HttpContext) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) IOException(java.io.IOException) URI(java.net.URI) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) HttpMethod(org.springframework.http.HttpMethod)

Example 25 with HttpMethod

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());
}
Also used : ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) AccessTokenRequiredException(org.springframework.security.oauth2.client.http.AccessTokenRequiredException) IOException(java.io.IOException) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Aggregations

HttpMethod (org.springframework.http.HttpMethod)35 Test (org.junit.Test)19 URI (java.net.URI)16 IOException (java.io.IOException)11 HttpHeaders (org.springframework.http.HttpHeaders)8 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)7 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)7 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)4 AccessTokenRequest (org.springframework.security.oauth2.client.token.AccessTokenRequest)4 DefaultAccessTokenRequest (org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)4 HttpRequest (org.springframework.http.HttpRequest)3 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 ResolvableType (org.springframework.core.ResolvableType)2 InvalidMediaTypeException (org.springframework.http.InvalidMediaTypeException)2 MediaType (org.springframework.http.MediaType)2 HttpRequestWrapper (org.springframework.http.client.support.HttpRequestWrapper)2