Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__commons_io_commons_io_2_4.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions ews-java-api.iml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.github.rwitzel.streamflyer:streamflyer-core:1.2.0" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.4.1" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.8" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
Expand All @@ -27,5 +29,4 @@
<orderEntry type="library" scope="TEST" name="Maven: ch.qos.logback:logback-core:1.1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:jcl-over-slf4j:1.7.12" level="project" />
</component>
</module>

</module>
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<maven-jxr-plugin.version>2.5</maven-jxr-plugin.version>
<maven-surefire-report-plugin.version>2.18.1</maven-surefire-report-plugin.version>
<!-- Dependencies [COMPILE]: -->
<streamflyer-core.version>1.2.0</streamflyer-core.version>
<httpclient.version>4.4.1</httpclient.version>
<httpcore.version>4.4.1</httpcore.version>
<commons-logging.version>1.2</commons-logging.version>
Expand Down Expand Up @@ -182,6 +183,12 @@
</distributionManagement>

<dependencies>
<dependency>
<groupId>com.github.rwitzel.streamflyer</groupId>
<artifactId>streamflyer-core</artifactId>
<version>${streamflyer-core.version}</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@

package microsoft.exchange.webservices.data.core;

import com.github.rwitzel.streamflyer.core.ModifyingReader;
import com.github.rwitzel.streamflyer.xml.InvalidXmlCharacterModifier;
import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlDeserializationException;
import microsoft.exchange.webservices.data.core.modifier.InvalidBothSchemaXmlCharacterModifier;
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.io.input.XmlStreamReader;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -49,6 +53,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;

/**
Expand Down Expand Up @@ -99,7 +104,13 @@ protected XMLEventReader initializeXmlReader(InputStream stream) throws Exceptio
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);

return inputFactory.createXMLEventReader(stream);
Reader reader = new XmlStreamReader(stream);
ModifyingReader
modifyingReader =
new ModifyingReader(reader,
new InvalidBothSchemaXmlCharacterModifier("", InvalidXmlCharacterModifier.XML_10_VERSION));

return inputFactory.createXMLEventReader(modifyingReader);
}


Expand Down Expand Up @@ -771,28 +782,6 @@ public void skipElement(String namespacePrefix, String localName)
}
}

/**
* Skips the element.
*
* @param xmlNamespace the xml namespace
* @param localName the local name
* @throws Exception the exception
*/
public void skipElement(XmlNamespace xmlNamespace, String localName)
throws Exception {
if (!this.isEndElement(xmlNamespace, localName)) {
if (!this.isStartElement(xmlNamespace, localName)) {
this.readStartElement(xmlNamespace, localName);
}

if (!this.isEmptyElement()) {
do {
this.read();
} while (!this.isEndElement(xmlNamespace, localName));
}
}
}

