use of org.apache.http.client.utils.URIBuilder in project musiccabinet by hakko.
the class AbstractWSGetClient method getURI.
/*
* Assemble URI for the Last.fm web service.
*/
protected URI getURI(List<NameValuePair> params) throws ApplicationException {
URI uri = null;
try {
URIBuilder uriBuilder = new URIBuilder();
uriBuilder.setScheme(HTTP);
uriBuilder.setHost(HOST);
uriBuilder.setPath(PATH);
for (NameValuePair param : params) {
uriBuilder.addParameter(param.getName(), param.getValue());
}
uri = uriBuilder.build();
} catch (URISyntaxException e) {
throw new ApplicationException("Could not create Last.fm URI!", e);
}
return uri;
}
use of org.apache.http.client.utils.URIBuilder in project musiccabinet by hakko.
the class AbstractWSPostClient method getURI.
/*
* Assemble URI for the Last.fm web service.
*/
protected URI getURI(List<NameValuePair> params) throws ApplicationException {
URI uri = null;
try {
URIBuilder uriBuilder = new URIBuilder();
uriBuilder.setScheme(HTTP);
uriBuilder.setHost(HOST);
uriBuilder.setPath(PATH);
uri = uriBuilder.build();
} catch (URISyntaxException e) {
throw new ApplicationException("Could not create Last.fm URI!", e);
}
return uri;
}
use of org.apache.http.client.utils.URIBuilder in project platformlayer by platformlayer.
the class MetricClientImpl method getMetrics.
@Override
public MetricServiceData getMetrics(MetricQuery query) throws RestClientException {
URI url = metricBaseUrl.resolve("api/metric/").resolve(project + "/");
URIBuilder uriBuilder = new URIBuilder(url);
if (query != null) {
for (String filter : query.filters) {
int firstEquals = filter.indexOf('=');
if (firstEquals == -1) {
uriBuilder.addParameter("has." + filter, "");
} else {
String key = filter.substring(0, firstEquals);
String value = filter.substring(firstEquals + 1);
uriBuilder.addParameter("filter." + key, value);
}
}
for (String projection : query.projections) {
int firstEquals = projection.indexOf('=');
if (firstEquals == -1) {
uriBuilder.addParameter("select." + projection, "");
} else {
throw new IllegalArgumentException();
}
}
if (query.flatten) {
uriBuilder.addParameter("flatten", "true");
}
}
try {
url = uriBuilder.build();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Error building URI", e);
}
HttpGet request = new HttpGet(url);
HttpResponse response = null;
try {
response = httpClient.execute(request);
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() != 200) {
log.info("Error reading from metrics service: " + statusLine);
throw new RestClientException("Error reading from metrics service", null, statusLine.getStatusCode());
} else {
MetricServiceData ret = new MetricServiceData(request, response);
// Don't close yet
response = null;
return ret;
}
} catch (IOException e) {
throw new RestClientException("Error reading from metrics service", e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.warn("Error consuming response", e);
}
}
}
}
use of org.apache.http.client.utils.URIBuilder in project wechat-mp-sdk by usc.
the class AccessServletRealTest method testGet.
private static void testGet() throws Exception {
String echoStr = RandomStringUtils.randomAlphabetic(36);
URI uri = new URIBuilder("http://localhost/wechat/mp/access").addParameter("echostr", echoStr).addParameter("nonce", "1366260493").addParameter("timestamp", "1366238018").addParameter("signature", "9498eeaaca0b8a35f1b027498e0c0fb37fec5fa0").build();
String rtn = Request.Get(uri).execute().returnContent().asString();
System.out.println(echoStr + " ==> " + rtn);
}
use of org.apache.http.client.utils.URIBuilder in project wechat-mp-sdk by usc.
the class AccessServletRealTest method testPost.
private static void testPost() throws Exception {
URI uri = new URIBuilder("http://localhost/wechat/mp/access").addParameter("nonce", "1366260493").addParameter("timestamp", "1366238018").addParameter("signature", "9498eeaaca0b8a35f1b027498e0c0fb37fec5fa0").build();
File parent = new File(AccessServletRealTest.class.getClassLoader().getResource("push").toURI());
for (File pushFile : parent.listFiles()) {
String body = FileUtils.readFileToString(pushFile);
String reply = Request.Post(uri).bodyString(body, ContentType.create("text/html", Consts.UTF_8)).execute().returnContent().asString();
System.out.println(pushFile + "\n" + body + "\n" + reply + "\n");
}
}
Aggregations