TCLUG Development Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG-DEVEL:300] User Auth in Java
Bob Tanner wrote:
>
> Quoting Perry Hoekstra (dutchman@uswest.net):
> > Greet the sun all:
> >
> > Quick question, has anybody worked with user authentication within the
> > context of the URLConnection/HttpURLConnection classes?
> >
>
> Yes, under Tomcat.
>
> With Tomcat 3.2dev there is a big ol'bug.
>
> What is the specific question.
I am trying to get the following chunk of code to work but I get a
connection refused error:
URL t_serverURL = new URL("http://www.somewhere.com/invoke");
HttpURLConnection t_urlConnection =
(HttpURLConnection)t_serverURL.openConnection();
t_urlConnection.setRequestProperty("CONTENT-TYPE",
"application/x-www-form-urlencoded");
String t_userLogin = "username" + ":" + "password";
String t_authEncoding = new sun.misc.BASE64Encoder().encode
(t_userLogin.getBytes());
t_urlConnection.setRequestProperty("Authorization", "Basic " +
t_authEncoding);
t_urlConnection.setRequestMethod("POST");
t_urlConnection.setDoOutput(true);
PrintWriter t_postOutputStream = new
PrintWriter(t_urlConnection.getOutputStream());
StringBuffer t_stringBuffer = new StringBuffer(MESSAGE_KEY);
t_stringBuffer.append("=");
t_stringBuffer.append(java.net.URLEncoder.encode("Hello World"));
t_postOutputStream.println(t_stringBuffer.toString());
t_postOutputStream.close();
InputStream t_inputStream = t_urlConnection.getInputStream();
if (t_inputStream != null) {
BufferedReader t_bufferedReader = new BufferedReader(new
InputStreamReader(t_inputStream));
String t_nextLine = null;
t_nextLine = t_bufferedReader.readLine();
while (t_nextLine != null) {
t_nextLine = t_bufferedReader.readLine();
}
System.out.println(" Sent message ...");
}
else {
System.out.println(" Could not retrieve an InputStream from the
connection");
System.exit(-1);
}
I am trying to figure out if it is my stuff or WebMethods.
--
Perry Hoekstra
E-Commerce Architect
Talent Software Services
dutchman@mn.uswest.net