List of usage examples for org.apache.http.client.methods HttpRequestBase addHeader
public void addHeader(String str, String str2)
From source file:com.oneandone.sdk.OneAndOneAPIBase.java
public OneAndOneAPIBase(String resource, String parentResource) { this.resource = resource; this.parentResource = parentResource; authorize = new RequestInterceptor() { @Override/*from ww w .ja v a 2 s. c o m*/ public void intercept(HttpRequestBase request) { request.addHeader("X-TOKEN", token); } }; Properties props = ConfigReader.getProperties(); if (props.getProperty("apiurl") != null) { urlBase = props.getProperty("apiurl"); } client = RestClient.builder().requestInterceptor(authorize).build(); }
From source file:com.oneandone.sdk.OneAndOneAPIBase.java
public OneAndOneAPIBase(String resource, String parentResource, String childResource) { this.resource = resource; this.parentResource = parentResource; this.childResource = childResource; authorize = new RequestInterceptor() { @Override//from www. jav a 2 s .c o m public void intercept(HttpRequestBase request) { request.addHeader("X-TOKEN", token); } }; Properties props = ConfigReader.getProperties(); if (props.getProperty("apiurl") != null) { urlBase = props.getProperty("apiurl"); } client = RestClient.builder().requestInterceptor(authorize).build(); }
From source file:org.wisdom.test.http.HttpClientHelper.java
private static HttpRequestBase prepareRequest(HttpRequest request) { if (!request.getHeaders().containsKey(HeaderNames.USER_AGENT)) { request.header(HeaderNames.USER_AGENT, USER_AGENT); }/*w w w.j a v a2s .c om*/ if (!request.getHeaders().containsKey(HeaderNames.ACCEPT_ENCODING)) { request.header(HeaderNames.ACCEPT_ENCODING, "gzip"); } Object defaultHeaders = Options.getOption(Options.Option.DEFAULT_HEADERS); if (defaultHeaders != null) { @SuppressWarnings("unchecked") Set<Map.Entry<String, String>> entrySet = ((Map<String, String>) defaultHeaders).entrySet(); for (Map.Entry<String, String> entry : entrySet) { request.header(entry.getKey(), entry.getValue()); } } HttpRequestBase reqObj = null; switch (request.getHttpMethod()) { case GET: reqObj = new HttpGet(request.getUrl()); break; case POST: reqObj = new HttpPost(request.getUrl()); break; case PUT: reqObj = new HttpPut(request.getUrl()); break; case DELETE: reqObj = new HttpDeleteWithBody(request.getUrl()); break; case OPTIONS: reqObj = new HttpOptions(request.getUrl()); break; default: break; } if (reqObj == null) { throw new IllegalStateException( "Cannot build the request - unsupported HTTP verb : " + request.getHttpMethod()); } for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) { reqObj.addHeader(entry.getKey(), entry.getValue()); } // Set body if (request.getHttpMethod() != HttpMethod.GET && request.getBody() != null && reqObj instanceof HttpEntityEnclosingRequestBase) { ((HttpEntityEnclosingRequestBase) reqObj).setEntity(request.getBody().getEntity()); } return reqObj; }
From source file:main.java.com.surevine.rssimporter.connection.BuddycloudClient.java
private HttpResponse execute(HttpRequestBase request) throws IOException { if (session != null) { request.addHeader(SESSION_HEADER, session); }//from www .j a va 2 s .c o m HttpResponse response = httpClient.execute(request); if (true == response.containsHeader(SESSION_HEADER)) { this.session = response.getFirstHeader(SESSION_HEADER).getValue(); } EntityUtils.consume(response.getEntity()); return response; }
From source file:com.kolich.havalo.client.service.HavaloClientSigner.java
@Override public void signHttpRequest(final HttpRequestBase request) { // Add a Date header to the request. request.addHeader(DATE, RFC822DateFormat.format(new Date())); final String signature = signer_.sign(credentials_, getStringToSign(request)); // Add the resulting Authorization header to the request. request.addHeader(AUTHORIZATION,/*ww w . j av a 2 s .co m*/ // The format of the Authorization header ... String.format("Havalo %s:%s", // The Access Key ID uniquely identifies a Havalo user. credentials_.getKey(), // The computed Havalo auth signature for this request. signature)); }
From source file:nl.surfnet.sab.HttpClientTransport.java
private InputStream handleRequest(HttpRequestBase request, UsernamePasswordCredentials credentials) { try {/* w ww . j a v a 2 s .c o m*/ request.addHeader("Authorization", "Basic " + encodeUserPass(credentials)); HttpResponse httpResponse = httpClient.execute(request); return httpResponse.getEntity().getContent(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.tcity.android.background.rest.RestClient.java
@NotNull private HttpResponse get(@NotNull String path, @NotNull String format) throws IOException { HttpRequestBase request = new HttpGet(); request.addHeader("Authorization", "Basic " + myPreferences.getAuth()); request.addHeader("Accept", format); request.setURI(URI.create(path)); return myHttpClient.execute(request); }
From source file:gmusic.api.comm.ApacheConnector.java
private HttpResponse execute(URI uri, HttpRequestBase request) throws IOException, URISyntaxException { request.addHeader("Accept-Encoding", "gzip, deflate"); HttpResponse response = httpClient.execute(adjustAddress(uri, request), localContext); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { EntityUtils.toString(response.getEntity()); throw new IllegalStateException( "Statuscode " + response.getStatusLine().getStatusCode() + " not supported"); }/*from w ww .jav a 2s.co m*/ return response; }
From source file:io.undertow.server.InvalidHtpRequestTestCase.java
@Test public void testInvalidCharacterInHeader() throws IOException { final TestHttpClient client = new TestHttpClient(); try {//from w w w . j av a 2 s . co m HttpRequestBase method = new HttpGet(DefaultServer.getDefaultServerURL()); method.addHeader("fake;header", "value"); HttpResponse result = client.execute(method); Assert.assertEquals(StatusCodes.BAD_REQUEST, result.getStatusLine().getStatusCode()); } finally { client.getConnectionManager().shutdown(); } }