Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Dev Blog - Johan Danforth

I'm Johan Danforth and this is my dev blog - a mix of .NET, ASP.NET, Rest, Azure and some other random coding stuff.

  • [Java] More about cookies in Vignette Application Portal (VAP)

    Another blog post about cookies in VAP...

    Other ways of setting cookies from a portlet?

    I got this message from Sascha about setting cookies from a VAP portlet:

    Hi, I've read you log about setting cookie in a portlet. First, I thought so too, but there actually _is_ a way to set a cookie from a VAP Portlet: you have to get the original HttpServletRequest from the HttpServletRequestWrapper instance in your JSP:

    public static HttpServletResponse getOriginalResponse(HttpServletResponse response) {
       HttpServletResponse result = response;
       if (response instanceof HttpServletResponseWrapper) {
          response = (HttpServletResponse)((HttpServletResponseWrapper) response).getResponse();
          result = getOriginalResponse( response );
       }
       return result;
    }

    I tried this, but from a JSP page in a JSR168 solution it doesn't seem to work. I think maybe Sascha meant a VAP specific portlet/module and not a JSR168 portlet. As far as I understand it, the HTTP headers have already been written when the portlet starts to execute, so it's too late.

    I got another obvious way of setting cookies from a portlet - do it from a client-side javascript:

    Setting cookie through javascript:

    <script>

    document.cookie = "jscriptcookie=testvalue";

    </script>

    This obviously works fine and you can also get cookies this way, but again, what I'm really after is a way to both get and set cookies from within a portlat class scope, say for example in the processAction() method. Below I have a way of getting a cookie from there, but setting it still seems to be impossible.

    A better way of getting cookies from within a portlet class

    Earlier we've had to grab cookies from a JSP page in a JSR168 portlet solution, but a friend of mine found out that VAP actually adds the "cookie" http header(s) to the PortletRequest properties collection, according to the JSR168 spec, section PLT.11.1.4. So from within a JSR168 portlet it's quite simple to get the cookies from the RenderRequest.getProperties("cookie"). Thank you Vignette, now make sure all future versions of VAP does the same please :)

  • [NET 2.0] Master Pages - Most useful feature in ASP.NET 2.0?

    I've started to read up on the new stuff in .NET 2.0 to prepare myself for the PDC, especially the ASP.NET stuff, and I must say that so far the most useful thing I've looked at is Master Pages. I've used the Wilson Master Pages in previous versions of ASP.NET and it has helped us much, but now in 2.0 with the intergration with the IDE it's just plain beautiful.

    I think the Master Pages feature will be used in a majority of the web sites out there in the future, don't you think?

  • Counting the days to the PDC

    Ah, back from vacation and haven't written anything in my blog for a long time now. Not long now until the PDC. Looks like I'll have 3-4 swedish buddies of mine visiting LA as well - it will be great! Have to sit down and plan my schedule on-line. According to the information on the webby, you should be able to have the schedul on your pocket pc! Have to have that!
  • [Books][.NET 2.0] Recommended .NET 2.0 books?

    I need your help. I'm going to the PDC and I need to read up on various .NET 2.0 stuff before going there, to get most out of it. ASP.NET and Web Services/Interop is my main focus, so if someone out there knows of a really good book to read, please comment. I got a few books that I've read already, like the "A First Look at ASP.NET v2.0" by Homer/Sussman/Howard, but I'm sure there are more updated ones.

    Thanks!

  • [PDC] Booked!

    I did my registration to the PDC today, it will be so interesting and fun going there. There will be so many cool tracks and session, it'll be a tough time figuring out which ones to attend to. When I get back I'll have to do some "awareness sessions" for my mates at work, but I don't mind at all doing that.

    It seems there will be lots of Swedish people going over the pond this time, so LA watch out :) The last time I was at the PDC I didn't get any chance to see anything of LA except for the Convention Center and the hotel. This time I'll try to go there a day or so ahead. 

  • Xml from a directory structure

    I needed to generate an XML document that showed all directories and html files in a certain folder and the folders below that. This is what I quickly wipped up:

    using System;

    using System.IO;

    using System.Xml;

     

    namespace MenuBuilder

    {

               /// <summary>

               /// Summary description for MenuBuilder.

               /// </summary>

               public class MenuBuilder

               {

                          public static void Main(string[] args)

                          {

                                     Console.WriteLine("Starting...");

     

                                     XmlDocument doc = new XmlDocument();

                                     doc.LoadXml("<directory>" +

                                                "</directory>");

     

                                     //recurse through directories and return XmlNodes

                                     XmlElement elem = GetData(@"c:\temp", doc);

                                     doc.DocumentElement.AppendChild(elem);

     

                                     doc.Save(@"c:\temp\dir.xml");

                          }

     

                          private static XmlElement GetData(string dirName, XmlDocument doc)

                          {

                                     //create a new node for this directory

                                     XmlElement elem = doc.CreateElement("dir");

                                     DirectoryInfo di = new DirectoryInfo(dirName);

                                     elem.SetAttribute("name",di.Name);

     

                                     foreach (DirectoryInfo dinf in di.GetDirectories())

                                     {

                                                //Recursively call the directory with all underlying dirs and files

                                                XmlElement elemDir = GetData(dirName + "\\" + dinf.Name, doc);

                                                elem.AppendChild(elemDir);

                                     }

     

                                     //Append the files in this directory to the current xml node

                                     foreach (FileInfo finf in di.GetFiles("*.htm*"))

                                     {

                                                XmlElement elemDir = doc.CreateElement("file");

                                                elemDir.SetAttribute("name",finf.Name);

                                                elem.AppendChild(elemDir);

                                     }

     

                                     return elem;

                          }

               }

    }

     

     

  • Back from vacation

    Back from 2 weeks of vacation in Turkey (Alanya) - probably the best vacation we've had. Great hotel, great staff, great weather. Apart from waking up at 4:30am from the pre-recorded morning prayers they play out from the top of the minaretes at maximum volume every morning I've got nothing to complain on :)

    Just a pile of e-mails to dig through now.... yack.

    I got several mails from my friend Jan-Erik about news in JCP, guess I have to check them out.