Could not load type Microsoft.VisualStudio.Services.Common.VssHttpClientBase

If your getting the following error on your TFS server web interface odds are that you are using incompatible version between TFS and VS or other Microsoft product. The object in question was moved from the common Dll to another. In my case I installed TFS RC and then never version of VS2013, after that I got the error.

Could not load type ‘Microsoft.VisualStudio.Services.Common.VssHttpClientBase’ from assembly ‘Microsoft.VisualStudio.Services.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.

To remedy the situation I upgraded TFS 2013 with the RTM version. After the upgrade I’m not getting the error anymore ant the TFS web interface works as expected.

Fireflies

I had an idea about writing a small code to animate fireflies. On Christmas break I was bored and I figured I had a few hours to play with it. I also wanted to use some tools I hadn’t used yet and figured that was a good time to do Javascript since I haven’t done much Javascript. I fired up the editor ( Sublime ) and used the browser to run / debug, Firefox and FireBug of course. There is a bit of a difference using this setup compared to writing Java code in Eclipse which I’m used to. First off you don’t get the compilation in Sublime and secondly you have to switch to another program to load and debug. Switching between the two was what annoyed me. Later I though, what if I can find a tool that is an editor and can Ftp to a server as well and runs within the browser. If on each save you can Ftp it to a sever that is serving the Javascript then I could do it all from the browser. I went looking around and fount Net2Ftp which is supposed to at least come close to the tool I’m wishing for. I will have to try it out the next time I’m coding in Javascript. The other thing that got me is that there is no good way of declaring your own classes, you have to work with prototypes and such, why that is beats me.

As you can see from the code, it’s not pretty.

If you want to see the Javascript in action click here.

fireflies

Java Spring MVC 3.2.0 UnitTests

I had a bit of a fight today, I wanted to UnitTest some Java Spring MVC code that I’m using for a demo application. But after a lot of Googling, StackOverflow and hitting different documentation of Spring 3.0, 3.1 and 3.2 I finally came to an acceptable solution. Mind you a minimal sample to test MVC controller without having to go crazy with decelerations, attributes, injections and so on and so forth, you catch my drift. There has been a lot of movement from those three versions I mentioned and finally the spring UnitTesting lib has now been folded into Spring itself, this is good news.
Btw, I found the answer in the Spring MVC showcase on GitHub, where else ?

So lets take a look at what you need, bare minimum just the way I like it.

Using Maven, you will need the ref in your POM file

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.2.0.RELEASE</version>
            <scope>test</scope>
        </dependency>

The controller class I’m using comes pretty much directly from creating a new MVC Spring project from Eclipse.

package us.kristjansson.springTest;
//
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
//
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Handles requests for the application home page.
 */

@Controller
public class CxHomeController
{
       
        private static final Logger logger = LoggerFactory.getLogger(CxHomeController.class);
       
        /**
         * Simply selects the home view to render by returning its name.
        */

        @RequestMapping(value = “/”, method = RequestMethod.GET)
        public String home(Locale locale, Model model)
        {
                logger.info(“Welcome home! The client locale is {}.”, locale);
                //
                Date date = new Date();
                DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
                String formattedDate = dateFormat.format(date);
                model.addAttribute(“serverTime”, formattedDate );
               
                return “home”;
        }
       
}

Then lets look at the Test itself.

//
package us.kristjansson.springTest;
//
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import org.springframework.test.web.servlet.MockMvc;
//
import org.junit.Before;
import org.junit.Test;

public class TxHomeController
{
         //
         private static final Logger logger = LoggerFactory.getLogger(TxSample.class);
         private MockMvc mockMvc;

         @Before
         public void setup() throws Exception
         {
                 logger.info( “Setup CxHomeController” );
                 this.mockMvc = standaloneSetup(new CxHomeController()).build();
         }

         @Test
         public void TestController() throws Exception
         {

                 //
                 logger.info( “testing CxHomeController” );
                
                 // The CxHomeController’s view is "home" without content
                 this.mockMvc.perform(
                           get(“/”))
                                 .andExpect(status().isOk())
                                 .andExpect(content().string(“”))
                                 .andExpect(view().name(“home”) 
                                 );

         }
       
}

curl: (60) SSL certificate problem: unable to get local issuer certificate

If you get the following error when using curl for SSL address, here is an easy fix. Your error will probably look something like the following.

curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a “bundle”
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn’t adequate, you can specify an alternate file
using the –cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you’d like to turn off curl’s verification of the certificate, use
the -k (or –insecure) option.

Just go to http://curl.haxx.se/ca/cacert.pem it has a list of certification providers. View as source and save it to a file cacert.pem. Then on the curl command just add this in the end pointing to your file –cacert cacert.pem Note you can also try the -k option but that’s cheating 🙂

Update

A better approach is to save the file as curl-ca-bundle.crt and save it in the Windows System directory (e.g. C:\windows\system32)

Maven Sonar plugin for your Java project

I needed to add Sonar reporting to a small Java project that uses Maven for the build. There is a Maven Sonar plugin available for this task here.

First add sonar properties file ( sonar-project.properties ) to your java project, put it in root.

# info
sonar.projectKey=javaTest
sonar.projectVersion=1.0
sonar.projectName=Sample java spring MVC project

# Comma-separated paths to directories with sources (required)
sonar.sources=src

# Language
sonar.language=java

# Encoding of the source files
sonar.sourceEncoding=UTF-8

Make Maven aware of the Sonar location etc, add that to the Maven settings \maven\conf\settings.xml

Something like this

