"(401)Authorization Required" when making a web service call using Axis

Posted by Arun P Johny on Stack Overflow See other posts from Stack Overflow or by Arun P Johny
Published on 2010-03-15T05:32:28Z Indexed on 2010/03/15 5:39 UTC
Read the original article Hit count: 1588

Hi,

I'm using apache axis to connect to my sugar crm instance. When I'm trying to connect to the instance it is throwing the following exception

     Exception in thread "main" AxisFault
  faultCode: {http://xml.apache.org/axis/}HTTP
  faultSubcode: 
  faultString: (401)Authorization Required
  faultActor: 
  faultNode: 
  faultDetail: 
  {}:return code:  401
 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
 <html><head>
 <title>401 Authorization Required</title>
 </head><body>
 <h1>Authorization Required</h1>
 <p>This server could not verify that you
 are authorized to access the document
 requested.  Either you supplied the wrong
 credentials (e.g., bad password), or your
 browser doesn't understand how to supply
 the credentials required.</p>
 </body></html>

  {http://xml.apache.org/axis/}HttpErrorCode:401

 (401)Authorization Required
  at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
  at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
  at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
  at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
  at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
  at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
  at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
  at org.apache.axis.client.Call.invoke(Call.java:2767)
  at org.apache.axis.client.Call.invoke(Call.java:2443)
  at org.apache.axis.client.Call.invoke(Call.java:2366)
  at org.apache.axis.client.Call.invoke(Call.java:1812)
  at org.beanizer.sugarcrm.SugarsoapBindingStub.get_server_info(SugarsoapBindingStub.java:1115)
  at com.greytip.sugarcrm.GreytipCrm.main(GreytipCrm.java:42)

This basically says that I do not have the authorization to the resource. The same code is working fine in my testing environment.

Sugarsoap service = new SugarsoapLocator();
  SugarsoapPortType port = service.getsugarsoapPort(new java.net.URL(
    SUGAR_CRM_LOCATION + "/soap.php"));

       System.out.println(port.get_server_info().getVersion());

  User_auth userAuth = new User_auth();
  userAuth.setUser_name("user_name");
  MessageDigest md = MessageDigest.getInstance("MD5");
  String password = getHexString(md.digest("password".getBytes()));
  userAuth.setPassword(password);
  // userAuth.setVersion("0.1");
  Entry_value login = port.login(userAuth, "myAppName", null);
  String sessionID = login.getId();

Above code is used to connect to the Sugar CRM installation. here line "System.out.println(port.get_server_info().getVersion());" is throwing the exception.

One difference I noticed between the test and production environment is when I used the soap url in the browser the production site pops up a 'Authentication Required' popup.

When I gives my proxy username and password in this popup, it shows the soap request details. The same is applicable for the login url also. First it will ask for the 'Authentication' then it will take to the sugar crm login page?

Is it a server security setting? If it is then how to set this user name and password using java in a web service call.

The authentication required popup is same as the one which comes when we try to access the tomcat manager through a browser.

Thanks

© Stack Overflow or respective owner

Related posts about apache-axis

Related posts about axis