use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestSendAndReceive method testSendDraftWithData.
@Test
public void testSendDraftWithData() throws Exception {
TestUtil.createAccount(USER_NAME);
TestUtil.createAccount(REMOTE_USER_NAME);
MailSender.registerPreSendMailListener(listener);
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
String subj = "Thorin";
String body = "far over the misty mountains cold";
String customHeaderValue = "https://zss.server/file2";
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
transport.setAuthToken(zmbox.getAuthToken());
//create a draft with a custom mime header
Element request = new Element.JSONElement(MailConstants.SAVE_DRAFT_REQUEST);
Element el = request.addUniqueElement(MailConstants.E_MSG);
el.addAttribute(MailConstants.E_SUBJECT, subj);
el.addUniqueElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, body);
el.addNonUniqueElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS_TYPE, EmailType.TO.toString()).addAttribute(MailConstants.A_ADDRESS, TestUtil.addDomainIfNecessary(REMOTE_USER_NAME));
el.addNonUniqueElement(MailConstants.E_HEADER).addAttribute(MailConstants.A_NAME, MailSender.PRE_SEND_HEADER).setText("custom");
el.addNonUniqueElement(MailConstants.E_HEADER).addAttribute(MailConstants.A_NAME, PUBLIC_LIST_HEADER).setText(customHeaderValue);
ZMessage draft = new ZMessage(transport.invoke(request).getElement(MailConstants.E_MSG), zmbox);
//Send the draft and save to Sent folder
request = new Element.JSONElement(MailConstants.SEND_MSG_REQUEST);
request.addUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.A_DRAFT_ID, draft.getId()).addAttribute(MailConstants.A_SEND_FROM_DRAFT, true).addAttribute(MailConstants.A_NO_SAVE_TO_SENT, false);
transport.invoke(request);
Assert.assertTrue("Listener was not triggered", listener.isTriggered());
Assert.assertEquals("listener should ahve been triggered only once", 1, listener.getTriggerCounter());
String[] listenersData = listener.getData();
Assert.assertNotNull("Listener did not get data from custom headers", listenersData);
Assert.assertTrue("wrong number of elements in custom header data", listenersData.length == 1);
Assert.assertTrue(String.format("wrong value in custom header: %s", listenersData[0]), customHeaderValue.equalsIgnoreCase(listenersData[0].replace("\"", "")));
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestSendAndReceive method testSendDraftNoHeader.
@Test
public void testSendDraftNoHeader() throws Exception {
TestUtil.createAccount(USER_NAME);
TestUtil.createAccount(REMOTE_USER_NAME);
MailSender.registerPreSendMailListener(listener);
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
String subj = "Thorin";
String body = "far over the misty mountains cold";
ZOutgoingMessage msg = TestUtil.getOutgoingMessage(REMOTE_USER_NAME, subj, body, null);
ZMessage draft = zmbox.saveDraft(msg, null, Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
Element request = new Element.JSONElement(MailConstants.SEND_MSG_REQUEST);
request.addUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.A_DRAFT_ID, draft.getId()).addAttribute(MailConstants.A_SEND_FROM_DRAFT, true);
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
transport.setAuthToken(zmbox.getAuthToken());
transport.invoke(request);
Assert.assertFalse("Listener was not supposed to be triggered", listener.isTriggered());
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestServiceServlet method getAdminAuthToken.
private String getAdminAuthToken(String adminName) throws ServiceException, IOException {
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
com.zimbra.soap.admin.message.AuthRequest authReq = new com.zimbra.soap.admin.message.AuthRequest(adminName, TestUtil.DEFAULT_PASSWORD);
authReq.setCsrfSupported(false);
Element response = transport.invoke(JaxbUtil.jaxbToElement(authReq, SoapProtocol.SoapJS.getFactory()));
com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(response);
return authResp.getAuthToken();
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class LmcSoapRequest method invoke.
/**
* After setting up all the request parameters, send this request to
* the targetURL and return the server's response.
* This method will side-effect the LmcSession object assigned with
* setSession, changing the session ID if the server changed it.
* @param targetURL - the URL of the SOAP service to send the request to
* @exception lotsOfthem
*/
public LmcSoapResponse invoke(String targetURL) throws LmcSoapClientException, IOException, SoapFaultException, ServiceException, SoapParseException {
LmcSoapResponse result = null;
SoapHttpTransport trans = null;
try {
trans = new SoapHttpTransport(targetURL);
trans.setTimeout(sTimeoutMillis);
trans.setRetryCount(sRetryCount);
trans.setUserAgent("lmc", null);
// set the auth token and session id in the transport for this request to use
String curSessionID = null;
if (mSession != null) {
ZAuthToken zat = mSession.getAuthToken();
trans.setAuthToken(zat);
curSessionID = mSession.getSessionID();
trans.setSessionId(curSessionID);
}
// send it over
Element requestXML = getRequestXML();
if (sDumpXML) {
sLog.info("Request:" + DomUtil.toString(requestXML, true));
}
com.zimbra.common.soap.Element requestElt = com.zimbra.common.soap.Element.convertDOM(requestXML);
//System.out.println("Sending over request " + DomUtil.toString(requestXML, true));
Element responseXML;
if (mRequestedAccountId == null)
responseXML = trans.invoke(requestElt).toXML();
else
responseXML = trans.invoke(requestElt, false, true, mRequestedAccountId).toXML();
if (sDumpXML) {
sLog.info("Response:" + DomUtil.toString(responseXML, true) + "\n");
}
/*
* check to see if the session ID changed. this will not change
* the session ID if there was one and trans.getSessionId() now
* returns null.
*/
String newSessionID = trans.getSessionId();
if (newSessionID != null && mSession != null) {
if (curSessionID == null)
mSession.setSessionID(newSessionID);
else if (!curSessionID.equals(newSessionID))
mSession.setSessionID(newSessionID);
}
// parse the response
//System.out.println(DomUtil.toString(responseXML, true));
result = parseResponseXML(responseXML);
} finally {
if (trans != null)
trans.shutdown();
}
return result;
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class LocalConfigCLI method reload.
private void reload() throws ServiceException {
String host = LC.zimbra_zmprov_default_soap_server.value();
int port = LC.zimbra_admin_service_port.intValue();
SoapHttpTransport transport = new SoapHttpTransport("https://" + host + ":" + port + AdminConstants.ADMIN_SERVICE_URI);
SoapProvisioning prov = new SoapProvisioning();
prov.soapSetURI(transport.getURI());
prov.soapZimbraAdminAuthenticate();
transport.setAuthToken(prov.getAuthToken());
try {
transport.invoke(JaxbUtil.jaxbToElement(new ReloadLocalConfigRequest()));
} catch (IOException e) {
throw ZClientException.IO_ERROR(e.getMessage(), e);
}
}
Aggregations