ews-java-api
ews-java-api copied to clipboard
userConfigurationItem.update failing when existing category contains unicode.
I am using EWS 1.2 to create categories and I am getting the EWSHttpException "Connection not established" when calling userConfigurationItem.update() if an existing category has the following unicode (美亞保險香港有限公司). The same code creates my categories flawlessly if I delete the unicode category (via outlook) and then run it.
Any suggestions or a fix for a future release would be appreciated.
Here is the code I am using to get the category:
public static CategoryList getExchangeCategoryList(UserDetail userDetail)
throws Exception {
UserConfiguration userConfiguration = null;
CategoryList mc = null;
InputStream stream = null;
XMLStreamReader xsr = null;
userConfiguration = UserConfiguration.bind(
userDetail.getExchangeService(), "CategoryList",
WellKnownFolderName.Calendar,
UserConfigurationProperties.All);
if (userConfiguration.getXmlData() == null)
{
throw new IllegalArgumentException("userConfiguration.getXmlData() returned null in CategoryList.getExchangeCategoryList()");
}
try {
Unmarshaller unmarshaller = JAXBContext.newInstance(CategoryList.class).createUnmarshaller();
XMLInputFactory xif = XMLInputFactory.newFactory();
stream = new ByteArrayInputStream(userConfiguration.getXmlData());
xsr = xif.createXMLStreamReader(stream);
mc = (CategoryList) unmarshaller.unmarshal(xsr);
mc.userConfigurationItem = userConfiguration;
}
finally
{
if (stream != null)
{
stream.close();
}
if (xsr != null)
{
xsr.close();
}
}
return mc;
}
Here is the code I am using to update the category.
public void updateExchangeCategories() throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(CategoryList.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
java.io.ByteArrayOutputStream baos = new ByteArrayOutputStream();
jaxbMarshaller.marshal(this, baos);
try {
userConfigurationItem.setXmlData(baos.toByteArray());
userConfigurationItem.update();
} catch (Exception ex) {
exceptionHandler.onException(ex);
throw ex;
}
finally
{
if (baos != null)
{
baos.flush();
baos.close();
}
}
}