use of org.apache.commons.httpclient.methods.GetMethod in project camel by apache.
the class NettyHttpBridgeEncodedPathTest method testEncodedPath.
@Test
public void testEncodedPath() throws Exception {
String path = URLEncoder.encode(" :/?#[]@!$", "UTF-8") + "/" + URLEncoder.encode("&'()+,;=", "UTF-8");
MockEndpoint mock = getMockEndpoint("mock:encodedPath");
mock.message(0).header(Exchange.HTTP_PATH).isEqualTo("/" + path);
mock.message(0).header(Exchange.HTTP_QUERY).isNull();
mock.message(0).header(Exchange.HTTP_RAW_QUERY).isNull();
// cannot use template as it automatically decodes some chars in the path
HttpClient httpClient = new HttpClient();
GetMethod httpGet = new GetMethod("http://localhost:" + port4 + "/nettyTestRouteC/" + path);
int status = httpClient.executeMethod(httpGet);
assertEquals("Get a wrong response status", 200, status);
assertMockEndpointsSatisfied();
}
use of org.apache.commons.httpclient.methods.GetMethod in project camel by apache.
the class WeatherConsumer method poll.
@Override
protected int poll() throws Exception {
LOG.debug("Going to execute the Weather query {}", query);
HttpClient httpClient = ((WeatherComponent) getEndpoint().getComponent()).getHttpClient();
GetMethod getMethod = new GetMethod(query);
try {
int status = httpClient.executeMethod(getMethod);
if (status != HttpStatus.SC_OK) {
LOG.warn("HTTP call for weather returned error status code {} - {} as a result with query: {}", status, getMethod.getStatusLine(), query);
return 0;
}
String weather = getEndpoint().getCamelContext().getTypeConverter().mandatoryConvertTo(String.class, getMethod.getResponseBodyAsStream());
LOG.debug("Got back the Weather information {}", weather);
if (ObjectHelper.isEmpty(weather)) {
// empty response
return 0;
}
Exchange exchange = getEndpoint().createExchange();
String header = getEndpoint().getConfiguration().getHeaderName();
if (header != null) {
exchange.getIn().setHeader(header, weather);
} else {
exchange.getIn().setBody(weather);
}
exchange.getIn().setHeader(WeatherConstants.WEATHER_QUERY, query);
getProcessor().process(exchange);
return 1;
} finally {
getMethod.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.GetMethod in project h2o-2 by h2oai.
the class WebAPI method listJobs.
/**
* Lists jobs currently running.
*/
static void listJobs() throws Exception {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(URL + "/Jobs.json");
int status = client.executeMethod(get);
if (status != 200)
throw new Exception(get.getStatusText());
Gson gson = new Gson();
JobsRes res = gson.fromJson(new InputStreamReader(get.getResponseBodyAsStream()), JobsRes.class);
System.out.println("Running jobs:");
for (Job job : res.jobs) System.out.println(job.description + " " + job.destination_key);
get.releaseConnection();
}
use of org.apache.commons.httpclient.methods.GetMethod in project h2o-2 by h2oai.
the class WebAPI method exportModel.
/**
* Exports a model to a JSON file.
*/
static void exportModel() throws Exception {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(URL + "/2/ExportModel.json?model=MyInitialNeuralNet");
int status = client.executeMethod(get);
if (status != 200)
throw new Exception(get.getStatusText());
JsonObject response = (JsonObject) new JsonParser().parse(new InputStreamReader(get.getResponseBodyAsStream()));
JsonElement model = response.get("model");
JsonWriter writer = new JsonWriter(new FileWriter(JSON_FILE));
writer.setLenient(true);
writer.setIndent(" ");
Streams.write(model, writer);
writer.close();
get.releaseConnection();
}
use of org.apache.commons.httpclient.methods.GetMethod in project h2o-2 by h2oai.
the class CloudConnect method launch.
/**
* Upload jars to an existing cloud and launches a custom job. Uses the Web API.
*/
public static void launch(String job, String host, File... jars) throws Exception {
HttpClient client = new HttpClient();
String args = "job_class=" + job + "&jars=";
for (File f : jars) {
PostMethod post = new PostMethod("http://" + host + "/Upload.json?key=" + f.getName());
Part[] parts = { new FilePart(f.getName(), f) };
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
if (200 != client.executeMethod(post))
throw new RuntimeException("Request failed: " + post.getStatusLine());
args += f.getName() + ",";
post.releaseConnection();
}
String href = new LaunchJar().href();
GetMethod get = new GetMethod("http://" + host + href + ".json?" + args);
if (200 != client.executeMethod(get))
throw new RuntimeException("Request failed: " + get.getStatusLine());
get.releaseConnection();
}
Aggregations