當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpMethod.POST屬性代碼示例

本文整理匯總了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));
	}
}
 
開發者ID:ligoj,項目名稱:plugin-vm-vcloud,代碼行數:44,代碼來源:VCloudPluginResource.java

示例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());
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:55,代碼來源:PersoniumCoreContainerFilterTest.java

示例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;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:10,代碼來源:PersoniumRequest.java


注:本文中的javax.ws.rs.HttpMethod.POST屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。