Search in sources :

Example 11 with ByteArrayRequestEntity

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

the class TestCalDav method checkPropFindSupportedReportSet.

public void checkPropFindSupportedReportSet(Account user, String fullurl, String shorturl) throws Exception {
    PropFindMethod method = new PropFindMethod(fullurl);
    addBasicAuthHeaderForUser(method, user);
    HttpClient client = new HttpClient();
    TestCalDav.HttpMethodExecutor executor;
    String respBody;
    Element respElem;
    method.addRequestHeader("Content-Type", MimeConstants.CT_TEXT_XML);
    method.setRequestEntity(new ByteArrayRequestEntity(propFindSupportedReportSet.getBytes(), MimeConstants.CT_TEXT_XML));
    executor = new TestCalDav.HttpMethodExecutor(client, method, HttpStatus.SC_MULTI_STATUS);
    respBody = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    respElem = Element.XMLElement.parseXML(respBody);
    assertEquals("name of top element in response", DavElements.P_MULTISTATUS, respElem.getName());
    assertTrue("top element response should have child elements", respElem.hasChildren());
    checkSupportedReportSet(respElem, shorturl);
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) Element(com.zimbra.common.soap.Element) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity)

Example 12 with ByteArrayRequestEntity

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

the class TestCalDav method delegateForExpandProperty.

public static Document delegateForExpandProperty(Account acct) throws IOException, ServiceException {
    ReportMethod method = new ReportMethod(getPrincipalUrl(acct));
    addBasicAuthHeaderForUser(method, acct);
    HttpClient client = new HttpClient();
    TestCalDav.HttpMethodExecutor executor;
    method.addRequestHeader("Content-Type", MimeConstants.CT_TEXT_XML);
    method.setRequestEntity(new ByteArrayRequestEntity(expandPropertyDelegateFor.getBytes(), MimeConstants.CT_TEXT_XML));
    executor = new TestCalDav.HttpMethodExecutor(client, method, HttpStatus.SC_MULTI_STATUS);
    String respBody = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    Document doc = W3cDomUtil.parseXMLToDoc(respBody);
    org.w3c.dom.Element docElement = doc.getDocumentElement();
    assertEquals("Report node name", DavElements.P_MULTISTATUS, docElement.getLocalName());
    return doc;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) Document(org.w3c.dom.Document) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity)

Example 13 with ByteArrayRequestEntity

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

the class TestCalDav method testCreateContactWithIfNoneMatchTesting.

@Test
public void testCreateContactWithIfNoneMatchTesting() throws ServiceException, IOException {
    Account dav1 = users[1].create();
    // Based on UID
    String davBaseName = "SCRUFF1.vcf";
    String contactsFolderUrl = getFolderUrl(dav1, "Contacts");
    String url = String.format("%s%s", contactsFolderUrl, davBaseName);
    HttpClient client = new HttpClient();
    PutMethod putMethod = new PutMethod(url);
    addBasicAuthHeaderForUser(putMethod, dav1);
    putMethod.addRequestHeader("Content-Type", "text/vcard");
    putMethod.setRequestEntity(new ByteArrayRequestEntity(simpleVcard.getBytes(), MimeConstants.CT_TEXT_VCARD));
    // Bug 84246 this used to fail with 409 Conflict because we used to require an If-None-Match header
    HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_CREATED);
    // Check that trying to put the same thing again when we don't expect it to exist (i.e. Using If-None-Match
    // header) will fail.
    putMethod = new PutMethod(url);
    addBasicAuthHeaderForUser(putMethod, dav1);
    putMethod.addRequestHeader("Content-Type", "text/vcard");
    putMethod.addRequestHeader(DavProtocol.HEADER_IF_NONE_MATCH, "*");
    putMethod.setRequestEntity(new ByteArrayRequestEntity(simpleVcard.getBytes(), MimeConstants.CT_TEXT_VCARD));
    HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_PRECONDITION_FAILED);
}
Also used : Account(com.zimbra.cs.account.Account) HttpClient(org.apache.commons.httpclient.HttpClient) PutMethod(org.apache.commons.httpclient.methods.PutMethod) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity) Test(org.junit.Test)

Example 14 with ByteArrayRequestEntity

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

the class TestCalDav method testPostToSchedulingOutbox.

@Test
public void testPostToSchedulingOutbox() throws Exception {
    Account dav1 = users[1].create();
    Account dav2 = users[2].create();
    Account dav3 = users[3].create();
    String url = getSchedulingOutboxUrl(dav1, dav1);
    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod(url);
    addBasicAuthHeaderForUser(method, dav1);
    method.addRequestHeader("Content-Type", "text/calendar");
    method.addRequestHeader("Originator", "mailto:" + dav1.getName());
    method.addRequestHeader("Recipient", "mailto:" + dav2.getName());
    method.addRequestHeader("Recipient", "mailto:" + dav3.getName());
    method.setRequestEntity(new ByteArrayRequestEntity(exampleCancelIcal(dav1, dav2, dav3).getBytes(), MimeConstants.CT_TEXT_CALENDAR));
    HttpMethodExecutor.execute(client, method, HttpStatus.SC_OK);
}
Also used : Account(com.zimbra.cs.account.Account) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity) Test(org.junit.Test)

