none
[E2010] [EWS Java API 1.1][JAVA] - Could not get all the tasks from the server if the value is a space for a field. RRS feed

  • Question

  • Hi,

    I am trying to get all the tasks from the Tasks folder. I am not getting the ParseException always. I think it has to do something with the Space. If I create a task with Companies field as space, when I try to find all the items from the tasks folder I get this exception.

     

    Exception in thread "main" microsoft.exchange.webservices.data.ServiceRequestException: The request failed. Could not read value from START_ELEMENT.Could not find CHARACTERS
    	at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:52)
    	at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:140)
    	at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:949)
    	at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:1002)
    	at microsoft.exchange.webservices.data.ExchangeService.findItems(ExchangeService.java:1093)
    	at test.GetTasks.main(GetTasks.java:14)
    Caused by: microsoft.exchange.webservices.data.ServiceXmlDeserializationException: Could not read value from START_ELEMENT.Could not find CHARACTERS
    	at microsoft.exchange.webservices.data.EwsXmlReader.readValue(EwsXmlReader.java:465)
    	at microsoft.exchange.webservices.data.StringList.tryReadElementFromXml(StringList.java:67)
    	at microsoft.exchange.webservices.data.ComplexProperty.loadFromXml(ComplexProperty.java:182)
    	at microsoft.exchange.webservices.data.ComplexProperty.loadFromXml(ComplexProperty.java:211)
    	at microsoft.exchange.webservices.data.ComplexPropertyDefinitionBase.internalLoadFromXml(ComplexPropertyDefinitionBase.java:95)
    	at microsoft.exchange.webservices.data.ComplexPropertyDefinitionBase.loadPropertyValueFromXml(ComplexPropertyDefinitionBase.java:118)
    	at microsoft.exchange.webservices.data.PropertyBag.loadFromXml(PropertyBag.java:487)
    	at microsoft.exchange.webservices.data.ServiceObject.loadFromXml(ServiceObject.java:268)
    	at microsoft.exchange.webservices.data.FindItemResponse.internalReadItemsFromXml(FindItemResponse.java:161)
    	at microsoft.exchange.webservices.data.FindItemResponse.readElementsFromXml(FindItemResponse.java:83)
    	at microsoft.exchange.webservices.data.ServiceResponse.loadFromXml(ServiceResponse.java:101)
    	at microsoft.exchange.webservices.data.MultiResponseServiceRequest.parseResponse(MultiResponseServiceRequest.java:52)
    	at microsoft.exchange.webservices.data.ServiceRequestBase.readResponse(ServiceRequestBase.java:445)
    	at microsoft.exchange.webservices.data.SimpleServiceRequestBase.readResponse(SimpleServiceRequestBase.java:102)
    	at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:39)
    	... 5 more

    Please use the following code to reproduce the issue.

    public class GetAllTasks
    {
      public static void main( String [] args ) throws Throwable
      {
        ExchangeService service = TestUtil.getService();
    
        // Clear all items in the tasks folder.
        clearAllItems( service );
    
        // Create a task with Companies name as " ".
        Task task = new Task( service );
        StringList value = new StringList();
        value.add( " " );
        task.setCompanies( value );
    
        Collection < Item > itemsToCreate = new ArrayList < Item >();
        itemsToCreate.add( task );
        service.createItems( itemsToCreate, new FolderId( WellKnownFolderName.Tasks ), MessageDisposition.SaveOnly,
            SendInvitationsMode.SendToNone );
    
        Folder tasksFolder = Folder.bind( service, WellKnownFolderName.Tasks );
        // Try to get all the tasks. The exception occurs at this line.
        FindItemsResults < Item > items = tasksFolder.findItems( new ItemView( 1000 ) );
    
        System.out.println( items.getTotalCount() );
      }
    
      private static void clearAllItems( ExchangeService service ) throws Exception, ServiceLocalException
      {
        // service.setTraceEnabled( true );
        Folder tasksFolder = Folder.bind( service, WellKnownFolderName.Tasks );
        FindItemsResults < Item > items = tasksFolder.findItems( new ItemView( 1000 ) );
        List < ItemId > itemIds = new ArrayList < ItemId >();
        for ( Item item : items )
        {
          System.out.println( item.getId() );
          itemIds.add( item.getId() );
        }
        if ( itemIds.size() > 0 )
        {
          service.deleteItems( itemIds, DeleteMode.HardDelete, SendCancellationsMode.SendToNone,
              AffectedTaskOccurrence.AllOccurrences );
          System.out.println( "Deleted all tasks" );
        }
      }
    }

    Please help us resolve the issue.

    Thanks,
    Paul
    Thursday, October 20, 2011 11:41 AM

All replies