ClientResource resource = (...) (...) Representation repr = resource.get(); JsonRepresentation jsonRepresentation = new JsonRepresentation(repr); JSONObject jsonObj = jsonRepresentation.getJsonObject();
// Create the client resource ClientResource resource = new ClientResource("http://www.restlet.org"); // Write the response entity on the console resource.get().write(System.out);
// Create a client resource which will call a given service ClientResource clientResource = new ClientResource("http://serviceToCall.com"); // Add a query parameter clientResource.addQueryParameter("queryParameterName", "queryParameterValue"); // Make a "GET" clientResource.get();
// Create the client resource ClientResource resource = new ClientResource("http://www.restlet.org"); // Add a query parameter equiv to ?A=1 resource.getReference().addQueryParameter("A","1"); // Customize the referrer property resource.setReferrerRef("http://www.mysite.org"); // Write the response entity on the console resource.get().write(System.out);
// Create the client resource ClientResource resource = new ClientResource("http://www.restlet.org"); // Customize the referrer property resource.setReferrerRef("http://www.mysite.org"); // Write the response entity on the console resource.get().write(System.out);
Reference ref = new Reference("https://username:password@www.myserver.com/my_secure_document"); String[] userinfo = ref.getUserInfo().split(":"); // "username:password" String username = userinfo[0]; String password = userinfo[1]; ClientResource clientRes = new ClientResource(ref); clientRes.setChallengeResponse(ChallengeScheme.HTTP_BASIC, username, password); clientRes.get();
ClientResource cr = new ClientResource("http://example.com/page"); Representation result = cr.get(); Series<Cookie> cookies = cr.getCookies();
//Samples for POST / PUT ClientResource cr = new ClientResource("http://..."); cr.post(new StringRepresentation("test")); MyBean bean = new MyBean(); (...) //Jackson is a tool for JSON format JacksonRepresentation<MyBean> repr = new JacksonRepresentation<MyBean>(bean); cr.put(repr); //Samples for GET Representation repr1 = cr.get(); bean = (new JacksonRepresentation<MyBean>(repr1, MyBean.class)).getObject();
ClientResource cr = new ClientResource("http://..."); cr.getReference().addQueryParameter("q", "restlet"); Representation repr = cr.get();
ClientResource cr = new ClientResource("http://localhost:8888/users"); cr.setRequestEntityBuffering(true); Representation representation = cr.get(MediaType.APPLICATION_JSON); String jsonContentAsString = representation.getText();
Client client = new Client(new Context(), Protocol.HTTP); for (int i = 0; i < 5; i++) { ClientResource clientResource = new ClientResource("http://..."); clientResource.setNext(client); Representation representation = clientResource.get(); (...) }
protected synchronized void deleteEmptyNamespace(final String name) { if (!name.equals("default") && isNamespaceEmpty(name)) { if (client.namespaces().withName(name).get() != null && !client.namespaces().withName(name).get().getStatus().getPhase().equals(PHASE_TERMINATING)) { client.namespaces().withName(name).delete(); ExitCondition exitCondition = new ExitCondition() { @Override public Boolean call() { return client.namespaces().withName(name).get() == null; } @Override public String getFailureMessage() { return "Namespace " + name + " still present"; } }; waitForExitCondition(exitCondition); } } }
ClientResource resource = new ClientResource(yourUrl); Form headers = (Form)resource.getRequestAttributes().get("org.restlet.http.headers"); if (headers == null) { headers = new Form(); resource.getRequestAttributes().put("org.restlet.http.headers", headers); } headers.add("yourHeaderName", yourHeaderValue); resource.get(); Response response = resource.getResponse(); String text = response.getEntity().getText(); String status = response.getStatus().toString();
ClientResource resource = new ClientResource(resouceURL); String token = "myToken"; resource.getRequest().getHeaders().add("Authorization", token); resource.get();
protected boolean handleResourceDelete(String resourceType, String resourceName, String namespace) { try { switch (resourceType) { case KubernetesResource.DEPLOYMENT: return client.extensions().deployments().inNamespace(namespace).withName(resourceName).delete(); case KubernetesResource.REPLICA_SET: return client.extensions().replicaSets().inNamespace(namespace).withName(resourceName).delete(); case KubernetesResource.CONFIG_MAP: return client.configMaps().inNamespace(namespace).withName(resourceName).delete(); case KubernetesResource.PERSISTENT_VOLUME: return client.persistentVolumes().withName(resourceName).delete(); case KubernetesResource.SECRET: return client.secrets().inNamespace(namespace).withName(resourceName).delete(); case KubernetesResource.SERVICE: return client.services().inNamespace(namespace).withName(resourceName).delete(); case KubernetesResource.REPLICATION_CONTROLLER: return client.replicationControllers().inNamespace(namespace).withName(resourceName).delete(); case KubernetesResource.NAMESPACE: return client.namespaces().withName(resourceName).delete(); } } catch (KubernetesClientException kce) { LOG.warn("Error deleting resource {}: {}", resourceName, kce); } return false; }
public static void cancelOpenShiftBuild(Build build) { logger.info("cancelling build in namespace " + build.getMetadata().getNamespace() + " with name: " + build.getMetadata().getName()); getOpenShiftClient().builds().inNamespace(build.getMetadata().getNamespace()).withName(build.getMetadata().getName()) .edit() .editStatus().withPhase(CANCELLED).endStatus() .done(); }
// Declare a custom Authenticator helper, if it is not standard Engine.getInstance().getRegisteredAuthenticators().add(new AuthenticatorHelper(ChallengeScheme.CUSTOM, true, false) {}); // set up the reusable challenge response ChallengeResponse cred = new ChallengeResponse(ChallengeScheme.CUSTOM); cred.setRawValue("12344"); ClientResource cr = new ClientResource("http://localhost:8183/"); cr.setChallengeResponse(cred); cr.get();
@Override protected synchronized void deleteEmptyNamespace(final String name) { if (!name.equals("default") && isNamespaceEmpty(name)) { if (client.projects().withName(name).get() != null && !client.projects().withName(name).get().getStatus().getPhase().equals(PHASE_TERMINATING)) { client.projects().withName(name).delete(); ExitCondition exitCondition = new ExitCondition() { @Override public Boolean call() { return client.projects().withName(name).get() == null; } @Override public String getFailureMessage() { return "Project " + name + " still present"; } }; waitForExitCondition(exitCondition); } } }
@Override protected boolean handleResourceDelete(String resourceType, String resourceName, String namespace) { if (super.handleResourceDelete(resourceType, resourceName, namespace)) { return true; } try { switch (resourceType) { case OpenShiftResource.DEPLOYMENT_CONFIG: return client.deploymentConfigs().inNamespace(namespace).withName(resourceName).delete(); case OpenShiftResource.PROJECT: return client.projects().withName(resourceName).delete(); case OpenShiftResource.TEMPLATE: return client.templates().inNamespace(namespace).withName(resourceName).delete(); case OpenShiftResource.BUILD_CONFIG: return client.buildConfigs().inNamespace(namespace).withName(resourceName).delete(); } } catch (KubernetesClientException kce) { LOG.warn("Error deleting resource {}: {}", resourceName, kce); } return false; }