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


Java HttpMethod.getResponseBodyAsString方法代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.HttpMethod.getResponseBodyAsString方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpMethod.getResponseBodyAsString方法的具體用法?Java HttpMethod.getResponseBodyAsString怎麽用?Java HttpMethod.getResponseBodyAsString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.httpclient.HttpMethod的用法示例。


在下文中一共展示了HttpMethod.getResponseBodyAsString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SwiftInvalidResponseException

import org.apache.commons.httpclient.HttpMethod; //導入方法依賴的package包/類
public SwiftInvalidResponseException(String message,
                                     String operation,
                                     URI uri,
                                     HttpMethod method) {
  super(message);
  this.statusCode = method.getStatusCode();
  this.operation = operation;
  this.uri = uri;
  String bodyAsString;
  try {
    bodyAsString = method.getResponseBodyAsString();
    if (bodyAsString == null) {
      bodyAsString = "";
    }
  } catch (IOException e) {
    bodyAsString = "";
  }
  this.body = bodyAsString;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:SwiftInvalidResponseException.java

示例2: checkResponseStatus

import org.apache.commons.httpclient.HttpMethod; //導入方法依賴的package包/類
/**
 *
 * @param methodName String
 * @param response int
 * @param method HttpMethod
 */
private void checkResponseStatus(String methodName, int response, HttpMethod method)
{
    if (response != 200)
    {
        Throwable error = null;
        try
        {
            log.error("Received \"unsuccessful\" response code from target server: " + response);
            String errorPayload = method.getResponseBodyAsString();
            JSONObject errorObj = new JSONObject(errorPayload);
            error = rehydrateError(errorObj);
        }
        catch (Exception ex)
        {
            throw new TransferException(MSG_UNSUCCESSFUL_RESPONSE, new Object[] {methodName, response});
        }
        if ((error != null) && TransferException.class.isAssignableFrom(error.getClass()))
        {
            throw (TransferException)error;
        }
        else
        {
            throw new TransferException(MSG_UNSUCCESSFUL_RESPONSE, new Object[] {methodName, response});
        }
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:33,代碼來源:HttpClientTransmitterImpl.java

示例3: analyzeServerErrorAndThrow

import org.apache.commons.httpclient.HttpMethod; //導入方法依賴的package包/類
private void analyzeServerErrorAndThrow(int code, HttpMethod streamedPostMethod) throws IOException
{
    throw new JrpipRuntimeException("Server error (" + code + ").\n" + streamedPostMethod.getResponseBodyAsString());
}
 
開發者ID:goldmansachs,項目名稱:jrpip,代碼行數:5,代碼來源:FastServletProxyInvocationHandler.java

示例4: testImportAutoCheckoutNodes

import org.apache.commons.httpclient.HttpMethod; //導入方法依賴的package包/類
/**
   * SLING-2108 Test import operation which auto checks out versionable nodes.
   */
  public void testImportAutoCheckoutNodes() throws IOException, JsonException {
      final String testPath = TEST_BASE_PATH;
      Map<String, String> props = new HashMap<String, String>();
      String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
      urlsToDelete.add(testNode);

      //1. first create some content to update.
      props.clear();
      props.put(SlingPostConstants.RP_OPERATION,
      		SlingPostConstants.OPERATION_IMPORT);

      String testNodeName = "testNode_" + String.valueOf(random.nextInt());
      props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName);
      testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport3.json"));
      props.put(SlingPostConstants.RP_CONTENT_TYPE, "json");
      props.put(SlingPostConstants.RP_REDIRECT_TO, SERVLET_CONTEXT + testPath + "/*");
      props.put(SlingPostConstants.RP_CHECKIN, "true");
      String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true,
      		testFile, SlingPostConstants.RP_CONTENT_FILE, null);

      // assert content at new location
      String content = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);

JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);

//assert that the versionable node is checked in.
assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));


//2. try an update with the :autoCheckout value set to false
      List<NameValuePair> postParams = new ArrayList<NameValuePair>();
      postParams.add(new NameValuePair(SlingPostConstants.RP_OPERATION,
      						SlingPostConstants.OPERATION_IMPORT));
      postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT_TYPE, "json"));
      postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
      postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
      postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "false"));
      postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
      assertPostStatus(importedNodeUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, "Expected error from VersionException");

//3. now try an update with the :autoCheckout value set to true
      postParams.clear();
      postParams.add(new NameValuePair(SlingPostConstants.RP_OPERATION,
		SlingPostConstants.OPERATION_IMPORT));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT_TYPE, "json"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
postParams.add(new NameValuePair(":http-equiv-accept", "application/json,*/*;q=0.9"));
      HttpMethod post = assertPostStatus(importedNodeUrl, HttpServletResponse.SC_CREATED, postParams, "Expected 201 status");
      
      String responseBodyAsString = post.getResponseBodyAsString();
JsonObject responseJSON = JsonUtil.parseObject(responseBodyAsString);
      JsonArray changes = responseJSON.getJsonArray("changes");
      JsonObject checkoutChange = changes.getJsonObject(0);
      assertEquals("checkout", checkoutChange.getString("type"));

      // assert content at new location
      String content2 = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);

JsonObject jsonObj2 = JsonUtil.parseObject(content2);
assertNotNull(jsonObj2);

//make sure it was really updated
assertEquals("def2", jsonObj2.getString("abc"));

//assert that the versionable node is checked back in.
assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));		
  }
 
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:75,代碼來源:PostServletImportTest.java


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