Package org.apache.http.entity.mime

Examples of org.apache.http.entity.mime.MultipartEntity


    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url.toURI());
   
    // We want to upload our sample application, containing custom module
    // definitions and DTK dependencies.
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
   
    InputStream is = getClass().getClassLoader().getResourceAsStream("user_app.zip");   
    InputStreamBody bin = new InputStreamBody(is, "application/zip", "user_app.zip");
    reqEntity.addPart("user_app", bin);
   
    httpPost.setEntity(reqEntity);
    HttpResponse response = httpclient.execute(httpPost);
   
    // HTTP 201, resource was created.
View Full Code Here


    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url.toURI());
   
    // We want to upload our sample application, containing custom module
    // definitions and DTK dependencies.
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
   
    httpPost.setEntity(reqEntity);
    HttpResponse response = httpclient.execute(httpPost);
   
    // HTTP 400, invalid request.
View Full Code Here

   * @throws ClientProtocolException
   */
  @Test
  public void test_AnalyseBlankSubmission() throws URISyntaxException, ClientProtocolException, IOException {
    // Simulate multipart html FORM submission with empty form.
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    HttpResponse response = simulateMultiPartFormSubmission(reqEntity);
   
    // HTTP 400, invalid client request.
    assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusLine().getStatusCode());
  }
View Full Code Here

   * @throws ClientProtocolException
   */
  @Test
  public void test_AnalyseMissingValueSubmission() throws URISyntaxException, ClientProtocolException, IOException {
    // Simulate multipart html FORM submission.
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
   
    // Add type parameter but not value.
    StringBody strBody = new StringBody("web_page");
    reqEntity.addPart("type", strBody);
   
    HttpResponse response = simulateMultiPartFormSubmission(reqEntity);
   
    // HTTP 400, invalid client request.
    assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusLine().getStatusCode());
View Full Code Here

   * @throws ClientProtocolException
   */
  @Test
  public void test_AnalyseMissingTypeSubmission() throws URISyntaxException, ClientProtocolException, IOException {
    // Simulate multipart html FORM submission.
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
   
    // Add value parameter but not type.
    StringBody strBody = new StringBody("Some content goes here!");
    reqEntity.addPart("value", strBody);

    HttpResponse response = simulateMultiPartFormSubmission(reqEntity);
   
    // HTTP 400, invalid client request.
    assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusLine().getStatusCode());
View Full Code Here

   */
  @Test
  public void test_AnalyseWebApplicationWithInvalidURLFormat()
    throws ClientProtocolException, IOException, URISyntaxException
    // Simulate multipart html FORM submission.
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
   
    // Add HTML file and type="web_page" fields using invalid web address
    StringBody strBody = new StringBody("url");
    reqEntity.addPart("type", strBody);
    StringBody webApplicationAddress = new StringBody(invalidWebAddress);
    reqEntity.addPart("value", webApplicationAddress);
   
    // Simulate form submission, check HTTP status and parse JSON from HTML response.
    HttpResponse response = simulateMultiPartFormSubmission(reqEntity);
    assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusLine().getStatusCode());
  }
View Full Code Here

   */
  @Test
  public void test_AnalyseWebApplicationWithNonExistantURL()
   throws ClientProtocolException, IOException, URISyntaxException {
    // Simulate multipart html FORM submission.
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
   
    // Add HTML file and type="web_page" fields using non existent web address.
    StringBody strBody = new StringBody("url");
    reqEntity.addPart("type", strBody);
    StringBody webApplicationAddress = new StringBody(nonExistentWebAddress);
    reqEntity.addPart("value", webApplicationAddress);
   
    // Simulate form submission, check HTTP status and parse JSON from HTML response.
    HttpResponse response = simulateMultiPartFormSubmission(reqEntity);
    assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusLine().getStatusCode());
  }
View Full Code Here

  }
 

  protected static HttpResponse generateHTMLFormPost(String key, String value)
  throws ClientProtocolException, IOException, URISyntaxException {
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

    reqEntity.addPart("type", new StringBody(key));
    reqEntity.addPart("value", new StringBody(value));
   
    return simulateMultiPartFormSubmission(reqEntity);   
  }
View Full Code Here

            if(haveContentEncoding) {
                charset = Charset.forName(contentEncoding);
            }

            // Write the request to our own stream
            MultipartEntity multiPart = new MultipartEntity(
                    getDoBrowserCompatibleMultipart() ? HttpMultipartMode.BROWSER_COMPATIBLE : HttpMultipartMode.STRICT,
                            null, charset);
            // Create the parts
            // Add any parameters
            PropertyIterator args = getArguments().iterator();
            while (args.hasNext()) {
               HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
               String parameterName = arg.getName();
               if (arg.isSkippable(parameterName)){
                   continue;
               }
               FormBodyPart formPart;
               StringBody stringBody = new StringBody(arg.getValue(), charset);
               formPart = new FormBodyPart(arg.getName(), stringBody);                  
               multiPart.addPart(formPart);
            }

            // Add any files
            // Cannot retrieve parts once added to the MultiPartEntity, so have to save them here.
            ViewableFileBody[] fileBodies = new ViewableFileBody[files.length];
            for (int i=0; i < files.length; i++) {
                HTTPFileArg file = files[i];
                fileBodies[i] = new ViewableFileBody(new File(file.getPath()), file.getMimeType());
                multiPart.addPart(file.getParamName(),fileBodies[i]);
            }

            post.setEntity(multiPart);

            if (multiPart.isRepeatable()){
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = true;
                }
                multiPart.writeTo(bos);
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = false;
                }
                bos.flush();
                // We get the posted bytes using the encoding used to create it
View Full Code Here

    }

    public File upload() throws UploadFailureException {
        URI uploadUrl = Urls.uploadBase();
        HttpPost request = new HttpPost(uploadUrl);
        MultipartEntity entity = new MultipartEntity();
        StringBody pubKeyBody = StringBody.create(client.getPublicKey(), "text/plain", null);
        entity.addPart("UPLOADCARE_PUB_KEY", pubKeyBody);
        entity.addPart("file", new InputStreamBody(inputStream, filename));
        request.setEntity(entity);
        String fileId = client.getRequestHelper().executeQuery(request, false, UploadBaseData.class).file;
        return client.getFile(fileId);
    }
View Full Code Here

TOP

Related Classes of org.apache.http.entity.mime.MultipartEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.