本文整理了Java中co.cask.common.http.HttpRequest.put()
方法的一些代码示例,展示了HttpRequest.put()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.put()
方法的具体详情如下:
包路径:co.cask.common.http.HttpRequest
类名称:HttpRequest
方法名:put
暂无
代码示例来源:origin: stackoverflow.com
YouTube youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
request.put("Authorization", "Bearer " + yourAccessTokenString);
}
}).setApplicationName("AppName").build();
代码示例来源:origin: co.cask.cdap/cdap-common
@Override
public void updateProperties(NamespaceId namespaceId, NamespaceMeta metadata) throws Exception {
URL url = resolve(String.format("namespaces/%s/properties", namespaceId.getNamespace()));
HttpResponse response = execute(HttpRequest.put(url).withBody(GSON.toJson(metadata)).build());
String responseBody = response.getResponseBodyAsString();
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return;
}
if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException("Bad request: " + responseBody);
}
throw new IOException(String.format("Cannot update namespace %s. Reason: %s", namespaceId, responseBody));
}
代码示例来源:origin: caskdata/cdap
@Override
public void updateProperties(NamespaceId namespaceId, NamespaceMeta metadata) throws Exception {
URL url = resolve(String.format("namespaces/%s/properties", namespaceId.getNamespace()));
HttpResponse response = execute(HttpRequest.put(url).withBody(GSON.toJson(metadata)).build());
String responseBody = response.getResponseBodyAsString();
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return;
}
if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException("Bad request: " + responseBody);
}
throw new IOException(String.format("Cannot update namespace %s. Reason: %s", namespaceId, responseBody));
}
代码示例来源:origin: caskdata/cdap
/**
* Stores RouteConfig of a service with different application versions.
*
* @param serviceId {@link ServiceId} of the service with the application version part ignored
* @param routeConfig a Map of {@link String} application version and {@link Integer} percentage of
* traffic routed to the version.
*/
public void storeRouteConfig(ServiceId serviceId, Map<String, Integer> routeConfig)
throws IOException, UnauthorizedException, UnauthenticatedException {
URL url = buildRouteConfigUrl(serviceId);
HttpRequest request = HttpRequest.put(url)
.withBody(GSON.toJson(routeConfig, MAP_STRING_INTEGER_TYPE)).build();
restClient.upload(request, config.getAccessToken());
}
代码示例来源:origin: caskdata/cdap
@Override
public void addRoleToPrincipal(Role role, Principal principal) throws IOException, FeatureDisabledException,
UnauthenticatedException, UnauthorizedException, NotFoundException,
co.cask.cdap.security.spi.authorization.NotFoundException {
URL url = config.resolveURLV3(String.format(AUTHORIZATION_BASE + "%s/%s/roles/%s", principal.getType(),
principal.getName(), role.getName()));
HttpRequest request = HttpRequest.put(url).build();
executeExistingRolesRequest(role, request);
}
代码示例来源:origin: caskdata/cdap
@Override
public void createRole(Role role) throws IOException, FeatureDisabledException, UnauthenticatedException,
UnauthorizedException, AlreadyExistsException, NotFoundException {
URL url = config.resolveURLV3(String.format(AUTHORIZATION_BASE + "roles/%s", role.getName()));
HttpRequest request = HttpRequest.put(url).build();
HttpResponse httpResponse = doExecuteRequest(request, HttpURLConnection.HTTP_CONFLICT);
if (httpResponse.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
throw new AlreadyExistsException(role);
}
}
代码示例来源:origin: caskdata/cdap
@Override
public void create(NamespaceMeta metadata) throws Exception {
URL url = resolve(String.format("namespaces/%s", metadata.getName()));
HttpResponse response = execute(HttpRequest.put(url).withBody(GSON.toJson(metadata)).build());
String responseBody = response.getResponseBodyAsString();
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
if (responseBody.equals(String.format("Namespace '%s' already exists.", metadata.getName()))) {
throw new NamespaceAlreadyExistsException(metadata.getNamespaceId());
}
return;
}
if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException("Bad request: " + responseBody);
}
throw new IOException(String.format("Cannot create namespace %s. Reason: %s", metadata.getName(), responseBody));
}
代码示例来源:origin: co.cask.cdap/cdap-common
@Override
public void create(NamespaceMeta metadata) throws Exception {
URL url = resolve(String.format("namespaces/%s", metadata.getName()));
HttpResponse response = execute(HttpRequest.put(url).withBody(GSON.toJson(metadata)).build());
String responseBody = response.getResponseBodyAsString();
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
if (responseBody.equals(String.format("Namespace '%s' already exists.", metadata.getName()))) {
throw new NamespaceAlreadyExistsException(metadata.getNamespaceId());
}
return;
}
if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException("Bad request: " + responseBody);
}
throw new IOException(String.format("Cannot create namespace %s. Reason: %s", metadata.getName(), responseBody));
}
代码示例来源:origin: cdapio/cdap
protected static HttpResponse doPut(String resource, @Nullable String body) throws Exception {
HttpRequest.Builder builder = HttpRequest.put(getEndPoint(resource).toURL());
builder.addHeader(Constants.Gateway.API_KEY, API_KEY);
if (body != null) {
builder.withBody(body);
}
return HttpRequests.execute(builder.build(), httpRequestConfig);
}
代码示例来源:origin: cdapio/cdap
public HttpResponse create(String key, SecureKeyCreateRequest keyCreateRequest) throws Exception {
return HttpRequests.execute(HttpRequest.put(getURL("/v3/namespaces/default/securekeys/" + key))
.withBody(GSON.toJson(keyCreateRequest)).build());
}
代码示例来源:origin: cdapio/cdap
protected HttpResponse deploy(Id.Application appId,
AppRequest<? extends Config> appRequest) throws Exception {
String deployPath = getVersionedAPIPath("apps/" + appId.getId(), appId.getNamespaceId());
return executeDeploy(HttpRequest.put(getEndPoint(deployPath).toURL()), appRequest);
}
代码示例来源:origin: cdapio/cdap
private void createPartition(URL serviceUrl, String body, String time) throws IOException {
HttpResponse response =
HttpRequests.execute(HttpRequest.put(new URL(serviceUrl, "lines?time=" + time)).withBody(body).build());
Assert.assertEquals(200, response.getResponseCode());
}
代码示例来源:origin: caskdata/cdap
private HttpResponse createInstance(DatasetId instance, String typeName, @Nullable String description,
@Nullable DatasetProperties props,
@Nullable String ownerPrincipal) throws IOException {
DatasetInstanceConfiguration creationProperties;
if (props != null) {
creationProperties = new DatasetInstanceConfiguration(typeName, props.getProperties(), description,
ownerPrincipal);
} else {
creationProperties = new DatasetInstanceConfiguration(typeName, null, description, ownerPrincipal);
}
HttpRequest request = HttpRequest.put(getUrl(instance.getNamespace(), "/data/datasets/" + instance.getEntityName()))
.withBody(GSON.toJson(creationProperties)).build();
return HttpRequests.execute(request);
}
代码示例来源:origin: cdapio/cdap
protected HttpResponse addArtifactProperties(Id.Artifact artifactId,
Map<String, String> properties) throws Exception {
String nonNamespacePath = String.format("artifacts/%s/versions/%s/properties",
artifactId.getName(), artifactId.getVersion());
String path = getVersionedAPIPath(nonNamespacePath, artifactId.getNamespace().getId());
HttpRequest request = HttpRequest.put(getEndPoint(path).toURL())
.withBody(properties.toString())
.build();
return HttpRequests.execute(request, httpRequestConfig);
}
代码示例来源:origin: caskdata/cdap
private void doAdd(ScheduleId scheduleId, String json) throws IOException,
UnauthenticatedException, NotFoundException, UnauthorizedException, AlreadyExistsException {
String path = String.format("apps/%s/versions/%s/schedules/%s",
scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path);
HttpRequest request = HttpRequest.put(url).withBody(json).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(),
HttpURLConnection.HTTP_NOT_FOUND,
HttpURLConnection.HTTP_CONFLICT);
if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
throw new NotFoundException(scheduleId);
} else if (HttpURLConnection.HTTP_CONFLICT == response.getResponseCode()) {
throw new AlreadyExistsException(scheduleId);
}
}
代码示例来源:origin: caskdata/cdap
private HttpResponse updateInstance(DatasetId instance, DatasetProperties props) throws IOException {
HttpRequest request = HttpRequest.put(getUrl(instance.getNamespace(),
"/data/datasets/" + instance.getEntityName() + "/properties"))
.withBody(GSON.toJson(props.getProperties())).build();
return HttpRequests.execute(request);
}
代码示例来源:origin: caskdata/cdap
private void validatePut(URL url, String body, Integer ... expected) throws IOException {
HttpRequest request = HttpRequest.put(url).withBody(body).build();
assertStatus(HttpRequests.execute(request).getResponseCode(), url, expected);
}
代码示例来源:origin: caskdata/cdap
protected HttpResponse deployModule(DatasetModuleId module, Class moduleClass, boolean force) throws Exception {
Location moduleJar = createModuleJar(moduleClass);
String urlPath = "/data/modules/" + module.getEntityName();
urlPath = force ? urlPath + "?force=true" : urlPath;
HttpRequest request = HttpRequest.put(getUrl(module.getNamespace(), urlPath))
.addHeader("X-Class-Name", moduleClass.getName())
.withBody((ContentProvider<? extends InputStream>) moduleJar::getInputStream).build();
return HttpRequests.execute(request);
}
代码示例来源:origin: cdapio/cdap
private void testAppConfig(String appName, ApplicationManager appManager,
ConfigTestApp.ConfigClass conf) throws Exception {
String datasetName = conf == null ? ConfigTestApp.DEFAULT_TABLE : conf.getTableName();
ServiceManager serviceManager = appManager.getServiceManager(ConfigTestApp.SERVICE_NAME).start();
URL serviceURL = serviceManager.getServiceURL(5, TimeUnit.SECONDS);
// Write data to the table using the service
URL url = new URL(serviceURL, "write/abcd");
Assert.assertEquals(200, HttpRequests.execute(HttpRequest.put(url).build()).getResponseCode());
url = new URL(serviceURL, "write/xyz");
Assert.assertEquals(200, HttpRequests.execute(HttpRequest.put(url).build()).getResponseCode());
DataSetManager<KeyValueTable> dsManager = getDataset(datasetName);
KeyValueTable table = dsManager.get();
Assert.assertEquals("abcd", Bytes.toString(table.read(appName + ".abcd")));
Assert.assertEquals("xyz", Bytes.toString(table.read(appName + ".xyz")));
}
代码示例来源:origin: caskdata/cdap
protected int deployModuleBundled(String moduleName, String moduleClassName, Class moduleClass,
Location...bundleEmbeddedJars) throws IOException {
Location moduleJar = createModuleJar(moduleClass, bundleEmbeddedJars);
HttpRequest request = HttpRequest.put(getUrl("/data/modules/" + moduleName))
.addHeader("X-Class-Name", moduleClassName)
.withBody((ContentProvider<? extends InputStream>) moduleJar::getInputStream).build();
return HttpRequests.execute(request).getResponseCode();
}
内容来源于网络,如有侵权,请联系作者删除!