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?
AbsenteAsked:
Who is Participating?
 
LeeDerbyshireConnect With a Mentor Commented:
This is a different error altogether.  In the sentitems problem, the server has at least accepted the request, and has begun to process it, but for some reason it doesn't recognise the well-known folder name.  This 405 thing is saying that the verb sent by the request object that the Java API is using is not allowed.  But all EWS requests use the POST verb, so I can't imagine what's happening here.  It might help to look at the IIS log file, and see what verb it's trying to use.  Like I say, I've not used the Java API, but I don't think you are going to have the opportunity to tell it for yourself which verb to use.
0
 
AbsenteAuthor Commented:
any answer ?
0
 
LeeDerbyshireCommented:
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.
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
AbsenteAuthor Commented:
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)
0
 
LeeDerbyshireCommented:
I don't see any code in your OP that accesses the sent items folder.  Has it changed since?
0
 
AbsenteAuthor Commented:
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)

0
 
LeeDerbyshireCommented:
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 :-)
0
 
AbsenteAuthor Commented:
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
0
 
AbsenteAuthor Commented:
Thanks LeeDerbyshire. My last problem wass weelknownfoldername.
I am in turkey.
I set to locate("English"). I solve. Thanks.
0
 
AbsenteAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.