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));
}
}
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;
}
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);
}
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;"));
}
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();
}
};
}
Aggregations