Search in sources :

Example 6 with InputStreamRequestEntity

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

the class HttpProxyImpl method copyRequestBodyToMethod.

protected void copyRequestBodyToMethod(PostMethod httpMethod, HttpServletRequest request) throws IOException {
    int contentLength = request.getContentLength();
    if (contentLength > 0) {
        String contentType = request.getContentType();
        InputStream content = request.getInputStream();
        httpMethod.setRequestEntity(new InputStreamRequestEntity(content, contentLength, contentType));
    }
}
Also used : InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) InputStream(java.io.InputStream)

Example 7 with InputStreamRequestEntity

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

the class HttpClientUtil method addInputStreamToHttpMethod.

public static <T extends EntityEnclosingMethod> T addInputStreamToHttpMethod(T method, InputStream is, long size, String contentType) {
    if (size < 0) {
        size = InputStreamRequestEntity.CONTENT_LENGTH_AUTO;
    }
    method.setRequestEntity(new InputStreamRequestEntity(is, size, contentType));
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new InputStreamRequestHttpRetryHandler());
    return method;
}
Also used : InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity)

Example 8 with InputStreamRequestEntity

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

the class TestUserServlet method testIcsImportExportGMTtoLondon.

/** Bug 84362 Confirm that import with London timezone incorrectly identified as "GMT" works */
@Test
public void testIcsImportExportGMTtoLondon() throws IOException, ServiceException {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String calName = NAME_PREFIX + "3rdCalendar";
    String calUri = String.format("/%s?fmt=ics", calName);
    TestUtil.createFolder(mbox, calName, ZFolder.View.appointment);
    URI uri = mbox.getRestURI(calUri);
    HttpClient client = mbox.getHttpClient(uri);
    PostMethod post = new PostMethod(uri.toString());
    post.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(TestCalDav.LOTUS_NOTES_WITH_BAD_GMT_TZID.getBytes()), MimeConstants.CT_TEXT_CALENDAR));
    ZimbraLog.test.debug("testIcsImportExport:ICS to be imported:%s", TestCalDav.LOTUS_NOTES_WITH_BAD_GMT_TZID);
    TestCalDav.HttpMethodExecutor.execute(client, post, HttpStatus.SC_OK);
    uri = mbox.getRestURI(calUri);
    GetMethod get = new GetMethod(uri.toString());
    TestCalDav.HttpMethodExecutor executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
    String respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    ZimbraLog.test.debug("testIcsImportExport:ICS exported:%s", respIcal);
    // If this is present, it implies that both the timezone and the references have been correctly changed.
    String dtstartWithNewTZID = "DTSTART;TZID=\"Europe/London\":20150721T140000";
    int dtstartIndex = respIcal.indexOf(dtstartWithNewTZID);
    Assert.assertTrue(String.format("'%s' should be present", dtstartWithNewTZID), -1 != dtstartIndex);
}
Also used : InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) ZMailbox(com.zimbra.client.ZMailbox) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ByteArrayInputStream(java.io.ByteArrayInputStream) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) URI(java.net.URI) Test(org.junit.Test)

Example 9 with InputStreamRequestEntity

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

the class TestUserServlet method testIcsImportExport.

/**
     * Test that can import into a new calendar from ICALENDAR containing an inline ATTACHment.
     * Test that it is possible to export calendar entry with an attachment with the attachment
     * inlined if icalAttach=inline or ignoring the attachment if icalAttach=none
     */
