Example usage for org.apache.http.message BasicNameValuePair getValue

List of usage examples for org.apache.http.message BasicNameValuePair getValue

Introduction

In this page you can find the example usage for org.apache.http.message BasicNameValuePair getValue.

Prototype

public String getValue() 

Source Link

Usage

From source file:com.ab.http.RequestParams.java

/**
 * Creates the multipart entity./*from   w  ww  .j  a  v a 2 s . c o  m*/
 *
 * @param progressHandler the progress handler
 * @return the http entity
 * @throws IOException Signals that an I/O exception has occurred.
 */
private HttpEntity createMultipartEntity(AsyncHttpResponseHandler progressHandler) throws IOException {
    SimpleMultipartEntity entity = new SimpleMultipartEntity(progressHandler);

    // Add string params
    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
        entity.addPart(entry.getKey(), entry.getValue());
    }

    // Add non-string params
    List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
    for (BasicNameValuePair kv : params) {
        entity.addPart(kv.getName(), kv.getValue());
    }

    // Add stream params
    for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
        StreamWrapper stream = entry.getValue();
        if (stream.inputStream != null) {
            entity.addPart(entry.getKey(), stream.name, stream.inputStream, stream.contentType);
        }
    }

    // Add file params
    for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
        FileWrapper fileWrapper = entry.getValue();
        entity.addPart(entry.getKey(), fileWrapper.file, fileWrapper.contentType);
    }

    return entity;
}

From source file:com.flyn.net.asynchttp.RequestParams.java

private HttpEntity createMultipartEntity(ResponseHandlerInterface progressHandler) throws IOException {

    SimpleMultipartEntity entity = new SimpleMultipartEntity(progressHandler);
    entity.setIsRepeatable(isRepeatable);

    // Add string params
    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
        entity.addPart(entry.getKey(), entry.getValue());
    }/*  w  ww . j av a  2s. c  o m*/

    // Add non-string params
    List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
    for (BasicNameValuePair kv : params) {
        entity.addPart(kv.getName(), kv.getValue());
    }

    // Add stream params
    for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
        StreamWrapper stream = entry.getValue();
        if (stream.inputStream != null) {
            entity.addPart(entry.getKey(), stream.name, stream.inputStream, stream.contentType);
        }
    }

    // Add file params
    for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
        FileWrapper fileWrapper = entry.getValue();
        entity.addPart(entry.getKey(), fileWrapper.file, fileWrapper.contentType);
    }

    return entity;
}

From source file:com.rothconsulting.android.websms.connector.mbudget.ConnectorMBudget.java

private void printPostParameter(final List<BasicNameValuePair> postParameter) {
    this.log("POST Parameter!!!!");
    if (postParameter != null) {
        for (BasicNameValuePair nameValue : postParameter) {
            this.log("POST: " + nameValue.getName() + " / " + nameValue.getValue());
        }//from   w ww .j  a  v a2s  .  c o  m
    } else {
        this.log("POST Parameter=null");
    }
}

From source file:com.box.androidlib.BoxFileUpload.java

/**
 * Execute a file upload.//  w  ww.j  av a  2s .  c o m
 * 
 * @param action
 *            Set to {@link com.box.androidlib.Box#UPLOAD_ACTION_UPLOAD} or {@link com.box.androidlib.Box#UPLOAD_ACTION_OVERWRITE} or
 *            {@link com.box.androidlib.Box#UPLOAD_ACTION_NEW_COPY}
 * @param sourceInputStream
 *            Input stream targeting the data for the file you wish to create/upload to Box.
 * @param filename
 *            The desired filename on Box after upload (just the file name, do not include the path)
 * @param destinationId
 *            If action is {@link com.box.androidlib.Box#UPLOAD_ACTION_UPLOAD}, then this is the folder id where the file will uploaded to. If action is
 *            {@link com.box.androidlib.Box#UPLOAD_ACTION_OVERWRITE} or {@link com.box.androidlib.Box#UPLOAD_ACTION_NEW_COPY}, then this is the file_id that
 *            is being overwritten, or copied.
 * @return A FileResponseParser with information about the upload.
 * @throws IOException
 *             Can be thrown if there is no connection, or if some other connection problem exists.
 * @throws FileNotFoundException
 *             File being uploaded either doesn't exist, is not a file, or cannot be read
 * @throws MalformedURLException
 *             Make sure you have specified a valid upload action
 */
