browser cookies from Java

817 views
Skip to first unread message

carljmosca

unread,
Feb 6, 2009, 12:15:59 PM2/6/09
to The Java Posse
Does anyone know of a library which will let me examine a browser's
cookies? I think it goes w/o saying I am wanting to do this in a
platform independent manner. :)

I have seen a few code snippets which will let me find the OS and
default browser and I realize Java will now launch the browser given a
URL (very nice, I use this a good bit).

What I have not found (I just started looking) is a way to find a
given cookie value. I realize I may have to roll my own and there are
some good starting points but if someone already knows of a nice
library which will do this I would like to use it.

TIA,
Carl

Van Riper

unread,
Feb 6, 2009, 3:42:52 PM2/6/09
to java...@googlegroups.com
On Fri, Feb 6, 2009 at 9:15 AM, carljmosca <carlj...@gmail.com> wrote:
> Does anyone know of a library which will let me examine a browser's
> cookies? I think it goes w/o saying I am wanting to do this in a
> platform independent manner. :)

At my company, we write a lot of spiders in Java. We are very happy
with Jakarta Commons HttpClient:

http://hc.apache.org/httpclient-3.x/

The support for retrieving browser cookies is well documented here:

http://hc.apache.org/httpclient-3.x/cookies.html

Although I have never looked at it myself, there is CookieDemoApp
checked into the code samples section of the project too:

http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/

Cheers, Van

--
| Michael "Van" Riper
| http://weblogs.java.net/blog/van_riper/
| http://www.linkedin.com/in/vanriper
----
| Silicon Valley Web JUG
| mailto:van_...@dev.java.net
| https://sv-web-jug.dev.java.net
----
| Silicon Valley Google Technology User Group
| mailto:van....@gmail.com
| http://sv-gtug.org

Marcelo Morales

unread,
Feb 6, 2009, 9:21:38 PM2/6/09
to java...@googlegroups.com
Hello

On Fri, Feb 6, 2009 at 1:15 PM, carljmosca <carlj...@gmail.com> wrote:
> Does anyone know of a library which will let me examine a browser's
> cookies? I think it goes w/o saying I am wanting to do this in a
> platform independent manner. :)

It should NOT be possible to examine browser cookies from an applet.
It would be a serious security issue. There is no other
platform-independent relation with the browser AFAIK.
So, I believe you can only tap onto the filesystem and work on a per
os, per browser, per version, per profile fashion.
Quite a problem I say.

regards

--
Marcelo Morales

carljmosca

unread,
Feb 7, 2009, 10:39:01 AM2/7/09
to The Java Posse

Not that it matters to your point but I am writing an application, not
an applet.

Still I am aware of the security implications.

Thank you.

carljmosca

unread,
Feb 7, 2009, 10:40:40 AM2/7/09
to The Java Posse
Yes, this is a nice library and I have used it in the past but I will
have to take a closer look. I am not sure it offers what I am after.

I want to examine the a browser's cookies from a Java application.

On Feb 6, 3:42 pm, Van Riper <van.ri...@gmail.com> wrote:
> On Fri, Feb 6, 2009 at 9:15 AM, carljmosca <carljmo...@gmail.com> wrote:
> > Does anyone know of a library which will let me examine a browser's
> > cookies?  I think it goes w/o saying I am wanting to do this in a
> > platform independent manner. :)
>
> At my company, we write a lot of spiders in Java. We are very happy
> with Jakarta Commons HttpClient:
>
> http://hc.apache.org/httpclient-3.x/
>
> The support for retrieving browser cookies is well documented here:
>
> http://hc.apache.org/httpclient-3.x/cookies.html
>
> Although I have never looked at it myself, there is CookieDemoApp
> checked into the code samples section of the project too:
>
> http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/
>
> Cheers, Van
>
> --
> | Michael "Van" Riper
> |http://weblogs.java.net/blog/van_riper/
> |http://www.linkedin.com/in/vanriper
> ----
> | Silicon Valley Web JUG
> | mailto:van_ri...@dev.java.net
> |https://sv-web-jug.dev.java.net
> ----
> | Silicon Valley Google Technology User Group
> | mailto:van.g...@gmail.com
> |http://sv-gtug.org

Marcelo Morales

unread,
Feb 7, 2009, 6:28:06 PM2/7/09
to java...@googlegroups.com
Firefox 3 uses sqlite to store cookies. Earlier mozillas used text files.
The Sqlite database contains only one table. The structure is:
moz_cookies (id INTEGER, name TEXT, value TEXT, host TEXT, path
TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER,
isHttpOnly INTEGER)
I don't think several processes can access the same database (I could
be wrong). So you will have to copy the database file and use
something like http://zentus.com/sqlitejdbc/ to access the data.
Webkit, IE, Chrome, older mozillas, etc. use different schemes. Is a
plug-in architecture called for?
--
Marcelo Morales

Steven Herod

unread,
Feb 7, 2009, 7:25:08 PM2/7/09
to The Java Posse
I've used that library and simulated up to 40 clients reading and
writing from an sqlite db. Unless moz is doing some thing unusual
sqlite only locks on write operations and the lock handling approach
is to just keep trying until it works.

Best of luck.

On Feb 8, 10:28 am, Marcelo Morales <marcelomorales.n...@gmail.com>
wrote:
> Firefox 3 uses sqlite to store cookies. Earlier mozillas used text files.
> The Sqlite database contains only one table. The structure is:
> moz_cookies (id INTEGER, name TEXT, value TEXT, host TEXT, path
> TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER,
> isHttpOnly INTEGER)
> I don't think several processes can access the same database (I could
> be wrong). So you will have to copy the database file and use
> something likehttp://zentus.com/sqlitejdbc/to access the data.

carljmosca

unread,
Feb 8, 2009, 8:14:07 AM2/8/09
to The Java Posse
Cool. Thank you both for the insight.

On Feb 7, 7:25 pm, Steven Herod <steven.he...@gmail.com> wrote:
> I've used that library and simulated up to 40 clients reading and
> writing from an sqlite db. Unless moz is doing some thing unusual
> sqlite only locks on write operations and the lock handling approach
> is to just keep trying until it works.
>
> Best of luck.
>
> On Feb 8, 10:28 am, Marcelo Morales <marcelomorales.n...@gmail.com>
> wrote:
>
> > Firefox 3 uses sqlite to store cookies. Earlier mozillas used text files.
> > The Sqlite database contains only one table. The structure is:
> > moz_cookies (id INTEGER, name TEXT, value TEXT, host TEXT, path
> > TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER,
> > isHttpOnly INTEGER)
> > I don't think several processes can access the same database (I could
> > be wrong). So you will have to copy the database file and use
> > something likehttp://zentus.com/sqlitejdbc/toaccess the data.
Reply all
Reply to author
Forward
0 new messages