Re: Barracuda: Updated HttpRequester

Jacob Kjome <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
Hi Shawn,


At 04:38 PM 12/11/2002 -0700, you wrote:
>Jake,
>
>I finally got around to finishing this up. I went ahead and utilized the 
>servlet Cookie class and created an HttpServices class to provide utility 
>cookie parsing and formatting methods (instead of extended 
>javax.servlet.http.Cookie).
>
>The updated code should pretty much support both Version 0 and Version 1 
>cookie specifications, though I haven't been able to thoroughly test it. 
>Search the attached files for "saw_121102.1" to see my changes.
>
>Christian told me he'll go ahead and incorporate this into CVS if all 
>looks well.
>
>Thanks,
>-shawn

Things look pretty good.  Looks like you've got some relatively robust code 
for dealing with raw Set-Cookie headers.  However, the one thing I'd add to 
HttpServices is a simple getCookie() method which returns a named cookie 
from an HttpServletRequest object.  This would be handy because the only 
method provide by the servlet api for getting cookies is an array of all 
Cookie objects.  When you only want a single cookie, it is a pain to have 
to do the following every time.  Might as well have this as a utility method.

public static Cookie getCookie(String cookieName, HttpServletRequest req) {
     if (cookieName == null || req == null) return null;
     Cookie cookie = null;
     Cookie[] cookies = req.getCookies();
     if (cookies!=null) {
         for (int i=0; i < cookies.length; i++) {
             if (cookies[i].getName().equals(cookieName)) {
                 cookie = cookies[i];
                 break;
             }
         }
     }
     return cookie;
}

Can you add that before checkin?  Thanks!


Jake
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.