Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.

Commit 5a05bdf

Browse files
committed
Ignore invalid xml chars... from https://github.com/RavnSystems/ews-java-api
See this commit: RavnSystems/ews-java-api@845f20f and this issue: #353 Looks like exchange does not properly excape some XML chars when present in email. There seems to be a way to allow unicode by forcing "Xml 1.1" instead of "Xml 1.0" but this is reported to not work in some versions of exchange.
1 parent f0d786e commit 5a05bdf

3 files changed

Lines changed: 93 additions & 19 deletions

File tree

pom.xml

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@
2828
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2929
<modelVersion>4.0.0</modelVersion>
3030

31-
<groupId>com.microsoft.ews-java-api</groupId>
32-
<artifactId>ews-java-api</artifactId>
31+
<groupId>com.onboardify.github</groupId>
32+
<artifactId>com.microsoft.ews-java-api-2.0</artifactId>
33+
<version>1</version>
3334

34-
<version>2.1-SNAPSHOT</version>
35-
36-
<name>Exchange Web Services Java API</name>
35+
<name>${bundle.symbolicName} ${wrapped.version} [github]</name>
3736
<description>Exchange Web Services (EWS) Java API</description>
3837

3938
<!-- Required by the site command for certain relative URL configuration. -->
@@ -73,6 +72,12 @@
7372
</developers>
7473

7574
<properties>
75+
<!-- RAVN -->
76+
<bundle.symbolicName>com.microsoft.ews-java-api</bundle.symbolicName>
77+
<wrapped.groupId>com.microsoft.ews-java-api</wrapped.groupId>
78+
<wrapped.artifactId>ews-java-api</wrapped.artifactId>
79+
<wrapped.version>2.0</wrapped.version>
80+
7681
<!-- Eliminates the file encoding warning. Of course, all of your files
7782
should probably be UTF-8 nowadays. -->
7883
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -108,6 +113,9 @@
108113
<mockito-core.version>1.10.19</mockito-core.version>
109114
<slf4j.version>1.7.12</slf4j.version>
110115
<logback.version>1.1.3</logback.version>
116+
117+
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
118+
<github.global.server>github</github.global.server>
111119
</properties>
112120

113121
<profiles>
@@ -202,13 +210,10 @@
202210
</scm>
203211

204212
<distributionManagement>
205-
<snapshotRepository>
206-
<id>ossrh-snapshot</id>
207-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
208-
</snapshotRepository>
209213
<repository>
210-
<id>ossrh</id>
211-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
214+
<id>internal.repo</id>
215+
<name>Temporary Staging Repository</name>
216+
<url>file://${project.build.directory}/mvn-repo</url>
212217
</repository>
213218
</distributionManagement>
214219

@@ -291,23 +296,28 @@
291296
<scope>test</scope>
292297
</dependency>
293298

299+
<dependency>
300+
<groupId>com.sun.xml.parsers</groupId>
301+
<artifactId>jaxp-ri</artifactId>
302+
<version>1.4.5</version>
303+
</dependency>
294304
</dependencies>
295305

