Hi,
Here is a sample code which is used to update a calendar item with a particular entry id and change key. For each of the property we update, we need to set the URI pointing to that property in calendar item and the object with the updated property.
private boolean sendMeetingUpdate(String id, String key)
{
boolean errorOccurred = false;
try
{
//ItemChangeType calendarChange
UpdateItemType updateCalendarItem = UpdateItemType.Factory.newInstance();
updateCalendarItem.setSendMeetingInvitationsOrCancellations(CalendarItemUpdateOperationType.SEND_TO_ALL_AND_SAVE_COPY);
updateCalendarItem.setConflictResolution(ConflictResolutionType.ALWAYS_OVERWRITE);
updateCalendarItem.setMessageDisposition(MessageDispositionType.SAVE_ONLY);
//setting the item identifier
ItemIdType itemIdentifier = ItemIdType.Factory.newInstance();
itemIdentifier.setId(id);
itemIdentifier.setChangeKey(key);
ItemChangeType[] itemChangesArray = new ItemChangeType[1];
itemChangesArray[0] = ItemChangeType.Factory.newInstance();
itemChangesArray[0].setItemId(itemIdentifier);
//Object to hold the properties.
SetItemFieldType[] itemFieldChangesArray = new SetItemFieldType[1];
//Setting the path to subject
//Forming the update calendar Object
CalendarItemType calendarItemObj = CalendarItemType.Factory.newInstance();
calendarItemObj.setSubject("Update Subject");
itemFieldChangesArray[0] = SetItemFieldType.Factory.newInstance();
itemFieldChangesArray[0].setCalendarItem(calendarItemObj);
PathToUnindexedFieldType pathToSubjectObj = PathToUnindexedFieldType.Factory.newInstance();
pathToSubjectObj.setFieldURI(UnindexedFieldURIType.ITEM_SUBJECT);
FieldURIDocument fieldURIDoc = FieldURIDocument.Factory.newInstance();
fieldURIDoc.setFieldURI(pathToSubjectObj);
itemFieldChangesArray[0].setPath(pathToSubjectObj);
NonEmptyArrayOfItemChangeDescriptionsType nonEmptyArrayOfItemChangeDescriptionsTypeObj = NonEmptyArrayOfItemChangeDescriptionsType.Factory.newInstance();
nonEmptyArrayOfItemChangeDescriptionsTypeObj.setSetItemFieldArray(itemFieldChangesArray);
itemChangesArray[0].setUpdates(nonEmptyArrayOfItemChangeDescriptionsTypeObj);
NonEmptyArrayOfItemChangesType nonEmptyArrayOfItemChangesTypeObj = NonEmptyArrayOfItemChangesType.Factory.newInstance();
nonEmptyArrayOfItemChangesTypeObj.setItemChangeArray(itemChangesArray);
updateCalendarItem.setItemChanges(nonEmptyArrayOfItemChangesTypeObj);
UpdateItemDocument updateMeetingRequest = UpdateItemDocument.Factory.newInstance();
updateMeetingRequest.setUpdateItem(updateCalendarItem);
UpdateItemResponseDocument updateItemResponseDocument = null;
System.out.println("Soap Request = \n" + updateMeetingRequest.toString());
try
{
updateItemResponseDocument = exService.updateItem(updateMeetingRequest, null, null, null, getServerVersionDetails(), null);
}
catch (Exception e)
{
System.out.println("\nError while updating calendar=" + e.getMessage());
e.printStackTrace();
return false;
}
ArrayOfResponseMessagesType arrayOfResponseMessagesType = updateItemResponseDocument.getUpdateItemResponse().getResponseMessages();
ItemInfoResponseMessageType[] infoResponseMessageType = arrayOfResponseMessagesType.getUpdateItemResponseMessageArray();
for (ItemInfoResponseMessageType type : infoResponseMessageType)
{
System.out.println("\nSOAP Response xml=" + type.xmlText());
if (type.getResponseClass() == ResponseClassType.SUCCESS)
{
ItemIdType itemId = type.getItems().getCalendarItemArray(0).getItemId();
System.out.println(itemId.getId());
System.out.println(itemId.getChangeKey());
}
else
{
System.out.println("Error occcured while createing calendar item. response = "
+ type.getResponseClass());
errorOccurred = true;
}
}
}
catch (Exception e)
{
System.out.println("Error Occured while updating meeting request - " + "\n" + e.getMessage());
e.printStackTrace();
return false;
}
if (errorOccurred)
return false;
else
return true;
}
Showing posts with label exchange web services. Show all posts
Showing posts with label exchange web services. Show all posts
Wednesday, December 16, 2009
Sunday, November 22, 2009
Creating Exchange Service Stub using AXIS 2
I had a good learning experience migrating our calendering functionality from exchange server 2003 to exchange server 2007. And in this post, I have jotted out how to create a proper exchange service client stub using Axis 2.
Creation of client stub is not straight forward as it seems. It is because the stub generated by Axis 2 without any changes to auto generated stub code has one malformed element and as a result the SOAP request is not formed correctly.
The final list of steps I followed are below,
Step-1: Download axis2- 1.5 from the net and unzip it.
Step-2: Download the Services.wsdl, types.xsd and messages.xsd from https://ExchangeServerURL/ews/Services.wsdl and place the same under the folder axis2- 1.5.
Step-3: In Services.wsdl file we need to add an XML element that defined the service. So add the following piece of code in the end just before the closure of wsdl:definition.
<wsdl:service name="ExchangeService">
<wsdl:port name="ExchangeServicePort" binding="tns:ExchangeServiceBinding">
<soap:address location="https://ExchangeServerURL/ews"/>
</wsdl:port>
</wsdl:service>
Step-4: Execute the below from command prompt to generate the source files. The source files will get generated under axis2-1.5/ews directory.
C:\exchange\axis2-1.5>bin\wsdl2java -d xmlbeans -s -ss -g -o ews -uri Services.wsdl
Step-5: We need to manually change the class ChangeDescriptionTypeImpl in the package com.microsoft.schemas.exchange.services._2006.types.impl so that the XML is formed correctly for the UpdateItem request. The issue was with specifying the element that denotes the property that needs to be changed. The XML was generated with tag but the exchange server was expecting the element . So we need to change the variable PATH$0 in the class from
private static final javax.xml.namespace.QName PATH$0 = new javax.xml.namespace.QName("http://schemas.microsoft.com/exchange/services/2006/types", "Path");
to
private static final javax.xml.namespace.QName PATH$0 = new javax.xml.namespace.QName("http://schemas.microsoft.com/exchange/services/2006/types", "FieldURI");
Step-6a: The above command also creates ant file that can be used to create the jar file (if ant is installed in windows).
or
Step-6b: If ant is not available in windows, you can still create the jar file by manually setting the unix paths in the build.xml and running ant from unix.
Step-7: After running ant, the aar and jar file gets created in axis2-1.5\ews\build\lib directory and this can be added to class path and used in programming.
I the next post we will see how to send a mail using the stub we generated.
If you face any issues with the creation or using the stub, provide your questions here and I would be happy to help.
Creation of client stub is not straight forward as it seems. It is because the stub generated by Axis 2 without any changes to auto generated stub code has one malformed element and as a result the SOAP request is not formed correctly.
The final list of steps I followed are below,
Step-1: Download axis2- 1.5 from the net and unzip it.
Step-2: Download the Services.wsdl, types.xsd and messages.xsd from https://ExchangeServerURL/ews/Services.wsdl and place the same under the folder axis2- 1.5.
Step-3: In Services.wsdl file we need to add an XML element that defined the service. So add the following piece of code in the end just before the closure of wsdl:definition.
<wsdl:service name="ExchangeService">
<wsdl:port name="ExchangeServicePort" binding="tns:ExchangeServiceBinding">
<soap:address location="https://ExchangeServerURL/ews"/>
</wsdl:port>
</wsdl:service>
Step-4: Execute the below from command prompt to generate the source files. The source files will get generated under axis2-1.5/ews directory.
C:\exchange\axis2-1.5>bin\wsdl2java -d xmlbeans -s -ss -g -o ews -uri Services.wsdl
Step-5: We need to manually change the class ChangeDescriptionTypeImpl in the package com.microsoft.schemas.exchange.services._2006.types.impl so that the XML is formed correctly for the UpdateItem request. The issue was with specifying the
private static final javax.xml.namespace.QName PATH$0 = new javax.xml.namespace.QName("http://schemas.microsoft.com/exchange/services/2006/types", "Path");
to
private static final javax.xml.namespace.QName PATH$0 = new javax.xml.namespace.QName("http://schemas.microsoft.com/exchange/services/2006/types", "FieldURI");
Step-6a: The above command also creates ant file that can be used to create the jar file (if ant is installed in windows).
or
Step-6b: If ant is not available in windows, you can still create the jar file by manually setting the unix paths in the build.xml and running ant from unix.
Step-7: After running ant, the aar and jar file gets created in axis2-1.5\ews\build\lib directory and this can be added to class path and used in programming.
I the next post we will see how to send a mail using the stub we generated.
If you face any issues with the creation or using the stub, provide your questions here and I would be happy to help.
Subscribe to:
Posts (Atom)