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!

http client 3.1-beta1 : processWWWAuthChallenge error with NTLM auth

843833Mar 7 2007 — edited Sep 10 2008
HI FOLKS,

1) I am using http client 3.1-beta1.
get the following error .HttpMethodDirector =================================== processWWWAuthChallenge WARNING: Unable to respond to any of these challenges: {negotiate=Negotiate} from accessing a aspx page. when I run the sample java codes from the jarkarta project.

2) Is there something wrong with the codes ? ========================================

3) The error message is as follows :
=================================
 
Mar 7, 2007 9:18:19 AM org.apache.commons.httpclient.HttpMethodDirector processWWWAuthChallenge WARNING: Unable to respond to any of these challenges: {negotiate=Negotiate} HTTP/1.1 401 Unauthorized <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML><HEAD><TITLE>You are not authorized to view this page</TITLE> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252"> <STYLE type="text/css"> BODY { font: 8pt/12pt verdana } H1 { font: 13pt/15pt verdana } H2 { font: 8pt/12pt verdana } A:link { color: red } A:visited { color: maroon } </STYLE> </HEAD><BODY><TABLE width=500 border=0 cellspacing=10><TR><TD> <h1>You are not authorized to view this page</h1> You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept. <hr> 
Please try the following:

<ul> <li>Contact the Web site administrator if you believe you should be able to view this directory or page.</li> <li>Click the <a href="javascript:location.reload()">Refresh</a> button to try again with different credentials.</li> </ul> <h2>HTTP Error 401.2 - Unauthorized: Access is denied due to server configuration.<br>Internet Information Services (IIS)</h2> <hr> 
Technical Information (for support personnel)

<ul> <li>Go to <a href="http://go.microsoft.com/fwlink/?linkid=8180">Microsoft Product Support Services</a> and perform a title search for the words <b>HTTP</b> and <b>401</b>.</li> <li>Open <b>IIS Help</b>, which is accessible in IIS Manager (inetmgr), and search for topics titled <b>About Security</b>, <b>Authentication</b>, and <b>About Custom Error Messages</b>.</li> </ul> </TD></TR></TABLE></BODY></HTML>
4) My java snipplet codes is as follows : ==============================
public class SendHTTPRequest{

        public String ITOURL = "";
        public String paraList = "";


        public String[] resultListArray = null;
        public String result = null;
        StringBuffer getURLBuffer = new StringBuffer();
        public String getURL = null;



        public SendHTTPRequest (String url) {
               System.out.println ("Param ::" + url );
               ITOURL = new StringBuffer(url).toString();
               getURL = getURLBuffer.append(ITOURL).toString();
        }

        public String getgetURL() {
                return getURL;
        }
        public void setgetURL(String val) {
                getURL = val;
        }

        public SendHTTPRequest () {
        }

public StringBuffer invoke() throws Exception {

        NTCredentials credentials = new NTCredentials("limlo", "ilovemama2", "ldnpsr0131", "intranet");
        HttpURL cliGetURL = new org.apache.commons.httpclient.HttpURL (getURL);
        HttpClient client = new org.apache.commons.httpclient.HttpClient();

        List authPrefs = new ArrayList();
        authPrefs.add(AuthPolicy.NTLM);

        client.getState().setCredentials( AuthScope.ANY, credentials);
        client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);

        GetMethod httpget = new GetMethod ("http://platman");
        httpget.setDoAuthentication(true);

        try {

            int status = client.executeMethod(httpget);
            System.out.println( "Output" + httpget.getResponseBodyAsString());

            String reply = null;

            BufferedReader in = new BufferedReader ( new InputStreamReader(httpget.getResponseBodyAsStream()));
            StringBuffer resultBuffer = new StringBuffer("N");
            boolean firstTime = true;

            while ( (reply = in.readLine()) != null) {
               for (int x=0; x < resultListArray.length; x++) {
                   if (reply.indexOf(resultListArray[x]) >= 0) {
                        if (firstTime) {
                             resultBuffer = new StringBuffer();
                             firstTime = false;
                             resultBuffer.append(resultListArray[x]);
                        } else {
                             String currentBuffer = resultBuffer.toString();
                             if (currentBuffer.indexOf(resultListArray[x]) < 0) {
                                 resultBuffer.append(",");
                                 resultBuffer.append(resultListArray[x]);
                             }

  }
                   }
               }//end for
            }

            return resultBuffer;
        }
        catch(Exception e) {
          return null;
        }

        finally
        {
          // release any connection resources used by the method
          httpget.releaseConnection();
        }
  }

  public static void main(String [ ] args)
  {

        try {
              SendHTTPRequest httpRequest = new SendHTTPRequest (args[0]);
              StringBuffer resultBuffer = httpRequest.invoke();
              System.out.println (resultBuffer.toString());

        } catch (Exception e) {}
  }

}

 
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 8 2008
Added on Mar 7 2007
1 comment
462 views