Package com.github.kevinsawicki.http

Examples of com.github.kevinsawicki.http.HttpRequest$Base64


    sendRequest( request );
    return new ResponseImpl( request );
  }
 
  public Response put() {
    HttpRequest request = HttpRequest.put( url );
    addContentType( request );
    addHeaders( request );
    addAuthentication( request );
    request.send( content );
    sendRequest( request );
    return new ResponseImpl( request );
  }
View Full Code Here


    sendRequest( request );
    return new ResponseImpl( request );
  }
 
  public Response head() {
    HttpRequest request = HttpRequest.head( url );
    addContentType( request );
    addHeaders( request );
    addAuthentication( request );
    sendRequest( request );
    return new ResponseImpl( request );
View Full Code Here

    sendRequest( request );
    return new ResponseImpl( request );
  }
 
  public Response options() {
    HttpRequest request = HttpRequest.options( url );
    addContentType( request );
    addHeaders( request );
    addAuthentication( request );
    sendRequest( request );
    return new ResponseImpl( request );
View Full Code Here

 
  private ResponseImpl response;

  @Before
  public void setUp() throws MalformedURLException {
    HttpRequest httpRequest = mockRequest();
    response = new ResponseImpl( httpRequest );
  }
View Full Code Here

    HttpRequest httpRequest = mockRequest();
    response = new ResponseImpl( httpRequest );
  }

  private HttpRequest mockRequest() throws MalformedURLException {
    HttpRequest httpRequest = mock( HttpRequest.class );
    HttpURLConnection connection = mock( HttpURLConnection.class );
    when( connection.getURL() ).thenReturn( new URL( "http://test.com" ) );
    when( httpRequest.getConnection() ).thenReturn( connection );
    when( httpRequest.body() ).thenReturn( "test" );
    when( httpRequest.code() ).thenReturn( 200 );
    when( httpRequest.contentType() ).thenReturn( MediaType.TEXT_PLAIN.toString() );
    HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
    List<String> values = new ArrayList<String>();
    values.add( "test" );
    headers.put( "test", values );
    when( httpRequest.headers() ).thenReturn( headers );
    return httpRequest;
  }
View Full Code Here

  void download(String path, File toFile) {
    String fullUrl = serverUrl + path;
    try {
      Logs.debug("Download " + fullUrl + " to " + toFile.getAbsolutePath());
      HttpRequest httpRequest = newHttpRequest(new URL(fullUrl));
      if (!httpRequest.ok()) {
        throw new IOException(MessageFormat.format(STATUS_RETURNED_BY_URL_IS_INVALID, fullUrl, httpRequest.code()));
      }
      httpRequest.receive(toFile);

    } catch (Exception e) {
      if (e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException) {
        Logs.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED, serverUrl));
      }
View Full Code Here

    }
  }

  String downloadString(String path) throws IOException {
    String fullUrl = serverUrl + path;
    HttpRequest httpRequest = newHttpRequest(new URL(fullUrl));
    try {
      String charset = getCharsetFromContentType(httpRequest.contentType());
      if (charset == null || "".equals(charset)) {
        charset = "UTF-8";
      }
      if (!httpRequest.ok()) {
        throw new IOException(MessageFormat.format(STATUS_RETURNED_BY_URL_IS_INVALID, fullUrl, httpRequest.code()));
      }
      return httpRequest.body(charset);

    } catch (HttpRequest.HttpRequestException e) {
      if (e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException) {
        Logs.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED, serverUrl));
      }
      throw e;

    } finally {
      httpRequest.disconnect();
    }
  }
View Full Code Here

      httpRequest.disconnect();
    }
  }

  private HttpRequest newHttpRequest(URL url) {
    HttpRequest request = HttpRequest.get(url);
    request.trustAllCerts().trustAllHosts();
    request.acceptGzipEncoding().uncompress(true);
    request.connectTimeout(CONNECT_TIMEOUT_MILLISECONDS).readTimeout(READ_TIMEOUT_MILLISECONDS);
    request.userAgent(userAgent);
    return request;
  }
View Full Code Here

  public int getReadTimeoutInMilliseconds() {
    return readTimeoutInMilliseconds;
  }

  public String get(String wsUrl, Map<String, Object> queryParams) {
    HttpRequest request = prepare(HttpRequest.get(buildUrl(wsUrl), queryParams, true));
    return execute(request);
  }
View Full Code Here

    HttpRequest request = prepare(HttpRequest.get(buildUrl(wsUrl), queryParams, true));
    return execute(request);
  }

  public String post(String wsUrl, Map<String, Object> queryParams) {
    HttpRequest request = prepare(HttpRequest.post(buildUrl(wsUrl), true)).form(queryParams, HttpRequest.CHARSET_UTF8);
    return execute(request);
  }
View Full Code Here

TOP

Related Classes of com.github.kevinsawicki.http.HttpRequest$Base64

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.