locked
EWS - Retrieving Calendar UID RRS feed

  • Question

  • Hello,

     

    I am writing a java application that fetches calendar data from EWS. One of the attribute that I am trying to fetch is the Calendar UID. I have upgraded my Exchange Server 2007 to SP1 and regenerate the classes from the new WSDL.

     

    The problem is, I always get a null value from CalendarItemType.getUID() method. I have tried many things.

     

    1. set ItemShape to ALL_PROPERTIES, still returns null

    2. I have tried to asked that attribute explicitly by using additional properties.

     

    NonEmptyArrayOfPathsToElementType noe = NonEmptyArrayOfPathsToElementType.Factory.newInstance();

     

    PathToUnindexedFieldType uidView = PathToUnindexedFieldType.Factory.newInstance();

    uidView.setFieldURI(UnindexedFieldURIType.CALENDAR_UID);

     

    BasePathToElementType[] pathArray = new BasePathToElementType[1];

    pathArray[0] = uidView;

     

    NonEmptyArrayOfPathsToElementType additionalProperties = NonEmptyArrayOfPathsToElementType.Factory.newInstance();

    additionalProperties.setPathArray(pathArray);

     

    shape.setAdditionalProperties(additionalProperties);

     

    I have run the code and I run into this error:

    org.apache.axis2.AxisFault: The request is valid but does not specify the correct server version in the RequestServerVersion SOAP header. Ensure that the RequestServerVersion SOAP header is set with the correct RequestServerVersionValue.

     

    Looking at the error, I then set the request server version accordingly:

    RequestServerVersionDocument serverVersionDoc = RequestServerVersionDocument.Factory.newInstance();

    serverVersionDoc.setRequestServerVersion(RequestServerVersion.Factory.newInstance());

    serverVersionDoc.getRequestServerVersion().setVersion(ExchangeVersionType.EXCHANGE_2007_SP_1);

     

    FindItemResponseDocument response = es.FindItem(request, null, null, null, serverVersionDoc);

     

    This run into cliend side schema validation upon receiving message from EWS. The error message is:

    org.apache.axis2.AxisFault: The request failed schema validation: The required attribute 'Version' is missing.

      at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:486)

      at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:343)

      at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:389)

     

    Has anyone else run into this issue? Based on the symptom, it looks like as if the exchange server is behaving like it's still running 2007 code. How can I determine whether the SP1 has been applied successfully. The console shows the following version:

     

    Exchange Server 2007

    Microsoft Corporation

    Version: 08.01.0240.006

     

    I thank you in advance for your time and help.

    Monday, July 14, 2008 4:31 PM

Answers

  • I found the issue. There's indeed an issue with the client stub class generated by Axis2. It overwrites any header attribute set earlier. The fix is to create a child class of the generated stub and override the method

     

    protected void addHeader(OMElement omElementToadd, SOAPEnvelope envelop, boolean mustUnderstand);

     

    Simply search the net for "AXIS2 addHeader" for various examples on how to override the method. Hope that helps for anyone that runs into this issue.

    Monday, July 14, 2008 10:04 PM