296306
<build>
297307
<plugins>
298308
<!-- Deployment / build plugins -->
299-
<plugin>
309+
<!--<plugin>
300310
<groupId>org.sonatype.plugins</groupId>
301311
<artifactId>nexus-staging-maven-plugin</artifactId>
302312
<version>${nexus-staging-maven-plugin.version}</version>
303313
<extensions>true</extensions>
304314
<configuration>
305-
<!-- Ref.: http://books.sonatype.com/nexus-book/reference/staging-deployment.html -->
315+
Ref.: http://books.sonatype.com/nexus-book/reference/staging-deployment.html
306316
<autoReleaseAfterClose>true</autoReleaseAfterClose>
307317
<serverId>ossrh</serverId>
308318
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
309319
</configuration>
310-
</plugin>
320+
</plugin>-->
311321
<plugin>
312322
<groupId>org.apache.maven.plugins</groupId>
313323
<artifactId>maven-compiler-plugin</artifactId>
@@ -389,6 +399,37 @@
389399
</execution>
390400
</executions>
391401
</plugin>
402+
<plugin>
403+
<artifactId>maven-deploy-plugin</artifactId>
404+
<version>2.8.1</version>
405+
<configuration>
406+
<altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo</altDeploymentRepository>
407+
</configuration>
408+
</plugin>
409+
<plugin>
410+
<groupId>com.github.github</groupId>
411+
<artifactId>site-maven-plugin</artifactId>
412+
<version>0.12</version>
413+
<configuration>
414+
<message>Maven artifacts for ${project.version}</message> <!-- git commit message -->
415+
<noJekyll>true</noJekyll> <!-- disable webpage processing -->
416+
<outputDirectory>${project.build.directory}/mvn-repo</outputDirectory> <!-- matches distribution management repository url above -->
417+
<branch>refs/heads/mvn-repo</branch> <!-- remote branch name -->
418+
<includes><include>**/*</include></includes>
419+
<merge>true</merge> <!-- don't delete old artifacts -->
420+
<repositoryName>ews-java-api</repositoryName> <!-- github repo name -->
421+
<repositoryOwner>hrajeshkumar</repositoryOwner> <!-- github username -->
422+
</configuration>
423+
<executions>
424+
<!-- run site-maven-plugin's 'site' target as part of the build's normal 'deploy' phase -->
425+
<execution>
426+
<goals>
427+
<goal>site</goal>
428+
</goals>
429+
<phase>deploy</phase>
430+
</execution>
431+
</executions>
432+
</plugin>
392433
<!-- Deployment / build plugins END -->
393434
</plugins>
394435
<!-- Used to bump all of the various core plugins up to Maven current.

src/main/java/microsoft/exchange/webservices/data/core/EwsServiceMultiResponseXmlReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static XMLEventReader createXmlReader(InputStream stream)
9898
* @throws Exception on error
9999
*/
100100
@Override
101-
protected XMLEventReader initializeXmlReader(InputStream stream)
101+
protected XMLEventReader initializeXmlReader(InputStream stream, boolean ignoreErrors)
102102
throws Exception {
103103
return createXmlReader(stream);
104104
}

src/main/java/microsoft/exchange/webservices/data/core/EwsXmlReader.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
package microsoft.exchange.webservices.data.core;
2525

26+
import com.sun.org.apache.xerces.internal.impl.Constants;
27+
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
28+
import com.sun.xml.internal.stream.XMLInputFactoryImpl;
2629
import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
2730
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlDeserializationException;
2831
import microsoft.exchange.webservices.data.misc.OutParam;
@@ -63,6 +66,13 @@ public class EwsXmlReader {
6366
*/
6467
private static final int ReadWriteBufferSize = 4096;
6568

69+
/**
70+
* Default setting for ignore xml errors
71+
*/
72+
73+
private static final boolean IgnoreErrorsDefault = true;
74+
75+
6676
/**
6777
* The xml reader.
6878
*/
@@ -85,7 +95,17 @@ public class EwsXmlReader {
8595
* @throws Exception on error
8696
*/
8797
public EwsXmlReader(InputStream stream) throws Exception {
88-
this.xmlReader = initializeXmlReader(stream);
98+
this.xmlReader = initializeXmlReader(stream, IgnoreErrorsDefault);
99+
}
100+
101+
/**
102+
* Initializes a new instance of the EwsXmlReader class.
103+
*
104+
* @param stream the stream
105+
* @throws Exception on error
106+
*/
107+
public EwsXmlReader(InputStream stream, boolean ignoreErrors) throws Exception {
108+
this.xmlReader = initializeXmlReader(stream, ignoreErrors);
89109
}
90110

91111
/**
@@ -95,13 +115,26 @@ public EwsXmlReader(InputStream stream) throws Exception {
95115
* @return An XML reader to use.
96116
* @throws Exception on error
97117
*/
98-
protected XMLEventReader initializeXmlReader(InputStream stream) throws Exception {
99-
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
118+
protected XMLEventReader initializeXmlReader(InputStream stream, boolean ignoreErrors) throws Exception {
119+
XMLInputFactory inputFactory = new XMLInputFactoryImpl();
100120
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
101121

102-
return inputFactory.createXMLEventReader(stream);
122+
XMLEventReader reader = inputFactory.createXMLEventReader(stream);
123+
124+
if (ignoreErrors) {
125+
//continue after fatal error to prevent "invalid character reference"
126+
XMLErrorReporter errorReporter =
127+
(XMLErrorReporter) reader.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY);
128+
129+
if (errorReporter != null) {
130+
errorReporter.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE, true);
131+
} else {
132+
LOG.warn("Failed to configure ignore errors for the XML Reader. Expected the Xerces parser implementation.");
133+
}
103134
}
104135

136+
return reader;
137+
}
105138

106139
/**
107140
* Formats the name of the element.

0 commit comments

Comments
 (0)