Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reg : Accessing Microsoft Exchange web services through Java

843833Sep 16 2009 — edited Dec 22 2010
Hello Everyone ,

I am accessing Microsoft exchange web services to validate an email account in Exchange server.

I am pasting the SOAP request i have prepared for this below. Here the operation i am using is not important for me , i need to validate the email acount username and password given in the Authentication detail. thats where I would require help.

SOAP Request :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2007_SP1"/></soap:Header>
<soap:Body>
<ResolveNames xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" ReturnFullContactData="false"><UnresolvedEntry>venkat</UnresolvedEntry></ResolveNames></soap:Body>
</soap:Envelope>

Response :
Not receiving valid response , but exception message with this

Sep 16, 2009 11:03:55 AM com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection post
SEVERE: SAAJ0008: Bad Response; Unauthorized
com.sun.xml.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Bad response: (401Unauthorized
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:127)
at WebServiceHelper.callRemoteProc(WebServiceHelper.java:75)
at ESWebServiceAccess.prepare1(ESWebServiceAccess.java:146)
at ESWebServiceAccess.main(ESWebServiceAccess.java:29)
Caused by: java.security.PrivilegedActionException: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Bad response: (401Unauthorized
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:121)
... 3 more
Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Bad response: (401Unauthorized
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:304)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(HttpSOAPConnection.java:150)
... 5 more
.
.
.

I know this unauthorized 401 message is because of Authentication info is not set properly .

The same SOAP message prepared in .Net and there authentication information is set using this below API :

NetworkCredential oCredentials;
oCredentials = new NetworkCredential("Venkat.sundarraman" /*username*/, "Password1" /*password*/);

I tried to set username and password using SOAPMessage setProperty API here
request.setProperty("UserName", "Venkat.sundarraman");
request.setProperty("Password", "Password1");

Can you let me know what is the equivalent API I can use in Java for NetworkCredential in .Net ? or anyother way i can try out to set username , password to get the proper SOAP Response ?

Thanks,
Venkat.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 19 2011
Added on Sep 16 2009
8 comments
3,243 views