<profile>
       <id>sonar</id>
       <activation>
          <activeByDefault>true</activeByDefault>
       </activation>
       <properties>
          <!– SERVER ON A REMOTE HOST –>
          <sonar.host.url>http://remotebox.com:9000</sonar.host.url>
          <sonar.jdbc.url>jdbc:h2:tcp://remotebox.com:9092/sonar</sonar.jdbc.url>
       </properties>
    </profile>

For Maven version 3+ add this to the POM file in the build section, else Maven version 2 ( below ).

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>2.1</version>
      </plugin>

For Maven 2.

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>1.0</version>
     </plugin>

Pass the sonar:sonar goal to the Maven script then kick off a build, the dependencies should be downloaded automatically. The report for your project displays on the Sonar server dashboard.

Chocolatey

I played with Chocolatey today, I figured lets create an package to setup a development machine. Add handy packages that you might want starting out on a new machine. This is handy as well when you have a new developer joining your team, you can set them up with some common tools.

First create the spec file as below

<?xml version=“1.0”?>
<package>
  <metadata>
    <id>SoftwareCreations.devset</id>
    <title>SoftwareCreations.devset</title>
    <version>0.09</version>
    <authors>Orn Kristjansson</authors>
    <summary>Software Creations, installs dev tools.</summary>
    <owners>Orn Kristjansson</owners>
    <description>Installs handy development tools.</description>
    <projectUrl>https://github.com/ornatwork/</projectUrl>
    <tags>SoftwareCreations devset tools development</tags>
    <copyright>Software Creations</copyright>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <iconUrl>http://kristjansson.us/favicon.ico</iconUrl>
    <dependencies>
      <dependency id=“fiddler” />
      <dependency id=“filezilla” />
      <dependency id=“winrar” />
      <dependency id=“sublime” />
      <dependency id=“gimp” />
      <dependency id=“dotpeek” />
      <dependency id=“grepwin” />
      <dependency id=“skype” />
      <dependency id=“testdriven.net” />
      <dependency id=“MagicDisc” />
      <dependency id=“winmerge” />
      <dependency id=“tortoisesvn” />
      <dependency id=“TortoiseGit” />
      <dependency id=“windowstelnet” />
    </dependencies>
    <releaseNotes>
    </releaseNotes>
  </metadata>
  <files>
    <file src=“tools\**” target=“tools” />
    <file src=“content\**” target=“content” />
  </files>
</package>

For this spec I have only dependencies which means I’m not really installing anything myself. Rather pulling and installing the dependencies. As such there is a /tool directory that has a PowerScript file that doesn’t do anything. Secondly since some of these packages have /content directory that needs to be created as well. If not an error will be thrown when the package is run ( that’s a bug ). There for I just put fake.txt file in that directory that is enough to get around the error.

My source can be found on GitHub

Since I don’t like doing tasks by hand that can be automated I created a nant script to create the package and push it up on the Chocolatey server. When I make a change to the package I save it and then on the command line just run the nant script.

For example
> nant -D:version=0.10

<?xml version=“1.0”?>

<!– Chocolatey fun –>
<project name = “SofwareCreateions.devset”
                 default = “PackAndDeploy”
                 basedir=“.”>

  <!–  Register the sys.* properties; most specifically, sys.env.* for all environment vars   –>
  <sysinfo failonerror=“false” />

  <!– The version number for the package –>
  <property name=“version” value=“0.01” dynamic=“true” overwrite=“true” />
  <property name=“BuildDrive” value=“${string::substring(project::get-base-directory(), 0, 1)}”  dynamic=“true” />
  <property name=“path.base.drive” value=“${BuildDrive}:\” />
  <property name=”cmdChocolateyPath” value=”${path.base.drive}\Chocolatey\bin\” />
  <property name=”cmdChocolatey” value=”chocolatey.bat” />
  <property name=”nugetFile” value=”softwarecreations.devset” />

  <!– This is the main / default target –>
  <target name=”PackAndDeploy” depends=”Start, UpdateVersion, Package, Deploy“>
    <echo message=”Done !“/>
  </target>

  <!– Individual targets below, those should NOT have any dependancies –>
  <target name=”Start” >
    <echo message=”*** Version number=${version} “/>

  </target>

  <!– Update version number –>
  <target name=”UpdateVersion” description=”Update version files to the current version being built.”  >
   
    <echo message=”*** Start updateVersions: ver=${version}“/>
   
    <!– Update NuGet package version –>
    <xmlpoke file=”softwarecreations.devset.nuspec” xpath=”/package/metadata/version” value=”${version}” />

  </target>

  <!– Package –>
  <target name=”Package“>
    <echo message=”Start Package:“/>

    <echo message=”Push to Nuget feed:“/>
    <!– Deploy to Nuget Gallery –>
    <exec program=”${cmdChocolateyPath}${cmdChocolatey}” verbose=”true
          commandline=”
pack ${nugetFile}.nuspec“/>
   
  </target>

  <!– Deploy –>
  <target name=”Deploy“>
    <echo message=”Start Deploy:“/>
   
    <exec program=”${cmdChocolateyPath}${cmdChocolatey}” verbose=”true
          commandline=”
push ${nugetFile}.${version}.nupkg“/>
   
  </target>

</project>

My package and it’s content can be found here If your have Chocolatey installed you can run it from the command line, like so.

> cinst SoftwareCreations.devset

Chocolatey is like apt-get on the Linux box, when you start using it its hard to go back to the manual search – webpage – download – install routine. There are only about 1200+ packages available at this point but that will grow going forward for sure.