diff --git a/.gitignore b/.gitignore index e2a23af44..529532305 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ *.class # Package Files -*.jar *.war *.ear /target @@ -28,4 +27,5 @@ .idea/dataSources.xml .idea/sqlDataSources.xml .idea/dynamic.xml -.idea/uiDesigner.xml \ No newline at end of file +.idea/uiDesigner.xml +secret*.properties diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 000000000..6ecbb05fd --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,294 @@ + + + 4.0.0 + com.microsoft.ews-java-api + ews-java-api + Exchange Web Services Java API + android-1.0 + Exchange Web Services (EWS) Java API + http://www.microsoft.com/ + + 3.1.0 + + + GitHub Issues + https://github.com/OfficeDev/ews-java-api/issues + + + travis + https://travis-ci.org/OfficeDev/ews-java-api + + 2012 + + + vboctor + Victor Boctor + vboctor@users.noreply.github.com + http://www.github.com/officedev/ews-java-api + Microsoft + http://www.microsoft.com + + administrator + developer + + America/New_York + + http://www.example.com/jdoe/pic + + + + + + MIT License + http://opensource.org/licenses/MIT + repo + + + + scm:git:ssh://git@github.com:OfficeDev/ews-java-api.git + scm:git:ssh://git@github.com:OfficeDev/ews-java-api.git + https://github.com/OfficeDev/ews-java-api + + + Microsoft + http://www.microsoft.com/ + + + + + + maven-site-plugin + ${maven-site-plugin.version} + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + true + ossrh + https://oss.sonatype.org/ + + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${project.build.sourceEncoding} + ${javaLanguage.version} + ${javaLanguage.version} + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + ${animal-sniffer-maven-plugin.version} + + + check-java16-sun + test + + check + + + + + + org.codehaus.mojo.signature + java16-sun + ${animal-sniffer-maven-plugin.signature.version} + + + + + maven-install-plugin + 3.0.0-M1 + + + pre-clean + + install-file + + + libs/classes_repacked_v2.jar + com.sathesh.android.classes.repacked + classrepacked + ${classesrepacked.version} + jar + + + + + + maven-shade-plugin + + + package + + shade + + + + + + + + + default-jdk18-profile + + -Xdoclint:none + + + + java-7-or-later-profile + + + + maven-checkstyle-plugin + 2.16 + + + verify + + checkstyle + + + true + google_checks.xml + + + + + true + google_checks.xml + + + + + + + release-sign-artifacts + + + + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + + + + + junit + junit + 4.12 + test + + + hamcrest-core + org.hamcrest + + + + + org.hamcrest + hamcrest-all + 1.3 + test + + + org.mockito + mockito-core + 1.10.19 + test + + + objenesis + org.objenesis + + + hamcrest-core + org.hamcrest + + + + + org.slf4j + slf4j-api + 1.7.12 + test + + + ch.qos.logback + logback-classic + 1.1.3 + test + + + logback-core + ch.qos.logback + + + + + org.slf4j + jcl-over-slf4j + 1.7.12 + test + + + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2 + + + ossrh-snapshot + https://oss.sonatype.org/content/repositories/snapshots + + + + 2.16 + 2.4 + 2.8 + 1.6 + 4.4.1 + 1.14 + 2.10.3 + 1.7.12 + 1.2 + UTF-8 + 3.4 + 2.18.1 + 2.5 + 4.12 + 0.8.3 + 2.4 + 1.1.3 + 1.1 + 1.6.5 + 2.2 + 3.3 + 1.3 + 4.4.1 + 1.8 + 2.8 + 1.10.19 + 3.4 + 2.0 + + diff --git a/libs/classes_repacked_v2.jar b/libs/classes_repacked_v2.jar new file mode 100644 index 000000000..ebaa94e77 Binary files /dev/null and b/libs/classes_repacked_v2.jar differ diff --git a/pom.xml b/pom.xml index e303359bc..4314db7fd 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ com.microsoft.ews-java-api ews-java-api - 2.1-SNAPSHOT + android-1.0 Exchange Web Services Java API Exchange Web Services (EWS) Java API @@ -76,7 +76,7 @@ UTF-8 - 1.6 + 1.8 @@ -94,7 +94,7 @@ 2.2 2.5 2.18.1 - 0.7.5.201505241946 + 0.8.3 4.4.1 4.4.1 @@ -108,6 +108,7 @@ 1.10.19 1.7.12 1.1.3 + 2.0 @@ -214,9 +215,9 @@ - org.apache.httpcomponents + cz.msebera.android httpclient - ${httpclient.version} + 4.4.1.1 @@ -291,6 +292,13 @@ test + + + com.sathesh.android.classes.repacked + classrepacked + ${classesrepacked.version} + + @@ -318,36 +326,6 @@ ${javaLanguage.version} - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - true - ${javadoc.doclint.param} - - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - attach-sources - - jar-no-fork - - - - org.codehaus.mojo animal-sniffer-maven-plugin @@ -370,26 +348,43 @@ + + + + - org.jacoco - jacoco-maven-plugin - ${jacoco-maven-plugin.version} + org.apache.maven.plugins + maven-install-plugin + 3.0.0-M1 + pre-clean - prepare-agent + install-file + + libs/classes_repacked_v2.jar + com.sathesh.android.classes.repacked + classrepacked + ${classesrepacked.version} + jar + + + + + + org.apache.maven.plugins + maven-shade-plugin + - report - test + package - report + shade - - - org.apache.maven.plugins - maven-project-info-reports-plugin - ${maven-project-info-reports-plugin.version} - - - - - org.codehaus.mojo - versions-maven-plugin - ${versions-maven-plugin.version} - - - - dependency-updates-report - plugin-updates-report - property-updates-report - - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - true - ${javadoc.doclint.param} - - - - - - org.apache.maven.plugins - maven-jxr-plugin - ${maven-jxr-plugin.version} - - - - org.apache.maven.plugins - maven-surefire-report-plugin - ${maven-surefire-report-plugin.version} - - - diff --git a/readme-android.md b/readme-android.md new file mode 100644 index 000000000..c1892093a --- /dev/null +++ b/readme-android.md @@ -0,0 +1,13 @@ +This version is based on EWS - release 2.0 in github + +1. In the IntelliJ, set the module SDK to `Android API 28 Platform` instead of `1.8` or others +2. Correct the path for classes repacked jar + +### Building JAR +To build the jar you need to run the `mvn clean` atleast once. This will install the classes repacked library to your local repo. Then you can run `mvn clean install` anytime. +Then copy the jar to android app. + + +Sources: +1. https://hc.apache.org/httpcomponents-client-4.5.x/android-port.html +2. https://github.com/smarek/httpclient-android/wiki/Project-Introduction \ No newline at end of file diff --git a/src/main/java/microsoft/exchange/webservices/data/autodiscover/request/GetUserSettingsRequest.java b/src/main/java/microsoft/exchange/webservices/data/autodiscover/request/GetUserSettingsRequest.java index d78e27120..6be3e5db9 100644 --- a/src/main/java/microsoft/exchange/webservices/data/autodiscover/request/GetUserSettingsRequest.java +++ b/src/main/java/microsoft/exchange/webservices/data/autodiscover/request/GetUserSettingsRequest.java @@ -23,6 +23,7 @@ package microsoft.exchange.webservices.data.autodiscover.request; +import cz.msebera.android.httpclient.extras.Base64; import microsoft.exchange.webservices.data.autodiscover.AutodiscoverService; import microsoft.exchange.webservices.data.autodiscover.enumeration.AutodiscoverErrorCode; import microsoft.exchange.webservices.data.autodiscover.response.AutodiscoverResponse; @@ -217,8 +218,8 @@ protected void writeAttributesToXml(EwsServiceXmlWriter writer) writer .writeElementValue(XmlNamespace.Autodiscover, XmlElementNames.BinarySecret, - new String(org.apache.commons.codec.binary.Base64. - encodeBase64(ExchangeServiceBase.getSessionKey()))); + new String(Base64. + encode(ExchangeServiceBase.getSessionKey(), 0))); } } diff --git a/src/main/java/microsoft/exchange/webservices/data/core/CookieProcessingTargetAuthenticationStrategy.java b/src/main/java/microsoft/exchange/webservices/data/core/CookieProcessingTargetAuthenticationStrategy.java index 6a1e1b81b..6fa03f5eb 100644 --- a/src/main/java/microsoft/exchange/webservices/data/core/CookieProcessingTargetAuthenticationStrategy.java +++ b/src/main/java/microsoft/exchange/webservices/data/core/CookieProcessingTargetAuthenticationStrategy.java @@ -23,17 +23,17 @@ package microsoft.exchange.webservices.data.core; -import org.apache.http.Header; -import org.apache.http.HttpException; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.apache.http.auth.MalformedChallengeException; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.client.protocol.RequestAddCookies; -import org.apache.http.client.protocol.ResponseProcessCookies; -import org.apache.http.impl.client.TargetAuthenticationStrategy; -import org.apache.http.protocol.HttpContext; +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.HttpException; +import cz.msebera.android.httpclient.HttpHost; +import cz.msebera.android.httpclient.HttpRequest; +import cz.msebera.android.httpclient.HttpResponse; +import cz.msebera.android.httpclient.auth.MalformedChallengeException; +import cz.msebera.android.httpclient.client.protocol.HttpClientContext; +import cz.msebera.android.httpclient.client.protocol.RequestAddCookies; +import cz.msebera.android.httpclient.client.protocol.ResponseProcessCookies; +import cz.msebera.android.httpclient.impl.client.TargetAuthenticationStrategy; +import cz.msebera.android.httpclient.protocol.HttpContext; import java.io.IOException; import java.util.Map; diff --git a/src/main/java/microsoft/exchange/webservices/data/core/EwsSSLProtocolSocketFactory.java b/src/main/java/microsoft/exchange/webservices/data/core/EwsSSLProtocolSocketFactory.java index d4d2fefec..852e95b18 100644 --- a/src/main/java/microsoft/exchange/webservices/data/core/EwsSSLProtocolSocketFactory.java +++ b/src/main/java/microsoft/exchange/webservices/data/core/EwsSSLProtocolSocketFactory.java @@ -23,9 +23,9 @@ package microsoft.exchange.webservices.data.core; -import org.apache.http.conn.ssl.DefaultHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.ssl.SSLContexts; +import cz.msebera.android.httpclient.conn.ssl.DefaultHostnameVerifier; +import cz.msebera.android.httpclient.conn.ssl.SSLConnectionSocketFactory; +import cz.msebera.android.httpclient.ssl.SSLContexts; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; diff --git a/src/main/java/microsoft/exchange/webservices/data/core/EwsServiceXmlWriter.java b/src/main/java/microsoft/exchange/webservices/data/core/EwsServiceXmlWriter.java index 4aeab0ba0..112c7ca77 100644 --- a/src/main/java/microsoft/exchange/webservices/data/core/EwsServiceXmlWriter.java +++ b/src/main/java/microsoft/exchange/webservices/data/core/EwsServiceXmlWriter.java @@ -23,11 +23,11 @@ package microsoft.exchange.webservices.data.core; +import cz.msebera.android.httpclient.extras.Base64; import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace; import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException; import microsoft.exchange.webservices.data.misc.OutParam; import microsoft.exchange.webservices.data.property.complex.ISearchStringProvider; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.CDATASection; @@ -497,8 +497,8 @@ public void writeElementValue(XmlNamespace xmlNamespace, String localName, public void writeBase64ElementValue(byte[] buffer) throws XMLStreamException { - String strValue = Base64.encodeBase64String(buffer); - this.xmlWriter.writeCharacters(strValue);//Base64.encode(buffer)); + byte[] strValue = Base64.encode(buffer, 0); + this.xmlWriter.writeCharacters(new String(strValue));//Base64.encode(buffer)); } /** @@ -523,8 +523,8 @@ public void writeBase64ElementValue(InputStream stream) throws IOException, bos.close(); } byte[] bytes = bos.toByteArray(); - String strValue = Base64.encodeBase64String(bytes); - this.xmlWriter.writeCharacters(strValue); + byte[] strValue = Base64.encode(bytes, 0); + this.xmlWriter.writeCharacters(new String(strValue)); } diff --git a/src/main/java/microsoft/exchange/webservices/data/core/EwsXmlReader.java b/src/main/java/microsoft/exchange/webservices/data/core/EwsXmlReader.java index ba1b1cc9d..32d5041e6 100644 --- a/src/main/java/microsoft/exchange/webservices/data/core/EwsXmlReader.java +++ b/src/main/java/microsoft/exchange/webservices/data/core/EwsXmlReader.java @@ -23,11 +23,11 @@ package microsoft.exchange.webservices.data.core; +import cz.msebera.android.httpclient.extras.Base64; import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace; import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlDeserializationException; import microsoft.exchange.webservices.data.misc.OutParam; import microsoft.exchange.webservices.data.security.XmlNodeType; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -566,7 +566,7 @@ public byte[] readBase64ElementValue() ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); - buffer = Base64.decodeBase64(this.xmlReader.getElementText().toString()); + buffer = Base64.decode(this.xmlReader.getElementText(),0); byteArrayStream.write(buffer); return byteArrayStream.toByteArray(); @@ -584,7 +584,7 @@ public void readBase64ElementValue(OutputStream outputStream) this.ensureCurrentNodeIsStartElement(); byte[] buffer = null; - buffer = Base64.decodeBase64(this.xmlReader.getElementText().toString()); + buffer = Base64.decode(this.xmlReader.getElementText(), 0); outputStream.write(buffer); outputStream.flush(); } diff --git a/src/main/java/microsoft/exchange/webservices/data/core/ExchangeServiceBase.java b/src/main/java/microsoft/exchange/webservices/data/core/ExchangeServiceBase.java index 9e383c582..367fc5a4c 100644 --- a/src/main/java/microsoft/exchange/webservices/data/core/ExchangeServiceBase.java +++ b/src/main/java/microsoft/exchange/webservices/data/core/ExchangeServiceBase.java @@ -59,19 +59,19 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.http.client.AuthenticationStrategy; -import org.apache.http.client.CookieStore; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.config.Registry; -import org.apache.http.config.RegistryBuilder; -import org.apache.http.conn.HttpClientConnectionManager; -import org.apache.http.conn.socket.ConnectionSocketFactory; -import org.apache.http.conn.socket.PlainConnectionSocketFactory; -import org.apache.http.impl.client.BasicCookieStore; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.conn.BasicHttpClientConnectionManager; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import cz.msebera.android.httpclient.client.AuthenticationStrategy; +import cz.msebera.android.httpclient.client.CookieStore; +import cz.msebera.android.httpclient.client.protocol.HttpClientContext; +import cz.msebera.android.httpclient.config.Registry; +import cz.msebera.android.httpclient.config.RegistryBuilder; +import cz.msebera.android.httpclient.conn.HttpClientConnectionManager; +import cz.msebera.android.httpclient.conn.socket.ConnectionSocketFactory; +import cz.msebera.android.httpclient.conn.socket.PlainConnectionSocketFactory; +import cz.msebera.android.httpclient.impl.client.BasicCookieStore; +import cz.msebera.android.httpclient.impl.client.CloseableHttpClient; +import cz.msebera.android.httpclient.impl.client.HttpClients; +import cz.msebera.android.httpclient.impl.conn.BasicHttpClientConnectionManager; +import cz.msebera.android.httpclient.impl.conn.PoolingHttpClientConnectionManager; /** * Represents an abstract binding to an Exchange Service. diff --git a/src/main/java/microsoft/exchange/webservices/data/core/request/ByteArrayOSRequestEntity.java b/src/main/java/microsoft/exchange/webservices/data/core/request/ByteArrayOSRequestEntity.java index cd94d2824..a56fc1629 100644 --- a/src/main/java/microsoft/exchange/webservices/data/core/request/ByteArrayOSRequestEntity.java +++ b/src/main/java/microsoft/exchange/webservices/data/core/request/ByteArrayOSRequestEntity.java @@ -23,9 +23,9 @@ package microsoft.exchange.webservices.data.core.request; -import org.apache.http.Header; -import org.apache.http.entity.BasicHttpEntity; -import org.apache.http.message.BasicHeader; +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.entity.BasicHttpEntity; +import cz.msebera.android.httpclient.message.BasicHeader; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/src/main/java/microsoft/exchange/webservices/data/core/request/HttpClientWebRequest.java b/src/main/java/microsoft/exchange/webservices/data/core/request/HttpClientWebRequest.java index 8cd6ccb8f..00cd60166 100644 --- a/src/main/java/microsoft/exchange/webservices/data/core/request/HttpClientWebRequest.java +++ b/src/main/java/microsoft/exchange/webservices/data/core/request/HttpClientWebRequest.java @@ -25,19 +25,19 @@ import microsoft.exchange.webservices.data.core.WebProxy; import microsoft.exchange.webservices.data.core.exception.http.EWSHttpException; -import org.apache.http.Header; -import org.apache.http.HttpHost; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.NTCredentials; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.config.AuthSchemes; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.util.EntityUtils; +import cz.msebera.android.httpclient.Header; +import cz.msebera.android.httpclient.HttpHost; +import cz.msebera.android.httpclient.auth.AuthScope; +import cz.msebera.android.httpclient.auth.NTCredentials; +import cz.msebera.android.httpclient.client.CredentialsProvider; +import cz.msebera.android.httpclient.client.config.AuthSchemes; +import cz.msebera.android.httpclient.client.config.RequestConfig; +import cz.msebera.android.httpclient.client.methods.CloseableHttpResponse; +import cz.msebera.android.httpclient.client.methods.HttpPost; +import cz.msebera.android.httpclient.client.protocol.HttpClientContext; +import cz.msebera.android.httpclient.impl.client.BasicCredentialsProvider; +import cz.msebera.android.httpclient.impl.client.CloseableHttpClient; +import cz.msebera.android.httpclient.util.EntityUtils; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; diff --git a/src/main/java/microsoft/exchange/webservices/data/core/response/ExecuteDiagnosticMethodResponse.java b/src/main/java/microsoft/exchange/webservices/data/core/response/ExecuteDiagnosticMethodResponse.java index f67322ab0..a1caa42e2 100644 --- a/src/main/java/microsoft/exchange/webservices/data/core/response/ExecuteDiagnosticMethodResponse.java +++ b/src/main/java/microsoft/exchange/webservices/data/core/response/ExecuteDiagnosticMethodResponse.java @@ -125,9 +125,9 @@ public Document retriveDocument(XMLEventReader xmlEventReader) } String xmlns = EwsUtilities.WSTrustFebruary2005Namespace;//"http://schemas.xmlsoap.org/wsdl/"; - ite = ele.getNamespaces(); - while (ite.hasNext()) { - Namespace ns = (Namespace) ite.next(); + Iterator ite2 = ele.getNamespaces(); + while (ite2.hasNext()) { + Namespace ns = ite2.next(); String name = ns.getPrefix(); if (!name.isEmpty()) { element.setAttributeNS(xmlns, name, diff --git a/src/main/java/microsoft/exchange/webservices/data/misc/IFunctions.java b/src/main/java/microsoft/exchange/webservices/data/misc/IFunctions.java index 99c07e0e5..91672295c 100644 --- a/src/main/java/microsoft/exchange/webservices/data/misc/IFunctions.java +++ b/src/main/java/microsoft/exchange/webservices/data/misc/IFunctions.java @@ -23,8 +23,8 @@ package microsoft.exchange.webservices.data.misc; +import cz.msebera.android.httpclient.extras.Base64; import microsoft.exchange.webservices.data.core.EwsUtilities; -import org.apache.commons.codec.binary.Base64; import java.util.Date; import java.util.UUID; @@ -75,7 +75,7 @@ public static class Base64Decoder implements IFunction { public static final Base64Decoder INSTANCE = new Base64Decoder(); public Object func(final String s) { - return Base64.decodeBase64(s); + return Base64.decode(s, 0); } } @@ -83,7 +83,7 @@ public static class Base64Encoder implements IFunction { public static final Base64Encoder INSTANCE = new Base64Encoder(); public String func(final Object o) { - return Base64.encodeBase64String((byte[]) o); + return new String(Base64.encode((byte[]) o, 0)); } } diff --git a/src/main/java/microsoft/exchange/webservices/data/misc/UserConfiguration.java b/src/main/java/microsoft/exchange/webservices/data/misc/UserConfiguration.java index 24cc11512..44e1c3238 100644 --- a/src/main/java/microsoft/exchange/webservices/data/misc/UserConfiguration.java +++ b/src/main/java/microsoft/exchange/webservices/data/misc/UserConfiguration.java @@ -23,6 +23,7 @@ package microsoft.exchange.webservices.data.misc; +import cz.msebera.android.httpclient.extras.Base64; import microsoft.exchange.webservices.data.core.EwsServiceXmlReader; import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter; import microsoft.exchange.webservices.data.core.EwsUtilities; @@ -41,7 +42,6 @@ import microsoft.exchange.webservices.data.property.complex.ItemId; import microsoft.exchange.webservices.data.property.complex.UserConfigurationDictionary; import microsoft.exchange.webservices.data.security.XmlNodeType; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -159,7 +159,7 @@ private static void writeByteArrayToXml(EwsServiceXmlWriter writer, writer.writeStartElement(XmlNamespace.Types, xmlElementName); if (byteArray != null && byteArray.length > 0) { - writer.writeValue(Base64.encodeBase64String(byteArray), xmlElementName); + writer.writeValue(new String(Base64.encode(byteArray,0)), xmlElementName); } writer.writeEndElement(); @@ -605,10 +605,10 @@ public void loadFromXml(EwsServiceXmlReader reader) throws Exception { XmlElementNames.Dictionary); } else if (reader.getLocalName() .equals(XmlElementNames.XmlData)) { - this.xmlData = Base64.decodeBase64(reader.readElementValue()); + this.xmlData = Base64.decode(reader.readElementValue(), 0); } else if (reader.getLocalName().equals( XmlElementNames.BinaryData)) { - this.binaryData = Base64.decodeBase64(reader.readElementValue()); + this.binaryData = Base64.decode(reader.readElementValue(), 0); } else { EwsUtilities.ewsAssert(false, "UserConfiguration.loadFromXml", "Xml element not supported: " + reader.getLocalName()); diff --git a/src/main/java/microsoft/exchange/webservices/data/notification/SubscriptionBase.java b/src/main/java/microsoft/exchange/webservices/data/notification/SubscriptionBase.java index 2f9a41381..4de6e0421 100644 --- a/src/main/java/microsoft/exchange/webservices/data/notification/SubscriptionBase.java +++ b/src/main/java/microsoft/exchange/webservices/data/notification/SubscriptionBase.java @@ -133,7 +133,7 @@ public String getId() { * * @param id the new id */ - protected void setId(String id) { + public void setId(String id) { this.id = id; } @@ -142,7 +142,7 @@ protected void setId(String id) { * * @param watermark the new water mark */ - protected void setWaterMark(String watermark) { + public void setWaterMark(String watermark) { this.watermark = watermark; } diff --git a/src/main/java/microsoft/exchange/webservices/data/property/complex/Attachment.java b/src/main/java/microsoft/exchange/webservices/data/property/complex/Attachment.java index 493b60b2b..16e3d769b 100644 --- a/src/main/java/microsoft/exchange/webservices/data/property/complex/Attachment.java +++ b/src/main/java/microsoft/exchange/webservices/data/property/complex/Attachment.java @@ -430,4 +430,7 @@ public void load() throws Exception { this.internalLoad(null, null); } + public void setId(String id) { + this.id = id; + } } diff --git a/src/main/java/microsoft/exchange/webservices/data/property/complex/FileAttachment.java b/src/main/java/microsoft/exchange/webservices/data/property/complex/FileAttachment.java index de3567f36..eee1afcf6 100644 --- a/src/main/java/microsoft/exchange/webservices/data/property/complex/FileAttachment.java +++ b/src/main/java/microsoft/exchange/webservices/data/property/complex/FileAttachment.java @@ -76,7 +76,7 @@ public final class FileAttachment extends Attachment { * * @param owner the owner */ - protected FileAttachment(Item owner) { + public FileAttachment(Item owner) { super(owner); } diff --git a/src/main/java/microsoft/exchange/webservices/data/property/complex/MimeContent.java b/src/main/java/microsoft/exchange/webservices/data/property/complex/MimeContent.java index 6170a1415..c128b1895 100644 --- a/src/main/java/microsoft/exchange/webservices/data/property/complex/MimeContent.java +++ b/src/main/java/microsoft/exchange/webservices/data/property/complex/MimeContent.java @@ -23,12 +23,12 @@ package microsoft.exchange.webservices.data.property.complex; +import cz.msebera.android.httpclient.extras.Base64; import microsoft.exchange.webservices.data.core.EwsServiceXmlReader; import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter; import microsoft.exchange.webservices.data.core.XmlAttributeNames; import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlDeserializationException; import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException; -import org.apache.commons.codec.binary.Base64; import javax.xml.stream.XMLStreamException; @@ -88,7 +88,7 @@ public void readAttributesFromXml(EwsServiceXmlReader reader) @Override public void readTextValueFromXml(EwsServiceXmlReader reader) throws XMLStreamException, ServiceXmlDeserializationException { - this.content = Base64.decodeBase64(reader.readValue()); + this.content = Base64.decode(reader.readValue(), 0); } /** @@ -176,7 +176,7 @@ public String toString() { "UTF-8" : this.getCharacterSet(); return new String(this.getContent(), charSet); } catch (Exception e) { - return Base64.encodeBase64String(this.getContent()); + return new String(Base64.encode(this.getContent(), 0)); } } } diff --git a/src/main/java/microsoft/exchange/webservices/data/property/complex/UserConfigurationDictionary.java b/src/main/java/microsoft/exchange/webservices/data/property/complex/UserConfigurationDictionary.java index 6eaee6997..ecbf0f9a2 100644 --- a/src/main/java/microsoft/exchange/webservices/data/property/complex/UserConfigurationDictionary.java +++ b/src/main/java/microsoft/exchange/webservices/data/property/complex/UserConfigurationDictionary.java @@ -23,6 +23,7 @@ package microsoft.exchange.webservices.data.property.complex; +import cz.msebera.android.httpclient.extras.Base64; import microsoft.exchange.webservices.data.attribute.EditorBrowsable; import microsoft.exchange.webservices.data.core.EwsServiceXmlReader; import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter; @@ -36,7 +37,6 @@ import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException; import microsoft.exchange.webservices.data.misc.OutParam; import microsoft.exchange.webservices.data.util.DateTimeUtils; -import org.apache.commons.codec.binary.Base64; import javax.xml.stream.XMLStreamException; @@ -347,7 +347,7 @@ private void writeObjectValueToXml(final EwsServiceXmlWriter writer, valueAsString = String.valueOf(dictionaryObject); } else if (dictionaryObject instanceof byte[]) { dictionaryObjectType = UserConfigurationDictionaryObjectType.ByteArray; - valueAsString = Base64.encodeBase64String((byte[]) dictionaryObject); + valueAsString = new String(Base64.encode((byte[]) dictionaryObject, 0)); } else if (dictionaryObject instanceof Byte[]) { dictionaryObjectType = UserConfigurationDictionaryObjectType.ByteArray; @@ -358,7 +358,7 @@ private void writeObjectValueToXml(final EwsServiceXmlWriter writer, to[currentIndex] = (byte) from[currentIndex]; } - valueAsString = Base64.encodeBase64String(to); + valueAsString = new String(Base64.encode(to, 0)); } else { throw new IllegalArgumentException(String.format( "Unsupported type: %s", dictionaryObject.getClass() @@ -590,7 +590,7 @@ private Object constructObject(UserConfigurationDictionaryObjectType type, } else if (type.equals(UserConfigurationDictionaryObjectType.Byte)) { dictionaryObject = Byte.parseByte(value.get(0)); } else if (type.equals(UserConfigurationDictionaryObjectType.ByteArray)) { - dictionaryObject = Base64.decodeBase64(value.get(0)); + dictionaryObject = Base64.decode(value.get(0), 0); } else if (type.equals(UserConfigurationDictionaryObjectType.DateTime)) { Date dateTime = DateTimeUtils.convertDateTimeStringToDate(value.get(0)); if (dateTime != null) { diff --git a/src/main/java/microsoft/exchange/webservices/data/property/definition/ByteArrayPropertyDefinition.java b/src/main/java/microsoft/exchange/webservices/data/property/definition/ByteArrayPropertyDefinition.java index 365a54c8d..cedbb2c1b 100644 --- a/src/main/java/microsoft/exchange/webservices/data/property/definition/ByteArrayPropertyDefinition.java +++ b/src/main/java/microsoft/exchange/webservices/data/property/definition/ByteArrayPropertyDefinition.java @@ -23,9 +23,9 @@ package microsoft.exchange.webservices.data.property.definition; +import cz.msebera.android.httpclient.extras.Base64; import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion; import microsoft.exchange.webservices.data.core.enumeration.property.PropertyDefinitionFlags; -import org.apache.commons.codec.binary.Base64; import java.util.EnumSet; @@ -55,7 +55,7 @@ public ByteArrayPropertyDefinition(String xmlElementName, String uri, */ @Override protected byte[] parse(String value) { - return Base64.decodeBase64(value); + return Base64.decode(value, 0); } /** @@ -66,7 +66,7 @@ protected byte[] parse(String value) { */ @Override protected String toString(byte[] value) { - return Base64.encodeBase64String(value); + return new String(Base64.encode(value, 0)); } /** diff --git a/src/main/java/microsoft/exchange/webservices/data/util/TimeZoneUtils.java b/src/main/java/microsoft/exchange/webservices/data/util/TimeZoneUtils.java index f0ab97d49..f5f8df7c1 100644 --- a/src/main/java/microsoft/exchange/webservices/data/util/TimeZoneUtils.java +++ b/src/main/java/microsoft/exchange/webservices/data/util/TimeZoneUtils.java @@ -241,6 +241,7 @@ public static Map createOlsonTimeZoneToMsMap() { map.put("America/Porto_Acre", "SA Pacific Standard Time"); map.put("America/Porto_Velho", "SA Western Standard Time"); map.put("America/Puerto_Rico", "SA Western Standard Time"); + map.put("America/Punta_Arenas", "SA Western Standard Time"); map.put("America/Rainy_River", "Central Standard Time"); map.put("America/Rankin_Inlet", "Central Standard Time"); map.put("America/Recife", "SA Eastern Standard Time"); @@ -465,6 +466,7 @@ public static Map createOlsonTimeZoneToMsMap() { map.put("Etc/Zulu", "UTC"); map.put("Europe/Amsterdam", "W. Europe Standard Time"); map.put("Europe/Andorra", "W. Europe Standard Time"); + map.put("Europe/Astrakhan", "W. Europe Standard Time"); map.put("Europe/Athens", "GTB Standard Time"); map.put("Europe/Belfast", "GMT Standard Time"); map.put("Europe/Belgrade", "Central Europe Standard Time"); @@ -485,6 +487,7 @@ public static Map createOlsonTimeZoneToMsMap() { map.put("Europe/Jersey", "GMT Standard Time"); map.put("Europe/Kaliningrad", "Kaliningrad Standard Time"); map.put("Europe/Kiev", "FLE Standard Time"); + map.put("Europe/Kirov", "FLE Standard Time"); map.put("Europe/Lisbon", "GMT Standard Time"); map.put("Europe/Ljubljana", "Central Europe Standard Time"); map.put("Europe/London", "GMT Standard Time"); @@ -505,6 +508,7 @@ public static Map createOlsonTimeZoneToMsMap() { map.put("Europe/Samara", "Russia Time Zone 3"); map.put("Europe/San_Marino", "W. Europe Standard Time"); map.put("Europe/Sarajevo", "Central European Standard Time"); + map.put("Europe/Saratov", "Central European Standard Time"); map.put("Europe/Simferopol", "Russian Standard Time"); map.put("Europe/Skopje", "Central European Standard Time"); map.put("Europe/Sofia", "FLE Standard Time"); @@ -513,6 +517,7 @@ public static Map createOlsonTimeZoneToMsMap() { map.put("Europe/Tirane", "Central Europe Standard Time"); map.put("Europe/Tiraspol", "GTB Standard Time"); map.put("Europe/Uzhgorod", "FLE Standard Time"); + map.put("Europe/Ulyanovsk", "FLE Standard Time"); map.put("Europe/Vaduz", "W. Europe Standard Time"); map.put("Europe/Vatican", "W. Europe Standard Time"); map.put("Europe/Vienna", "W. Europe Standard Time"); diff --git a/src/test/java/com/sathesh/integration/test/AttachmentsTest.java b/src/test/java/com/sathesh/integration/test/AttachmentsTest.java new file mode 100644 index 000000000..b2246891d --- /dev/null +++ b/src/test/java/com/sathesh/integration/test/AttachmentsTest.java @@ -0,0 +1,83 @@ +package com.sathesh.integration.test; + +import microsoft.exchange.webservices.data.core.ExchangeService; +import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName; +import microsoft.exchange.webservices.data.core.service.item.EmailMessage; +import microsoft.exchange.webservices.data.core.service.item.Item; +import microsoft.exchange.webservices.data.credential.ExchangeCredentials; +import microsoft.exchange.webservices.data.credential.WebCredentials; +import microsoft.exchange.webservices.data.property.complex.Attachment; +import microsoft.exchange.webservices.data.property.complex.FileAttachment; +import microsoft.exchange.webservices.data.search.FindItemsResults; +import microsoft.exchange.webservices.data.search.ItemView; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Properties; + +/** + * @author Sathesh Sivashanmugam + * date 2019-02-22 + */ +public class AttachmentsTest { + public static void main(String[] args) throws Exception { + ExchangeService service; + Properties properties = getProperties("./secret.properties"); + service = initConnection(properties.getProperty("username"), properties.getProperty("pwd"), properties.getProperty("url")); + service.setTraceEnabled(true); + getMailAttachments(service); + } + + private static Properties getProperties(String file) throws IOException { + Properties properties = new Properties(); + properties.load(new FileInputStream(file) ); + return properties; + } + + private static ExchangeService initConnection(String username, String pwd, String url) throws URISyntaxException { + ExchangeService service = new ExchangeService(); + ExchangeCredentials credentials = new WebCredentials(username, pwd); + service.setCredentials(credentials); + service.setUrl(new URI(url)); + return service; + } + + private static void getMailAttachments(ExchangeService service) throws Exception { + + int counter=0; + ItemView view = new ItemView(1); + FindItemsResults findResults = null; + findResults = service.findItems(WellKnownFolderName.Inbox, view); + + System.out.println("CONNECTION SUCCESSFUL"); + //convert the list of Item to List of VO + for(Item item : findResults){ + System.out.println("MAIL::" + ++counter); + System.out.println(item.getDateTimeReceived()); + System.out.println(item.getSubject()); + + EmailMessage message = EmailMessage.bind(service, item.getId()); + + for(Attachment attachment : message.getAttachments()){ + if (!attachment.getIsInline()){ + System.out.println("Attachment ContentId: " + attachment.getContentId()); + System.out.println("Attachment Name: " + attachment.getName()); + System.out.println("Attachment Size: " + attachment.getSize()); + System.out.println("Attachment Content Type: " + attachment.getContentType()); + System.out.println("Attachment Item Id: " + item.getId()); + System.out.println("Attachment Message Id: " + message.getId()); + System.out.println("\n\n\n"); + + // FileAttachment fileAttachment = (FileAttachment) attachment; + + //Recreating the object to test whether the attachment object can be stored and retrieved + FileAttachment fileAttachment = new FileAttachment(new Item(service)); + fileAttachment.setId(attachment.getId()); + fileAttachment.load("/Users/ssiva17/Desktop/test/"+attachment.getName()); + } + } + } + } +} diff --git a/src/test/java/com/sathesh/integration/test/AutoDiscoverTest.java b/src/test/java/com/sathesh/integration/test/AutoDiscoverTest.java new file mode 100644 index 000000000..5f6e88e04 --- /dev/null +++ b/src/test/java/com/sathesh/integration/test/AutoDiscoverTest.java @@ -0,0 +1,67 @@ +package com.sathesh.integration.test; + +import microsoft.exchange.webservices.data.autodiscover.IAutodiscoverRedirectionUrl; +import microsoft.exchange.webservices.data.core.ExchangeService; +import microsoft.exchange.webservices.data.core.enumeration.misc.TraceFlags; +import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName; +import microsoft.exchange.webservices.data.core.service.item.Item; +import microsoft.exchange.webservices.data.search.FindItemsResults; +import microsoft.exchange.webservices.data.search.ItemView; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.EnumSet; +import java.util.Properties; + +/** + * @author Sathesh Sivashanmugam + * date 2019-02-22 + */ +public class AutoDiscoverTest { + public static void main(String[] args) throws Exception { + ExchangeService service; + Properties properties = getProperties("./secret.properties"); + service = initConnection(properties.getProperty("username"), properties.getProperty("pwd"), properties.getProperty("email")); + getFirstMail(service); + } + + private static Properties getProperties(String file) throws IOException { + Properties properties = new Properties(); + properties.load(new FileInputStream(file) ); + return properties; + } + + private static ExchangeService initConnection(String username, String pwd, String email) throws Exception { + ExchangeService service = new ExchangeService(); + service.setTraceEnabled(true); + EnumSet traceFlags = EnumSet.of(TraceFlags.AutodiscoverRequest, TraceFlags.EwsRequest, TraceFlags.EwsResponse, TraceFlags.AutodiscoverResponse); + service.setTraceFlags(traceFlags); +// ExchangeCredentials credentials = new WebCredentials(username, pwd); +// service.setCredentials(credentials); + service.autodiscoverUrl(email, new RedirectionUrlCallback()); + return service; + } + + static class RedirectionUrlCallback implements IAutodiscoverRedirectionUrl { + public boolean autodiscoverRedirectionUrlValidationCallback( + String redirectionUrl) { + return true; + } + } + + private static void getFirstMail(ExchangeService service) throws Exception { + + int counter=0; + ItemView view = new ItemView(1); + FindItemsResults findResults = null; + findResults = service.findItems(WellKnownFolderName.Inbox, view); + + System.out.println("CONNECTION SUCCESSFUL"); + //convert the list of Item to List of VO + for(Item item : findResults){ + System.out.println("MAIL::" + ++counter); + System.out.println(item.getDateTimeReceived()); + System.out.println(item.getSubject()); + } + } +} diff --git a/src/test/java/com/sathesh/integration/test/ContactReadTest.java b/src/test/java/com/sathesh/integration/test/ContactReadTest.java new file mode 100644 index 000000000..7262d82bf --- /dev/null +++ b/src/test/java/com/sathesh/integration/test/ContactReadTest.java @@ -0,0 +1,61 @@ +package com.sathesh.integration.test; + +import microsoft.exchange.webservices.data.core.ExchangeService; +import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName; +import microsoft.exchange.webservices.data.core.enumeration.search.ResolveNameSearchLocation; +import microsoft.exchange.webservices.data.core.service.item.Contact; +import microsoft.exchange.webservices.data.core.service.item.Item; +import microsoft.exchange.webservices.data.credential.ExchangeCredentials; +import microsoft.exchange.webservices.data.credential.WebCredentials; +import microsoft.exchange.webservices.data.misc.NameResolution; +import microsoft.exchange.webservices.data.misc.NameResolutionCollection; +import microsoft.exchange.webservices.data.search.FindItemsResults; +import microsoft.exchange.webservices.data.search.ItemView; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Properties; + +/** + * @author Sathesh Sivashanmugam + * date 2019-02-22 + */ +public class ContactReadTest { + public static void main(String[] args) throws Exception { + ExchangeService service; + Properties properties = getProperties("./secret3.properties"); + service = initConnection(properties.getProperty("username"), properties.getProperty("pwd"), properties.getProperty("url")); + getFirstMail(service); + } + + private static Properties getProperties(String file) throws IOException { + Properties properties = new Properties(); + properties.load(new FileInputStream(file) ); + return properties; + } + + private static ExchangeService initConnection(String username, String pwd, String url) throws URISyntaxException { + ExchangeService service = new ExchangeService(); + ExchangeCredentials credentials = new WebCredentials(username, pwd); + service.setCredentials(credentials); + service.setUrl(new URI(url)); + return service; + } + + private static void getFirstMail(ExchangeService service) throws Exception { + + // Resolve a partial name against the Active Directory and the Contacts folder (in that order). + NameResolutionCollection nameResolutions = service.resolveName("sathesh", ResolveNameSearchLocation.DirectoryOnly, true); + System.out.println("nameResolutions==="+nameResolutions.getCount()); + + for (NameResolution nameResolution : nameResolutions) { + System.out.println("NAME==="+nameResolution.getMailbox().getName()); + Contact contact = nameResolution.getContact(); + System.out.println(" Contact===" + contact.getAlias()); + + System.out.println("----------"); + } + } +} diff --git a/src/test/java/com/sathesh/integration/test/PullSubscriptionTest.java b/src/test/java/com/sathesh/integration/test/PullSubscriptionTest.java new file mode 100644 index 000000000..a43861f12 --- /dev/null +++ b/src/test/java/com/sathesh/integration/test/PullSubscriptionTest.java @@ -0,0 +1,103 @@ +package com.sathesh.integration.test; + +import microsoft.exchange.webservices.data.core.ExchangeService; +import microsoft.exchange.webservices.data.core.enumeration.notification.EventType; +import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName; +import microsoft.exchange.webservices.data.core.service.item.EmailMessage; +import microsoft.exchange.webservices.data.core.service.item.Item; +import microsoft.exchange.webservices.data.credential.ExchangeCredentials; +import microsoft.exchange.webservices.data.credential.WebCredentials; +import microsoft.exchange.webservices.data.notification.GetEventsResults; +import microsoft.exchange.webservices.data.notification.ItemEvent; +import microsoft.exchange.webservices.data.notification.PullSubscription; +import microsoft.exchange.webservices.data.property.complex.FolderId; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +/** + * @author Sathesh Sivashanmugam + * date 2019-02-22 + */ +public class PullSubscriptionTest { + public static void main(String[] args) throws Exception { + ExchangeService service; + Properties properties = getProperties("./secret.properties"); + service = initConnection(properties.getProperty("username"), properties.getProperty("pwd"), properties.getProperty("url")); + subscriptionTesting(service); + } + + private static Properties getProperties(String file) throws IOException { + Properties properties = new Properties(); + properties.load(new FileInputStream(file)); + return properties; + } + + private static ExchangeService initConnection(String username, String pwd, String url) throws URISyntaxException { + ExchangeService service = new ExchangeService(); + ExchangeCredentials credentials = new WebCredentials(username, pwd); + service.setCredentials(credentials); + service.setUrl(new URI(url)); + service.setTraceEnabled(false); + return service; + } + + private static void subscriptionTesting(ExchangeService service) throws Exception { + + // Subscribe to pull notifications in the Inbox folder, and get notified when a new mail is received, when an item or folder is created, or when an item or folder is deleted. + List folder = new ArrayList(); + folder.add(new FolderId().getFolderIdFromWellKnownFolderName(WellKnownFolderName.Inbox)); + + PullSubscription subscription = service.subscribeToPullNotifications(folder, 1 + + /* timeOut: the subscription will end if the server is not polled within 5 minutes. */, "AQAAAE0/7+Wfk0NCmqLvwJ4Ma7Mmv0+PAAAAAAA=" /* watermark: null to start a new subscription. */, EventType.NewMail, EventType.Created, EventType.Deleted); + + + pullEvents(service, subscription, folder); + + } + + private static void pullEvents(ExchangeService service, PullSubscription subscription, List folder ) { + // Wait a couple minutes, then poll the server for new events. + GetEventsResults events1; + PullSubscription ps = null; + try { + System.out.println("ID 1 " + subscription.getId()); + events1 = subscription.getEvents(); + System.out.println("ID 2 " + subscription.getId()); + + System.out.println("THIS WATERMARK: " + subscription.getWaterMark()); + //Creating a new subscription object just to check whether this object can be created from scratch. + // Ideally we can call the same subscription obj forever. + // The same subscription will get updated with the new id and watermark after each call to the subscription.getEvents() + ps = new PullSubscription(service); + + ps.setId(subscription.getId()); + ps.setWaterMark(subscription.getWaterMark()); + + // Loop through all item-related events. + for (ItemEvent itemEvent : events1.getItemEvents()) { + if (itemEvent.getEventType() == EventType.NewMail) { + EmailMessage message = EmailMessage.bind(service, itemEvent.getItemId()); + System.out.println("NEW EMAIL: " + message.getSubject() + " BODY: " + message.getBody()); + } else if (itemEvent.getEventType() == EventType.Created) { + Item item = Item.bind(service, itemEvent.getItemId()); + } else if (itemEvent.getEventType() == EventType.Deleted) { + break; + } + } + System.out.println("-----------------------------"); + Thread.sleep(1000 * 15); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + pullEvents(service, ps, folder); + + + } +} diff --git a/src/test/java/com/sathesh/integration/test/PushSubscriptionTest.java b/src/test/java/com/sathesh/integration/test/PushSubscriptionTest.java new file mode 100644 index 000000000..9a0b74cc3 --- /dev/null +++ b/src/test/java/com/sathesh/integration/test/PushSubscriptionTest.java @@ -0,0 +1,61 @@ +package com.sathesh.integration.test; + +import microsoft.exchange.webservices.data.core.ExchangeService; +import microsoft.exchange.webservices.data.core.enumeration.notification.EventType; +import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName; +import microsoft.exchange.webservices.data.credential.ExchangeCredentials; +import microsoft.exchange.webservices.data.credential.WebCredentials; +import microsoft.exchange.webservices.data.notification.PushSubscription; +import microsoft.exchange.webservices.data.property.complex.FolderId; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Collections; +import java.util.Properties; + +/** + * @author Sathesh Sivashanmugam + * date 2019-02-22 + */ +public class PushSubscriptionTest { + public static void main(String[] args) throws Exception { + ExchangeService service; + Properties properties = getProperties("./secret.properties"); + service = initConnection(properties.getProperty("username"), properties.getProperty("pwd"), properties.getProperty("url")); + subscriptionTesting(service); + } + + private static Properties getProperties(String file) throws IOException { + Properties properties = new Properties(); + properties.load(new FileInputStream(file)); + return properties; + } + + private static ExchangeService initConnection(String username, String pwd, String url) throws URISyntaxException { + ExchangeService service = new ExchangeService(); + ExchangeCredentials credentials = new WebCredentials(username, pwd); + service.setCredentials(credentials); + service.setUrl(new URI(url)); + service.setTraceEnabled(false); + return service; + } + + private static void subscriptionTesting(ExchangeService service) throws Exception { +// Subscribe to push notifications on the Inbox folder, and only listen +// to "new mail" events. + FolderId fid = new FolderId().getFolderIdFromWellKnownFolderName(WellKnownFolderName.Inbox); + + // service.unsubscribe("JwBzbjZwcjA2bWI1MjQ1Lm5hbXByZDA2LnByb2Qub3V0bG9vay5jb20QAAAArfTSYXBLkUiuRRWptHA9i9MTOne3MdgIEAAAAP5/AwBgyMRNAAAAAAAAAAA="); + PushSubscription pushSubscription = service.subscribeToPushNotifications( + Collections.singletonList(fid), + new URI("https://webhook.site/a8e9c1b8-e234-4dab-96a6-848350a5fca3"), + 1, + null, + EventType.NewMail); + System.out.println(pushSubscription.getId()); + + } + +} diff --git a/src/test/java/com/sathesh/integration/test/ReadMailTest.java b/src/test/java/com/sathesh/integration/test/ReadMailTest.java new file mode 100644 index 000000000..fc78fa2e4 --- /dev/null +++ b/src/test/java/com/sathesh/integration/test/ReadMailTest.java @@ -0,0 +1,58 @@ +package com.sathesh.integration.test; + +import microsoft.exchange.webservices.data.core.ExchangeService; +import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName; +import microsoft.exchange.webservices.data.core.service.item.Item; +import microsoft.exchange.webservices.data.credential.ExchangeCredentials; +import microsoft.exchange.webservices.data.credential.WebCredentials; +import microsoft.exchange.webservices.data.search.FindItemsResults; +import microsoft.exchange.webservices.data.search.ItemView; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Properties; + +/** + * @author Sathesh Sivashanmugam + * date 2019-02-22 + */ +public class ReadMailTest { + public static void main(String[] args) throws Exception { + ExchangeService service; + Properties properties = getProperties("./secret.properties"); + service = initConnection(properties.getProperty("username"), properties.getProperty("pwd"), properties.getProperty("url")); + getFirstMail(service); + } + + private static Properties getProperties(String file) throws IOException { + Properties properties = new Properties(); + properties.load(new FileInputStream(file) ); + return properties; + } + + private static ExchangeService initConnection(String username, String pwd, String url) throws URISyntaxException { + ExchangeService service = new ExchangeService(); + ExchangeCredentials credentials = new WebCredentials(username, pwd); + service.setCredentials(credentials); + service.setUrl(new URI(url)); + return service; + } + + private static void getFirstMail(ExchangeService service) throws Exception { + + int counter=0; + ItemView view = new ItemView(1); + FindItemsResults findResults = null; + findResults = service.findItems(WellKnownFolderName.Inbox, view); + + System.out.println("CONNECTION SUCCESSFUL"); + //convert the list of Item to List of VO + for(Item item : findResults){ + System.out.println("MAIL::" + ++counter); + System.out.println(item.getDateTimeReceived()); + System.out.println(item.getSubject()); + } + } +} diff --git a/src/test/java/com/sathesh/integration/test/StreamNotificationTest.java b/src/test/java/com/sathesh/integration/test/StreamNotificationTest.java new file mode 100644 index 000000000..c7d1bdc45 --- /dev/null +++ b/src/test/java/com/sathesh/integration/test/StreamNotificationTest.java @@ -0,0 +1,128 @@ +package com.sathesh.integration.test; + +import microsoft.exchange.webservices.data.core.ExchangeService; +import microsoft.exchange.webservices.data.core.PropertySet; +import microsoft.exchange.webservices.data.core.enumeration.notification.EventType; +import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName; +import microsoft.exchange.webservices.data.core.response.GetItemResponse; +import microsoft.exchange.webservices.data.core.response.ServiceResponseCollection; +import microsoft.exchange.webservices.data.core.service.schema.ItemSchema; +import microsoft.exchange.webservices.data.credential.ExchangeCredentials; +import microsoft.exchange.webservices.data.credential.WebCredentials; +import microsoft.exchange.webservices.data.notification.*; +import microsoft.exchange.webservices.data.property.complex.FolderId; +import microsoft.exchange.webservices.data.property.complex.ItemId; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +/** + * @author Sathesh Sivashanmugam + * date 2019-02-22 + */ +public class StreamNotificationTest{ + public static void main(String[] args) throws Exception { + ExchangeService service; + Properties properties = getProperties("./secret.properties"); + service = initConnection(properties.getProperty("username"), properties.getProperty("pwd"), properties.getProperty("url")); + (new StreamSubscription()).subscriptionTesting(service); + } + + private static Properties getProperties(String file) throws IOException { + Properties properties = new Properties(); + properties.load(new FileInputStream(file)); + return properties; + } + + private static ExchangeService initConnection(String username, String pwd, String url) throws URISyntaxException { + ExchangeService service = new ExchangeService(); + ExchangeCredentials credentials = new WebCredentials(username, pwd); + service.setCredentials(credentials); + service.setUrl(new URI(url)); + service.setTraceEnabled(false); + return service; + } + + public static class StreamSubscription implements StreamingSubscriptionConnection.INotificationEventDelegate, StreamingSubscriptionConnection.ISubscriptionErrorDelegate { + + ExchangeService service; + private void subscriptionTesting(ExchangeService service) throws Exception { + + this.service = service; + WellKnownFolderName sd = WellKnownFolderName.Inbox; + FolderId folderId = new FolderId(sd); + + List folder = new ArrayList(); + folder.add(folderId); + + StreamingSubscription subscription = service.subscribeToStreamingNotifications(folder, EventType.NewMail); + + StreamingSubscriptionConnection conn = new StreamingSubscriptionConnection(service, 30); + conn.addSubscription(subscription); + conn.addOnNotificationEvent(this); + conn.addOnDisconnect(this); + conn.open(); + + System.out.println("listening.."); + Thread.sleep(30*60*1000); + + } + + void connection_OnDisconnect(Object sender, SubscriptionErrorEventArgs args) { + System.out.println("disconnecting........"); + } + + void connection_OnNotificationEvent(Object sender, NotificationEventArgs args) throws Exception { + System.out.println("==== hi notification event=========="); + // First retrieve the IDs of all the new emails + List newMailsIds = new ArrayList(); + + Iterator it = args.getEvents().iterator(); + while (it.hasNext()) { + ItemEvent itemEvent = (ItemEvent) it.next(); + if (itemEvent != null) { + newMailsIds.add(itemEvent.getItemId()); + } + } + + if (newMailsIds.size() > 0) { + // Now retrieve the Subject property of all the new emails in one call to EWS. + ServiceResponseCollection responses = service.bindToItems(newMailsIds, new PropertySet(ItemSchema.Subject)); + System.out.println("count=======" + responses.getCount()); + + //this.listBox1.Items.Add(string.Format("{0} new mail(s)", newMailsIds.Count)); + + for (GetItemResponse response : responses) { + System.out.println("count=======" + responses.getClass().getName()); + System.out.println("subject=======" + response.getItem().getSubject()); + // Console.WriteLine("subject====" + response.Item.Subject); + } + } + } + + @Override + public void notificationEventDelegate(Object sender, NotificationEventArgs args) { + try { + this.connection_OnNotificationEvent(sender, args); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void subscriptionErrorDelegate(Object sender, SubscriptionErrorEventArgs args) { + try { + connection_OnDisconnect(sender, args); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + +} diff --git a/src/test/java/com/sathesh/integration/test/UnsubscribeTest.java b/src/test/java/com/sathesh/integration/test/UnsubscribeTest.java new file mode 100644 index 000000000..2934d8503 --- /dev/null +++ b/src/test/java/com/sathesh/integration/test/UnsubscribeTest.java @@ -0,0 +1,47 @@ +package com.sathesh.integration.test; + +import microsoft.exchange.webservices.data.core.ExchangeService; +import microsoft.exchange.webservices.data.credential.ExchangeCredentials; +import microsoft.exchange.webservices.data.credential.WebCredentials; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Properties; + +/** + * @author Sathesh Sivashanmugam + * date 2019-02-22 + */ +public class UnsubscribeTest { + public static void main(String[] args) throws Exception { + ExchangeService service; + Properties properties = getProperties("./secret.properties"); + service = initConnection(properties.getProperty("username"), properties.getProperty("pwd"), properties.getProperty("url")); + subscriptionTesting(service); + } + + private static Properties getProperties(String file) throws IOException { + Properties properties = new Properties(); + properties.load(new FileInputStream(file)); + return properties; + } + + private static ExchangeService initConnection(String username, String pwd, String url) throws URISyntaxException { + ExchangeService service = new ExchangeService(); + ExchangeCredentials credentials = new WebCredentials(username, pwd); + service.setCredentials(credentials); + service.setUrl(new URI(url)); + service.setTraceEnabled(false); + return service; + } + + private static void subscriptionTesting(ExchangeService service) throws Exception { + service.unsubscribe("JwBzbjZwcjA2bWI1MjQ1Lm5hbXByZDA2LnByb2Qub3V0bG9vay5jb20QAAAAlAbwumPv0kSMLBYioFvbdUamrY/AMdgIEAAAAP5/AwBgyMRNAAAAAAAAAAA="); + + + } + + +} diff --git a/src/test/java/microsoft/exchange/webservices/data/misc/IFunctionsTest.java b/src/test/java/microsoft/exchange/webservices/data/misc/IFunctionsTest.java index 4ee453423..e28b65361 100644 --- a/src/test/java/microsoft/exchange/webservices/data/misc/IFunctionsTest.java +++ b/src/test/java/microsoft/exchange/webservices/data/misc/IFunctionsTest.java @@ -23,9 +23,9 @@ package microsoft.exchange.webservices.data.misc; +import cz.msebera.android.httpclient.extras.Base64; import microsoft.exchange.webservices.data.core.EwsUtilities; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.binary.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -76,14 +76,24 @@ public void testToUUID() { public void testBase64Decoder() { final String value = "123"; final IFunctions.Base64Decoder f = IFunctions.Base64Decoder.INSTANCE; - Assert.assertArrayEquals(Base64.decodeBase64(value), (byte[]) f.func(value)); + Assert.assertArrayEquals(Base64.decode(value, 0), (byte[]) f.func(value)); } @Test public void testBase64Encoder() { - final byte[] value = StringUtils.getBytesUtf8("123"); + final byte[] value = "123".getBytes(); final IFunctions.Base64Encoder f = IFunctions.Base64Encoder.INSTANCE; - Assert.assertEquals(Base64.encodeBase64String(value), f.func(value)); + Assert.assertEquals(new String(Base64.encode(value, 0)), f.func(value)); + } + + @Test + public void testBase64EncoderDecoder() { + String testValue = " fsfsdfsdAAS#ssf@43(_ _#$@#?>