*
The moose likes Sockets and Internet Protocols and the fly likes set userid in HTTP Request - URLStreamHandler, JEditorPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "set userid in HTTP Request - URLStreamHandler, JEditorPane" Watch "set userid in HTTP Request - URLStreamHandler, JEditorPane" New topic
Author

set userid in HTTP Request - URLStreamHandler, JEditorPane

Fran Varin
Greenhorn

Joined: Aug 08, 2003
Posts: 22
I have written a simple HTML browser application using JEditorPane. The setPage() function works great when I give it a simple string or URL object.

However, I have need to add the userid to the HTTP Request so that we can authenticate the user running the application. In looking at the URL JavaDoc the setter that includes the userid is not accessible on the public interface. According to what I have read, it appears that URLStreamHandler is apparently the only entity allowed to modify such data.

I've tried to envision a scenario where I might incorporate that into the JEditPane and setPage() but, I seem to be missing something. So, I'm looking for some guidance on how I might accomplish this. Has anyone accomplished this? Is there a sample or tutorial that I might look at?

thanks,
Fran Varin
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Are you using HTTP Authentication? That's covered by java.net.Authenticator. Read this article for the how-to. If you aren't using HTTP authentication and just want to log in to a web app, that has nothing to do with the Java API. The parameters for a request get appended to the url (as with any form post):


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Fran Varin
Greenhorn

Joined: Aug 08, 2003
Posts: 22
In my case the Authenticator object is not an option. We have a situation where another application will need to hit the same URL and cannot support handling a popup for authentication. So, I was researching the URL class and the setters their that allow the userid information to be included in the http request are not exposed. Also, the setPage() method on the JEditorPane does not seem to allow you to access the HTTP request information. What I would like to do is simply set the userid into the HTTP Request. But, I don't see a way to do that using the JEditorPane scenario. Here is a code snipit to give some idea of what it looks like:

try {
jep.setPage(urlString);
} catch (IOException e) {
JOptionPane.showMessageDialog(frame,
"IOException trying to setPage.\n msg: "+
e.getMessage()+"\n URL: "+urlString,
"AWF Administration ERROR",
JOptionPane.ERROR_MESSAGE);
System.err.println(e);
}

"jep" is an instance of JEditorPane. setPage() can take either a java.lang.String or URL object. All you need to do is call setPage() and
the page is retrieved. However, I don't know of a way to actually get at the HTTP Request header from here.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
The only way possible is to append userid with the urlstring in the format given above ie http://somepage.com/?uid=someid

That you can do by appending the userid beforehand to the urlstring and then doing the check on the webpage side.
If you have no server to run then you will have to use javascript to pick up the uid at opening of the page and redirect to error page if your javascript don't have the uid sent by the user.

Maki Jav
[ April 01, 2005: Message edited by: Maki Jav ]

Help gets you when you need it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: set userid in HTTP Request - URLStreamHandler, JEditorPane
 
Similar Threads
Form in NetBeans
Question about help file ,
Help Info.
Displaying a HTML file from a local file system(relative path) using JEditorPane?
JEditorPane and finding the page to load