public FileResponseParser execute(final String action, final InputStream sourceInputStream,
        final String filename, final long destinationId)
        throws IOException, MalformedURLException, FileNotFoundException {

    if (!action.equals(Box.UPLOAD_ACTION_UPLOAD) && !action.equals(Box.UPLOAD_ACTION_OVERWRITE)
            && !action.equals(Box.UPLOAD_ACTION_NEW_COPY)) {
        throw new MalformedURLException("action must be upload, overwrite or new_copy");
    }

    final Uri.Builder builder = new Uri.Builder();
    builder.scheme(BoxConfig.getInstance().getUploadUrlScheme());
    builder.encodedAuthority(BoxConfig.getInstance().getUploadUrlAuthority());
    builder.path(BoxConfig.getInstance().getUploadUrlPath());
    builder.appendPath(action);
    builder.appendPath(mAuthToken);
    builder.appendPath(String.valueOf(destinationId));
    if (action.equals(Box.UPLOAD_ACTION_OVERWRITE)) {
        builder.appendQueryParameter("file_name", filename);
    } else if (action.equals(Box.UPLOAD_ACTION_NEW_COPY)) {
        builder.appendQueryParameter("new_file_name", filename);
    }

    List<BasicNameValuePair> customQueryParams = BoxConfig.getInstance().getCustomQueryParameters();
    if (customQueryParams != null && customQueryParams.size() > 0) {
        for (BasicNameValuePair param : customQueryParams) {
            builder.appendQueryParameter(param.getName(), param.getValue());
        }
    }

    if (BoxConfig.getInstance().getHttpLoggingEnabled()) {
        //            DevUtils.logcat("Uploading : " + filename + "  Action= " + action + " DestinionID + " + destinationId);
        DevUtils.logcat("Upload URL : " + builder.build().toString());
    }
    // Set up post body
    final HttpPost post = new HttpPost(builder.build().toString());
    final MultipartEntityWithProgressListener reqEntity = new MultipartEntityWithProgressListener(
            HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName(HTTP.UTF_8));

    if (mListener != null && mHandler != null) {
        reqEntity.setProgressListener(new MultipartEntityWithProgressListener.ProgressListener() {

            @Override
            public void onTransferred(final long bytesTransferredCumulative) {
                mHandler.post(new Runnable() {

                    @Override
                    public void run() {
                        mListener.onProgress(bytesTransferredCumulative);
                    }
                });
            }
        });
    }

    reqEntity.addPart("file_name", new InputStreamBody(sourceInputStream, filename) {

        @Override
        public String getFilename() {
            return filename;
        }
    });
    post.setEntity(reqEntity);

    // Send request
    final HttpResponse httpResponse;
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpProtocolParams.setUserAgent(httpClient.getParams(), BoxConfig.getInstance().getUserAgent());
    post.setHeader("Accept-Language", BoxConfig.getInstance().getAcceptLanguage());
    try {
        httpResponse = httpClient.execute(post);
    } catch (final IOException e) {
        // Detect if the download was cancelled through thread interrupt. See CountingOutputStream.write() for when this exception is thrown.
        if (BoxConfig.getInstance().getHttpLoggingEnabled()) {
            //                DevUtils.logcat("IOException Uploading " + filename + " Exception Message: " + e.getMessage() + e.toString());
            DevUtils.logcat(" Exception : " + e.toString());
            e.printStackTrace();
            DevUtils.logcat("Upload URL : " + builder.build().toString());
        }
        if ((e.getMessage() != null && e.getMessage().equals(FileUploadListener.STATUS_CANCELLED))
                || Thread.currentThread().isInterrupted()) {
            final FileResponseParser handler = new FileResponseParser();
            handler.setStatus(FileUploadListener.STATUS_CANCELLED);
            return handler;
        } else {
            throw e;
        }
    } finally {
        if (httpClient != null && httpClient.getConnectionManager() != null) {
            httpClient.getConnectionManager().closeIdleConnections(500, TimeUnit.MILLISECONDS);
        }
    }
    if (BoxConfig.getInstance().getHttpLoggingEnabled()) {
        DevUtils.logcat("HTTP Response Code: " + httpResponse.getStatusLine().getStatusCode());
        Header[] headers = httpResponse.getAllHeaders();
        //            DevUtils.logcat("User-Agent : " + HttpProtocolParams.getUserAgent(httpClient.getParams()));
        //            for (Header header : headers) {
        //                DevUtils.logcat("Response Header: " + header.toString());
        //            }
    }

    // Server returned a 503 Service Unavailable. Usually means a temporary unavailability.
    if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
        final FileResponseParser handler = new FileResponseParser();
        handler.setStatus(ResponseListener.STATUS_SERVICE_UNAVAILABLE);
        return handler;
    }

    String status = null;
    BoxFile boxFile = null;
    final InputStream is = httpResponse.getEntity().getContent();
    final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    final StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
        sb.append(line);
    }
    is.close();
    httpResponse.getEntity().consumeContent();
    final String xml = sb.toString();

    try {
        final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new ByteArrayInputStream(xml.getBytes()));
        final Node statusNode = doc.getElementsByTagName("status").item(0);
        if (statusNode != null) {
            status = statusNode.getFirstChild().getNodeValue();
        }
        final Element fileEl = (Element) doc.getElementsByTagName("file").item(0);
        if (fileEl != null) {
            try {
                boxFile = Box.getBoxFileClass().newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < fileEl.getAttributes().getLength(); i++) {
                boxFile.parseAttribute(fileEl.getAttributes().item(i).getNodeName(),
                        fileEl.getAttributes().item(i).getNodeValue());
            }
        }

        // errors are NOT returned as properly formatted XML yet so in this case the raw response is the error status code see
        // http://developers.box.net/w/page/12923951/ApiFunction_Upload-and-Download
        if (status == null) {
            status = xml;
        }
    } catch (final SAXException e) {
        // errors are NOT returned as properly formatted XML yet so in this case the raw response is the error status code see
        // http://developers.box.net/w/page/12923951/ApiFunction_Upload-and-Download
        status = xml;
    } catch (final ParserConfigurationException e) {
        e.printStackTrace();
    }
    final FileResponseParser handler = new FileResponseParser();
    handler.setFile(boxFile);
    handler.setStatus(status);
    return handler;
}

