Search in sources :

Example 11 with InputStreamRequestEntity

use of org.apache.commons.httpclient.methods.InputStreamRequestEntity in project zm-mailbox by Zimbra.

the class UserServlet method putMailItem.

public static Pair<Header[], HttpInputStream> putMailItem(ZAuthToken authToken, String url, MailItem item) throws ServiceException, IOException {
    if (item instanceof Document) {
        Document doc = (Document) item;
        StringBuilder u = new StringBuilder(url);
        u.append("?").append(QP_AUTH).append('=').append(AUTH_COOKIE);
        if (doc.getType() == MailItem.Type.WIKI) {
            u.append("&fmt=wiki");
        }
        PutMethod method = new PutMethod(u.toString());
        String contentType = doc.getContentType();
        method.addRequestHeader("Content-Type", contentType);
        method.setRequestEntity(new InputStreamRequestEntity(doc.getContentStream(), doc.getSize(), contentType));
        method = HttpClientUtil.addInputStreamToHttpMethod(method, doc.getContentStream(), doc.getSize(), contentType);
        method.addRequestHeader("X-Zimbra-Description", doc.getDescription());
        method.setRequestEntity(new InputStreamRequestEntity(doc.getContentStream(), doc.getSize(), contentType));
        Pair<Header[], HttpMethod> pair = doHttpOp(authToken, method);
        return new Pair<Header[], HttpInputStream>(pair.getFirst(), new HttpInputStream(pair.getSecond()));
    }
    return putRemoteResource(authToken, url, item.getContentStream(), null);
}
Also used : InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) Header(org.apache.commons.httpclient.Header) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Document(com.zimbra.cs.mailbox.Document) HttpMethod(org.apache.commons.httpclient.HttpMethod) Pair(com.zimbra.common.util.Pair)

Example 12 with InputStreamRequestEntity

use of org.apache.commons.httpclient.methods.InputStreamRequestEntity in project sling by apache.

the class SlingIntegrationTestClient method upload.

/** Upload a file to the Sling repository
     *  @return the HTTP status code
     */
public int upload(String toUrl, InputStream is) throws IOException {
    final PutMethod put = new PutMethod(toUrl);
    put.setRequestEntity(new InputStreamRequestEntity(is));
    return httpClient.executeMethod(put);
}
Also used : InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) PutMethod(org.apache.commons.httpclient.methods.PutMethod)

Aggregations

InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)12 PostMethod (org.apache.commons.httpclient.methods.PostMethod)5 HttpClient (org.apache.commons.httpclient.HttpClient)4 HttpMethod (org.apache.commons.httpclient.HttpMethod)4 GetMethod (org.apache.commons.httpclient.methods.GetMethod)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 Header (org.apache.commons.httpclient.Header)3 PutMethod (org.apache.commons.httpclient.methods.PutMethod)3 ZMailbox (com.zimbra.client.ZMailbox)2 Pair (com.zimbra.common.util.Pair)2 IOException (java.io.IOException)2 URI (java.net.URI)2 SharedByteArrayInputStream (javax.mail.util.SharedByteArrayInputStream)2 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)2 RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)2 Test (org.junit.Test)2 ServiceException (com.zimbra.common.service.ServiceException)1 Document (com.zimbra.cs.mailbox.Document)1