Example usage for org.apache.http.client.methods HttpUriRequest setHeader

List of usage examples for org.apache.http.client.methods HttpUriRequest setHeader

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpUriRequest setHeader.

Prototype

void setHeader(String str, String str2);

Source Link

Usage

From source file:com.aerofs.baseline.auth.TestAuth.java

@Test
public void shouldGetInternalServerErrorIfAuthenticatorThrows() throws Exception {
    HttpUriRequest request = new HttpGet(ServiceConfiguration.SERVICE_URL + "/everyone");
    request.setHeader("Throw", "bogus");

    Future<HttpResponse> future = client.getClient().execute(request, null);
    HttpResponse response = future.get();

    assertThat(response.getStatusLine().getStatusCode(),
            equalTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
}

From source file:com.aerofs.baseline.auth.TestAuth.java

@Test
public void shouldAllowAuthorizedUserAccessToUserResource() throws Exception {
    HttpUriRequest request = new HttpGet(ServiceConfiguration.SERVICE_URL + "/everyone");
    request.setHeader("Authorization",
            "Basic " + getEncodedCredentials(HttpBasicAuthenticator.USER, HttpBasicAuthenticator.PASS));

    Future<HttpResponse> future = client.getClient().execute(request, null);
    HttpResponse response = future.get();

    assertThat(response.getStatusLine().getStatusCode(), equalTo(Response.Status.OK.getStatusCode()));
    assertThat(HttpUtils.readResponseEntityToString(response), equalTo(UserResource.BORING));
}

From source file:com.aerofs.baseline.auth.TestAuth.java

@Test
public void shouldAllowAuthorizedRootAccessToUserResource() throws Exception {
    HttpUriRequest request = new HttpGet(ServiceConfiguration.SERVICE_URL + "/everyone");
    request.setHeader("Authorization",
            "Basic " + getEncodedCredentials(HttpBasicAuthenticator.ROOT, HttpBasicAuthenticator.PASS));

    Future<HttpResponse> future = client.getClient().execute(request, null);
    HttpResponse response = future.get();

    assertThat(response.getStatusLine().getStatusCode(), equalTo(Response.Status.OK.getStatusCode()));
    assertThat(HttpUtils.readResponseEntityToString(response), equalTo(UserResource.BORING));
}

From source file:com.aerofs.baseline.auth.TestAuth.java

@Test
public void shouldAllowFancyAuthorizedUserAccessToUserResource() throws Exception {
    HttpUriRequest request = new HttpGet(ServiceConfiguration.SERVICE_URL + "/everyone");
    request.setHeader("Fancy-Authentication",
            "Fancy " + getEncodedCredentials(HeFancyAuthenticator.USER, HeFancyAuthenticator.PASS));

    Future<HttpResponse> future = client.getClient().execute(request, null);
    HttpResponse response = future.get();

    assertThat(response.getStatusLine().getStatusCode(), equalTo(Response.Status.OK.getStatusCode()));
    assertThat(HttpUtils.readResponseEntityToString(response), equalTo(UserResource.BORING));
}

From source file:com.aerofs.baseline.auth.TestAuth.java

@Test
public void shouldRejectUserAccessWhenFirstAuthenticatorInChainFails() throws Exception {
    HttpUriRequest request = new HttpGet(ServiceConfiguration.SERVICE_URL + "/everyone");
    request.setHeader("Fancy-Authentication", "Fancy " + getEncodedCredentials("NONE", "NONE"));
    request.setHeader("Authorization",
            "Basic " + getEncodedCredentials(HttpBasicAuthenticator.USER, HttpBasicAuthenticator.PASS));

    Future<HttpResponse> future = client.getClient().execute(request, null);
    HttpResponse response = future.get();

    assertThat(response.getStatusLine().getStatusCode(), equalTo(Response.Status.FORBIDDEN.getStatusCode()));
}

From source file:com.aerofs.baseline.auth.TestAuth.java

@Test
public void shouldRejectUserAccessToRestrictedResource() throws Exception {
    HttpUriRequest request = new HttpGet(ServiceConfiguration.SERVICE_URL + "/restricted");
    request.setHeader("Authorization",
            "Basic " + getEncodedCredentials(HttpBasicAuthenticator.USER, HttpBasicAuthenticator.PASS));

    Future<HttpResponse> future = client.getClient().execute(request, null);
    HttpResponse response = future.get();

    assertThat(response.getStatusLine().getStatusCode(), equalTo(Response.Status.FORBIDDEN.getStatusCode()));
}

From source file:com.aerofs.baseline.auth.TestAuth.java

@Test
public void shouldRejectFancyAuthorizedUserAccessToUserResource() throws Exception {
    HttpUriRequest request = new HttpGet(ServiceConfiguration.SERVICE_URL + "/restricted");
    request.setHeader("Fancy-Authentication",
            "Fancy " + getEncodedCredentials(HeFancyAuthenticator.USER, HeFancyAuthenticator.PASS));

    Future<HttpResponse> future = client.getClient().execute(request, null);
    HttpResponse response = future.get();

    assertThat(response.getStatusLine().getStatusCode(), equalTo(Response.Status.FORBIDDEN.getStatusCode()));
}

From source file:com.aerofs.baseline.auth.TestAuth.java

@Test
public void shouldAllowAuthorizedRootAccessToRestrictedResource() throws Exception {
    HttpUriRequest request = new HttpGet(ServiceConfiguration.SERVICE_URL + "/restricted");
    request.setHeader("Authorization",
            "Basic " + getEncodedCredentials(HttpBasicAuthenticator.ROOT, HttpBasicAuthenticator.PASS));

    Future<HttpResponse> future = client.getClient().execute(request, null);
    HttpResponse response = future.get();

    assertThat(response.getStatusLine().getStatusCode(), equalTo(Response.Status.OK.getStatusCode()));
    assertThat(HttpUtils.readResponseEntityToString(response), equalTo(RootResource.SUPER_SECRET));
}

From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java

/**
 * ????GET.//from w w w.  j a  va  2s  .  c  o  m
 * @param url URL
 * @param headers ??
 * @return DcResponse
 * @throws DcException DAO
 */
public final DcResponse getAcceptEncodingGzip(final String url, final HashMap<String, String> headers)
        throws DcException {
    HttpUriRequest req = new HttpGet(url);
    req.addHeader("Accept-Encoding", "gzip");
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        req.setHeader(entry.getKey(), entry.getValue());
    }
    req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion());

    debugHttpRequest(req, "");
    DcResponse res = this.request(req);
    return res;
}

From source file:io.personium.test.jersey.PersoniumRestAdapter.java

/**
 * ????GET./*www .  j a  v  a  2  s.com*/
 * @param url URL
 * @param headers ??
 * @return DcResponse
 * @throws PersoniumException DAO
 */
public final PersoniumResponse getAcceptEncodingGzip(final String url, final HashMap<String, String> headers)
        throws PersoniumException {
    HttpUriRequest req = new HttpGet(url);
    req.addHeader("Accept-Encoding", "gzip");
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        req.setHeader(entry.getKey(), entry.getValue());
    }
    req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion());

    debugHttpRequest(req, "");
    PersoniumResponse res = this.request(req);
    return res;
}