From source file:cn.edu.zzu.wemall.http.RequestParams.java

@Override
public String toString() {
    StringBuilder result = new StringBuilder();
    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
        if (result.length() > 0)
            result.append("&");

        result.append(entry.getKey());/*from   w w  w  .ja v a  2s . c o  m*/
        result.append("=");
        result.append(entry.getValue());
    }

    for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
        if (result.length() > 0)
            result.append("&");

        result.append(entry.getKey());
        result.append("=");
        result.append("STREAM");
    }

    for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
        if (result.length() > 0)
            result.append("&");

        result.append(entry.getKey());
        result.append("=");
        result.append("FILE");
    }

    List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
    for (BasicNameValuePair kv : params) {
        if (result.length() > 0)
            result.append("&");

        result.append(kv.getName());
        result.append("=");
        result.append(kv.getValue());
    }

    return result.toString();
}

From source file:com.android.yijiang.kzx.http.RequestParams.java

private HttpEntity createMultipartEntity(ResponseHandlerInterface progressHandler) throws IOException {
    SimpleMultipartEntity entity = new SimpleMultipartEntity(progressHandler);
    entity.setIsRepeatable(isRepeatable);

    // Add string params
    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
        entity.addPartWithCharset(entry.getKey(), entry.getValue(), contentEncoding);
    }//from w w  w.  jav  a2s  . co m

    // Add non-string params
    List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
    for (BasicNameValuePair kv : params) {
        entity.addPartWithCharset(kv.getName(), kv.getValue(), contentEncoding);
    }

    // Add stream params
    for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
        StreamWrapper stream = entry.getValue();
        if (stream.inputStream != null) {
            entity.addPart(entry.getKey(), stream.name, stream.inputStream, stream.contentType);
        }
    }

    // Add file params
    for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
        FileWrapper fileWrapper = entry.getValue();
        entity.addPart(entry.getKey(), fileWrapper.file, fileWrapper.contentType);
    }

    return entity;
}

From source file:com.appfirst.activities.details.AFServerDetail.java

/**
 * Draw a ScrollView to display the CPU value for each core.
 * //www  . j a v a 2  s . c o m
 * @return a ScrollView containing a list of BarView.
 */
