Example usage for org.apache.commons.httpclient.methods.multipart StringPart setCharSet

List of usage examples for org.apache.commons.httpclient.methods.multipart StringPart setCharSet

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods.multipart StringPart setCharSet.

Prototype

public void setCharSet(String paramString) 

Source Link

Usage

From source file:com.bdaum.juploadr.uploadapi.locrrest.upload.LocrUpload.java

/**
 * @param parts//  w  w w.j  a  va 2  s .  com
 * @param string
 * @param title
 */
private void addNonNullStringPart(List<Part> parts, String paramName, String paramValue) {
    if (paramValue != null) {
        StringPart part = new StringPart(paramName, paramValue);
        part.setCharSet("UTF-8"); //$NON-NLS-1$
        parts.add(part);
        params.put(paramName, paramValue);
    }
}

From source file:com.benfante.jslideshare.SlideShareConnectorImpl.java

private StringPart createStringPart(String name, String value) {
    StringPart stringPart = new StringPart(name, value);
    stringPart.setContentType(null);//from ww  w  .  j  a va2s  .  c o m
    stringPart.setTransferEncoding(null);
    stringPart.setCharSet("UTF-8");
    return stringPart;
}

From source file:com.celamanzi.liferay.portlets.rails286.OnlineClient.java

private StringPart createStringPart(NameValuePair pair) {
    StringPart part = new StringPart(pair.getName(), pair.getValue());

    //HACK: When content type is null, Rack will interpretate as string param, 
    //otherwise this will be treated like a file.
    part.setContentType(null);/*from ww  w. j  a  va2 s. co  m*/

    part.setCharSet("UTF-8");
    return part;
}

From source file:JiraWebClient.java

public void attachFile(final JiraIssue issue, final String comment, final FilePart filePart,
        final String contentType, IProgressMonitor monitor) throws JiraException {
    doInSession(monitor, new JiraWebSessionCallback() {
        @Override// w w  w.  j av  a2s. co  m
        public void run(JiraClient server, String baseUrl, IProgressMonitor monitor) throws JiraException {
            StringBuilder attachFileURLBuffer = new StringBuilder(baseUrl);
            attachFileURLBuffer.append("/secure/AttachFile.jspa"); //$NON-NLS-1$

            PostMethod post = new PostMethod(attachFileURLBuffer.toString());
            prepareSecurityToken(post);

            List<PartBase> parts = new ArrayList<PartBase>();

            StringPart idPart = new StringPart("id", issue.getId()); //$NON-NLS-1$
            StringPart commentLevelPart = new StringPart("commentLevel", ""); //$NON-NLS-1$ //$NON-NLS-2$

            // The transfer encodings have to be removed for some reason
            // There is no need to send the content types for the strings,
            // as they should be in the correct format
            idPart.setTransferEncoding(null);
            idPart.setContentType(null);

            if (comment != null) {
                StringPart commentPart = new StringPart("comment", comment); //$NON-NLS-1$
                commentPart.setTransferEncoding(null);
                commentPart.setContentType(null);
                commentPart.setCharSet(client.getCharacterEncoding(monitor));
                parts.add(commentPart);
            }

            commentLevelPart.setTransferEncoding(null);
            commentLevelPart.setContentType(null);

            filePart.setTransferEncoding(null);
            if (contentType != null) {
                filePart.setContentType(contentType);
            }
            parts.add(filePart);
            parts.add(idPart);
            parts.add(commentLevelPart);

            post.setRequestEntity(
                    new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), post.getParams()));

            try {
                execute(post);
                if (!expectRedirect(post, "/secure/ManageAttachments.jspa?id=" + issue.getId())) { //$NON-NLS-1$
                    handleErrorMessage(post);
                }
            } finally {
                post.releaseConnection();
            }
        }
    });
}