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


Java InputStreamRequestEntity類代碼示例

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


InputStreamRequestEntity類屬於org.apache.commons.httpclient.methods包,在下文中一共展示了InputStreamRequestEntity類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
  if (args.length != 1)  {
      System.out.println("Usage: ChunkEncodedPost <file>");
      System.out.println("<file> - full path to a file to be posted");
      System.exit(1);
  }
  HttpClient client = new HttpClient();

  PostMethod httppost = new PostMethod("http://localhost:8080/httpclienttest/body");

  File file = new File(args[0]);
  httppost.setRequestEntity(new InputStreamRequestEntity(
      new FileInputStream(file), file.length()));

  try {
      client.executeMethod(httppost);

      if (httppost.getStatusCode() == HttpStatus.SC_OK) {
          System.out.println(httppost.getResponseBodyAsString());
      } else {
        System.out.println("Unexpected failure: " + httppost.getStatusLine().toString());
      }
  } finally {
      httppost.releaseConnection();
  }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:27,代碼來源:UnbufferedPost.java

示例2: handleMultipartPost

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
/**
 * Sets up the given {@link org.apache.commons.httpclient.methods.PostMethod} to send the same multipart POST data
 * as was sent in the given {@link HttpServletRequest}
 *
 * @param postMethodProxyRequest The {@link org.apache.commons.httpclient.methods.PostMethod} that we are configuring to send a
 * multipart POST request
 * @param httpServletRequest The {@link HttpServletRequest} that contains the multipart
 * POST data to be sent via the {@link org.apache.commons.httpclient.methods.PostMethod}
 */
