Examples of MultipartEntity


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

    }

    /** Updates a node at specified path, with optional properties
    */
     public void setProperties(String path, Map<String, Object> properties) throws IOException {
        final MultipartEntity entity = new MultipartEntity();
        // Add user properties
        if(properties != null) {
            for(Map.Entry<String, Object> e : properties.entrySet()) {
                entity.addPart(e.getKey(), new StringBody(e.getValue().toString()));
            }
        }

        final HttpResponse response =
                executor.execute(
View Full Code Here

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

    return request;
  }

  private HttpPost composeMultiPartFormRequest(final String uri, final Parameters parameters, final Map<String, ContentBody> files) {
    HttpPost request = new HttpPost(uri);
    MultipartEntity multiPartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

    try {
      Charset utf8 = Charset.forName("UTF-8");
      for(Parameter param : parameters)
        if(param.isSingleValue())
          multiPartEntity.addPart(param.getName(), new StringBody(param.getValue(), utf8));
        else
          for(String value : param.getValues())
            multiPartEntity.addPart(param.getName(), new StringBody(value, utf8));
    } catch (UnsupportedEncodingException e) {
      throw MechanizeExceptionFactory.newException(e);
    }

    List<String> fileNames = new ArrayList<String>(files.keySet());
    Collections.sort(fileNames);
    for(String name : fileNames) {
      ContentBody contentBody = files.get(name);
      multiPartEntity.addPart(name, contentBody);
    }
    request.setEntity(multiPartEntity);
    return request;
  }
View Full Code Here

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

    @Test
    public void testResourceResolver() throws Exception {
        RequestBuilder rb = new RequestBuilder("http://localhost:9000");

        final MultipartEntity entity = new MultipartEntity();
        // Add Sling POST options
        entity.addPart("lang", new StringBody("esp"));
        entity.addPart("code", new InputStreamBody(getClass().getResourceAsStream("/test.js"), "test.js"));
        executor.execute(
                rb.buildPostRequest("/system/console/scriptconsole.json")
                 .withEntity(entity)
                 .withCredentials("admin","admin")
            ).assertStatus(200);
View Full Code Here

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

    private HttpResponse uploadMultiPart(String path,
            Map<String, String> reqParams, InputStream ins, String fileName)
            throws Exception {
        Charset utf8 = Charset.availableCharsets().get("UTF-8");
        MultipartEntity reqEntity = new MultipartEntity();
        HttpPost httppost = new HttpPost(getRequestBuilder().buildUrl(path));
        if (reqParams != null) {
            for (Map.Entry<String, String> entry : reqParams.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                reqEntity.addPart(key, new StringBody(value, utf8));
            }
        }
        if (ins != null) {
            ContentBody contentBody = new InputStreamBody(ins, fileName);
            reqEntity.addPart(fileName, contentBody);
        }
        httppost.setEntity(reqEntity);
        HttpResponse response = getRequestExecutor().execute(
            getRequestBuilder().buildOtherRequest(httppost).withCredentials(
                getServerUsername(), getServerPassword())).getResponse();
View Full Code Here

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

public class ValidationServiceTest extends SlingTestBase {

    @Test
    public void testValidRequestModel1() throws IOException, JSONException {
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("sling:resourceType", new StringBody("validation/test/resourceType1"));
        entity.addPart("field1", new StringBody("HelloWorld"));
        entity.addPart("field2", new StringBody("30.01.1988"));
        entity.addPart(SlingPostConstants.RP_OPERATION, new StringBody("validation"));
        RequestExecutor re = getRequestExecutor().execute(getRequestBuilder().buildPostRequest
                ("/validation/testing/fakeFolder1/resource").withEntity(entity)).assertStatus(200);
        JSONObject jsonResponse = new JSONObject(re.getContent());
        assertTrue(jsonResponse.getBoolean("valid"));
    }
View Full Code Here

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

        assertTrue(jsonResponse.getBoolean("valid"));
    }

    @Test
    public void testInvalidRequestModel1() throws IOException, JSONException {
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("sling:resourceType", new StringBody("validation/test/resourceType1"));
        entity.addPart("field1", new StringBody("Hello World"));
        entity.addPart(SlingPostConstants.RP_OPERATION, new StringBody("validation"));
        RequestExecutor re = getRequestExecutor().execute(getRequestBuilder().buildPostRequest
                ("/validation/testing/fakeFolder1/resource").withEntity(entity)).assertStatus(200);
        String content = re.getContent();
        JSONObject jsonResponse = new JSONObject(content);
        assertFalse(jsonResponse.getBoolean("valid"));
View Full Code Here

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

   
    public Long addNoteWithImage(String note, File imageFile) throws Exception {
        HttpPost request = new HttpPost(DailyMileUtil.ENTRIES_URL);
        HttpResponse response = null;
        try {
            MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            mpEntity.addPart("media[data]",
                    new FileBody(imageFile, "image/jpeg"));
            mpEntity.addPart("media[type]", new StringBody("image"));
            mpEntity.addPart("message", new StringBody(note));
            mpEntity.addPart("[share_on_services][facebook]", new StringBody("false"));
            mpEntity.addPart("[share_on_services][twitter]", new StringBody("false"));
            mpEntity.addPart("oauth_token", new StringBody(oauthToken));

            request.setEntity(mpEntity);
            // send the request
            response = httpClient.execute(request);
            int statusCode = response.getStatusLine().getStatusCode();
View Full Code Here

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

                "/servlets-examples/servlet/RequestInfoExample");

        FileBody bin = new FileBody(new File(args[0]));
        StringBody comment = new StringBody("A binary file of some kind");

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("bin", bin);
        reqEntity.addPart("comment", comment);
       
        httppost.setEntity(reqEntity);
       
        System.out.println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
View Full Code Here

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

    private void execute(ContentBody code) throws Exception
    {
        RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());

        final MultipartEntity entity = new MultipartEntity();
        // Add Sling POST options
        entity.addPart("lang", new StringBody("groovy"));
        entity.addPart("code", code);
        executor.execute(
            rb.buildPostRequest("/system/console/sc").withEntity(entity).withCredentials(
                    "admin", "admin")).assertStatus(200);
    }
View Full Code Here

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

                "/servlets-examples/servlet/RequestInfoExample");

        FileBody bin = new FileBody(new File(args[0]));
        StringBody comment = new StringBody("A binary file of some kind");

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("bin", bin);
        reqEntity.addPart("comment", comment);
       
        httppost.setEntity(reqEntity);
       
        System.out.println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.