Example usage for org.apache.http.entity.mime MultipartEntity MultipartEntity

List of usage examples for org.apache.http.entity.mime MultipartEntity MultipartEntity

Introduction

In this page you can find the example usage for org.apache.http.entity.mime MultipartEntity MultipartEntity.

Prototype

public MultipartEntity() 

Source Link

Usage

From source file:org.wikipedia.vlsergey.secretary.jwpf.actions.Edit.java

public Edit(boolean bot, Page page, Revision revision, String token, String text, String summary,
        boolean minor) {
    super(bot);//from ww  w .  ja  v a2 s .  c  om
    if (revision.getTimestamp() == null) {
        throw new IllegalArgumentException("Current revision must have timestamp to prevent edit conflicts");
    }

    log.info("[action=edit]: " + page + "; " + revision + "; " + token + "; " + toLog(text) + "; " + summary
            + "; " + minor + ")");

    HttpPost postMethod = new HttpPost("/api.php");

    MultipartEntity multipartEntity = new MultipartEntity();
    setMaxLag(multipartEntity);
    setFormatXml(multipartEntity);

    setParameter(multipartEntity, "action", "edit");
    setParameter(multipartEntity, "title", page.getTitle());
    setParameter(multipartEntity, "text", text);

    setParameter(multipartEntity, "summary", summary);
    if (minor) {
        setParameter(multipartEntity, "minor", "1");
    } else {
        setParameter(multipartEntity, "minor", "0");
    }

    if (isBot()) {
        setParameter(multipartEntity, "bot", "1");
    } else {
        setParameter(multipartEntity, "bot", "0");
    }

    setParameter(multipartEntity, "basetimestamp", revision.getTimestamp());
    setParameter(multipartEntity, "nocreate", "1");
    setParameter(multipartEntity, "token", token);

    postMethod.setEntity(multipartEntity);

    msgs.add(postMethod);
}

From source file:net.asplode.tumblr.Post.java

public Post() {
    entity = new MultipartEntity();
}

From source file:org.opencastproject.remotetest.server.resource.IngestResources.java

/**
 * /*www .  j  ava  2s  .  c om*/
 * @param type
 *          Type of media to add: Track, Catalog, Attachment
 * 
 */
public static HttpResponse addTrack(TrustedHttpClient client, String type, InputStream media, String flavor,
        String mediaPackage) throws Exception {
    HttpPost post = new HttpPost(getServiceUrl() + "add" + type);
    MultipartEntity entity = new MultipartEntity();
    entity.addPart("flavor", new StringBody(flavor));
    entity.addPart("mediaPackage", new StringBody(mediaPackage));
    post.setEntity(entity);
    return client.execute(post);
}

From source file:org.apache.sling.validation.testservices.ValidationServiceTest.java

@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);/*w w  w .  jav a2 s  .  c o  m*/
    JSONObject jsonResponse = new JSONObject(re.getContent());
    assertTrue(jsonResponse.getBoolean("valid"));
}

From source file:org.deviceconnect.android.manager.test.MultipartTest.java

/**
 * POST????????.//w w w  . java  2s  .co m
 */
public void testParsingMutilpartAsRequestParametersMethodPost() {
    URIBuilder builder = TestURIBuilder.createURIBuilder();
    builder.setProfile(NotificationProfileConstants.PROFILE_NAME);
    builder.setAttribute(NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    try {
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(DConnectProfileConstants.PARAM_DEVICE_ID, new StringBody(getDeviceId()));
        entity.addPart(NotificationProfileConstants.PARAM_TYPE, new StringBody("0"));
        entity.addPart(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, new StringBody(getAccessToken()));
        HttpPost request = new HttpPost(builder.toString());
        request.setEntity(entity);
        JSONObject response = sendRequest(request);
        assertResultOK(response);
    } catch (UnsupportedEncodingException e) {
        fail(e.getMessage());
    } catch (JSONException e) {
        fail(e.getMessage());
    }
}

From source file:com.puppetlabs.geppetto.forge.client.OAuthModule.java

@Override
public AuthResponse authenticate(HttpClient httpClient) throws IOException {
    HttpPost request = new HttpPost(oauthURL);

    MultipartEntity entity = new MultipartEntity();
    entity.addPart("grant_type", new StringBody("password"));
    entity.addPart("client_id", new StringBody(clientId));
    entity.addPart("client_secret", new StringBody(clientSecret));
    entity.addPart("username", new StringBody(username));
    entity.addPart("password", new StringBody(password));
    request.setEntity(entity);//  w w  w  . ja v  a2 s  .c o m

    return httpClient.execute(request, new JSonResponseHandler<OAuthResponse>(gson, OAuthResponse.class));
}

From source file:uf.edu.uploadTraces.java

boolean sendFile(String Filename) {
    boolean success = false;
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(con.getResources().getString((R.string.uploadURL)));

    FileBody bin = new FileBody(new File(Filename));
    try {//from ww w  .j a  v a  2 s. c o m

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("filename", bin);
        //reqEntity.addPart("comment", comment);
        httppost.setEntity(reqEntity);

        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        Log.i("iTrust", resEntity.toString());
        success = true;

        //save the last upload time
        pres = con.getSharedPreferences("iTrust", 0);
        SharedPreferences.Editor ed = pres.edit();
        ed.putLong("LastUploadTime", System.currentTimeMillis() / 1000);
        ed.commit();

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return success;

}