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

Parsing UserConfiguration dictionary entry with null value fails with ServiceXmlDeserializationException #523

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ private void loadEntry(EwsServiceXmlReader reader) throws Exception {

String nil = reader.readAttributeValue(XmlNamespace.XmlSchemaInstance,
XmlAttributeNames.Nil);
boolean hasValue = (nil == null)
|| (!nil.getClass().equals(Boolean.TYPE));
boolean hasValue = (nil == null);
if (hasValue) {
value = this.getDictionaryObject(reader);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* The MIT License
* Copyright (c) 2012 Microsoft Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package microsoft.exchange.webservices.data.core.request;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add the license header to all new files.


import microsoft.exchange.webservices.base.BaseTest;
import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
import microsoft.exchange.webservices.data.core.enumeration.service.ServiceResult;
import microsoft.exchange.webservices.data.core.response.GetUserConfigurationResponse;
import microsoft.exchange.webservices.data.core.response.ServiceResponseCollection;
import microsoft.exchange.webservices.data.misc.OutParam;
import microsoft.exchange.webservices.data.property.complex.UserConfigurationDictionary;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.InputStream;

@RunWith(JUnit4.class)
public class UserConfigurationTest extends BaseTest {

@Test
public void testNilDictionaryEntry() throws Exception {
GetUserConfigurationRequest request = new GetUserConfigurationRequest(exchangeServiceMock);
request.setName("Calendar");

InputStream inputStream = getClass().getResourceAsStream("/nil.xml");
EwsServiceXmlReader ewsXmlReader = new EwsServiceXmlReader(inputStream, exchangeServiceMock);
ServiceResponseCollection<GetUserConfigurationResponse> responses = request.readResponse(ewsXmlReader);

Assert.assertEquals(ServiceResult.Success, responses.getOverallResult());
Assert.assertNull(getDictionaryEntryValue(responses, "RequestInPolicy"));
}

private Object getDictionaryEntryValue(ServiceResponseCollection<GetUserConfigurationResponse> responses,
String requestInPolicy) {
UserConfigurationDictionary dictionary = responses.iterator().next().getUserConfiguration().getDictionary();
OutParam<Object> value = new OutParam<Object>();
dictionary.tryGetValue(requestInPolicy, value);
return value.getParam();
}

}
51 changes: 51 additions & 0 deletions src/test/resources/nil.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add the license header to all new files.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
MajorVersion="14" MinorVersion="3" MajorBuildNumber="266" MinorBuildNumber="1"
Version="Exchange2010_SP2"/>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<m:GetUserConfigurationResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:GetUserConfigurationResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:UserConfiguration>
<t:UserConfigurationName Name="Calendar">
<t:DistinguishedFolderId Id="calendar">
<t:Mailbox>
<t:EmailAddress>room@company.com</t:EmailAddress>
</t:Mailbox>
</t:DistinguishedFolderId>
</t:UserConfigurationName>
<t:ItemId
Id="AAMkADM1ZTI1ZDFkLTVhYzAtNGM1OS1hNWU0LTRkYWMyN2IxY2NhYgBGAAAAAABpRr8ivxS3SpNwMWdbqv/CBwBC8RoCDnbYSbjqYWwdG9viAKfx+eOZAABC8RoCDnbYSbjqYWwdG9viAKfx+6f2AAA="
ChangeKey="CQAAABYAAADXBP/PKsWQRKG/Fv+wtIlbAAASQjNo"/>
<t:Dictionary>
<t:DictionaryEntry>
<t:DictionaryKey>
<t:Type>String</t:Type>
<t:Value>RequestInPolicy</t:Value>
</t:DictionaryKey>
<t:DictionaryValue xsi:nil="true"/>
</t:DictionaryEntry>
<t:DictionaryEntry>
<t:DictionaryKey>
<t:Type>String</t:Type>
<t:Value>RemovePrivateProperty</t:Value>
</t:DictionaryKey>
<t:DictionaryValue>
<t:Type>Boolean</t:Type>
<t:Value>true</t:Value>
</t:DictionaryValue>
</t:DictionaryEntry>
</t:Dictionary>
</m:UserConfiguration>
</m:GetUserConfigurationResponseMessage>
</m:ResponseMessages>
</m:GetUserConfigurationResponse>
</s:Body>
</s:Envelope>