protected Folder getFolder(ExchangeService service) { Folder folder; if(folderName.equals("INBOX")){ try { folder = Folder.bind(service, WellKnownFolderName.Inbox); } catch (Exception e) { throw new ProcessException("Failed to bind Inbox Folder on EWS Server", e); } } else { FolderView view = new FolderView(10); view.setTraversal(FolderTraversal.Deep); SearchFilter searchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, folderName); try { FindFoldersResults foldersResults = service.findFolders(WellKnownFolderName.Root,searchFilter, view); ArrayList<Folder> folderIds = foldersResults.getFolders(); if(folderIds.size() > 1){ throw new ProcessException("More than 1 folder found with the name " + folderName); } folder = Folder.bind(service, folderIds.get(0).getId()); } catch (Exception e) { throw new ProcessException("Search for Inbox Subfolder failed.", e); } } return folder; }
/** * Reads to the next descendant element with the specified local name and * namespace. * * @param xmlNamespace The namespace of the element you with to move to. * @param localName The local name of the element you wish to move to. * @throws XMLStreamException the XML stream exception */ public void readToDescendant(XmlNamespace xmlNamespace, String localName) throws XMLStreamException { readToDescendant(localName, EwsUtilities.getNamespaceUri(xmlNamespace)); }
protected ExchangeService initializeIfNecessary(ProcessContext context) throws ProcessException { ExchangeVersion ver = ExchangeVersion.valueOf(context.getProperty(EXCHANGE_VERSION).getValue()); ExchangeService service = new ExchangeService(ver); final String timeoutInMillis = String.valueOf(context.getProperty(CONNECTION_TIMEOUT).evaluateAttributeExpressions().asTimePeriod(TimeUnit.MILLISECONDS)); service.setTimeout(Integer.parseInt(timeoutInMillis)); String userEmail = context.getProperty(USER).evaluateAttributeExpressions().getValue(); String password = context.getProperty(PASSWORD).evaluateAttributeExpressions().getValue(); ExchangeCredentials credentials = new WebCredentials(userEmail, password); service.setCredentials(credentials); Boolean useAutodiscover = context.getProperty(USE_AUTODISCOVER).asBoolean(); if(useAutodiscover){ try { service.autodiscoverUrl(userEmail, new RedirectionUrlCallback()); } catch (Exception e) { throw new ProcessException("Failure setting Autodiscover URL from email address.", e); } } else { String ewsURL = context.getProperty(EWS_URL).getValue(); try { service.setUrl(new URI(ewsURL)); } catch (URISyntaxException e) { throw new ProcessException("Failure setting EWS URL.", e); } } return service; }
FindItemsResults<Item> findResults = service.findItems(folder.getId(), sf, view); service.loadPropertiesForItems(findResults, PropertySet.FirstClassProperties); ewsMessage.delete(DeleteMode.HardDelete); } else if(markAsRead){ ewsMessage.setIsRead(true); ewsMessage.update(ConflictResolutionMode.AlwaysOverwrite); service.close(); } catch (Exception e) { throw new ProcessException("Failed retrieving new messages from EWS.", e);
/** * Internal constructor. * * @param service the service * @throws Exception the exception */ protected ServiceObject(ExchangeService service) throws Exception { EwsUtilities.validateParam(service, "service"); EwsUtilities.validateServiceObjectVersion(this, service .getRequestedServerVersion()); this.service = service; this.propertyBag = new PropertyBag(this); }
/** * Loads from XML. * * @param reader The reader. * @param xmlElementName Name of the XML element. * @throws Exception the exception */ public void loadFromXml(EwsServiceXmlReader reader, String xmlElementName) throws Exception { reader.ensureCurrentNodeIsStartElement(XmlNamespace.Types, xmlElementName); EwsUtilities.parseEnumValueList(DayOfTheWeek.class, this.items, reader.readElementValue(), ' '); }
/** * Skips the current element. * * @throws Exception the exception */ public void skipCurrentElement() throws Exception { this.skipElement(this.getNamespacePrefix(), this.getLocalName()); }
/** * Reads the attribute value. * * @param <T> the generic type * @param cls the cls * @param attributeName the attribute name * @return T * @throws Exception the exception */ public <T> T readAttributeValue(Class<T> cls, String attributeName) throws Exception { return EwsUtilities.parse(cls, this.readAttributeValue(attributeName)); }
/** * Reads the attribute from XML. * * @param reader the reader * @throws Exception the exception */ @Override public void readAttributesFromXml(EwsServiceXmlReader reader) throws Exception { this.id = reader.readAttributeValue(XmlAttributeNames.Id); this.name = reader.readAttributeValue(XmlAttributeNames.Name); this.bias = EwsUtilities.getXSDurationToTimeSpan(reader.readAttributeValue(XmlAttributeNames.Bias)); }
/** * Writes the attribute to XML. * * @param writer the writer * @throws ServiceXmlSerializationException the service xml serialization exception */ @Override public void writeAttributesToXml(EwsServiceXmlWriter writer) throws ServiceXmlSerializationException { writer.writeAttributeValue(XmlAttributeNames.Bias, EwsUtilities .getTimeSpanToXSDuration(this.bias)); writer.writeAttributeValue(XmlAttributeNames.Name, this.name); writer.writeAttributeValue(XmlAttributeNames.Id, this.id); }
/** * Initializes a new instance of the ExecuteDiagnosticMethodResponse class. * * @param service The service */ public ExecuteDiagnosticMethodResponse(ExchangeService service) { super(); EwsUtilities.ewsAssert(service != null, "ExecuteDiagnosticMethodResponse.ctor", "service is null"); }
public AsyncRequestResult(ServiceRequestBase serviceRequest, HttpWebRequest webRequest, Future<?> task, Object asyncState) throws Exception { EwsUtilities.validateParam(serviceRequest, "serviceRequest"); EwsUtilities.validateParam(webRequest, "webRequest"); EwsUtilities.validateParam(task, "task"); this.serviceRequest = serviceRequest; this.webRequest = webRequest; this.asyncState = asyncState; this.task = task; }
/** * Writes the attribute to XML. * * @param writer the writer * @throws ServiceXmlSerializationException the service xml serialization exception */ @Override public void writeAttributesToXml(EwsServiceXmlWriter writer) throws ServiceXmlSerializationException { writer.writeAttributeValue(XmlAttributeNames.Id, this.id); }
/** * Formats the name of the element. * * @param namespacePrefix The namespace prefix * @param localElementName Element name * @return the string */ private static String formatElementName(String namespacePrefix, String localElementName) { return isNullOrEmpty(namespacePrefix) ? localElementName : namespacePrefix + ":" + localElementName; }
/** * Reads attribute from XML. * * @param reader the reader * @throws Exception the exception */ @Override public void readAttributesFromXml(EwsServiceXmlReader reader) throws Exception { this.id = reader.readAttributeValue(XmlAttributeNames.Id); }
/** * Convert instance to string. * * @param value The value. * @return String representation of property value. */ @Override protected String toString(TimeSpan value) { return EwsUtilities.getTimeSpanToXSDuration(value); } }
/** * Gets Folder instance. * * @param service The service. * @param xmlElementName Name of the XML element. * @return folder * @throws Exception the exception */ private Folder getObjectInstance(ExchangeService service, String xmlElementName) throws Exception { return EwsUtilities.createEwsObjectFromXmlElementName(Folder.class, service, xmlElementName); }
/** * Initializes a new instance of the CreateAttachmentResponse class. * * @param attachment the attachment */ public CreateAttachmentResponse(Attachment attachment) { super(); EwsUtilities.ewsAssert(attachment != null, "CreateAttachmentResponse.ctor", "attachment is null"); this.attachment = attachment; }
/** * Validate request. * * @throws Exception */ public void validate() throws Exception { EwsUtilities.validateParam(this.conversationId, "conversationId"); }