All replies

  • In the first case, the request was a compliant SP1 request, but no SP1 request header was passed in.  Then you added the request server version, but for some reason the Version attribute is not being emitted into the request, hence the schema validation error.  I am no Java guru, but what happens if you create a new instance of RequestServerVersion from the factory, set the version attribute on that and *then* call setRequestServerVersion on the document? 

     

    Monday, July 14, 2008 7:56 PM
  • I have verified that Exchange 2007 Server SP1 has been upgraded successfully. The schema violation error seems to be caused by the generated file from Axis2.  I have dumped the wire content of the request, and I found:

     

    2008/07/14 12:42:35:593 PDT [DEBUG] header - >> "POST /EWS/Exchange.asmx HTTP/1.1[\r][\n]"

    2008/07/14 12:42:35:593 PDT [DEBUG] HttpMethodBase - Adding Host request header

    2008/07/14 12:42:35:593 PDT [DEBUG] header - >> "Content-Type: text/xml; charset=UTF-8[\r][\n]"

    2008/07/14 12:42:35:593 PDT [DEBUG] header - >> "SOAPAction: "http://schemas.microsoft.com/exchange/services/2006/messages/FindItem"[\r][\n]"

    2008/07/14 12:42:35:593 PDT [DEBUG] header - >> "User-Agent: Axis2[\r][\n]"

    2008/07/14 12:42:35:593 PDT [DEBUG] header - >> "Content-Length: 1085[\r][\n]"

    2008/07/14 12:42:35:593 PDT [DEBUG] header - >> "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAFwAAAAAAAAAdAAAAAYABgBAAAAACgAKAEYAAAAMAAwAUAAAAAAAAAB0AAAABlIAAEVXU0RFVkNUTUVXU1VTRVJUU0JVLUNUTVBDMjS5zkOWEAaFET0qdAqF0/XuMhDgsOMyKCk=[\r][\n]"

    2008/07/14 12:42:35:593 PDT [DEBUG] header - >> "Host: tsbu-ctmpc24[\r][\n]"

    2008/07/14 12:42:35:593 PDT [DEBUG] header - >> "[\r][\n]"

    2008/07/14 12:42:35:593 PDT [DEBUG] content - >> "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlnsTongue Tiedoapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><RequestServerVersion xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soapenv:mustUnderstand="0" /></soapenv:Header><soapenv:Body><FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" Traversal="Shallow"><ItemShape><BaseShape xmlns="http://schemas.microsoft.com/exchange/services/2006/types">AllProperties</BaseShape><AdditionalProperties xmlns="http://schemas.microsoft.com/exchange/services/2006/types"><Path xmlns:typ="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" FieldURI="calendar:UID" xsi:type="typStick out tongueathToUnindexedFieldType" /></AdditionalProperties></ItemShape><ParentFolderIds><DistinguishedFolderId xmlns="http://schemas.microsoft.com/exchange/services/2006/types" Id="calendar"><Mailbox><EmailAddress>ctmewsuser@ewsdev.com</EmailAddress></Mailbox></DistinguishedFolderId></ParentFolderIds></FindItem></soapenv:Body></soapenv:Envelope>"

    2008/07/14 12:42:35:593 PDT [DEBUG] EntityEnclosingMethod - Request body sent

     

    Note that the RequestServerVersion does not contain the version.

    "<soapenv:Header><RequestServerVersion xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soapenv:mustUnderstand="0" /></soapenv:Header>"

     

    I have debugged the generated code.

     

    // add the children only if the parameter is not null

    if (requestServerVersion140 != null) {

      org.apache.axiom.om.OMElement omElementrequestServerVersion140 = toOM(requestServerVersion140,

        optimizeContent(

           new javax.xml.namespace.QName(

           "http://schemas.microsoft.com/exchange/services/2006/messages",

            "FindItem")));

      addHeader(omElementrequestServerVersion140, env); //at this point, omElement...140 still contains the Version

    }

     

    //adding SOAP soap_headers

    _serviceClient.addHeadersToEnvelope(env); //the env header does not contain the version

     

    Will check if there's issue in general with the generated class using axis2.

     

     

     

     

    Monday, July 14, 2008 8:00 PM
  • Hi David,

     

    Thanks for the reply, didn't see your response while composing my latest message. What you hinted is inlined with what I found. The request header does not contain the Version that I set. It looks like there's an issue with the generated classed. I will look into those more,

     

    One question if I may, do we need to ask for Calendar UID to be returned explicitly? Right now, I always get a null value

     

    Regards,

     

    Ridwan

     

    Monday, July 14, 2008 8:03 PM
  • Uid should be included in the AllProperties shape for calendar items and meeting messages, but it will only show up for SP1 requests.

    Monday, July 14, 2008 8:14 PM
  • Hi David,

     

    Thanks against for the reply.

     

    Regards,

     

    Ridwan

     

    Monday, July 14, 2008 8:57 PM
  • I found the issue. There's indeed an issue with the client stub class generated by Axis2. It overwrites any header attribute set earlier. The fix is to create a child class of the generated stub and override the method

     

    protected void addHeader(OMElement omElementToadd, SOAPEnvelope envelop, boolean mustUnderstand);

     

    Simply search the net for "AXIS2 addHeader" for various examples on how to override the method. Hope that helps for anyone that runs into this issue.

    Monday, July 14, 2008 10:04 PM
  • For the above issue what worked for me was to extend the ExchangeWebServiceStub, implement all the constructors and override the addHeader method as follows:

     

    Code Snippet

        @Override

        protected void addHeader(OMElement omElementToadd, SOAPEnvelope envelope, boolean mustUnderstand) {

            super.addHeader(omElementToadd, envelope, mustUnderstand);

            SOAPHeader soapHeaderBlock = envelope.getHeader();

           

            Iterator children = soapHeaderBlock.getChildElements();

           

            while(children.hasNext()){

                OMElement headerElement = (OMElement)children.next();

               

                if(headerElement.getLocalName() != null && headerElement.getLocalName().equals(omElementToadd.getLocalName())){

                    addAllAttributes(omElementToadd, headerElement);

                }

            }

        }

     

        /**

         * @param omElementToadd

         * @param headerElement

         */

        private void addAllAttributes(OMElement omElementToadd, OMElement headerElement) {

            Iterator atribIterator = omElementToadd.getAllAttributes();

     

            while (atribIterator.hasNext()) {

                OMAttribute omAttribute = (OMAttribute) atribIterator.next();

                if (headerElement.getAttribute(omAttribute.getQName()) == null) {

                    headerElement.addAttribute(omAttribute);

                }

            }

        }

     

     

    Then when creating the stub instance just refer to the one you created instead.

     

     

     

    Monday, December 1, 2008 8:41 PM