@Test
public void testIcsImportExport() throws IOException, ValidationException, ServiceException {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String calName = NAME_PREFIX + "2ndCalendar";
    String calUri = String.format("/%s?fmt=ics", calName);
    TestUtil.createFolder(mbox, calName, ZFolder.View.appointment);
    net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
    calendar.getProperties().add(new ProdId("-//ZimbraTest 1.0//EN"));
    calendar.getProperties().add(Version.VERSION_2_0);
    calendar.getProperties().add(CalScale.GREGORIAN);
    java.util.Calendar start = java.util.Calendar.getInstance();
    start.set(java.util.Calendar.MONTH, java.util.Calendar.SEPTEMBER);
    start.set(java.util.Calendar.DAY_OF_MONTH, 03);
    VEvent wwII = new VEvent(new Date(start.getTime()), NAME_PREFIX + " Declarations of war");
    wwII.getProperties().getProperty(Property.DTSTART).getParameters().add(Value.DATE);
    wwII.getProperties().add(new Uid("3-14159"));
    Attach attach = new Attach("Attachment.\nIsn't it short.".getBytes(MimeConstants.P_CHARSET_ASCII));
    attach.getParameters().add(new XParameter("X-APPLE-FILENAME", "short.txt"));
    attach.getParameters().add(new FmtType(MimeConstants.CT_TEXT_PLAIN));
    wwII.getProperties().add(attach);
    calendar.getComponents().add(wwII);
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    CalendarOutputter outputter = new CalendarOutputter();
    outputter.setValidating(false);
    outputter.output(calendar, buf);
    URI uri = mbox.getRestURI(calUri);
    HttpClient client = mbox.getHttpClient(uri);
    PostMethod post = new PostMethod(uri.toString());
    post.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(buf.toByteArray()), MimeConstants.CT_TEXT_CALENDAR));
    ZimbraLog.test.info("testIcsImportExport:ICS to be imported:%s", new String(buf.toByteArray()));
    TestCalDav.HttpMethodExecutor.execute(client, post, HttpStatus.SC_OK);
    uri = mbox.getRestURI(calUri + "&icalAttach=inline");
    GetMethod get = new GetMethod(uri.toString());
    TestCalDav.HttpMethodExecutor executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
    String respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    ZimbraLog.test.info("testIcsImportExport:ICS exported (with icalAttach=inline):%s", respIcal);
    int attachNdx = respIcal.indexOf("ATTACH;");
    Assert.assertTrue("ATTACH should be present", -1 != attachNdx);
    String fromAttach = respIcal.substring(attachNdx);
    Assert.assertTrue("BINARY should be present", -1 != fromAttach.indexOf("VALUE=BINARY"));
    uri = mbox.getRestURI(calUri + "&icalAttach=none");
    get = new GetMethod(uri.toString());
    executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
    respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    ZimbraLog.test.debug("testIcsImportExport:ICS exported (with icalAttach=none):%s", respIcal);
    Assert.assertTrue("ATTACH should be present", -1 == respIcal.indexOf("ATTACH;"));
    uri = mbox.getRestURI(calUri);
    get = new GetMethod(uri.toString());
    executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
    respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    ZimbraLog.test.debug("testIcsImportExport:ICS exported (default - same as icalAttach=none):%s", respIcal);
    Assert.assertTrue("ATTACH should be present", -1 == respIcal.indexOf("ATTACH;"));
}
Also used : InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ProdId(net.fortuna.ical4j.model.property.ProdId) URI(java.net.URI) ZMailbox(com.zimbra.client.ZMailbox) XParameter(net.fortuna.ical4j.model.parameter.XParameter) VEvent(net.fortuna.ical4j.model.component.VEvent) Attach(net.fortuna.ical4j.model.property.Attach) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(net.fortuna.ical4j.model.Date) Uid(net.fortuna.ical4j.model.property.Uid) ByteArrayInputStream(java.io.ByteArrayInputStream) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) HttpClient(org.apache.commons.httpclient.HttpClient) FmtType(net.fortuna.ical4j.model.parameter.FmtType) GetMethod(org.apache.commons.httpclient.methods.GetMethod) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter) Test(org.junit.Test)

Example 10 with InputStreamRequestEntity

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

the class DavMethod method toHttpMethod.

public HttpMethod toHttpMethod(DavContext ctxt, String targetUrl) throws IOException, DavException {
    if (ctxt.getUpload() != null && ctxt.getUpload().getSize() > 0) {
        PostMethod method = new PostMethod(targetUrl) {

            @Override
            public String getName() {
                return getMethodName();
            }
        };
        RequestEntity reqEntry;
        if (ctxt.hasRequestMessage()) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(baos);
            writer.write(ctxt.getRequestMessage());
            reqEntry = new ByteArrayRequestEntity(baos.toByteArray());
        } else {
            // this could be a huge upload
            reqEntry = new InputStreamRequestEntity(ctxt.getUpload().getInputStream(), ctxt.getUpload().getSize());
        }
        method.setRequestEntity(reqEntry);
        return method;
    }
    return new GetMethod(targetUrl) {

        @Override
        public String getName() {
            return getMethodName();
        }
    };
}
Also used : InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity) InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) RequestEntity(org.apache.commons.httpclient.methods.RequestEntity) XMLWriter(org.dom4j.io.XMLWriter) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity)

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