本文整理了Java中co.cask.common.http.HttpRequest.get()
方法的一些代码示例,展示了HttpRequest.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.get()
方法的具体详情如下:
包路径:co.cask.common.http.HttpRequest
类名称:HttpRequest
方法名:get
暂无
代码示例来源:origin: co.cask.cdap/cdap-authentication-client
private AccessToken fetchAccessToken() throws IOException {
LOG.debug("Authentication is enabled in the gateway server. Authentication URI {}.", getAuthURI());
return execute(HttpRequest.get(getAuthURI().toURL())
.addHeaders(getAuthenticationHeaders())
.build()
);
}
代码示例来源:origin: caskdata/cdap
@Override
public List<NamespaceMeta> list() throws Exception {
HttpRequest request = HttpRequest.get(resolve("namespaces")).build();
HttpResponse response = execute(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return ObjectResponse.fromJsonBody(response, new TypeToken<List<NamespaceMeta>>() { }).getResponseObject();
}
throw new IOException(String.format("Cannot list namespaces. Reason: %s", response.getResponseBodyAsString()));
}
代码示例来源:origin: co.cask.cdap/cdap-common
@Override
public List<NamespaceMeta> list() throws Exception {
HttpRequest request = HttpRequest.get(resolve("namespaces")).build();
HttpResponse response = execute(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return ObjectResponse.fromJsonBody(response, new TypeToken<List<NamespaceMeta>>() { }).getResponseObject();
}
throw new IOException(String.format("Cannot list namespaces. Reason: %s", response.getResponseBodyAsString()));
}
代码示例来源:origin: caskdata/cdap
private Set<Role> listRolesHelper(@Nullable Principal principal) throws IOException, FeatureDisabledException,
UnauthenticatedException, UnauthorizedException, NotFoundException {
URL url = principal == null ? config.resolveURLV3(AUTHORIZATION_BASE + "roles") :
config.resolveURLV3(String.format(AUTHORIZATION_BASE + "%s/%s/roles", principal.getType(), principal.getName()));
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = doExecuteRequest(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return ObjectResponse.fromJsonBody(response, TYPE_OF_ROLE_SET).getResponseObject();
}
throw new IOException(String.format("Cannot list roles. Reason: %s", response.getResponseBodyAsString()));
}
代码示例来源:origin: co.cask.cdap/cdap-common
@Override
public NamespaceMeta get(NamespaceId namespaceId) throws Exception {
HttpResponse response =
execute(HttpRequest.get(resolve(String.format("namespaces/%s", namespaceId.getNamespace()))).build());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NamespaceNotFoundException(namespaceId);
} else if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return ObjectResponse.fromJsonBody(response, NamespaceMeta.class).getResponseObject();
}
throw new IOException(String.format("Cannot get namespace %s. Reason: %s",
namespaceId, response.getResponseBodyAsString()));
}
代码示例来源:origin: caskdata/cdap
@Override
public Set<Privilege> listPrivileges(Principal principal) throws IOException, FeatureDisabledException,
UnauthenticatedException, UnauthorizedException, NotFoundException {
URL url = config.resolveURLV3(String.format(AUTHORIZATION_BASE + "%s/%s/privileges", principal.getType(),
principal.getName()));
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = doExecuteRequest(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return ObjectResponse.fromJsonBody(response, TYPE_OF_PRIVILEGE_SET, GSON).getResponseObject();
}
throw new IOException(String.format("Cannot list privileges. Reason: %s", response.getResponseBodyAsString()));
}
代码示例来源:origin: caskdata/cdap
@Override
public NamespaceMeta get(NamespaceId namespaceId) throws Exception {
HttpResponse response =
execute(HttpRequest.get(resolve(String.format("namespaces/%s", namespaceId.getNamespace()))).build());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NamespaceNotFoundException(namespaceId);
} else if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return ObjectResponse.fromJsonBody(response, NamespaceMeta.class).getResponseObject();
}
throw new IOException(String.format("Cannot get namespace %s. Reason: %s",
namespaceId, response.getResponseBodyAsString()));
}
代码示例来源:origin: cdapio/cdap
/**
* This test failure in creating SSH tunnel
*/
@Test(expected = IOException.class)
public void testFailTunnel() throws Exception {
InetSocketAddress httpAddr = httpService.getBindAddress();
// Close the SSH session, hence can't create port forwarding
sshSession.close();
// On proxy failure, IOException will be thrown
URL url = new URL(String.format("http://%s:%d/ping", httpAddr.getHostName(), httpAddr.getPort()));
HttpRequests.execute(co.cask.common.http.HttpRequest.get(url).build());
}
代码示例来源:origin: cdapio/cdap
protected static HttpResponse doGet(String resource, @Nullable Map<String, String> headers) throws Exception {
HttpRequest.Builder builder = HttpRequest.get(getEndPoint(resource).toURL());
if (headers != null) {
builder.addHeaders(headers);
}
builder.addHeader(Constants.Gateway.API_KEY, API_KEY);
return HttpRequests.execute(builder.build(), httpRequestConfig);
}
代码示例来源:origin: cdapio/cdap
private Long getCount(URL serviceUrl, String word) throws IOException {
HttpResponse response =
HttpRequests.execute(HttpRequest.get(new URL(serviceUrl, "counts?word=" + word)).build());
Assert.assertEquals(200, response.getResponseCode());
return Long.valueOf(response.getResponseBodyAsString());
}
}
代码示例来源:origin: caskdata/cdap
private HttpResponse makeInstancesRequest(String namespace) throws IOException {
HttpRequest request = HttpRequest.get(getUrl(namespace, "/data/datasets")).build();
return HttpRequests.execute(request);
}
代码示例来源:origin: cdapio/cdap
public HttpResponse list() throws Exception {
return HttpRequests.execute(HttpRequest.get(getURL("/v3/namespaces/default/securekeys")).build());
}
}
代码示例来源:origin: caskdata/cdap
private ObjectResponse<DatasetMeta> getInstanceObject(String instanceName) throws IOException {
HttpRequest request = HttpRequest.get(getUrl("/data/datasets/" + instanceName)).build();
HttpResponse response = HttpRequests.execute(request);
return ObjectResponse.fromJsonBody(response, DatasetMeta.class);
}
代码示例来源:origin: caskdata/cdap
protected HttpResponse makeModulesRequest(NamespaceId namespaceId) throws IOException {
HttpRequest request = HttpRequest.get(getUrl(namespaceId.getEntityName(), "/data/modules")).build();
return HttpRequests.execute(request);
}
代码示例来源:origin: caskdata/cdap
private void validateGet(URL url, Integer ... expected) throws IOException {
HttpRequest request = HttpRequest.get(url).build();
assertStatus(HttpRequests.execute(request).getResponseCode(), url, expected);
}
代码示例来源:origin: caskdata/cdap
private HttpResponse makeTypesRequest(NamespaceId namespaceId) throws IOException {
HttpRequest request = HttpRequest.get(getUrl(namespaceId.getEntityName(), "/data/types")).build();
return HttpRequests.execute(request);
}
代码示例来源:origin: caskdata/cdap
private HttpResponse makeTypeInfoRequest(DatasetTypeId datasetType) throws IOException {
HttpRequest request = HttpRequest.get(
getUrl(datasetType.getNamespace(), "/data/types/" + datasetType.getEntityName())).build();
return HttpRequests.execute(request);
}
}
代码示例来源:origin: caskdata/cdap
private HttpResponse getInstance(DatasetId instance) throws IOException {
URL instanceUrl = getUrl(instance.getNamespace(), "/data/datasets/" + instance.getEntityName());
HttpRequest request = HttpRequest.get(instanceUrl).build();
return HttpRequests.execute(request);
}
代码示例来源:origin: caskdata/cdap
private ObjectResponse<Map<String, String>> getInstanceProperties(String instanceName) throws IOException {
HttpRequest request = HttpRequest.get(getUrl("/data/datasets/" + instanceName + "/properties")).build();
HttpResponse response = HttpRequests.execute(request);
return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() { }.getType());
}
代码示例来源:origin: caskdata/cdap
private HttpResponse makeModuleInfoRequest(DatasetModuleId module) throws IOException {
HttpRequest request = HttpRequest.get(getUrl(module.getNamespace(),
"/data/modules/" + module.getEntityName())).build();
return HttpRequests.execute(request);
}
内容来源于网络,如有侵权,请联系作者删除!