/** * Gets the namespace URI from an XmlNamespace enum value. * * @param xmlNamespace The XML namespace. * @return Uri as string */ public static String getNamespaceUri(XmlNamespace xmlNamespace) { return xmlNamespace.getNameSpaceUri(); }
/** * Gets the namespace prefix from an XmlNamespace enum value. * * @param xmlNamespace The XML namespace * @return Namespace prefix string. */ public static String getNamespacePrefix(XmlNamespace xmlNamespace) { return xmlNamespace.getNameSpacePrefix(); }
/** * Determines whether the specified property may be accessed. * * @param property Property to access. * @throws PropertyException the property exception */ private void validatePropertyAccess(UserConfigurationProperties property) throws PropertyException { if (!this.propertiesAvailableForAccess.contains(property)) { throw new PropertyException("You must load or assign this property before you can read its value.", property .toString()); } }
/** * Validates property version against the request version. * * @param service The Exchange service. * @param minimumServerVersion The minimum server version * @param propertyName The property name * @throws ServiceVersionException The service version exception */ public static void validatePropertyVersion( ExchangeService service, ExchangeVersion minimumServerVersion, String propertyName) throws ServiceVersionException { if (service.getRequestedServerVersion().ordinal() < minimumServerVersion.ordinal()) { throw new ServiceVersionException( String.format("The property %s is valid only for Exchange %s or later versions.", propertyName, minimumServerVersion)); } }
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; }
/** * Validates service object version against the request version. * * @param serviceObject The service object. * @param requestVersion The request version. * @throws ServiceVersionException Raised if this service object type requires a later version * of Exchange. */ public static void validateServiceObjectVersion( ServiceObject serviceObject, ExchangeVersion requestVersion) throws ServiceVersionException { ExchangeVersion minimumRequiredServerVersion = serviceObject .getMinimumRequiredServerVersion(); if (requestVersion.ordinal() < minimumRequiredServerVersion.ordinal()) { String msg = String.format( "The object type %s is only valid for Exchange Server version %s or later versions.", serviceObject.getClass().getName(), minimumRequiredServerVersion.toString()); throw new ServiceVersionException(msg); } }
/** * Logs the specified XML to the TraceListener if tracing is enabled. * * @param traceType Kind of trace entry. * @param stream The stream containing XML. */ public void traceXml(TraceFlags traceType, ByteArrayOutputStream stream) { if (this.isTraceEnabledFor(traceType)) { String traceTypeStr = traceType.toString(); String logMessage = EwsUtilities.formatLogMessageWithXmlContent(traceTypeStr, stream); this.traceListener.trace(traceTypeStr, logMessage); } }
/** * Determines whether the specified flag is set. * * @param flag The flag. * @param version Requested version. * @return true/false if the specified flag is set,otherwise false. */ @Override public boolean hasFlag(PropertyDefinitionFlags flag, ExchangeVersion version) { if (version != null && this.getVersion() .compareTo(ExchangeVersion.Exchange2010_SP2) >= 0) { if (AttachmentsPropertyDefinition.Exchange2010SP2PropertyDefinitionFlags .contains(flag)) { return true; } else { return false; } } return super.hasFlag(flag, version); }
/** * Gets st ring representation of requested server version. In order to support E12 RTM servers, * ExchangeService has another flag indicating that we should use "Exchange2007" as the server version * string rather than Exchange2007_SP1. * * @return String representation of requested server version. */ private String getRequestedServiceVersionString() { if (this.service.getRequestedServerVersion() == ExchangeVersion.Exchange2007_SP1 && this.service .getExchange2007CompatibilityMode()) { return "Exchange2007"; } else { return this.service.getRequestedServerVersion().toString(); } }
/** * Writes to XML. * * @param writer The writer * @throws Exception the exception */ public void writeToXml(EwsServiceXmlWriter writer) throws Exception { if (this.id == null || this.id.isEmpty()) { throw new Exception("The Id property must be set."); } writer.writeStartElement(XmlNamespace.Types, XmlElementNames.ExchangeImpersonation); writer.writeStartElement(XmlNamespace.Types, XmlElementNames.ConnectingSID); // For 2007 SP1, use PrimarySmtpAddress for type SmtpAddress String connectingIdTypeLocalName = (this.idType == ConnectingIdType.SmtpAddress) && (writer.getService().getRequestedServerVersion() == ExchangeVersion.Exchange2007_SP1) ? XmlElementNames.PrimarySmtpAddress : this.getIdType().toString(); writer.writeElementValue(XmlNamespace.Types, connectingIdTypeLocalName, this.id); writer.writeEndElement(); // ConnectingSID writer.writeEndElement(); // ExchangeImpersonation }
/** * Validates class version against the request version. * * @param service the service * @param minimumServerVersion The minimum server version that supports the method. * @param className Name of the class. * @throws ServiceVersionException */ public static void validateClassVersion( ExchangeService service, ExchangeVersion minimumServerVersion, String className) throws ServiceVersionException { if (service.getRequestedServerVersion().ordinal() < minimumServerVersion.ordinal()) { throw new ServiceVersionException( String.format("Class %s is only valid for Exchange version %s or later.", className, minimumServerVersion)); } }
/** * Logs the specified string to the TraceListener if tracing is enabled. * * @param traceType kind of trace entry * @param logEntry the entry to log * @throws XMLStreamException the XML stream exception * @throws IOException signals that an I/O exception has occurred */ public void traceMessage(TraceFlags traceType, String logEntry) throws XMLStreamException, IOException { if (this.isTraceEnabledFor(traceType)) { String traceTypeStr = traceType.toString(); String logMessage = EwsUtilities.formatLogMessage(traceTypeStr, logEntry); this.traceListener.trace(traceTypeStr, logMessage); } }
default: EwsUtilities.ewsAssert(false, "UserConfiguration.IsPropertyUpdated", "property not supported: " + property.toString()); break;
/** * Retrieves the specified settings for a set of users. * * @param userSmtpAddresses the user smtp addresses * @param userSettingNames The user setting names. * @return A GetUserSettingsResponseCollection object containing the * response for each individual user. * @throws Exception the exception */ public GetUserSettingsResponseCollection getUsersSettings( Iterable<String> userSmtpAddresses, UserSettingName... userSettingNames) throws Exception { if (this.getRequestedServerVersion().compareTo(MinimumRequestVersionForAutoDiscoverSoapService) < 0) { throw new ServiceVersionException( String.format("The Autodiscover service only supports %s or a later version.", MinimumRequestVersionForAutoDiscoverSoapService)); } List<String> smtpAddresses = new ArrayList<String>(); smtpAddresses.addAll((Collection<? extends String>) userSmtpAddresses); List<UserSettingName> settings = new ArrayList<UserSettingName>(); settings.addAll(Arrays.asList(userSettingNames)); return this.getUserSettings(smtpAddresses, settings); }
/** * Validate method version. * * @param service the service * @param minimumServerVersion the minimum server version * @param methodName the method name * @throws ServiceVersionException the service version exception */ public static void validateMethodVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String methodName) throws ServiceVersionException { if (service.getRequestedServerVersion().ordinal() < minimumServerVersion.ordinal()) { throw new ServiceVersionException(String.format( "Method %s is only valid for Exchange Server version %s or later.", methodName, minimumServerVersion)); } }
/** * Traces the HTTP response headers. * * @param traceType kind of trace entry * @param request the HttpRequest object * @throws XMLStreamException the XML stream exception * @throws IOException signals that an I/O exception has occurred * @throws EWSHttpException the EWS http exception */ private void traceHttpResponseHeaders(TraceFlags traceType, HttpWebRequest request) throws XMLStreamException, IOException, EWSHttpException { if (this.isTraceEnabledFor(traceType)) { String traceTypeStr = traceType.toString(); String headersAsString = EwsUtilities.formatHttpResponseHeaders(request); String logMessage = EwsUtilities.formatLogMessage(traceTypeStr, headersAsString); this.traceListener.trace(traceTypeStr, logMessage); } }
/** * Throw exception if request is not supported in requested server version. * * @throws ServiceVersionException the service version exception */ protected void throwIfNotSupportedByRequestedServerVersion() throws ServiceVersionException { if (this.service.getRequestedServerVersion().ordinal() < this.getMinimumRequiredServerVersion() .ordinal()) { throw new ServiceVersionException(String.format( "The service request %s is only valid for Exchange version %s or later.", this.getXmlElementName(), this.getMinimumRequiredServerVersion())); } }
/** * Traces the HTTP request headers. * * @param traceType Kind of trace entry. * @param request The request * @throws EWSHttpException EWS http exception * @throws URISyntaxException URI syntax error * @throws IOException signals that an I/O exception has occurred * @throws XMLStreamException the XML stream exception */ public void traceHttpRequestHeaders(TraceFlags traceType, HttpWebRequest request) throws URISyntaxException, EWSHttpException, XMLStreamException, IOException { if (this.isTraceEnabledFor(traceType)) { String traceTypeStr = traceType.toString(); String headersAsString = EwsUtilities.formatHttpRequestHeaders(request); String logMessage = EwsUtilities.formatLogMessage(traceTypeStr, headersAsString); this.traceListener.trace(traceTypeStr, logMessage); } }
/** * Writes elements to XML. * * @param writer the writer * @throws Exception the exception */ @Override public void writeElementsToXml(EwsServiceXmlWriter writer) throws Exception { writer.writeElementValue(XmlNamespace.Types, XmlElementNames.Name, this .getName()); writer.writeElementValue(XmlNamespace.Types, XmlElementNames.ContentType, this.getContentType()); writer.writeElementValue(XmlNamespace.Types, XmlElementNames.ContentId, this.getContentId()); writer.writeElementValue(XmlNamespace.Types, XmlElementNames.ContentLocation, this.getContentLocation()); if (writer.getService().getRequestedServerVersion().ordinal() > ExchangeVersion.Exchange2007_SP1 .ordinal()) { writer.writeElementValue(XmlNamespace.Types, XmlElementNames.IsInline, this.getIsInline()); } }
/** * Writes the attribute to XML. * * @param writer accepts EwsServiceXmlWriter * @throws ServiceXmlSerializationException throws ServiceXmlSerializationException */ @Override public void writeAttributesToXml(EwsServiceXmlWriter writer) throws ServiceXmlSerializationException { super.writeAttributesToXml(writer); if (writer.getService().getRequestedServerVersion().ordinal() > ExchangeVersion.Exchange2007_SP1 .ordinal()) { writer.writeAttributeValue(XmlAttributeNames.Name, this .getEmailAddress().getName()); writer.writeAttributeValue(XmlAttributeNames.RoutingType, this .getEmailAddress().getRoutingType()); if (this.getEmailAddress().getMailboxType() != MailboxType.Unknown) { writer.writeAttributeValue(XmlAttributeNames.MailboxType, this .getEmailAddress().getMailboxType()); } } }