public String location() { if ( response.getLocation() != null ) { return response.getLocation().toString(); } throw new RuntimeException( "The request did not contain a location header, " + "unable to provide location. Status code was: " + status() ); }
public JaxRsResponse( ClientResponse response, String entity ) { status = response.getStatus(); metaData = extractMetaData( response ); headers = extractHeaders( response ); location = response.getLocation(); type = response.getType(); data = entity; response.close(); }
@Override public URI getLocation() { return _response.getLocation(); }
@Override public URI getLocation() { return _response.getLocation(); }
@Override public URI getLocation() { return _response.getLocation(); }
private static URI createNode() { final String nodeEntryPointUri = SERVER_ROOT_URI + "node"; // http://localhost:7474/db/data/node WebResource resource = Client.create() .resource( nodeEntryPointUri ); // POST {} to the node entry point URI ClientResponse response = resource.accept( MediaType.APPLICATION_JSON ) .type( MediaType.APPLICATION_JSON ) .entity( "{}" ) .post( ClientResponse.class ); final URI location = response.getLocation(); System.out.println( String.format( "POST to [%s], status code [%d], location header [%s]", nodeEntryPointUri, response.getStatus(), location.toString() ) ); response.close(); return location; }
@Override public ListenableFuture<RpcResult<Void>> startListening() { ClientResponse response = null; try { response = extractWebSocketUriFromRpc(this.streamInfo.getIdentifier()); } catch (ExecutionException e) { logger.trace("Execution exception while extracting stream name {}",e); throw new IllegalStateException(e); } catch (InterruptedException e) { logger.trace("InterruptedException while extracting stream name {}",e); throw new IllegalStateException(e); } catch (UnsupportedEncodingException e) { logger.trace("UnsupportedEncodingException while extracting stream name {}",e); throw new IllegalStateException(e); } boolean success = true; if (response.getStatus() != 200) { success = false; } final RestRpcResult rpcResult = new RestRpcResult(success,response.getLocation()); createWebsocketClient(response.getLocation()); ListenableFuture<RpcResult<Void>> future = pool.submit(new Callable<RpcResult<Void>>() { @Override public RpcResult<Void> call() { return rpcResult; } }); return future; }
/** * Attempts to create a BufferedImage using the data retrieved from some * URI. * * @param uriRef * An absolute URI reference ('http' or 'file' schemes). * @return A BufferedImage object containing the image data, or * <code>null</code>. * @throws IOException * If an error occurs while reading the image data. */ BufferedImage readImageDataFromURI(URI uriRef) throws IOException { BufferedImage image = null; if (uriRef.getScheme().equalsIgnoreCase("file")) { image = ImageIO.read(uriRef.toURL()); } else { WebResource resource = this.client.resource(uriRef); Builder builder = resource.accept("image/*"); ClientResponse rsp = builder.get(ClientResponse.class); if (null != rsp.getLocation()) { // 3nn Redirection resource = this.client.resource(rsp.getLocation()); rsp = resource.accept("image/*").get(ClientResponse.class); } int status = rsp.getStatus(); if (status == Response.Status.OK.getStatusCode() && rsp.hasEntity()) { image = ImageIO.read(rsp.getEntityInputStream()); } } return image; }
private static URI addRelationship( URI startNode, URI endNode, String relationshipType, String jsonAttributes ) throws URISyntaxException { URI fromUri = new URI( startNode.toString() + "/relationships" ); String relationshipJson = generateJsonRelationship( endNode, relationshipType, jsonAttributes ); WebResource resource = Client.create() .resource( fromUri ); // POST JSON to the relationships URI ClientResponse response = resource.accept( MediaType.APPLICATION_JSON ) .type( MediaType.APPLICATION_JSON ) .entity( relationshipJson ) .post( ClientResponse.class ); final URI location = response.getLocation(); System.out.println( String.format( "POST to [%s], status code [%d], location header [%s]", fromUri, response.getStatus(), location.toString() ) ); response.close(); return location; } // END SNIPPET: insideAddRel
private static URI createNode() { // START SNIPPET: createNode final String nodeEntryPointUri = SERVER_ROOT_URI + "node"; // http://localhost:7474/db/data/node WebResource resource = Client.create() .resource( nodeEntryPointUri ); // POST {} to the node entry point URI ClientResponse response = resource.accept( MediaType.APPLICATION_JSON ) .type( MediaType.APPLICATION_JSON ) .entity( "{}" ) .post( ClientResponse.class ); final URI location = response.getLocation(); System.out.println( String.format( "POST to [%s], status code [%d], location header [%s]", nodeEntryPointUri, response.getStatus(), location.toString() ) ); response.close(); return location; // END SNIPPET: createNode }
if (response.getLocation() != null) { links.add(new Link(Rel.SELF, new org.gedcomx.common.URI(response.getLocation().toString())));
if (rsp.getStatusInfo().getFamily() == Response.Status.Family.REDIRECTION) { URI newURI = rsp.getLocation(); req.setURI(newURI); rsp = this.httpClient.handle(req);
@Test public void testAuthUrl() { String code = authClient.authorizeClient(clientEntity, "test1 test2").getCode(); assertNotNull(code); restClient.setFollowRedirects(false); ResourceClient client = new ResourceClient(clientEntity); 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=")); authUrl = client.getAuthUrl("stateTest"); webResource = restClient.resource(authUrl); clientResponse = webResource.get(ClientResponse.class); assertEquals(302, clientResponse.getStatus()); assertTrue(clientResponse.getLocation().toString().contains("state=stateTest")); }
@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 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 testResourceAccess() 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.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); Token accessToken = client.parseFragment(fragment); client.sendTestRequestSample1(accessToken); }