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


Java PostMethod.getResponseBodyAsStream方法代碼示例

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


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

示例1: chcekConnectionStatus

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void chcekConnectionStatus() throws IOException {

        HttpClient httpClient = new HttpClient();
        //TODO : add connection details while testing only,remove it once done
        String teradatajson = "{\"username\":\"\",\"password\":\"\",\"hostname\":\"\",\"database\":\"\",\"dbtype\":\"\",\"port\":\"\"}";
        PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/getConnectionStatus");

        //postMethod.addParameter("request_parameters", redshiftjson);
        postMethod.addParameter("request_parameters", teradatajson);

        int response = httpClient.executeMethod(postMethod);
        InputStream inputStream = postMethod.getResponseBodyAsStream();

        byte[] buffer = new byte[1024 * 1024 * 5];
        String path = null;
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            path = new String(buffer);
        }
        System.out.println("Response of service: " + path);
        System.out.println("==================");
    }
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:23,代碼來源:HydrographServiceClient.java

示例2: calltoReadService

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void calltoReadService() throws IOException {

        HttpClient httpClient = new HttpClient();

        PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/read");
        postMethod.addParameter("jobId", JOB_ID);
        postMethod.addParameter("componentId", COMPONENT_ID);
        postMethod.addParameter("socketId", SOCKET_ID);
        postMethod.addParameter("basePath", BASE_PATH);
        postMethod.addParameter("userId", USER_ID);
        postMethod.addParameter("password", PASSWORD);
        postMethod.addParameter("file_size", FILE_SIZE_TO_READ);
        postMethod.addParameter("host_name", HOST_NAME);

        InputStream inputStream = postMethod.getResponseBodyAsStream();

        byte[] buffer = new byte[1024 * 1024 * 5];
        String path = null;
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            path = new String(buffer);
        }
        System.out.println("response of service: " + path);
    }
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:25,代碼來源:HydrographServiceClient.java

示例3: calltoReadMetastore

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void calltoReadMetastore() throws IOException {

        HttpClient httpClient = new HttpClient();
      //TODO : add connection details while testing only,remove it once done
        String teradatajson = "{\"table\":\"testting2\",\"username\":\"\",\"password\":\"\",\"hostname\":\"\",\"database\":\"\",\"dbtype\":\"\",\"port\":\"\"}";

        PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/readFromMetastore");

        //postMethod.addParameter("request_parameters", redshiftjson);
        postMethod.addParameter("request_parameters", teradatajson);

        int response = httpClient.executeMethod(postMethod);
        InputStream inputStream = postMethod.getResponseBodyAsStream();

        byte[] buffer = new byte[1024 * 1024 * 5];
        String path = null;
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            path = new String(buffer);
        }
        System.out.println("Response of service: " + path);
        System.out.println("==================");
    }
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:24,代碼來源:HydrographServiceClient.java

示例4: getFilePathFromPostResponse

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
private String getFilePathFromPostResponse(PostMethod postMethod) throws IOException {
	String path = null;
	InputStream inputStream = postMethod.getResponseBodyAsStream();
	byte[] buffer = IOUtils.toByteArray(inputStream);
	path = new String(buffer);
	return path;
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:8,代碼來源:DebugServiceClient.java

示例5: calltoFilterService

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void calltoFilterService() throws IOException {

        HttpClient httpClient = new HttpClient();

        // String json =
        // "{\"condition\":\"abc\",\"schema\":[{\"fieldName\":\"f1\",\"dateFormat\":\"\",\"dataType\":\"1\",\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.String\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f2\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.util.Date\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f3\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.util.Date\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f4\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.math.BigDecimal\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"}],\"fileSize\":1,\"jobDetails\":{\"host\":\"127.0.0.1\",\"port\":\"8005\",\"username\":\"hduser\",\"password\":\"Bitwise2012\",\"basepath\":\"C:/Users/santlalg/git/Hydrograph/hydrograph.engine/hydrograph.engine.command-line\",\"uniqueJobID\":\"debug_job\",\"componentID\":\"input\",\"componentSocketID\":\"out0\",\"isRemote\":false}}";
        String json = "{\"condition\":\"(f1 LIKE 'should')\",\"schema\":[{\"fieldName\":\"f1\",\"dateFormat\":\"\",\"dataType\":\"1\",\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.String\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f2\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.util.Date\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f3\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.Float\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f4\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.Double\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"}],\"fileSize\":"
                + FILE_SIZE_TO_READ + ",\"jobDetails\":{\"host\":\"" + HOST_NAME + "\",\"port\":\"" + PORT
                + "\",\"username\":\"" + USER_ID + "\",\"password\":\"" + PASSWORD + "\",\"basepath\":\"" + BASE_PATH
                + "\",\"uniqueJobID\":\"" + JOB_ID + "\",\"componentID\":\"" + COMPONENT_ID
                + "\",\"componentSocketID\":\"" + SOCKET_ID + "\",\"isRemote\":false}}";

        PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/filter");

        postMethod.addParameter("request_parameters", json);

        int response = httpClient.executeMethod(postMethod);
        InputStream inputStream = postMethod.getResponseBodyAsStream();

        byte[] buffer = new byte[1024 * 1024 * 5];
        String path = null;
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            path = new String(buffer);
        }
        System.out.println("response of service: " + path);
    }
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:28,代碼來源:HydrographServiceClient.java

