@Test public void shouldLogStartup() { // Check the logs String logContent = out.toString(); assertThat( logContent.length(), is( greaterThan( 0 ) ) ); assertThat( logContent, containsString( NEO4J_IS_STARTING_MESSAGE ) ); // Check the server is alive Client nonRedirectingClient = Client.create(); nonRedirectingClient.setFollowRedirects( false ); final JaxRsResponse response = new RestRequest( server.baseUri(), nonRedirectingClient ).get(); assertThat( response.getStatus(), is( greaterThan( 199 ) ) ); } }
@Test public void shouldRedirectOnHtmlRequest() { Client nonRedirectingClient = Client.create(); nonRedirectingClient.setFollowRedirects( false ); JaxRsResponse clientResponse = new RestRequest( null, nonRedirectingClient ).get( server().baseUri().toString(), TEXT_HTML_TYPE ); assertEquals( 303, clientResponse.getStatus() ); }
@Test public void shouldRedirectToBrowser() throws Exception { Client nonRedirectingClient = Client.create(); nonRedirectingClient.setFollowRedirects( false ); final JaxRsResponse response = new RestRequest( server.baseUri(), nonRedirectingClient ).accept( MediaType .TEXT_HTML_TYPE ).get( server.baseUri().toString() ); assertEquals( 303, response.getStatus() ); assertEquals( new URI( server.baseUri() + "browser/" ), response.getLocation() ); response.close(); }
@Test public void shouldRedirectToBrowserUsingXForwardedHeaders() throws Exception { Client nonRedirectingClient = Client.create(); nonRedirectingClient.setFollowRedirects( false ); final JaxRsResponse response = new RestRequest( server.baseUri(), nonRedirectingClient ).accept( MediaType .TEXT_HTML_TYPE ).header( "X-Forwarded-Host", "foo.bar:8734" ).header( "X-Forwarded-Proto", "https" ).get( server.baseUri().toString() ); assertEquals( 303, response.getStatus() ); assertEquals( new URI( "https://foo.bar:8734/browser/" ), response.getLocation() ); response.close(); } }
public DoiBibtexCacheEntryFactory(){ client.setFollowRedirects(true); }
@Override public void setup(OperatorContext context) { wsClient = Client.create(); wsClient.setFollowRedirects(true); logger.debug("URL: {}", url); }
@Override public void setup(OperatorContext context) { wsClient = Client.create(); wsClient.setFollowRedirects(true); wsClient.setReadTimeout(readTimeoutMillis); resource = wsClient.resource(url.toString()); // side step "not absolute URL" after serialization LOG.info("URL: {}", url); }
ChannelFinderClientImpl(URI uri, ClientConfig config, HTTPBasicAuthFilter httpBasicAuthFilter, ExecutorService executor) { Client client = Client.create(config); if (httpBasicAuthFilter != null) { client.addFilter(httpBasicAuthFilter); } client.addFilter(new RawLoggingFilter(Logger .getLogger(RawLoggingFilter.class.getName()))); client.setFollowRedirects(true); service = client.resource(UriBuilder.fromUri(uri).build()); this.executor = executor; }
private Client createClient() { Set<Class<?>> providers = new HashSet<Class<?>>(); providers.add(JacksonJsonProvider.class); ClientConfig config = new DefaultClientConfig(providers); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); Client client = ApacheHttpClient4.create(config); client.setFollowRedirects(true); client.addFilter(new ContentTypeFromTextToJsonClientFilter()); return client; }
/** * Initializes the HTTP client component. It is configured to follow * redirects (status code 3nn) and log the request/response messages to the * test suite logger (at INFO level). */ @BeforeClass public void initHttpClient() { this.client = Client.create(); this.client.setFollowRedirects(true); this.client.addFilter(new LoggingFilter(TestSuiteLogger.getLogger())); }
@Test public void testAuthCodeWithImplicit() throws ClientException { String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); ResourceClient client = new ResourceClient(clientEntity.getClientId(), GrantType.AUTHORIZATION_REQUEST, ResponseType.CODE); String authUrl = client.getAuthUrl(null); WebResource webResource = restClient.resource(authUrl); ClientResponse clientResponse = webResource.get(ClientResponse.class); assertTrue(clientResponse.getLocation().toString().startsWith("http://localhost:9998/testsuite?error=unsupported_response_type")); } }
@Test public void testInvalidScopes() { String code = authClient.authorizeClient(clientEntity, "test1 someScope").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); ResourceClient client = new ResourceClient(clientEntity.getClientId(), clientEntity.getClientSecret(), "test1 test2"); String authUrl = client.getAuthUrl(null); WebResource webResource = restClient.resource(authUrl); ClientResponse clientResponse = webResource.get(ClientResponse.class); assertEquals(302, clientResponse.getStatus()); assertTrue(clientResponse.getLocation().toString().startsWith("http://localhost:9998/testsuite?code=")); }
@Test public void testNoRefreshToken() { String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); ResourceClient client = new ResourceClient(clientEntity.getClientId(), GrantType.AUTHORIZATION_REQUEST, ResponseType.TOKEN); String authUrl = client.getAuthUrl(null); WebResource webResource = restClient.resource(authUrl); ClientResponse clientResponse = webResource.get(ClientResponse.class); assertEquals(302, clientResponse.getStatus()); String fragment = clientResponse.getLocation().getFragment(); assertNotNull(fragment); assertTrue(!fragment.contains("refresh_token")); }
@Test public void testInvalidCode() { String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); ResourceClient client = new ResourceClient(clientEntity); try { client.getAccessToken("A"+code); fail(); } catch (TokenExtractorException e) { } }
@Test public void testAccessToken() { String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); ResourceClient client = new ResourceClient(clientEntity.getClientId(), GrantType.AUTHORIZATION_REQUEST, ResponseType.TOKEN); String authUrl = client.getAuthUrl(null); WebResource webResource = restClient.resource(authUrl); ClientResponse clientResponse = webResource.get(ClientResponse.class); assertEquals(302, clientResponse.getStatus()); String fragment = clientResponse.getLocation().getFragment(); assertNotNull(fragment); }
@Test public void testInvalidClientSecret() { String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); ResourceClient client = new ResourceClient(clientEntity.getClientId(), "Invalid", "test1 test2"); try { client.getAccessToken(code); fail(); } catch (TokenExtractorException e) { } }
@Test public void testDoubleUseOfCode() { String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); ResourceClient client = new ResourceClient(clientEntity); client.getAccessToken(code); try { client.getAccessToken(code); fail(); } catch (TokenExtractorException e) { } }
@Test public void testClassAnnotation() throws ClientException { String code = authClient.authorizeClient(clientEntity, "").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); ResourceClient client = new ResourceClient(clientEntity); Token oldToken = client.getAccessToken(code); assertNotNull(oldToken); assertNotNull(oldToken.getToken()); client.sendTestRequestSample2(oldToken); }
@BeforeClass public static void classSetup() { ClientConfig cc = new DefaultClientConfig(); Client restClient = Client.create(cc); ClientManagerClient authClient = new ClientManagerClient(restClient); clientEntity = authClient.createClient("confidential"); String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); client = new ResourceClient(clientEntity); token = client.getAccessToken(code); }
@Test public void testInvalidScopes() { String code = authClient.authorizeClient(clientEntity, "test1 invalidScope").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); ResourceClient client = new ResourceClient(clientEntity); Token tok = client.getAccessToken(code); assertNotNull(tok); assertNotNull(tok.getToken()); try { client.sendTestRequestSample1(tok); fail(); } catch (ClientException cex) { } }