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

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

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:bluej.collect.DataSubmitter.java

/**
 * Actually post the data to the server.
 * /*from w  w w.ja v  a  2 s.com*/
 * Returns false if there was an error.
 */
private static boolean postData(Event evt) {
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 10000);
    HttpConnectionParams.setSoTimeout(params, 10000);
    HttpClient client = new DefaultHttpClient(params);

    try {
        HttpPost post = new HttpPost(submitUrl);

        /*
        if (errFilePath != null) {
        mpe.addPart("filepath", new StringBody(errFilePath, utf8));
        }
        if (errMsg != null) {
        mpe.addPart("errormsg", new StringBody(errMsg, utf8));
        }
        if (errline != 0) {
        mpe.addPart("errorline", new StringBody("" + errline, utf8));
        }
                
        int i = 0;
        for (SourceContent changedFile : changedFiles) {
        mpe.addPart("sourcefileName" + i, new StringBody(changedFile.getFilePath(), utf8));
        mpe.addPart("sourcefileContent" + i, new ByteArrayBody(changedFile.getFileContent(),
                changedFile.getFilePath()));
        }
        */
        MultipartEntity mpe = evt.makeData(sequenceNum, fileVersions);
        if (mpe == null)
            return true; // nothing to send, no error
        //Only increment sequence number if we actually send data:
        sequenceNum += 1;
        post.setEntity(mpe);
        HttpResponse response = client.execute(post);

        for (Header h : response.getAllHeaders()) {
            if ("X-Status".equals(h.getName()) && !"Created".equals(h.getValue())) {
                // Temporary printing:
                System.err.println("Problem response: " + mpe.toString() + " " + response.toString());
                return false;
            }
        }

        if (response.getStatusLine().getStatusCode() != 200) {
            System.err.println("Problem code: " + response.getStatusLine().getStatusCode());
            return false;
        }

        evt.success(fileVersions);

        EntityUtils.consume(response.getEntity());
    } catch (ClientProtocolException cpe) {
        return false;
    } catch (IOException ioe) {
        //For now:
        ioe.printStackTrace();

        return false;
    }

    return true;
}

From source file:org.andrico.andjax.http.HttpClientService.java

/**
 * Put an http request on the queue to be executed. Upon completion of the
 * http request, a runnable will be called. Right now this is limited in
 * that you can only pass one value per key in the http post. (The Map is
 * the limiter)./*w  w  w .ja  v  a2 s .c  om*/
 * 
 * @param url The url to access.
 * @param multipartEntity The POST parameters to pass to this request.
 * @param responseRunnable The runnable to execute upon http request
 *            completion.
 * @throws URISyntaxException
 */
public void submit(String url, MultipartEntity multipartEntity, IHttpResponseRunnable responseRunnable)
        throws URISyntaxException {
    Log.d(TAG, "submitting multipartentity dodad");
    HttpMessage httpMessage;

    httpMessage = this.mHttpMessageFactory.createFromParts(url, multipartEntity);
    Log.d(TAG, "Posting multipartEntity" + multipartEntity.toString());
    Log.d(TAG, String.valueOf(multipartEntity.getContentLength()));
    Log.d(TAG, multipartEntity.toString());
    this.submit(new HttpChainingRunnable(new HttpMessageCallable(httpMessage), responseRunnable));
}