@Override protected void addExtraHeaders(Builder webResource) { webResource.header(PeerEurekaNode.HEADER_REPLICATION, "true"); }
@Test public void testReceiveListOfStrings() throws Exception { WebResource webResource = resource(); ClientResponse responseMsg = webResource.path("/v1/test/receiveListOfStrings") .queryParam("list", "one") .queryParam("list", "two") .queryParam("list", "three") .get(ClientResponse.class); Assert.assertEquals(200, responseMsg.getStatus()); }
@Test public void shouldUseBaseUriOnBadXForwardedHostHeader() { // when ClientResponse response = client.resource( getManageUri() ) .accept( APPLICATION_JSON ) .header( X_FORWARDED_HOST, ":bad_URI" ) .get( ClientResponse.class ); // then String entity = response.getEntity( String.class ); assertTrue( entity.contains( getServerUri() ) ); }
Client client = Client.create(); WebResource webResource =client.resource("uri"); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); queryParams.add("json", js); //set parametes for request appKey = "Bearer " + appKey; // appKey is unique number //Get response from RESTful Server get(ClientResponse.class); ClientResponse response = null; response = webResource.queryParams(queryParams) .header("Content-Type", "application/json;charset=UTF-8") .header("Authorization", appKey) .get(ClientResponse.class); String jsonStr = response.getEntity(String.class);
private Builder builder( String path, final MediaType accept ) { WebResource resource = client.resource( uri( pathOrAbsolute( path ) ) ); Builder builder = resource.accept( accept ); if ( !headers.isEmpty() ) { for ( Map.Entry<String,String> header : headers.entrySet() ) { builder = builder.header( header.getKey(), header.getValue() ); } } return builder; }
public int status() { return response.getStatus(); }
private static void decompressResponse(ClientResponse response) { InputStream entityInputStream = response.getEntityInputStream(); GZIPInputStream uncompressedIS; try { uncompressedIS = new GZIPInputStream(entityInputStream); } catch (IOException ex) { try { entityInputStream.close(); } catch (IOException ignored) { } throw new ClientHandlerException(ex); } response.setEntityInputStream(uncompressedIS); }
private MultivaluedMap<String,String> extractHeaders( ClientResponse jettyResponse ) { return jettyResponse.getHeaders(); }
/** * Set the expected status of the response. The test will fail if the * response has a different status. Defaults to HTTP 200 OK. * * @param expectedStatus the expected response status */ public RESTRequestGenerator expectedStatus( final ClientResponse.Status expectedStatus ) { this.expectedResponseStatus = expectedStatus.getStatusCode(); return this; }
@Test public void shouldUseBaseUriIfFirstAddressInXForwardedHostHeaderIsBad() { // when ClientResponse response = client.resource( getManageUri() ) .accept( APPLICATION_JSON ) .header( X_FORWARDED_HOST, ":bad_URI,good-host" ) .get( ClientResponse.class ); // then String entity = response.getEntity( String.class ); assertTrue( entity.contains( getServerUri() ) ); }
@Override protected void addExtraHeaders(Builder webResource) { if (additionalHeaders != null) { for (String key : additionalHeaders.keySet()) { webResource.header(key, additionalHeaders.get(key)); } } } }
@Test public void shouldUseBaseUriOnBadXForwardedProtoHeader() { // when ClientResponse response = client.resource( getManageUri() ) .accept( APPLICATION_JSON ) .header( X_FORWARDED_PROTO, "%%%DEFINITELY-NOT-A-PROTO!" ) .get( ClientResponse.class ); // then String entity = response.getEntity( String.class ); assertTrue( entity.contains( getServerUri() ) ); }
@Test public void shouldPickFirstXForwardedHostHeaderValueFromCommaOrCommaAndSpaceSeparatedList() { // when ClientResponse response = client.resource( getManageUri() ) .accept( APPLICATION_JSON ) .header( X_FORWARDED_HOST, "jimwebber.org, kathwebber.com,neo4j.org" ) .get( ClientResponse.class ); // then String entity = response.getEntity( String.class ); assertTrue( entity.contains( "http://jimwebber.org" ) ); assertFalse( entity.contains( "http://localhost" ) ); }
@Test public void shouldUseXForwardedProtoHeaderWhenPresent() { // when ClientResponse response = client.resource( getManageUri() ) .accept( APPLICATION_JSON ) .header( X_FORWARDED_PROTO, "https" ) .get( ClientResponse.class ); // then String entity = response.getEntity( String.class ); assertTrue( entity.contains( "https://localhost" ) ); assertFalse( entity.contains( "http://localhost" ) ); }
@Test public void shouldUseXForwardedHostHeaderWhenPresent() { // when ClientResponse response = client.resource( getManageUri() ) .accept( APPLICATION_JSON ) .header( X_FORWARDED_HOST, "jimwebber.org" ) .get( ClientResponse.class ); // then String entity = response.getEntity( String.class ); assertTrue( entity.contains( "http://jimwebber.org" ) ); assertFalse( entity.contains( "http://localhost" ) ); }
@Test public void shouldUseXForwardedHostAndXForwardedProtoHeadersWhenPresent() { // when ClientResponse response = client.resource( getManageUri() ) .accept( APPLICATION_JSON ) .header( X_FORWARDED_HOST, "jimwebber.org" ) .header( X_FORWARDED_PROTO, "https" ) .get( ClientResponse.class ); // then String entity = response.getEntity( String.class ); assertTrue( entity.contains( "https://jimwebber.org" ) ); assertFalse( entity.contains( getServerUri() ) ); }