Package org.springframework.http.client

Examples of org.springframework.http.client.ClientHttpRequest


    this.requestFactory = requestFactory;
  }

  @Override
  public WebServiceConnection createConnection(URI uri) throws IOException {
    ClientHttpRequest request = requestFactory.createRequest(uri, HttpMethod.POST);
    if (isAcceptGzipEncoding()) {
      request.getHeaders().add(HttpTransportConstants.HEADER_ACCEPT_ENCODING,
          HttpTransportConstants.CONTENT_ENCODING_GZIP);
    }
    return new ClientHttpRequestConnection(request);
  }
View Full Code Here


    @Override
    public void delete(final Long taskId) {
        ClientHttpResponse response = null;
        try {
            ClientHttpRequest request = getRestTemplate().getRequestFactory().createRequest(
                    URI.create(baseUrl + "task/delete/" + taskId), HttpMethod.GET);
            response = request.execute();
        } catch (IOException e) {
            throw new WebServiceException("Cannot send request to delete task " + taskId, e);
        } finally {
            if (response != null) {
                response.close();
View Full Code Here

    public Metadata putFile(String path, byte[] file) {
      UriTemplate uriTemplate = new UriTemplate(FILE_PUT_URL);
    URI uri = uriTemplate.expand(appFolderUrl, path);
     
    try {
        ClientHttpRequest request = getRestTemplate().getRequestFactory().createRequest(uri, HttpMethod.PUT);
        request.getBody().write(file);
       
        ClientHttpResponse response = request.execute();
        ResponseErrorHandler errorHandler = new DefaultResponseErrorHandler();
        if (errorHandler.hasError(response)) {
          errorHandler.handleError(response);
          return null;
        }
View Full Code Here

    Assert.notNull(url, "'url' must not be null");
    Assert.notNull(method, "'method' must not be null");
    ClientHttpResponse response = null;
    try {
      ClientHttpRequest request = createRequest(url, method);
      if (requestCallback != null) {
        requestCallback.doWithRequest(request);
      }
      response = request.execute();
      if (!getErrorHandler().hasError(response)) {
        logResponseStatus(method, url, response);
      }
      else {
        handleResponseError(method, url, response);
View Full Code Here

   * @param method the HTTP method to exectute (GET, POST, etc.)
   * @return the created request
   * @throws IOException in case of I/O errors
   */
  protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
    ClientHttpRequest request = getRequestFactory().createRequest(url, method);
    if (logger.isDebugEnabled()) {
      logger.debug("Created " + method.name() + " request for \"" + url + "\"");
    }
    return request;
  }
View Full Code Here

    Assert.notNull(url, "'url' must not be null");
    Assert.notNull(method, "'method' must not be null");
    ClientHttpResponse response = null;
    try {
      ClientHttpRequest request = createRequest(url, method);
      if (requestCallback != null) {
        requestCallback.doWithRequest(request);
      }
      response = request.execute();
      if (!getErrorHandler().hasError(response)) {
        logResponseStatus(method, url, response);
      }
      else {
        handleResponseError(method, url, response);
View Full Code Here

  }

  @Test
  public void createRequest() throws Exception {
    URI uri = new URI("/foo");
    ClientHttpRequest expected = (ClientHttpRequest) this.server.expect(anything());
    ClientHttpRequest actual = this.factory.createRequest(uri, HttpMethod.GET);

    assertSame(expected, actual);
    assertEquals(uri, actual.getURI());
    assertEquals(HttpMethod.GET, actual.getMethod());
  }
View Full Code Here

      // use BASIC auth if configured to do so
      restTemplate = new RestTemplate(factory) {

        @Override
        protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
          ClientHttpRequest httpRequest = super.createRequest(url, method);
          httpRequest.getHeaders().add("Authorization",
              String.format("Basic %s", Base64.encode(String.format("%s:%s", clientId, clientSecret)) ));
          return httpRequest;
        }
      };
    } else //Alternatively use form based auth
View Full Code Here

      if (serverConfiguration.getUserInfoTokenMethod() == null || serverConfiguration.getUserInfoTokenMethod().equals(UserInfoTokenMethod.HEADER)) {
        RestTemplate restTemplate = new RestTemplate(factory) {
         
          @Override
          protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
            ClientHttpRequest httpRequest = super.createRequest(url, method);
            httpRequest.getHeaders().add("Authorization", String.format("Bearer %s", token.getAccessTokenValue()));
            return httpRequest;
          }
        };
       
        userInfoString = restTemplate.getForObject(serverConfiguration.getUserInfoUri(), String.class);
View Full Code Here

      // use BASIC auth if configured to do so
      restTemplate = new RestTemplate(factory) {

        @Override
        protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
          ClientHttpRequest httpRequest = super.createRequest(url, method);
          httpRequest.getHeaders().add("Authorization",
              String.format("Basic %s", Base64.encode(String.format("%s:%s", clientConfig.getClientId(), clientConfig.getClientSecret())) ));



          return httpRequest;
View Full Code Here

TOP

Related Classes of org.springframework.http.client.ClientHttpRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.