本文整理汇总了Java中javax.ws.rs.HttpMethod.POST属性的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.POST属性的具体用法?Java HttpMethod.POST怎么用?Java HttpMethod.POST使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.ws.rs.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.POST属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
@Override
public void execute(final int subscription, final VmOperation operation) throws Exception {
final Map<String, String> parameters = subscriptionResource.getParametersNoCheck(subscription);
final String vmUrl = "/vApp/vm-" + parameters.get(PARAMETER_VM);
// First get VM state
final VCloudVm vm = getVmDetails(parameters);
final VmStatus status = vm.getStatus();
// Get the right operation depending on the current state
final VmOperation operationF = failSafeOperation(status, operation);
if (operationF == null) {
// Final operation is considered as useless
log.info("Requested operation {} is marked as useless considering the status {} of vm {}", operation, status,
parameters.get(PARAMETER_VM));
return;
}
final String action = MapUtils.getObject(OPERATION_TO_VCLOUD, operationF, operationF.name().toLowerCase(Locale.ENGLISH));
// Check if undeployment is requested to shutdown completely the VM
if (operationF == VmOperation.SHUTDOWN || operationF == VmOperation.OFF) {
// The requested operation needs the VM to be undeployed
final String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1.5\"><UndeployPowerAction>"
+ action + "</UndeployPowerAction></UndeployVAppParams>";
final String url = StringUtils.removeEnd(parameters.get(PARAMETER_API), "/");
final CurlRequest request = new CurlRequest(HttpMethod.POST, url + vmUrl + "/action/undeploy", content,
"Content-Type:application/vnd.vmware.vcloud.undeployVAppParams+xml");
request.setSaveResponse(true);
// Use the preempted authentication
final VCloudCurlProcessor processor = new VCloudCurlProcessor();
authenticate(parameters, processor);
// Execute the request
processor.process(request);
processor.close();
checkSchedulerResponse(request.getResponse());
} else {
// Operation does not require to undeploy the VM
checkSchedulerResponse(authenticateAndExecute(parameters, HttpMethod.POST, vmUrl + "/power/action/" + action));
}
}
示例2: testFilterContainerRequest
/**
* リクエストフィルタとしてメソッド/ヘッダオーバライドを実施していることを確認.
* X-FORWARDED-PROTO、X-FORWARDED-HOSTヘッダでリクエストUri, Base UriのPROTO, HOST部が書き換わることを確認。
* @throws URISyntaxException URISyntaxException
*/
@Test
public void testFilterContainerRequest() throws URISyntaxException {
// 被テストオブジェクトを準備
PersoniumCoreContainerFilter containerFilter = new PersoniumCoreContainerFilter();
// ContainerRequiestを準備
WebApplication wa = mock(WebApplication.class);
InBoundHeaders headers = new InBoundHeaders();
// メソッドオーバーライド
headers.add(PersoniumCoreUtils.HttpHeaders.X_HTTP_METHOD_OVERRIDE, HttpMethod.OPTIONS);
// ヘッダオーバーライド
String authzValue = "Bearer tokenstring";
String acceptValue = "text/html";
String contentTypeValue = "application/xml";
headers.add(PersoniumCoreUtils.HttpHeaders.X_OVERRIDE, HttpHeaders.AUTHORIZATION + ": " + authzValue);
headers.add(HttpHeaders.ACCEPT, contentTypeValue);
headers.add(PersoniumCoreUtils.HttpHeaders.X_OVERRIDE, HttpHeaders.ACCEPT + ": " + acceptValue);
headers.add(HttpHeaders.CONTENT_TYPE, contentTypeValue);
// X-FORWARDED-* 系のヘッダ設定
String scheme = "https";
String host = "example.org";
headers.add(PersoniumCoreUtils.HttpHeaders.X_FORWARDED_PROTO, scheme);
headers.add(PersoniumCoreUtils.HttpHeaders.X_FORWARDED_HOST, host);
ContainerRequest request = new ContainerRequest(wa, HttpMethod.POST,
new URI("http://dc1.example.com/hoge"),
new URI("http://dc1.example.com/hoge/hoho"),
headers, null);
// HttpServletRequestのmockを準備
HttpServletRequest mockServletRequest = mock(HttpServletRequest.class);
when(mockServletRequest.getRequestURL()).thenReturn(new StringBuffer("http://dc1.example.com"));
ServletContext mockServletContext = mock(ServletContext.class);
when(mockServletContext.getContextPath()).thenReturn("");
when(mockServletRequest.getServletContext()).thenReturn(mockServletContext);
containerFilter.setHttpServletRequest(mockServletRequest);
// 被テスト処理の実行
ContainerRequest filteredRequest = containerFilter.filter(request);
// 結果の検証。
Assert.assertEquals(HttpMethod.OPTIONS, filteredRequest.getMethod());
Assert.assertEquals(authzValue, filteredRequest.getHeaderValue(HttpHeaders.AUTHORIZATION));
Assert.assertEquals(acceptValue, filteredRequest.getHeaderValue(HttpHeaders.ACCEPT));
Assert.assertEquals(contentTypeValue, filteredRequest.getHeaderValue(HttpHeaders.CONTENT_TYPE));
Assert.assertEquals(scheme, filteredRequest.getRequestUri().getScheme());
Assert.assertEquals(host, filteredRequest.getRequestUri().getHost());
}
示例3: post
/**
* POSTメソッドとしてRequestオブジェクトを生成する.
* @param url URL
* @return req DcRequestオブジェクト
*/
public static PersoniumRequest post(String url) {
PersoniumRequest req = new PersoniumRequest(url);
req.method = HttpMethod.POST;
return req;
}