How to authenticate in a Domino server using the Java URLConnection object

I would like to access forms and views through the URLConnection object in Java, but these pages are secure, so need authentication.
How do I log in once and I do not need to authenticate when accessing the other pages?
guilhermeclenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
httpclient is a better tool for doing that sort of thing

0
Mick BarryJava DeveloperCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
guilhermeclenAuthor Commented:
It was a good tip, but when I test returned the following error when trying to instantiate the HTTPClient object:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
      at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:66)
      at UrlReader2.main(UrlReader2.java:11)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClassInternal(Unknown Source)
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
 
public class UrlReader2 {
 
	public static void main(String[] args) {
		HttpClient client = new HttpClient();
		client.getState().setCredentials(
	            new AuthScope("www.verisign.com", 443, "realm"),
	            new UsernamePasswordCredentials("[username]", "[password]")
	        );
		GetMethod get = new GetMethod("https://extranet.bbraun.com.br/extranet/pedidoweb.nsf/($fo_gridview)?OpenForm");
 
		get.setDoAuthentication( true );
 
        try {
            int status = client.executeMethod( get );
            System.out.println(status + "\n" + get.getResponseBodyAsString());
        } catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
            get.releaseConnection();
        }
 
	}
 
}

Open in new window

0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Mick BarryJava DeveloperCommented:
it uses commons logging, can download it here
http://commons.apache.org/logging/

0
guilhermeclenAuthor Commented:
I added the libraries, but now has the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
      at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
      at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
      at UrlReader2.main(UrlReader2.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClassInternal(Unknown Source)
      ... 3 more
0
Mick BarryJava DeveloperCommented:
and commons codec :)

http://commons.apache.org/codec/

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.