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