There's a bug in the Java URL handling code, try using
http://<username>:<password>@<yourURL>:
The trailing colon won't hurt anything and it prevents Java's URL parser
from getting confused (you can also use :80)
(*Chris*)
----- Original Message -----
From: Navid Bazari <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, September 06, 1999 8:28 AM
Subject: Re: HttpURLConnection - Access Control Lists, URLs
> I've also been having a problem with ACLs and tried the code given below
but got
> these errors!
>
> Any clues as to why I am getting these errors? Also I can access the ACL
> protected urls by having the username and password embedded in the url
like so
> http://<username>:<password>@<yourURL>.
>
> This works fine when I type it in the browser but doesn't work within java
with
> URLConnection as it does something strange with the url.
> E.g. When I give this as my url in the java program,
> http://user:[EMAIL PROTECTED]/dir ...when it tries to make a url
connection it
> tries to connect to>>>>>> http://user/dir <<<<<< - any ideas!!!
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>> HERE ARE THE ERRORS I GOT when running the
sample
> prog. below...
>
> GetAuthURL.java:6: Class java.security.Permission not found in import.
> import java.security.Permission;
> ^
> GetAuthURL.java:22: ';' expected.
> URLConnection connection = url.openConnection();
> ^
> GetAuthURL.java:39: Superclass Authenticator of inner class GetAuthURL.
MyAuth
> not found.
> public class MyAuth extends Authenticator
> ^
> 3 errors
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
> Can you help?
>
>
> thanks, navid
>
>
>
> Java List <[EMAIL PROTECTED]> on 03/09/99 19:23:49
>
> Please respond to "A mailing list for discussion about Sun Microsystem's
Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>
> To: [EMAIL PROTECTED]
> cc: (bcc: Navid Bazari/UK/IBM)
> Subject: Re: HttpURLConnection
>
>
>
>
> Scott,
>
> I just had the same problem last week. Below is a copy of the code that
> worked for me, without needing to create any HTTP headers or do any Base64
> encoding! You'll need to update the URL and the passwd to your own.
>
> -Nash
>
> ---------------------
> import java.io.*;
> import java.util.*;
> import java.net.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.security.Permission;
>
> public class GetAuthURL extends HttpServlet {
>
> public void init(ServletConfig config) throws ServletException {
> super.init(config);
> }
>
> public void service(HttpServletRequest req, HttpServletResponse
res)
> throws ServletException, IOException {
>
> ServletOutputStream out = res.getOutputStream();
> HttpSession sesssion = req.getSession(false);
> URL url = new URL("http://www.yahoo.com"); ///put your ACL
> protected URL
> here
> URLConnection connection = url.openConnection();
> Authenticator.setDefault(new MyAuth());
> String contentType = connection.getContentType();
> res.setContentType(contentType);
> InputStream in = connection.getInputStream();
>
> char ch;
> int data = in.read();
> while (data != -1) {
> out.write(data);
> data = in.read();
> }
> out.close();
>
> }
>
> public class MyAuth extends Authenticator {
>
> protected PasswordAuthentication
getPasswordAuthentication() {
> String login = "bnash";
> char[] passwd = {'b','o','g','u','s','9','9','9'};
> return new PasswordAuthentication(login, passwd);
> }
> }
>
> }
>
> ------------------------
>
>
>
> [EMAIL PROTECTED] writes:
> >We're trying to get an HttpURLConnection to retrieve a document on a web
> >server that is ACL-protected by the listener. Is there a way to pass
> >authentication information with the request?
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html