Example 15 with ByteArrayRequestEntity

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

the class TestCalDav method testCreateUsingClientChosenName.

/**
     *  dav - sending http error 302 because: wrong url - redirecting to:
     *  http://pan.local:7070/dav/dav1@pan.local/Calendar/d123f102-42a7-4283-b025-3376dabe53b3.ics
     *  com.zimbra.cs.dav.DavException: wrong url - redirecting to:
     *  http://pan.local:7070/dav/dav1@pan.local/Calendar/d123f102-42a7-4283-b025-3376dabe53b3.ics
     *      at com.zimbra.cs.dav.resource.CalendarCollection.createItem(CalendarCollection.java:431)
     *      at com.zimbra.cs.dav.service.method.Put.handle(Put.java:49)
     *      at com.zimbra.cs.dav.service.DavServlet.service(DavServlet.java:322)
     */
@Test
public void testCreateUsingClientChosenName() throws ServiceException, IOException {
    Account dav1 = users[1].create();
    String davBaseName = "clientInvented.now";
    String calFolderUrl = getFolderUrl(dav1, "Calendar");
    String url = String.format("%s%s", calFolderUrl, davBaseName);
    HttpClient client = new HttpClient();
    PutMethod putMethod = new PutMethod(url);
    addBasicAuthHeaderForUser(putMethod, dav1);
    putMethod.addRequestHeader("Content-Type", "text/calendar");
    putMethod.setRequestEntity(new ByteArrayRequestEntity(simpleEvent(dav1), MimeConstants.CT_TEXT_CALENDAR));
    if (DebugConfig.enableDAVclientCanChooseResourceBaseName) {
        HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_CREATED);
    } else {
        HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_MOVED_TEMPORARILY);
        // Not testing much in this mode but...
        return;
    }
    doGetMethod(url, dav1, HttpStatus.SC_OK);
    PropFindMethod propFindMethod = new PropFindMethod(getFolderUrl(dav1, "Calendar"));
    addBasicAuthHeaderForUser(propFindMethod, dav1);
    TestCalDav.HttpMethodExecutor executor;
    String respBody;
    Element respElem;
    propFindMethod.addRequestHeader("Content-Type", MimeConstants.CT_TEXT_XML);
    propFindMethod.addRequestHeader("Depth", "1");
    propFindMethod.setRequestEntity(new ByteArrayRequestEntity(propFindEtagResType.getBytes(), MimeConstants.CT_TEXT_XML));
    executor = new TestCalDav.HttpMethodExecutor(client, propFindMethod, HttpStatus.SC_MULTI_STATUS);
    respBody = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    respElem = Element.XMLElement.parseXML(respBody);
    assertEquals("name of top element in propfind response", DavElements.P_MULTISTATUS, respElem.getName());
    assertTrue("propfind response should have child elements", respElem.hasChildren());
    Iterator<Element> iter = respElem.elementIterator();
    boolean hasCalendarHref = false;
    boolean hasCalItemHref = false;
    while (iter.hasNext()) {
        Element child = iter.next();
        if (DavElements.P_RESPONSE.equals(child.getName())) {
            Iterator<Element> hrefIter = child.elementIterator(DavElements.P_HREF);
            while (hrefIter.hasNext()) {
                Element href = hrefIter.next();
                calFolderUrl.endsWith(href.getText());
                hasCalendarHref = hasCalendarHref || calFolderUrl.endsWith(href.getText());
                hasCalItemHref = hasCalItemHref || url.endsWith(href.getText());
            }
        }
    }
    assertTrue("propfind response contained entry for calendar", hasCalendarHref);
    assertTrue("propfind response contained entry for calendar entry ", hasCalItemHref);
    doDeleteMethod(url, dav1, HttpStatus.SC_NO_CONTENT);
}
Also used : Account(com.zimbra.cs.account.Account) HttpClient(org.apache.commons.httpclient.HttpClient) Element(com.zimbra.common.soap.Element) PutMethod(org.apache.commons.httpclient.methods.PutMethod) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity) Test(org.junit.Test)

Aggregations

ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)30 HttpClient (org.apache.commons.httpclient.HttpClient)20 PostMethod (org.apache.commons.httpclient.methods.PostMethod)11 Account (com.zimbra.cs.account.Account)9 PutMethod (org.apache.commons.httpclient.methods.PutMethod)8 Test (org.junit.Test)8 Header (org.apache.commons.httpclient.Header)5 RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)5 Document (org.w3c.dom.Document)5 Element (com.zimbra.common.soap.Element)4 GetMethod (org.apache.commons.httpclient.methods.GetMethod)4 ZMailbox (com.zimbra.client.ZMailbox)3 HttpMethod (org.apache.commons.httpclient.HttpMethod)3 EntityEnclosingMethod (org.apache.commons.httpclient.methods.EntityEnclosingMethod)3 SearchRequest (com.zimbra.soap.mail.message.SearchRequest)2 SearchResponse (com.zimbra.soap.mail.message.SearchResponse)2 SearchHit (com.zimbra.soap.type.SearchHit)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2