示例6: makeRestCallPost

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public MirrorGateResponse makeRestCallPost(String url, String jsonString, String user, String password) {

        MirrorGateResponse response;
        PostMethod post = new PostMethod(url);
        try {
            HttpClient client = getHttpClient();

            if (user != null && password != null) {
                client.getState().setCredentials(
                        AuthScope.ANY,
                        new UsernamePasswordCredentials(user, password));
                post.setDoAuthentication(true);
            }

            StringRequestEntity requestEntity = new StringRequestEntity(
                    jsonString,
                    "application/json",
                    "UTF-8");
            post.setRequestEntity(requestEntity);
            int responseCode = client.executeMethod(post);
            String responseString = post.getResponseBodyAsStream() != null ?
                    getResponseString(post.getResponseBodyAsStream()) : "";
            response = new MirrorGateResponse(responseCode, responseString);
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "MirrorGate: Error posting to MirrorGate", e);
            response = new MirrorGateResponse(HttpStatus.SC_BAD_REQUEST, "");
        } finally {
            post.releaseConnection();
        }
        return response;
    }
 
開發者ID:BBVA,項目名稱:mirrorgate-jenkins-builds-collector,代碼行數:32,代碼來源:RestCall.java

示例7: postQuery

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
protected JSONObject postQuery(HttpClient httpClient, String url, JSONObject body) throws UnsupportedEncodingException,
            IOException, HttpException, URIException, JSONException
{
    PostMethod post = new PostMethod(url);
    if (body.toString().length() > DEFAULT_SAVEPOST_BUFFER)
    {
        post.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
    }
    post.setRequestEntity(new ByteArrayRequestEntity(body.toString().getBytes("UTF-8"), "application/json"));

    try
    {
        httpClient.executeMethod(post);

        if(post.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || post.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY)
        {
            Header locationHeader = post.getResponseHeader("location");
            if (locationHeader != null)
            {
                String redirectLocation = locationHeader.getValue();
                post.setURI(new URI(redirectLocation, true));
                httpClient.executeMethod(post);
            }
        }

        if (post.getStatusCode() != HttpServletResponse.SC_OK)
        {
            throw new LuceneQueryParserException("Request failed " + post.getStatusCode() + " " + url.toString());
        }

        Reader reader = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream(), post.getResponseCharSet()));
        // TODO - replace with streaming-based solution e.g. SimpleJSON ContentHandler
        JSONObject json = new JSONObject(new JSONTokener(reader));

        if (json.has("status"))
        {
            JSONObject status = json.getJSONObject("status");
            if (status.getInt("code") != HttpServletResponse.SC_OK)
            {
                throw new LuceneQueryParserException("SOLR side error: " + status.getString("message"));
            }
        }
        return json;
    }
    finally
    {
        post.releaseConnection();
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:50,代碼來源:SolrQueryHTTPClient.java

示例8: getAuthenticatedPostContent

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/** retrieve the contents of given URL and assert its content type
  * @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be checked
  * @throws IOException
  * @throws HttpException */
 public String getAuthenticatedPostContent(Credentials creds, String url, String expectedContentType, List<NameValuePair> postParams, int expectedStatusCode) throws IOException {
     final PostMethod post = new PostMethod(url);

     URL baseUrl = new URL(HTTP_BASE_URL);
     AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
     post.setDoAuthentication(true);
     Credentials oldCredentials = httpClient.getState().getCredentials(authScope);
 	try {
httpClient.getState().setCredentials(authScope, creds);

      if(postParams!=null) {
          final NameValuePair [] nvp = {};
          post.setRequestBody(postParams.toArray(nvp));
      }

      final int status = httpClient.executeMethod(post);
      final InputStream is = post.getResponseBodyAsStream();
      final StringBuffer content = new StringBuffer();
      final String charset = post.getResponseCharSet();
      final byte [] buffer = new byte[16384];
      int n = 0;
      while( (n = is.read(buffer, 0, buffer.length)) > 0) {
          content.append(new String(buffer, 0, n, charset));
      }
      assertEquals("Expected status " + expectedStatusCode + " for " + url + " (content=" + content + ")",
              expectedStatusCode,status);
      final Header h = post.getResponseHeader("Content-Type");
      if(expectedContentType == null) {
          if(h!=null) {
              fail("Expected null Content-Type, got " + h.getValue());
          }
      } else if(CONTENT_TYPE_DONTCARE.equals(expectedContentType)) {
          // no check
      } else if(h==null) {
          fail(
                  "Expected Content-Type that starts with '" + expectedContentType
                  +" but got no Content-Type header at " + url
          );
      } else {
          assertTrue(
              "Expected Content-Type that starts with '" + expectedContentType
              + "' for " + url + ", got '" + h.getValue() + "'",
              h.getValue().startsWith(expectedContentType)
          );
      }
      return content.toString();

 	} finally {
     	httpClient.getState().setCredentials(authScope, oldCredentials);
 	}
 }
 
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:56,代碼來源:AuthenticatedTestUtil.java

示例9: getResponseBody

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/**
 * Extract the response body from the given executed remote invocation
 * request.
 * <p>The default implementation simply fetches the PostMethod's response
 * body stream. If the response is recognized as GZIP response, the
 * InputStream will get wrapped in a GZIPInputStream.
 * @param config the HTTP invoker configuration that specifies the target service
 * @param postMethod the PostMethod to read the response body from
 * @return an InputStream for the response body
 * @throws IOException if thrown by I/O methods
 * @see #isGzipResponse
 * @see java.util.zip.GZIPInputStream
 * @see org.apache.commons.httpclient.methods.PostMethod#getResponseBodyAsStream()
 * @see org.apache.commons.httpclient.methods.PostMethod#getResponseHeader(String)
 */
protected InputStream getResponseBody(PostMethod postMethod)
		throws IOException {

	if (isGzipResponse(postMethod)) {
		return new GZIPInputStream(postMethod.getResponseBodyAsStream());
	}
	else {
		return postMethod.getResponseBodyAsStream();
	}
}
 
開發者ID:ITYug,項目名稱:kaltura-ce-sakai-extension,代碼行數:26,代碼來源:KalturaClientBase.java


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