July 06, 2012

SVN Username Mysteriously Changes on Windows

Introduction

While using SVN, I recently noticed my commits to the repository were no longer using my computer login username.  Somehow, something happened to tell SVN to use a different username.  If you are using Windows for you development environment and you have run into this issue, this article will give you hints on where to look to fix it.

Subversion's "Application Data"

I am running the Window's SVN client SlikSVN v1.6.1.  After running the Maven release plugin on my project, I noticed commits to the SVN repository were no longer using my computer login username, but were instead using the username associated with running the Maven release plugin.  Since not all users are given Nexus permissions to write releases, the Maven release plugin needs to be executed with a different username.  SlikSVN somehow "remembered" this username and all commits to the SVN repository after that were using it.  This is of course a major problem because looking back through the SVN history it is not possible to determine who really made the changes.

After searching online for this problem, I spent some time running through the "Application Data" directory.  I eventually found this directory:
XP: "C:\Documents and Settings\[username]\Application Data\Subversion\auth\svn.simple"
7: "C:\Users\[username]\AppData\Roaming\Subversion\auth\svn.simple"
Inside this directory is what looks like a randomly generated file:
42a1ce589862a9b8acde6133f937c22d
With contents that looks like this:
K 8
passtype
V 8
wincrypt
K 8
password
V 280
[SOME_ENCRYPTED_PASSWORD]
K 15
svn:realmstring
V 28
<http://bjcesinf03:80> crowd
K 8
username
V 14
[SOME_SVN_USERNAME]
END

The [SOME_SVN_USERNAME] was my problem. 

The solution is to delete this file.

Summary

If you are running Windows and your SVN username mysteriously becomes something else when performing commits to the repository, try going to this directory:
 "C:\Documents and Settings\[username]\Application Data\Subversion\auth\svn.simple"
and delete the randomly generated file in this directory which contains the username.

Enjoy!

June 14, 2012

Spring Not Setting Cookie On AJAX Response

Overview

I was working on a problem where any request to a Spring Controller needed to have a Cookie set on its response.  Normal page to page navigation worked fine, but I noticed some (not all) of the of AJAX responses were missing the Cookie.  Even though I verified through log files and stepping through the code that the Cookie was being set on the Response, once the AJAX Response got back to the browser, there was no Cookie.  This article describes how I was able to configure Spring to always return a Cookie on a Spring Controller AJAX Response.

CookieInterceptor

A class was created in the project  which was responsible for setting the cookie on the Response.  Call  this class CookieInterceptor and have it implement the org.springframework.web.servlet.HandlerInterceptor interface.  A Spring Intecepter is similar to an Java EE Filter in that it allows the request and response to be intercepted and cross cutting concerns be added in the Interceptor instead of adding them to every Controller.  In my case, the cross cutting concern was to make sure the Response always had an updated value set for a Cookie.  I implemented HandlerInterceptor interface and added the code to set the Cookie in the postHandle() method.

Registering the Interceptor with Spring is easy:

<mvc:interceptors>
   <bean id="cookieInterceptor" class="com.widgit.CookieInterceptor"/>
</mvc:interceptors>

Testing

After creating CookieInterceptor and registering it with Spring, I performed some testing.  Navigating from page to page the Cookie value was found in the Response and the browser was getting the new Cookie as it should.

...however...

When testing AJAX calls, I got mixed results.  If  the Controller used the @ResponseBody  annotation to return the AJAX Response, I saw no Cookie in the Response.  However, if the Controller did NOT use @ResponseBody but instead returned a view string which was turned into a JSON object later, I did get the Cookie.  In all cases, I verified through log files and stepping through the code that the code for the CookieInterceptor was being called and the cookie was being set.  So why was one case getting the Cookie, and the other case not getting the Cookie?

Content-Type

A difference I saw in the responses had to do with the Response Content-Type.  When using the @ResponsBody annotation, the Response had a Content-Type="application/json".  However using other methods to return  the responses, the Response had a Content-type="text/html".  When the Content-Type was application/json no Cookie was set however when the Content-Type was text/html, the Cookie was there.  But why was this?

A Matter of Timing

At first I thought perhaps a Cookie could not be set on a Response of type application/json.  Research showed this was not the case.  So instead I turned to the CookieInterceptor.  The implementation had the Cookie setting code in the postHandle() method and even though this code was always being run, The Cookie was not being set when the Controller used @ResponseBody.  Through some research, my colleague Joseph Flatt thought this might be a matter of timing, meaning that for some reason when @ResponsBody was used to return the Response by the time you got back to running the code in the CookieInterceptor it was too late to make any changes to the Response: Perhaps the response had already been written.  So instead of using the postHandle() method, we tested using the preHandle() method.  Moving the Cookie setting code to the preHandle() method worked!  The Cookie was properly set on all Controller requests regardless of the request being page to page navigation or AJAX calls.

Conclusion

If you want Spring to set a Cookie on ALL requests to Controllers - whether they be page to page requests or AJAX calls, put your code in the preHandle() method of the  HandlerInterceptor interface.




May 18, 2012

Yahoo! Mail Signatures With Pictures

Introduction

Do you use Yahoo! Mail?  Do you want to create a signature for you emails which includes images?  I wanted to create a signature with an image to go and view my LinkedIn account, but every time I tried to create the signature the image would never appear.  I finally figured out the trick.  Read on.

How To

To include an image in your Yahoo! Mail signature is actually very easy, however you need to do it in the right way otherwise it will not work.  This is what you need to do.
  1. Go to your Yahoo! Mail options and select Signature.
  2. Select "Show a rich text signature" from the dropdown box.
  3. Go to the website which has your image, right click the image on the website, and select "copy image". This is the trick!  You cannot simply copy an image from your desktop.  You must Go to the website which has your image, right click the image on the website, and select "copy image".  If the image you want is not on any website, see below for what to do about that...
  4. Go back to the Signature, put the cursor where you want to have the image, right-click and paste.
That's it.  Again, the trick is you must Go to the website which has your image, right click the image on the website, and select "copy image".  You cannot simply copy an image from your desktop!

Now when you send an email, your signature with the image will be included.  Some email clients will initially block the image, but right-clicking on the email and selecting something like "show images" will reveal it.

Image Not On A Website?

If the image you want on your Yahoo! Mail signature is not on a website, then you need to get it on one. How do you do this?  Easiest thing to do is to use Flickr. Create an account, and upload your image.  After the image is uploaded, click on the image in your photostream to view it.  Above the image select "Actions" then "View all sizes".  On the All Sizes page, click whatever sized image you want to have on your signature (typically will be a small image!), then right click the image and select "copy image".  Then go back to the Signature, put the cursor where you want to have the image, right-click and paste.

Do you have to use Flickr?  No, any photo sharing site should allow you to do the same thing.  You will have to try it out.

That's it, Enjoy!