hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srinivasch <sri...@gmail.com>
Subject Re: Authentication Help needed. Urgent
Date Thu, 16 Apr 2009 15:11:05 GMT

Please help I am unable to authenticate. I get 401 Authentication Error with
the error stack as below

Apr 16, 2009 11:03:19 AM
org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: basic authentication scheme selected
Apr 16, 2009 11:03:52 AM org.apache.commons.httpclient.HttpMethodDirector
processWWWAuthChallenge
INFO: Failure authenticating with BASIC 'CICS application ABDRT   
'@xyz.com:8303
Apr 16, 2009 11:03:52 AM org.apache.commons.httpclient.HttpMethodBase
getResponseBody
WARNING: Going to buffer response body of large or unknown size. Using
getResponseBodyAsStream instead is recommended.
Status401
response as String  <H1>401 Basic Authentication Error</H1>
[#document: null]
<?xml version="1.0" encoding="UTF-8"?>
<H1>401 Basic Authentication Error</H1>


My program is as follows


public class ClientConnection {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		
        HttpClient client = new HttpClient();
     
        String encodedLoginCredentials1 = new
sun.misc.BASE64Encoder().encode("opensesame".getBytes());
		String encodedLoginCredentials2 = new
sun.misc.BASE64Encoder().encode("opensesame".getBytes());
		HttpState state = client.getState();
		AuthScope scope = new AuthScope("xyz.com", 8303);
		UsernamePasswordCredentials cred = new
UsernamePasswordCredentials(encodedLoginCredentials1+":"+encodedLoginCredentials2);
		state.setCredentials(scope, cred);
		client.setState(state);
		
	

        // create a GET method that reads a file over HTTPS, we're assuming
        // that this file requires basic authentication using the realm
above.
        PostMethod post = new
PostMethod("http://xyz.com:8303/CICS/CWBA/ABDPIQ22");
        HttpMethodParams httpParams = post.getParams();
        httpParams.setParameter("http.useragent", "Test Client");
        httpParams.setParameter("Input_calling_program", "RESENDER");
       
        post.setParams(httpParams);
        post.setDoAuthentication( true );
        
        Transformer transformer;
		StreamResult result;
		DOMSource source;
        

        try {
            // execute the GET
            int status = client.executeMethod( post );

            // print the status and response
            System.out.println("Status"  +   status + "\n" + "response as
String  "+ post.getResponseBodyAsString());
            DocumentBuilder parser;
            Document myXMLdoc;
            DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
            parser = factory.newDocumentBuilder();
            myXMLdoc = parser.parse(post.getResponseBodyAsStream());
            System.out.println(myXMLdoc.toString());
            
            transformer = TransformerFactory.newInstance().newTransformer();
			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
			result = new StreamResult(new StringWriter());
			source = new DOMSource(myXMLdoc);
			transformer.transform(source, result);
			String xmlString = result.getWriter().toString();
			System.out.println(xmlString);

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

-- 
View this message in context: http://www.nabble.com/Authentication-Help-needed.-Urgent-tp22974079p23079974.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message