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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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
LeeDerbyshireCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.