@SuppressWarnings("unchecked")
public static void handleMultipartPost(
    EntityEnclosingMethod postMethodProxyRequest,
    HttpServletRequest httpServletRequest,
    DiskFileItemFactory diskFileItemFactory)
    throws ServletException {
    // TODO: this function doesn't set any history data
    try {
        // just pass back the binary data
        InputStreamRequestEntity ire = new InputStreamRequestEntity(httpServletRequest.getInputStream());
        postMethodProxyRequest.setRequestEntity(ire);
        postMethodProxyRequest.setRequestHeader(STRING_CONTENT_TYPE_HEADER_NAME, httpServletRequest.getHeader(STRING_CONTENT_TYPE_HEADER_NAME));
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
 
開發者ID:groupon,項目名稱:odo,代碼行數:26,代碼來源:HttpUtilities.java

示例3: testEnclosedEntityAutoLength

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
public void testEnclosedEntityAutoLength() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNull(method.getRequestHeader("Transfer-Encoding"));
        assertNotNull(method.getRequestHeader("Content-Length"));
        assertEquals(input.length, Integer.parseInt(
                method.getRequestHeader("Content-Length").getValue()));
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:24,代碼來源:TestEntityEnclosingMethod.java

示例4: testEnclosedEntityExplicitLength

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
public void testEnclosedEntityExplicitLength() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, 14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals("This is a test", body);
        assertNull(method.getRequestHeader("Transfer-Encoding"));
        assertNotNull(method.getRequestHeader("Content-Length"));
        assertEquals(14, Integer.parseInt(
                method.getRequestHeader("Content-Length").getValue()));
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:24,代碼來源:TestEntityEnclosingMethod.java

示例5: testEnclosedEntityChunked

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
public void testEnclosedEntityChunked() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(true);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNotNull(method.getRequestHeader("Transfer-Encoding"));
        assertNull(method.getRequestHeader("Content-Length"));
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:23,代碼來源:TestEntityEnclosingMethod.java

示例6: testEnclosedEntityChunkedHTTP1_0

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
public void testEnclosedEntityChunkedHTTP1_0() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(true);
    method.getParams().setVersion(HttpVersion.HTTP_1_0);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        fail("ProtocolException should have been thrown");
    } catch (ProtocolException ex) {
        // expected
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:22,代碼來源:TestEntityEnclosingMethod.java

示例7: testEnclosedEntityNegativeLength

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
public void testEnclosedEntityNegativeLength() throws Exception {
    
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, -14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(false);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNotNull(method.getRequestHeader("Transfer-Encoding"));
        assertNull(method.getRequestHeader("Content-Length"));
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:24,代碼來源:TestEntityEnclosingMethod.java

示例8: testEnclosedEntityNegativeLengthHTTP1_0

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
public void testEnclosedEntityNegativeLengthHTTP1_0() throws Exception {
    
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, -14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(false);
    method.getParams().setVersion(HttpVersion.HTTP_1_0);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        fail("ProtocolException should have been thrown");
    } catch (ProtocolException ex) {
        // expected
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:23,代碼來源:TestEntityEnclosingMethod.java

示例9: createRequest

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
private void createRequest(final RequestParameters requestParameters, final PostMethod httpPost) throws IOException,
        ParserConfigurationException, SAXException {
    InputStream inputStream = requestParameters.getInputStream();
    if (requestParameters.getContentType().contains("fastinfoset")) {
        inputStream = fastInfosetCompressor.compress(inputStream);
    }
    if (requestParameters.getContentEncoding().contains("gzip")) {
        inputStream = gzipCompressor.compress(inputStream);
        httpPost.setRequestHeader("Content-Encoding", requestParameters.getContentEncoding());
    }
    final InputStreamRequestEntity entity = new InputStreamRequestEntity(inputStream, requestParameters.getContentType());
    httpPost.setRequestEntity(entity);
    httpPost.setRequestHeader("Accept", requestParameters.getAcceptHeader());
    httpPost.addRequestHeader("Accept-Encoding", requestParameters.getAcceptEncoding());
    if (requestParameters.getSpecialHeader() != null) {
        httpPost.addRequestHeader("Special-Header", requestParameters.getSpecialHeader());
    }
    for (Entry<String, String> header : requestParameters.getCustomHeaders()) {
        httpPost.addRequestHeader(header.getKey(), header.getValue());
    }
}
 
開發者ID:epam,項目名稱:Wilma,代碼行數:22,代碼來源:HttpPostRequestSender.java

示例10: createRequest

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
private void createRequest(final MultiStubRequestParameters requestParameters, final PostMethod httpPost) throws IOException,
        ParserConfigurationException, SAXException {
    InputStream inputStream = requestParameters.getInputStream();
    if (requestParameters.getContentType().contains("fastinfoset")) {
        inputStream = fastInfosetCompressor.compress(inputStream);
    }
    if (requestParameters.getContentEncoding().contains("gzip")) {
        inputStream = gzipCompressor.compress(inputStream);
        httpPost.setRequestHeader("Content-Encoding", requestParameters.getContentEncoding());
    }
    final InputStreamRequestEntity entity = new InputStreamRequestEntity(inputStream, requestParameters.getContentType());
    httpPost.setRequestEntity(entity);
    httpPost.setRequestHeader("Accept", requestParameters.getAcceptHeader());
    httpPost.addRequestHeader("Accept-Encoding", requestParameters.getAcceptEncoding());
    if (requestParameters.getSpecialHeader() != null) {
        httpPost.addRequestHeader("Special-Header", requestParameters.getSpecialHeader());
    }
    httpPost.addParameter("nextstatus", requestParameters.getStatus());
    httpPost.addParameter("direction", requestParameters.getDirection());
    httpPost.addParameter("groupname", requestParameters.getGroupName());
}
 
開發者ID:epam,項目名稱:Wilma,代碼行數:22,代碼來源:MultiStubHttpPostRequestSender.java

示例11: davPut

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
public boolean davPut(File upload, String toPath) {
    try {
        PutMethod put = new PutMethod(getResourceUrl(toPath));
        RequestEntity requestEntity = new InputStreamRequestEntity(new BufferedInputStream(
                            new FileInputStream(upload), HttpServices.BUFFER_SIZE), upload.length());
        put.setRequestEntity(requestEntity);
        /** is to allow a client that is sending a request message with a request body
         *  to determine if the origin server is willing to accept the request
         * (based on the request headers) before the client sends the request body.
         * this require server supporting HTTP/1.1 protocol.
         */
        put.getParams().setBooleanParameter(
                HttpMethodParams.USE_EXPECT_CONTINUE, true);

        if (!executeMethod(put)) {
            // handle error
            System.out.println("Unable to upload file:" + toPath + " -- " + put.getStatusText());
            return false;
        }

        return true;
    } catch (Exception e) {
        LOG.error(e, "Error while uploading file:" + upload.getPath());
    }
    return false;
}
 
開發者ID:lsst,項目名稱:firefly,代碼行數:27,代碼來源:WorkspaceManager.java

示例12: saveStream

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
/**
 * Saves a stream into a file in the repository.
 * 
 * @param text
 *            Stream to be stored.
 * @param url
 *            URL to the file that will be created.
 */
public void saveStream(InputStream stream, String url) throws IOException {

	PutMethod putMethod = new PutMethod(url);

	putMethod.setRequestEntity(new InputStreamRequestEntity(stream));
	try {
		client.executeMethod(putMethod);
		putMethod.releaseConnection();

	} catch (IOException e) {
		throw new IOException(e);
	}
	finally { 
		stream.close();
		
	}

}
 
開發者ID:impactcentre,項目名稱:iif-resultsrepository,代碼行數:27,代碼來源:DavHandler.java

示例13: testRetrieveTextFile

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
@Test
public void testRetrieveTextFile() throws HttpException, IOException {
	DavHandler dav = new DavHandler(folders);

	InputStream stream = new ByteArrayInputStream("some text".getBytes());
	PutMethod putMethod = new PutMethod(
			"http://localhost:9002/parent/child/textToRetrieve.txt");
	putMethod.setRequestEntity(new InputStreamRequestEntity(stream));
	HttpClient client = new HttpClient();
	client.executeMethod(putMethod);
	stream.close();
	putMethod.releaseConnection();

	String retrieved = dav.retrieveTextFile("http://localhost:9002/parent/child/textToRetrieve.txt");
	assertEquals("some text", retrieved);
}
 
開發者ID:impactcentre,項目名稱:iif-resultsrepository,代碼行數:17,代碼來源:DavHandlerTest.java

示例14: startLoading

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
/**
 * Kicks the GDC platform to inform it that the FTP transfer is finished.
 *
 * @param projectId the project's ID
 * @param remoteDir the remote (FTP) directory that contains the data
 * @return the link that is used for polling the loading progress
 * @throws GdcRestApiException
 */
public String startLoading(String projectId, String remoteDir) throws GdcRestApiException {
    l.debug("Initiating data load project id=" + projectId + " remoteDir=" + remoteDir);
    PostMethod pullPost = createPostMethod(getProjectMdUrl(projectId) + PULL_URI);
    JSONObject pullStructure = getPullStructure(remoteDir);
    InputStreamRequestEntity request = new InputStreamRequestEntity(new ByteArrayInputStream(pullStructure.toString().getBytes()));
    pullPost.setRequestEntity(request);
    String taskLink = null;
    try {
        String response = executeMethodOk(pullPost);
        JSONObject responseObject = JSONObject.fromObject(response);
        taskLink = responseObject.getJSONObject("pullTask").getString("uri");
    } catch (HttpMethodException ex) {
        throw new GdcRestApiException("Loading fails: " + ex.getMessage());
    } finally {
        pullPost.releaseConnection();
    }
    l.debug("Data load project id=" + projectId + " remoteDir=" + remoteDir + " initiated. Status is on uri=" + taskLink);
    return taskLink;
}
 
開發者ID:koles,項目名稱:gooddata-agent,代碼行數:28,代碼來源:GdcRESTApiWrapper.java

示例15: executeMAQL

import org.apache.commons.httpclient.methods.InputStreamRequestEntity; //導入依賴的package包/類
/**
 * Executes the MAQL and creates/modifies the project's LDM
 *
 * @param projectId the project's ID
 * @param maql      String with the MAQL statements
 * @return result String
 * @throws GdcRestApiException
 */
public String[] executeMAQL(String projectId, String maql) throws GdcRestApiException {
    l.debug("Executing MAQL projectId=" + projectId + " MAQL:\n" + maql);
    PostMethod maqlPost = createPostMethod(getProjectMdUrl(projectId) + MAQL_EXEC_URI);
    JSONObject maqlStructure = getMAQLExecStructure(maql);
    InputStreamRequestEntity request = new InputStreamRequestEntity(new ByteArrayInputStream(
            maqlStructure.toString().getBytes()));
    maqlPost.setRequestEntity(request);
    String result = null;
    try {
        String response = executeMethodOk(maqlPost);
        JSONObject responseObject = JSONObject.fromObject(response);
        JSONArray uris = responseObject.getJSONArray("uris");
        return (String[]) uris.toArray(new String[]{""});
    } catch (HttpMethodException ex) {
        l.debug("MAQL execution: ", ex);
        throw new GdcRestApiException("MAQL execution: " + ex.getMessage(), ex);
    } finally {
        maqlPost.releaseConnection();
    }
}
 
開發者ID:koles,項目名稱:gooddata-agent,代碼行數:29,代碼來源:GdcRESTApiWrapper.java


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