List of usage examples for org.apache.http.client.fluent Request Get
public static Request Get(final String uri)
From source file:org.mule.module.http.functional.listener.HttpListenerResponseBuilderTestCase.java
@Test public void httpHeadersResponseBuilder() throws Exception { final String url = getUrl(httpHeadersResponseBuilderPath); final Response response = Request.Get(url).connectTimeout(1000).execute(); final HttpResponse httpResponse = response.returnResponse(); assertThat(httpResponse.getFirstHeader(HTTP_RELATIVE_PATH).getValue(), is("relativePath")); Header[] requestPathHeaders = httpResponse.getHeaders(HTTP_REQUEST_PATH_PROPERTY); assertThat(requestPathHeaders, is(arrayWithSize(2))); assertThat(requestPathHeaders[0].getValue(), isOneOf("requestPath1", "requestPath2")); assertThat(requestPathHeaders[1].getValue(), isOneOf("requestPath1", "requestPath2")); }
From source file:com.adobe.acs.commons.remoteassets.impl.RemoteAssetsNodeSyncImpl.java
/** * Get {@link JsonObject} from URL response. * * @param path String// w w w. j a va 2s . com * @return JsonObject * @throws IOException exception */ private JsonObject getJsonFromUri(final String path) throws IOException { URI pathUri; try { pathUri = new URI(null, null, path, null); } catch (URISyntaxException e) { LOG.error("URI Syntax Exception", e); throw new IOException("Invalid URI", e); } // we want to traverse the JCR one level at a time, hence the '1' selector. String url = this.remoteAssetsConfig.getServer() + pathUri.toString() + ".1.json"; Executor executor = this.remoteAssetsConfig.getRemoteAssetsHttpExecutor(); String responseString = executor.execute(Request.Get(url)).returnContent().asString(); try { JsonObject responseJson = new JsonParser().parse(responseString).getAsJsonObject(); LOG.debug("JSON successfully fetched for URL '{}'.", url); return responseJson; } catch (JsonSyntaxException | IllegalStateException e) { LOG.error("Unable to grab JSON Object. Please ensure URL {} is valid. \nRaw Response: {}", url, responseString); throw new IOException("Invalid JSON response", e); } }
From source file:org.exist.security.RestApiSecurityTest.java
private void executeQuery(final String xquery, final String uid, final String pwd) throws ApiException { final Executor exec = getExecutor(uid, pwd); try {//from ww w.jav a 2s . c om final String queryUri = createQueryUri(xquery); final HttpResponse resp = exec.execute(Request.Get(queryUri)).returnResponse(); if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new ApiException( "Could not execute query uri: " + queryUri + ". " + getResponseBody(resp.getEntity())); } } catch (final IOException ioe) { throw new ApiException(ioe); } }
From source file:com.qwazr.search.index.IndexSingleClient.java
@Override public LinkedHashMap<String, AnalyzerDefinition> getAnalyzers(String schema_name, String index_name) { UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name, "/analyzers"); Request request = Request.Get(uriBuilder.build()); return commonServiceRequest(request, null, null, AnalyzerDefinition.MapStringAnalyzerTypeRef, 200); }
From source file:org.restheart.test.integration.SecurityAuthTokenIT.java
@Test public void testAuthTokenInvalidation() throws Exception { Response resp = adminExecutor.execute(Request.Get(rootUri)); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp);/* w w w . ja v a 2 s. co m*/ StatusLine statusLine = httpResp.getStatusLine(); assertNotNull(statusLine); assertEquals("check authorized", HttpStatus.SC_OK, statusLine.getStatusCode()); Header[] _authToken = httpResp.getHeaders(AUTH_TOKEN_HEADER.toString()); Header[] _authTokenValid = httpResp.getHeaders(AUTH_TOKEN_VALID_HEADER.toString()); Header[] _authTokenLocation = httpResp.getHeaders(AUTH_TOKEN_LOCATION_HEADER.toString()); assertNotNull("check not null auth token header", _authToken); assertNotNull("check not null auth token valid header", _authTokenValid); assertNotNull("check not null auth token location header", _authTokenLocation); assertTrue("check not empty array auth token header array ", _authToken.length == 1); assertTrue("check not empty array auth token valid header", _authTokenValid.length == 1); assertTrue("check not empty array auth token location header", _authTokenLocation.length == 1); String locationURI = _authTokenLocation[0].getValue(); URI authTokenResourceUri = rootUri.resolve(locationURI); Response resp2 = unauthExecutor.auth(new Credentials() { @Override public Principal getUserPrincipal() { return new BasicUserPrincipal("admin"); } @Override public String getPassword() { return _authToken[0].getValue(); } }).execute(Request.Delete(authTokenResourceUri)); HttpResponse httpResp2 = resp2.returnResponse(); assertNotNull(httpResp2); StatusLine statusLine2 = httpResp2.getStatusLine(); assertNotNull(statusLine2); assertEquals("check auth token resource URI", HttpStatus.SC_NO_CONTENT, statusLine2.getStatusCode()); Response resp3 = unauthExecutor.auth(new Credentials() { @Override public Principal getUserPrincipal() { return new BasicUserPrincipal("admin"); } @Override public String getPassword() { return _authToken[0].getValue(); } }).execute(Request.Get(rootUri)); HttpResponse httpResp3 = resp3.returnResponse(); assertNotNull(httpResp3); StatusLine statusLine3 = httpResp3.getStatusLine(); assertNotNull(statusLine3); assertEquals("check auth token resource URI", HttpStatus.SC_UNAUTHORIZED, statusLine3.getStatusCode()); }
From source file:org.jboss.arquillian.container.was.wlp_remote_8_5.WLPRestClient.java
/** * Checks the application State using the WLP rest api. * //from www . j a va 2s . com * @param applicationName * @return true if the application is in STARTED state * @throws DeploymentException */ public boolean isApplicationStarted(String applicationName) { if (log.isLoggable(Level.FINER)) { log.entering(className, "isApplicationStarted"); } String restEndpoint = String.format( "https://%s:%d%sWebSphere:service=com.ibm.websphere.application.ApplicationMBean,name=%s/attributes/State", configuration.getHostName(), configuration.getHttpsPort(), MBEANS_ENDPOINT, applicationName); String status = ""; try { String jsonResponse = executor.execute(Request.Get(restEndpoint)).returnContent().asString(); status = parseJsonResponse(jsonResponse); } catch (ClientProtocolException e) { // This exception is expected if the application hasn't been // deployed yet as its MBean won't exist. // We expect this and can continue, set status to error. log.finest("Expected error occurred while checking if application " + applicationName + " is already started, app may not have been deployed yet. Ok to continue. " + e); status = "error"; } catch (IOException e) { log.severe("IOException occurred while checking if application " + applicationName + " is already started " + e); status = "error"; } boolean applicationState; if (STARTED.equals(status)) { applicationState = true; } else { applicationState = false; } if (log.isLoggable(Level.FINER)) { log.exiting(className, "isApplicationStarted", applicationState); } return applicationState; }
From source file:me.vertretungsplan.parser.CSVParser.java
@Override public List<String> getAllClasses() throws IOException, JSONException { if (data.has(PARAM_CLASSES_URL)) { String url = data.getString(PARAM_CLASSES_URL); String response = executor.execute(Request.Get(url)).returnContent().asString(); List<String> classes = new ArrayList<>(); for (String string : response.split("\n")) { classes.add(string.trim());/*w w w .j a va 2s . c o m*/ } return classes; } else { JSONArray classesJson = data.getJSONArray(PARAM_CLASSES); List<String> classes = new ArrayList<>(); for (int i = 0; i < classesJson.length(); i++) { classes.add(classesJson.getString(i)); } return classes; } }
From source file:com.streamsets.stage.destination.waveanalytics.WaveAnalyticsTarget.java
private String getDataflowId() throws IOException { LOG.info("*** " + restEndpoint + dataflowList); String json = Request.Get(restEndpoint + dataflowList) .addHeader("Authorization", "OAuth " + connection.getConfig().getSessionId()).execute() .returnContent().asString(); LOG.info("Got dataflow list: {}", json); ObjectMapper mapper = new ObjectMapper(); DataflowList dataflows = mapper.readValue(json, DataflowList.class); for (int i = 0; i < dataflows.result.size(); i++) { Result r = dataflows.result.get(i); if (r.name.equals(getDataflowName())) { return r._uid; }//w w w. j a v a 2 s. c om } return null; }
From source file:com.mywork.framework.util.RemoteHttpUtil.java
public static byte[] getImageByUrl(String imageUrl) throws ClientProtocolException, IOException { if (imageUrl != null) { byte[] resultBytes = Request.Get(imageUrl).connectTimeout(TIMEOUT_SECONDS * 1000) .socketTimeout(TIMEOUT_SECONDS * 1000).execute().returnContent().asBytes(); return resultBytes; }/*www . ja v a 2 s . c om*/ return null; }
From source file:com.qwazr.search.index.IndexSingleClient.java
@Override public AnalyzerDefinition getAnalyzer(String schema_name, String index_name, String analyzer_name) { UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name, "/analyzers/", analyzer_name); Request request = Request.Get(uriBuilder.build()); return commonServiceRequest(request, null, null, AnalyzerDefinition.class, 200); }