/** * Creates a protected child context. This is especially useful for new * application attached to their parent component, to ensure their isolation * from the other applications. By default it just creates a new context * instance. * * @return The child context. */ public Context createChildContext() { return new Context(); }
/** * Constructor. * * @param protocol * The server's protocol such as "HTTP" or "HTTPS". * @param port * The port number. */ public SpringServer(String protocol, int port) { super(new Context(), Protocol.valueOf(protocol), port, null); }
/** * Constructor. * * @param protocol * The server's protocol such as "HTTP" or "HTTPS". */ public SpringServer(String protocol) { super(new Context(), Protocol.valueOf(protocol), null); }
/** * Constructor. * * @param protocol * The server's protocol such as "HTTP" or "HTTPS". * @param address * The IP address. * @param port * The port number. */ public SpringServer(String protocol, String address, int port) { super(new Context(), Protocol.valueOf(protocol), address, port, null); }
/** * Constructor. * * @param context * The Servlet context. * @param target * The target Restlet. */ public ServletConverter(ServletContext context, Restlet target) { super(new Context(new ServletLogger(context))); this.target = target; }
/** * Constructor. * * @param context * The Servlet context. * @param target * The target Restlet. */ public ServletConverter(ServletContext context, Restlet target) { super(new Context(new ServletLogger(context))); this.target = target; }
/** * Constructor. * * @param context * The Servlet context. * @param target * The target Restlet. */ public ServletAdapter(ServletContext context, Restlet target) { super(new Context(new ServletLogger(context))); this.target = target; }
private ClientResource createClientResource(String url, boolean buffering) { ClientResource clientResource = new ClientResource(new Context(), url); clientResource.getContext().getParameters().add("socketConnectTimeoutMs", String.valueOf(CONNECTION_TIMEOUT)); clientResource.getContext().getParameters().add("maxIoIdleTimeMs", String.valueOf(CONNECTION_TIMEOUT)); clientResource.setEntityBuffering(buffering); return clientResource; }
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; }
public RestClientHelper( String baseUrl, String username, String password ) { ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC; ChallengeResponse authentication = new ChallengeResponse( scheme, username, password ); this.challenge = authentication; this.baseUrl = baseUrl; this.restContext = new Context(); this.restClient = new Client( restContext, Protocol.HTTP ); xstream = XStreamConfigurator.configureXStream( new XStream( new LookAheadXppDriver() ) ); MIndexerXStreamConfigurator.configureXStream( xstream ); }
@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(); }
/** * default constructor for UmlgRestletComponent */ public UmlgRestletComponent() { setName("restAndJson"); setDescription("Halo, I am your first comment."); getClients().add(Protocol.FILE); getClients().add(Protocol.CLAP); getClients().add(Protocol.RIAP); Server server = new Server(new Context(), Protocol.HTTP, 8111); server.getContext().getParameters().set("tracing", "true"); getServers().add(server); attachApplications(); }
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(); }
/** * Indicates if the Component hosted by this Servlet is the default one or * one provided by the user. * * @return True if the Component is the default one, false otherwise. */ private boolean isDefaultComponent() { // The Component is provided via an XML configuration file. Client client = createWarClient(new Context(), getServletConfig()); Response response = client.get("war:///WEB-INF/restlet.xml"); if (response.getStatus().isSuccess() && response.isEntityAvailable()) { return false; } // The Component is provided via a context parameter in the "web.xml" // file. final String componentAttributeName = getInitParameter(COMPONENT_KEY, null); if (componentAttributeName != null) { return false; } return true; }
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(); }
/** * Indicates if the Component hosted by this Servlet is the default one or * one provided by the user. * * @return True if the Component is the default one, false otherwise. */ private boolean isDefaultComponent() { // The Component is provided via an XML configuration file. Client client = createWarClient(new Context(), getServletConfig()); Response response = client.handle(new Request(Method.GET, "war:///WEB-INF/restlet.xml")); if (response.getStatus().isSuccess() && response.isEntityAvailable()) { return false; } // The Component is provided via a context parameter in the "web.xml" // file. String componentAttributeName = getInitParameter(COMPONENT_KEY, null); if (componentAttributeName != null) { return false; } return true; }
/** * Constructor. * * @param uri * Target resource URI. */ public UacClientResource(String uri) { this.clientResource = new SipClientResource(uri); this.clientResource.setCallId("a84b4c76e66710@pc33.atlanta.com"); this.clientResource.setCommandSequence("314159"); this.clientResource.setFrom(new Address("sip:alice@atlanta.com", "Alice")); this.clientResource.setTo(new Address("sip:bob@biloxi.com", "Bob")); Client client = new Client(new Context(), Protocol.SIP); client.getContext().getParameters().add("minThreads", "1"); client.getContext().getParameters().add("tracing", "true"); client.getContext().getParameters().add("proxyHost", "localhost"); client.getContext().getParameters().add("proxyPort", "5060"); this.clientResource.setNext(client); this.proxy = this.clientResource.wrap(UacResource.class); }
public static void main( String[] args ) throws Exception { Energy4Java polygene = new Energy4Java( ); Server server = new Server( Protocol.HTTP, 8888 ); Application app = polygene.newApplication( new ForumAssembler(), new MetadataService() ); app.activate(); ContextRestlet restlet = app.findModule( "REST", "Restlet" ).newObject( ContextRestlet.class, new org.restlet.Context() ); ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm"); MapVerifier mapVerifier = new MapVerifier(); mapVerifier.getLocalSecrets().put("rickard", "secret".toCharArray()); guard.setVerifier(mapVerifier); guard.setNext(restlet); server.setNext( restlet ); server.start(); } }