Client client = new Client(crCtx, Protocol.HTTPS); ClientResource clientResource = new ClientResource("https://example.com"); clientResource.setNext(client);
/** * Returns the next Restlet. By default, it is the client dispatcher if a * context is available. * * @return The next Restlet or null. */ public Uniform getNext() { Uniform result = this.next; if (result == null) { synchronized (this) { if (result == null) { result = createNext(); if (result != null) { setNext(result); this.nextCreated = true; } } } } return result; }
Client client = new Client(new Context(), Protocol.HTTP); client.getContext().getParameters().add ( "parameter", "value" ); ClientResource cr = new ClientResource("http://example.com"); cr.setNext(client);
public static ClientResource createAuthenticatedClientResource(String url, String userName, String password) { ClientResource cr = new ClientResource(url); cr.setNext(client); cr.accept(MediaType.APPLICATION_JSON); if (!StringUtils.isNullOrEmpty(userName) && !StringUtils.isNullOrEmpty(password)) { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userName, password); } return cr; }
public static ClientResource createAuthenticatedClientResource(String url, String userName, String password) { ClientResource cr = new ClientResource(url); cr.setNext(client); cr.accept(MediaType.APPLICATION_JSON); if (!StringUtils.isNullOrEmpty(userName) && !StringUtils.isNullOrEmpty(password)) { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userName, password); } return cr; }
public static ClientResource createAuthenticatedClientResource(String url, String userName, String password) { ClientResource cr = new ClientResource(url); cr.setNext(client); cr.accept(MediaType.APPLICATION_JSON); if (!StringUtils.isNullOrEmpty(userName) && !StringUtils.isNullOrEmpty(password)) { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userName, password); } return cr; }
public static ClientResource createAuthenticatedClientResource(String url, String userName, String password) { ClientResource cr = new ClientResource(url); cr.setNext(client); cr.accept(MediaType.APPLICATION_JSON); if (!StringUtils.isNullOrEmpty(userName) && !StringUtils.isNullOrEmpty(password)) { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userName, password); } return cr; }
public static ClientResource createAuthenticatedClientResource(String url, String userName, String password) { ClientResource cr = new ClientResource(url); cr.setNext(client); cr.accept(MediaType.APPLICATION_JSON); if (!StringUtils.isNullOrEmpty(userName) && !StringUtils.isNullOrEmpty(password)) { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userName, password); } return cr; }
protected ClientResource createClient(final String path) { String assembledPath = assembleEndpoint(path); log.debug("Endpoint URL: " + assembledPath); final ClientResource service = new ClientResource(new Context(getClass().getName()), assembledPath); service.setNext(client); ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC; if (context.getEmailAddress() != null) { ChallengeResponse authentication = new ChallengeResponse(scheme, context.getEmailAddress(), context.getCredentials()); service.setChallengeResponse(authentication); } else { service.setChallengeResponse(null); } return service; }
Client client = new Client(new Context(), Protocol.HTTP); ClientResource service = new ClientResource("http://localhost:8111"); service.setNext(client);
/** * Releases the resource by stopping any connector automatically created and * associated to the "next" property (see {@link #getNext()} method. */ @Override protected void doRelease() throws ResourceException { if ((getNext() != null) && this.nextCreated) { if (getNext() instanceof Restlet) { try { ((Restlet) getNext()).stop(); } catch (Exception e) { throw new ResourceException(e); } } setNext(null); } }
service.setChallengeResponse(new ChallengeResponse( ChallengeScheme.HTTP_BASIC, "chunkylover53", "pwd")); service.setNext(client);
@Get Representation retrieve() { // Create the mail URI inside the API application String accountId = getAttribute("accountId"); String mailId = getAttribute("mailId"); String mailApiUri = "riap://component/api/accounts/" + accountId + "/mails/" + mailId; // Optimal internal call using the server dispatcher ClientResource cr = new ClientResource(mailApiUri); cr.setNext(getContext().getServerDispatcher()); MailRepresentation mail = cr.get(MailRepresentation.class); // Load the FreeMarker template Representation mailFtl = new ClientResource( LocalReference.createClapReference(getClass().getPackage()) + "/Mail.ftl").get(); // Wraps the bean with a FreeMarker representation return new TemplateRepresentation(mailFtl, mail, MediaType.TEXT_HTML); }
@Override public List<Car> list() { Client client = new Client(new Context(), Protocol.HTTPS); Series<Parameter> parameters = client.getContext().getParameters(); parameters.add("truststorePath", System.getProperty("javax.net.ssl.trustStore")); ClientResource clientResource = new ClientResource("https://localhost:8043/api/cars/cars"); clientResource.setNext(client); ChallengeResponse challenge = new ChallengeResponse(ChallengeScheme.HTTP_OAUTH_BEARER); challenge.setRawValue(Request.getCurrent().getAttributes().getOrDefault("token", "").toString()); clientResource.setChallengeResponse(challenge); CarServiceInterface carServiceInterface = clientResource.wrap(CarServiceInterface.class); Car[] allCars = carServiceInterface.getAllCars(); try { client.stop(); } catch (Exception e) { throw new RuntimeException(e); } return asList(allCars); } }
public static void main(String[] args) throws Exception { Client client = new Client(new Context(), Protocol.HTTPS); Series<Parameter> parameters = client.getContext().getParameters(); parameters.add("truststorePath", "src/org/restlet/example/book/restlet/ch05/clientTrust.jks"); parameters.add("truststorePassword", "password"); parameters.add("truststoreType", "JKS"); ClientResource clientResource = new ClientResource( "https://localhost:8183/accounts/chunkylover53/mails/123"); clientResource.setNext(client); MailResource mailClient = clientResource.wrap(MailResource.class); mailClient.store(mailClient.retrieve()); client.stop(); }
public static void main(String[] args) throws Exception { // Create and configure HTTPS client Client client = new Client(new Context(), Protocol.HTTPS); Series<Parameter> parameters = client.getContext().getParameters(); parameters.add("truststorePath", "src/org/restlet/example/book/restlet/ch05/clientTrust.jks"); parameters.add("truststorePassword", "password"); parameters.add("truststoreType", "JKS"); // Create and configure client resource ClientResource clientResource = new ClientResource( "https://localhost:8183/accounts/chunkylover53/mails/123"); clientResource.setNext(client); // Preemptively configure the authentication credentials ChallengeResponse authentication = new ChallengeResponse( ChallengeScheme.HTTP_BASIC, "chunkylover53", "pwd"); clientResource.setChallengeResponse(authentication); // Communicate with remote resource MailResource mailClient = clientResource.wrap(MailResource.class); mailClient.store(mailClient.retrieve()); // Store HTTPS client client.stop(); }
public static void main(String[] args) throws Exception { // Create and configure HTTPS client Client client = new Client(new Context(), Protocol.HTTPS); Series<Parameter> parameters = client.getContext().getParameters(); parameters.add("truststorePath", "src/org/restlet/example/book/restlet/ch05/clientTrust.jks"); parameters.add("truststorePassword", "password"); parameters.add("truststoreType", "JKS"); // Create and configure client resource ClientResource clientResource = new ClientResource( "https://localhost:8183/accounts/chunkylover53/mails/123"); clientResource.setNext(client); // Preemptively configure the authentication credentials ChallengeResponse authentication = new ChallengeResponse( ChallengeScheme.HTTP_BASIC, "chunkylover53", "pwd"); clientResource.setChallengeResponse(authentication); // Communicate with remote resource MailResource mailClient = clientResource.wrap(MailResource.class); mailClient.store(mailClient.retrieve()); // Store HTTPS client client.stop(); }
public static void main(String[] args) throws Exception { // Create and configure HTTPS client Client client = new Client(new Context(), Protocol.HTTPS); Series<Parameter> parameters = client.getContext().getParameters(); parameters.add("truststorePath", "src/org/restlet/example/book/restlet/ch05/clientTrust.jks"); parameters.add("truststorePassword", "password"); parameters.add("truststoreType", "JKS"); // Create and configure client resource ClientResource clientResource = new ClientResource( "https://localhost:8183/accounts/chunkylover53/mails/123"); clientResource.setNext(client); // Preemptively configure the authentication credentials ChallengeResponse authentication = new ChallengeResponse( ChallengeScheme.HTTP_BASIC, "chunkylover53", "pwd"); clientResource.setChallengeResponse(authentication); // Communicate with remote resource MailResource mailClient = clientResource.wrap(MailResource.class); mailClient.store(mailClient.retrieve()); // Store HTTPS client client.stop(); }
public static void main(String[] args) throws Exception { // Create and configure HTTPS client Client client = new Client(new Context(), Protocol.HTTPS); Series<Parameter> parameters = client.getContext().getParameters(); parameters.add("keystorePath", "src/org/restlet/example/book/restlet/ch05/clientKey.jks"); parameters.add("keystorePassword", "password"); parameters.add("keystoreType", "JKS"); parameters.add("keyPassword", "password"); parameters.add("truststorePath", "src/org/restlet/example/book/restlet/ch05/clientTrust.jks"); parameters.add("truststorePassword", "password"); parameters.add("truststoreType", "JKS"); // Create and configure client resource ClientResource clientResource = new ClientResource( "https://localhost:8183/accounts/chunkylover53/mails/123"); clientResource.setNext(client); // Preemptively configure the authentication credentials ChallengeResponse authentication = new ChallengeResponse( ChallengeScheme.HTTP_BASIC, "chunkylover53", "pwd"); clientResource.setChallengeResponse(authentication); // Communicate with remote resource MailResource mailClient = clientResource.wrap(MailResource.class); mailClient.store(mailClient.retrieve()); // Store HTTPS client client.stop(); }
clientResource.setNext(client); MailResource mailClient = clientResource.wrap(MailResource.class);