private View createCPUListDialog() {
    ScrollView container = createOuterContainer();
    LinearLayout innerContainer = createInnerContainer();

    List<BasicNameValuePair> items = data.getCpu_cores();
    for (int i = 0; i < items.size(); i++) {
        BasicNameValuePair item = items.get(i);
        Double value = Double.parseDouble(item.getValue());
        LinearLayout row = createTableRow(LinearLayout.HORIZONTAL);
        AFBarView barView = createBarView(value);
        row.addView(barView);
        innerContainer.addView(row);
    }
    container.addView(innerContainer);
    innerContainer.invalidate();
    container.invalidate();
    return container;
}

From source file:com.example.pierre.applicompanies.library_http.RequestParams.java

private HttpEntity createMultipartEntity(ResponseHandlerInterface progressHandler) throws IOException {
    SimpleMultipartEntity entity = new SimpleMultipartEntity(progressHandler);
    entity.setIsRepeatable(isRepeatable);

    // Add string params
    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
        entity.addPartWithCharset(entry.getKey(), entry.getValue(), contentEncoding);
    }/*w ww  . j a  v  a2s.co m*/

    // Add non-string params
    List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
    for (BasicNameValuePair kv : params) {
        entity.addPartWithCharset(kv.getName(), kv.getValue(), contentEncoding);
    }

    // Add stream params
    for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
        StreamWrapper stream = entry.getValue();
        if (stream.inputStream != null) {
            entity.addPart(entry.getKey(), stream.name, stream.inputStream, stream.contentType);
        }
    }

    // Add file params
    for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
        FileWrapper fileWrapper = entry.getValue();
        entity.addPart(entry.getKey(), fileWrapper.file, fileWrapper.contentType, fileWrapper.customFileName);
    }

    return entity;
}

From source file:com.appfirst.activities.details.AFServerDetail.java

/**
 * Draw a ScrollView to display the Disk usage for each disk.
 * //from w w  w .  ja  v a 2 s  . c  om
 * @return a ScrollView containing a list of AFBarView and AFPieView.
 */
private View createDiskListDialog() {
    // use the scroll view to scale
    ScrollView container = createOuterContainer();
    LinearLayout innerContainer = createInnerContainer();

    List<BasicNameValuePair> items = data.getDisk_percent_part();
    for (int i = 0; i < items.size(); i++) {
        BasicNameValuePair item = items.get(i);
        Double value = Double.parseDouble(item.getValue());
        String name = item.getName();
        LinearLayout row = createTableRow(LinearLayout.HORIZONTAL);
        AFPieView pieView = createPieView(value);
        row.addView(pieView);
        TextView text = new TextView(this);
        text.setPadding(10, 0, 0, 0);
        text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        text.setText(String.format("%s - %.1f %s used", name, value, "%"));

        row.addView(text);
        innerContainer.addView(row);
    }
    container.addView(innerContainer);
    innerContainer.invalidate();
    container.invalidate();
    return container;
}

From source file:derson.com.httpsender.AsyncHttpClient.RequestParams.java

private HttpEntity createMultipartEntity(ResponseHandlerInterface progressHandler) throws IOException {
    SimpleMultipartEntity entity = new SimpleMultipartEntity(progressHandler);
    entity.setIsRepeatable(isRepeatable);

    // Add string params
    for (Entry<String, String> entry : urlParams.entrySet()) {
        entity.addPartWithCharset(entry.getKey(), entry.getValue(), contentEncoding);
    }// w  w w  .  j a  v a 2 s.  c  om

    // Add non-string params
    List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
    for (BasicNameValuePair kv : params) {
        entity.addPartWithCharset(kv.getName(), kv.getValue(), contentEncoding);
    }

    // Add stream params
    for (Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
        StreamWrapper stream = entry.getValue();
        if (stream.inputStream != null) {
            entity.addPart(entry.getKey(), stream.name, stream.inputStream, stream.contentType);
        }
    }

    // Add file params
    for (Entry<String, FileWrapper> entry : fileParams.entrySet()) {
        FileWrapper fileWrapper = entry.getValue();
        entity.addPart(entry.getKey(), fileWrapper.file, fileWrapper.contentType, fileWrapper.customFileName);
    }

    return entity;
}