/**
* Skips the current element.
*
Expand Down Expand Up @@ -1030,11 +1019,18 @@ public boolean hasAttributes() {
* Gets a value indicating whether current element is empty.
*
* @return boolean
* @throws XMLStreamException the XML stream exception
*/
public boolean isEmptyElement() throws XMLStreamException {
boolean isPresentStartElement = this.presentEvent.isStartElement();
boolean isNextEndElement = this.xmlReader.peek().isEndElement();
public boolean isEmptyElement() {
boolean isPresentStartElement = false;
boolean isNextEndElement = false;
try {
isPresentStartElement = this.presentEvent.isStartElement();
} catch (Exception e) {
}
try {
isNextEndElement = this.xmlReader.peek().isEndElement();
} catch (Exception e) {
}
return isPresentStartElement && isNextEndElement;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package microsoft.exchange.webservices.data.core.modifier;

import com.github.rwitzel.streamflyer.xml.InvalidXmlCharacterModifier;

public class InvalidBothSchemaXmlCharacterModifier extends InvalidXmlCharacterModifier {

public InvalidBothSchemaXmlCharacterModifier(String replacement, String xmlVersion) {
super(replacement, xmlVersion);
}

protected String getInvalidXmlCharacterRegex_Xml10() {
return "[^\\u0009\\u000A\\u000D\\u0020-\\uD7FF\\uE000-\\uFFFD\\x{10000}-\\x{10FFFF}]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package microsoft.exchange.webservices.data.core;

import microsoft.exchange.webservices.data.security.XmlNodeType;
import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayInputStream;

public class EwsXmlReaderModifierTest {

@Test public void testReadValidDocumentXml10() throws Exception {
final String validDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><test>testContent</test>";
byte[] bytes = validDocument.getBytes("UTF-8");
EwsXmlReader impl = new EwsXmlReader(new ByteArrayInputStream(bytes));
impl.read(new XmlNodeType(XmlNodeType.START_DOCUMENT));
impl.read(new XmlNodeType(XmlNodeType.START_ELEMENT));
String content = impl.readValue();
Assert.assertEquals(content, "testContent");
impl.read(new XmlNodeType(XmlNodeType.END_DOCUMENT));
}

@Test public void testReadInvalidDocumentXml10With0xA1() throws Exception {
final String invalidDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><test>test\u001AContent</test>";
byte[] bytes = invalidDocument.getBytes("UTF-8");
EwsXmlReader impl = new EwsXmlReader(new ByteArrayInputStream(bytes));
impl.read(new XmlNodeType(XmlNodeType.START_DOCUMENT));
impl.read(new XmlNodeType(XmlNodeType.START_ELEMENT));
String content = impl.readValue();
Assert.assertEquals(content, "testContent");
impl.read(new XmlNodeType(XmlNodeType.END_DOCUMENT));
}

@Test public void testReadInvalidDocumentXml10WithNullCharacter() throws Exception {
final String
invalidDocument =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><test>test\u0000Content\0</test>";
byte[] bytes = invalidDocument.getBytes("UTF-8");
EwsXmlReader impl = new EwsXmlReader(new ByteArrayInputStream(bytes));
impl.read(new XmlNodeType(XmlNodeType.START_DOCUMENT));
impl.read(new XmlNodeType(XmlNodeType.START_ELEMENT));
String content = impl.readValue();
Assert.assertEquals(content, "testContent");
impl.read(new XmlNodeType(XmlNodeType.END_DOCUMENT));
}

@Test public void testReadValidDocumentXml11() throws Exception {
final String validDocument = "<?xml version=\"1.1\" encoding=\"UTF-8\"?><test>testContent</test>";
byte[] bytes = validDocument.getBytes("UTF-8");
EwsXmlReader impl = new EwsXmlReader(new ByteArrayInputStream(bytes));
impl.read(new XmlNodeType(XmlNodeType.START_DOCUMENT));
impl.read(new XmlNodeType(XmlNodeType.START_ELEMENT));
String content = impl.readValue();
Assert.assertEquals(content, "testContent");
impl.read(new XmlNodeType(XmlNodeType.END_DOCUMENT));
}

@Test public void testReadInvalidDocumentXml11With0xA1() throws Exception {
final String invalidDocument = "<?xml version=\"1.1\" encoding=\"UTF-8\"?><test>test\u001AContent</test>";
byte[] bytes = invalidDocument.getBytes("UTF-8");
EwsXmlReader impl = new EwsXmlReader(new ByteArrayInputStream(bytes));
impl.read(new XmlNodeType(XmlNodeType.START_DOCUMENT));
impl.read(new XmlNodeType(XmlNodeType.START_ELEMENT));
String content = impl.readValue();
Assert.assertEquals(content, "testContent");
impl.read(new XmlNodeType(XmlNodeType.END_DOCUMENT));
}

@Test public void testReadInvalidDocumentXml11WithNullCharacter() throws Exception {
final String invalidDoc = "<?xml version=\"1.1\" encoding=\"UTF-8\"?><test>test\u0000Content\0</test>";
byte[] bytes = invalidDoc.getBytes("UTF-8");
EwsXmlReader impl = new EwsXmlReader(new ByteArrayInputStream(bytes));
impl.read(new XmlNodeType(XmlNodeType.START_DOCUMENT));
impl.read(new XmlNodeType(XmlNodeType.START_ELEMENT));
String content = impl.readValue();
Assert.assertEquals(content, "testContent");
impl.read(new XmlNodeType(XmlNodeType.END_DOCUMENT));
}

@Test public void testReadInvalidDocumentWithNullCharacter() throws Exception {
final String invalidDoc = "<test>test\u0000Content\0</test>";
byte[] bytes = invalidDoc.getBytes();
EwsXmlReader impl = new EwsXmlReader(new ByteArrayInputStream(bytes));
impl.read(new XmlNodeType(XmlNodeType.START_DOCUMENT));
impl.read(new XmlNodeType(XmlNodeType.START_ELEMENT));
String content = impl.readValue();
Assert.assertEquals(content, "testContent");
impl.read(new XmlNodeType(XmlNodeType.END_DOCUMENT));
}
}