Search in sources :

Example 6 with DocumentResult

use of org.dom4j.io.DocumentResult in project zm-mailbox by Zimbra.

the class TestJaxb method doBrowseRequest.

public BrowseResponse doBrowseRequest(BrowseRequest browseRequest) throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String authToken = mbox.getAuthToken().getValue();
    DocumentResult dr = new DocumentResult();
    marshaller.marshal(browseRequest, dr);
    Document doc = dr.getDocument();
    ZimbraLog.test.debug(doc.getRootElement().asXML());
    return (BrowseResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "BrowseRequest");
}
Also used : BrowseResponse(com.zimbra.soap.mail.message.BrowseResponse) ZMailbox(com.zimbra.client.ZMailbox) DocumentResult(org.dom4j.io.DocumentResult) Document(org.dom4j.Document)

Example 7 with DocumentResult

use of org.dom4j.io.DocumentResult in project zm-mailbox by Zimbra.

the class TestWaitSetRequest method testWaitSetRequest.

@Test
public void testWaitSetRequest() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String authToken = mbox.getAuthToken().getValue();
    CreateWaitSetRequest req = new CreateWaitSetRequest("all");
    WaitSetAddSpec add = new WaitSetAddSpec();
    add.setId(mbox.getAccountInfo(false).getId());
    req.addAccount(add);
    DocumentResult dr = new DocumentResult();
    marshaller.marshal(req, dr);
    Document doc = dr.getDocument();
    ZimbraLog.test.info(doc.getRootElement().asXML());
    CreateWaitSetResponse createResp = (CreateWaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "CreateWaitSetRequest");
    String waitSetId = createResp.getWaitSetId();
    Assert.assertNotNull(waitSetId);
    WaitSetRequest waitSet = new com.zimbra.soap.mail.message.WaitSetRequest(waitSetId, "0");
    dr = new DocumentResult();
    marshaller.marshal(waitSet, dr);
    doc = dr.getDocument();
    WaitSetResponse wsResp = (WaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "WaitSetRequest");
    Assert.assertEquals("0", wsResp.getSeqNo());
    String subject = NAME_PREFIX + " test wait set request 1";
    TestUtil.addMessageLmtp(subject, USER_NAME, "user999@example.com");
    try {
        Thread.sleep(500);
    } catch (Exception e) {
    }
    wsResp = (WaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "WaitSetRequest");
    Assert.assertFalse(wsResp.getSeqNo().equals("0"));
}
Also used : WaitSetRequest(com.zimbra.soap.mail.message.WaitSetRequest) CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest) ZMailbox(com.zimbra.client.ZMailbox) WaitSetAddSpec(com.zimbra.soap.type.WaitSetAddSpec) WaitSetResponse(com.zimbra.soap.mail.message.WaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) DocumentResult(org.dom4j.io.DocumentResult) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) Document(org.dom4j.Document) IOException(java.io.IOException) ServiceException(com.zimbra.common.service.ServiceException) HttpException(org.apache.commons.httpclient.HttpException) CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest) Test(org.junit.Test)

Example 8 with DocumentResult

use of org.dom4j.io.DocumentResult in project zm-mailbox by Zimbra.

the class TestJaxb method doBadBrowseRequest.

public Element doBadBrowseRequest(BrowseRequest browseRequest) throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String authToken = mbox.getAuthToken().getValue();
    DocumentResult dr = new DocumentResult();
    marshaller.marshal(browseRequest, dr);
    Document doc = dr.getDocument();
    ZimbraLog.test.debug(doc.getRootElement().asXML());
    return sendReqExpectingFail(envelope(authToken, doc.getRootElement().asXML()), "BrowseRequest", 500);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) DocumentResult(org.dom4j.io.DocumentResult) Document(org.dom4j.Document)

Example 9 with DocumentResult

use of org.dom4j.io.DocumentResult in project zm-mailbox by Zimbra.

the class JaxbUtil method jaxbToElement.

/**
     * JAXB marshaling creates XML which makes heavy use of namespace prefixes.  Historical Zimbra SOAP XML
     * has generally not used them inside the SOAP body.  JAXB uses randomly assigned prefixes such as "ns2" which
     * makes the XML ugly and verbose.  If {@link removePrefixes} is set then all namespace prefix usage is
     * expunged from the XML.
     *
     * @param o - associated JAXB class.  <b>MUST</b> have an @XmlRootElement annotation
     * @param factory - e.g. XmlElement.mFactory or JSONElement.mFactory
     * @param removePrefixes - If true then remove namespace prefixes from unmarshalled XML.
     * @param useContextMarshaller - Set true if Object is a JAXB Request or Response listed in {@code MESSAGE_CLASSES}
     */
public static Element jaxbToElement(Object o, Element.ElementFactory factory, boolean removePrefixes, boolean useContextMarshaller) throws ServiceException {
    if (o == null) {
        return null;
    }
    if (Element.JSONElement.mFactory.equals(factory)) {
        return JacksonUtil.jaxbToJSONElement(o);
    }
    try {
        Marshaller marshaller;
        if (useContextMarshaller) {
            marshaller = getContext().createMarshaller();
        } else {
            marshaller = createMarshaller(o.getClass());
        }
        // marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        DocumentResult dr = new DocumentResult();
        marshaller.marshal(o, dr);
        Document theDoc = dr.getDocument();
        org.dom4j.Element rootElem = theDoc.getRootElement();
        if (removePrefixes) {
            JaxbUtil.removeNamespacePrefixes(rootElem);
        }
        return Element.convertDOM(rootElem, factory);
    } catch (Exception e) {
        throw ServiceException.FAILURE("Unable to convert " + o.getClass().getName() + " to Element", e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) DocumentResult(org.dom4j.io.DocumentResult) Document(org.dom4j.Document) ServiceException(com.zimbra.common.service.ServiceException) JAXBException(javax.xml.bind.JAXBException)

Aggregations

DocumentResult (org.dom4j.io.DocumentResult)9 Document (org.dom4j.Document)5 Transformer (javax.xml.transform.Transformer)4 DocumentSource (org.dom4j.io.DocumentSource)4 ZMailbox (com.zimbra.client.ZMailbox)3 ServiceException (com.zimbra.common.service.ServiceException)3 Test (org.junit.Test)3 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)2 Graph (com.thoughtworks.studios.shine.semweb.Graph)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 JAXBException (javax.xml.bind.JAXBException)2 Marshaller (javax.xml.bind.Marshaller)2 TransformerException (javax.xml.transform.TransformerException)2 TransformerFactory (javax.xml.transform.TransformerFactory)2 StreamSource (javax.xml.transform.stream.StreamSource)2 SAXReader (org.dom4j.io.SAXReader)2 InputSource (org.xml.sax.InputSource)2 GrddlTransformException (com.thoughtworks.studios.shine.semweb.grddl.GrddlTransformException)1 BrowseResponse (com.zimbra.soap.mail.message.BrowseResponse)1