Link to home
Start Free TrialLog in
Avatar of Absente
Absente

asked on

Exchange Web Service API - Java

Hi I  am triying to access exchange web service using java.

I have got trail excahn ge web service account from microsoft.

I am trying to acces the following code.

----------

java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        System.setProperty(
            "java.protocol.handler.pkgs",
            "com.sun.net.ssl.internal.www.protocol");
        try {
            // TODO code application logic here
            ExchangeService service = new ExchangeService();
            // Provide credentials.
            service.setCredentials(new WebCredentials("asdasd@asdasdl", "asdsa","HM.DM.AD"));
            // Autodiscover EWS end point.

            URI url = new URI("https://chsdasd802.outlook.com/owa/Exchange.asmx");
 

            System.out.println(service.getRequestedServerVersion());

            ItemView view = new ItemView(50);
            FindItemsResults<Item> findResults;

            do {
                findResults = service.findItems(WellKnownFolderName.Inbox, view);

                for (Item item : findResults.getItems()) {
// Do something with the item.
                }

                view.setOffset(view.getOffset() + 50);
            } while (findResults.isMoreAvailable());


        } catch (Exception ex) {
            ex.printStackTrace();
        }
-----------

I got error.

microsoft.exchange.webservices.data.HttpErrorException: The remote server returned an error: (440)Login Timeout
      at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(Unknown Source)
      at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
      at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
      at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
      at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
      at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
      at ewsdeneme.EWSDeneme.main(EWSDeneme.java:53)

-I think it is about ssl connection.

How can i solve this?
Avatar of Absente
Absente

ASKER

any answer ?
Avatar of LeeDerbyshire
Your URI is incorrect - try replacing /owa/ with /EWS/ .  What you are encountering (the 440 login timeout) is the server's response when you try to get past the OWA login form without actually submitting the correct values.
Avatar of Absente

ASKER

now I got this error.

org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: Basic authentication scheme selected
microsoft.exchange.webservices.data.ServiceResponseException: The request failed schema validation: The 'Id' attribute is invalid - The value 'sentitems' is invalid according to its datatype 'http://schemas.microsoft.com/exchange/services/2006/types:DistinguishedFolderIdNameType' - The Enumeration constraint failed.
      at microsoft.exchange.webservices.data.ServiceRequestBase.processWebException(Unknown Source)
      at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(Unknown Source)
      at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
      at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
      at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
      at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
      at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
      at ewsdeneme.EWSDeneme.main(EWSDeneme.java:57)
I don't see any code in your OP that accesses the sent items folder.  Has it changed since?
Avatar of Absente

ASKER

This it the Code

    public static void main(String[] args) {
        try {
            ExchangeService service = new ExchangeService();
            service.setCredentials(new WebCredentials("asdl@yasd.onmicrosoft.com", "1Ysnciiim2", "HM.DM.AD"));
            WebCredentials webCredentials = new WebCredentials();
            URI url = new URI("https://chtrt1p802.outlook.com/ews/Exchange.asmx");
            service.setUrl(url);
            System.out.println(service.getRequestedServerVersion());
            ItemView view = new ItemView(50);
            FindItemsResults<Item> findResults;
            do {
                findResults = service.findItems(WellKnownFolderName.SentItems, view);
                for (Item item : findResults.getItems()) {
                }
                view.setOffset(view.getOffset() + 50);
            } while (findResults.isMoreAvailable());
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

Open in new window


This it the Error




Ara 14, 2011 5:34:41 PM org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: Basic authentication scheme selected
microsoft.exchange.webservices.data.ServiceResponseException: The request failed schema validation: The 'Id' attribute is invalid - The value 'sentitems' is invalid according to its datatype 'http://schemas.microsoft.com/exchange/services/2006/types:DistinguishedFolderIdNameType' - The Enumeration constraint failed.
      at microsoft.exchange.webservices.data.ServiceRequestBase.processWebException(Unknown Source)
      at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(Unknown Source)
      at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
      at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
      at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
      at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
      at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
      at ewsdeneme.EWSDeneme.main(EWSDeneme.java:39)

Hm.  I've never used the Java API, but WellKnownFolderName.SentItems looks exactly like what you'd use in any other language, so I can only assume that it's correct.  What happens if you use other folders, such as JunkEmail (should be something in there, no doubt)?

It's not impossible that the Java API is broken, too.  I recently discovered a flaw in EWS replying to IPM.Post items in public folders.  The EWS SDK guy acknowledged the flaw, but said it was unlikely to be fixed since I was apparently the only person that had ever tried it :-)
Avatar of Absente

ASKER

I think it related to connection.


org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: Basic authentication scheme selected
microsoft.exchange.webservices.data.HttpErrorException: The remote server returned an error: (405)Method Not Allowed

I try to send mail. but I fail and i get same error.

org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: Basic authentication scheme selected
microsoft.exchange.webservices.data.HttpErrorException: The remote server returned an error: (405)Method Not Allowed
ASKER CERTIFIED SOLUTION
Avatar of LeeDerbyshire
LeeDerbyshire
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Absente

ASKER

Thanks LeeDerbyshire. My last problem wass weelknownfoldername.
I am in turkey.
I set to locate("English"). I solve. Thanks.
Avatar of Absente

ASKER

Thanks