• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EWS : Transport error: 401 Error: Unauthorized

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I get the following Exception when trying to access a EWS Service from a java client using JAX-RPC:

Nov 5, 2009 5:53:34 PM org.apache.commons.httpclient.HttpMethodDirector authenticateHost
WARNING: Required credentials not available for BASIC <any realm>@abc.def.xyz:443
Nov 5, 2009 5:53:34 PM org.apache.commons.httpclient.HttpMethodDirector authenticateHost
WARNING: Preemptive authentication requested but no default credentials available
Nov 5, 2009 5:53:36 PM org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: NTLM authentication scheme selected
Nov 5, 2009 5:53:36 PM org.apache.commons.httpclient.HttpMethodDirector processWWWAuthChallenge
INFO: No credentials available for NTLM <any realm>@abc.def.xyz:443
Nov 5, 2009 5:53:36 PM org.apache.axis2.transport.http.HTTPSender sendViaPost
INFO: Unable to sendViaPost to url[https://abc.def.xyz/EWS/Exchange.asmx]
org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:295)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:190)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:389)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:222)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.microsoft.schemas.exchange.services._2006.messages.ExchangeWebServiceStub.FindFolder(ExchangeWebServiceStub.java:8768)
at com.client.ExchangeClient.findFolder(ExchangeClient.java:208)
at com.client.ExchangeClient.execute(ExchangeClient.java:160)
at com.client.ExchangeClient.main(ExchangeClient.java:52)

This is the source cde:

public class ExchangeClient {

public void execute() {

...
try {
/***** Keystore Setting *****/

System.setProperty("javax.net.ssl.trustStore", "key.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "pwd");
// This is the STUB generated using AXIS WSDL 2 JAVA //
ExchangeWebServiceStub serviceStub = new ExchangeWebServiceStub(wsdlURL);
/***** Setting Trust Issues *****/
TrustManager[] trustAllCerts = new TrustManager[] { trustAllCerts() };
sslContextGenerator(trustAllCerts);

/***** Setting Authenticator *****/
List authScheme = new ArrayList();
authScheme.add(Authenticator.NTLM);
Authenticator authenticator = new Authenticator();
authenticator.setAuthSchemes(authScheme);
authenticator.setUsername("aaa");
authenticator.setPassword("eee");
authenticator.setHost("HOST");
authenticator.setDomain("DOMAIN");
authenticator.setPort(443);
authenticator.setAllowedRetry(true);
authenticator.setPreemptiveAuthentication(true);

/***** Setting Options *****/
Options options = serviceStub._getServiceClient().getOptions();
options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
options.setTransportInProtocol("https");
options.setTo(new EndpointReference("https://abc.def.com/EWS/Exchange.asmx"));
serviceStub._getServiceClient().setOptions(options);

/***********************/
//Find folder
findFolder(serviceStub);
} catch (Exception e) {
e.printStackTrace();
}
}

private void findFolder(ExchangeWebServiceStub serviceStub)
throws RemoteException {
// SerializedSecurityContext
SerializedSecurityContext ssc = new SerializedSecurityContext();
SerializedSecurityContextType param3 = new SerializedSecurityContextType();
param3.setUserSid("aaa");
ssc.setSerializedSecurityContext(param3);

// MailboxCulture
MailboxCulture mbc = new MailboxCulture();
Language param4 = new Language();
mbc.setMailboxCulture(param4);

FindFolder find = new FindFolder();
FindFolderType fft = new FindFolderType();
FolderQueryTraversalType fqt = new FolderQueryTraversalType("", true);
fft.setTraversal(fqt);
FolderResponseShapeType frst = new FolderResponseShapeType();
frst.setBaseShape(DefaultShapeNamesType.AllProperties);
fft.setFolderShape(frst);
NonEmptyArrayOfBaseFolderIdsType neaobft = new NonEmptyArrayOfBaseFolderIdsType();
NonEmptyArrayOfBaseFolderIdsTypeChoice[] param = new NonEmptyArrayOfBaseFolderIdsTypeChoice [1];
param[0] = new NonEmptyArrayOfBaseFolderIdsTypeChoice();
neaobft.setNonEmptyArrayOfBaseFolderIdsTypeChoice(param);
fft.setParentFolderIds(neaobft);
find.setFindFolder(fft);

// ExchangeImpersonation
ExchangeImpersonation ei = new ExchangeImpersonation();
ExchangeImpersonationType param2 = new ExchangeImpersonationType();
ConnectingSIDType sid = new ConnectingSIDType();
param2.setConnectingSID(sid);
ei.setExchangeImpersonation(param2);

RequestServerVersion rsv = new RequestServerVersion();
rsv.setVersion(ExchangeVersionType.Exchange2007_SP1);

serviceStub.FindFolder(find, ei, ssc, mbc, rsv);
}


private static void sslContextGenerator(TrustManager[] trustAllCerts) {
try {
SSLContext sc;
sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());

// For certificate issues
HttpsURLConnection
.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (KeyManagementException e1) {
e1.printStackTrace();
}
HttpsURLConnection.setFollowRedirects(false);
}


private static X509TrustManager trustAllCerts() {
return new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}

public void checkClientTrusted(final X509Certificate[] certs,
final String authType) {

}

public void checkServerTrusted(
final java.security.cert.X509Certificate[] certs,
final String authType) {

}
};
}
}

I have very less idea why this is happening. The credentials are correct. Please let me know your thoughts on the same.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It appears that it did not accept your authentication scheme (Basic Auth).

If the web service supports integrated windows authentication or kerberos, you should be able to use the client from this open source library...

http://spnego.sourceforge.net/protected_soap_service.html
reply
    Bookmark Topic Watch Topic
  • New Topic