Tuesday, December 21, 2010

Visual Studio : Counting lines of code

Had a look at a vb application to get a feeling for how much work it would take to support it.

One of the measures of complexity is "lines of code" (LoC). Yes, I know it's a crap measure but it's better than nothing and a useful guide.

Mr. Google to the rescue and (no surprise), a good answer on Stackoverflow.

So downloaded the code from here and installed it.

Warning - I had to open and close the project a few times before I could get it to "take" but I got it working and I found that it was a really useful tool.

Hasn't been updated for ages so very much in the Visual Studio 2003 / 2005 era but luckily that was the ballpark I was in.


Wednesday, December 08, 2010

Visual Studio : Unable to make the session state request

I was running up Visual Studio for an ASP.NET project when I got this error:

"Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection."

Mr. Google to the rescue and you have to start up:

Control Panel / Administrative Tools / Services.

Right click on ASP.NET State Service / Start

Refresh the browser and you're good to go.


Friday, November 26, 2010

Web services : cURL

If you need to do some web service client testing, there are a number of tools like SOAPUI but they all involve installing programs etc.

Then I came across this neat tool cURL

To quote from the docs:

"curl is a command line tool for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and a busload of other useful tricks."

It runs on a wide variety of platforms.

So how do you use it to test a web service?

You need to mock-up what the actual SOAP packet looks like e.g.

to test a web service called TestWS, the information might look like:


Save this in a file called TestWS.xml.

The command line for cURL would then be:

curl --data @TestWS.xml --header "Content-Type: text/xml" --header "Accept-Encoding: gzip,deflate" --verbose http://host:port/TestWSService

This then sends the HTTP POST which itself contains a SOAP message which invokes the web service.

The verbose option prints out both the request and the response.


Tuesday, November 23, 2010

Netbeans : Providing command line arguments inside Netbeans

I write a lot of command line Netbeans (6.9) Java programs. A lot of them take command line arguments e.g.

java Program Option1 Option2

and you access them from "String[] args".

When you are running inside Netbeans, you need to provide the arguments by:

Right click the project / Properties / Run / Arguments

If you right click the Java file you are testing (the Main class) and select "Run File" the program runs but ignores the configured arguments.

To get around this, you have to right click the project and select "Run".


Java : Checking if environment variables are valid

Has a few problems with environment variables and I couldn't find a utility that would check them for me e.g. checking if all the entries in my PATH environment variable were valid.

So I rolled my own:

public class CheckEnv {

* @param args the command line arguments
static String envVar = "";
static String envValue = "";
static String envValueStrings[];
static String envValueString = "";
static boolean valid = false;

public static void main(String[] args) {
// TODO code application logic here

if (args.length < 1) {
System.out.println("\nUsage is 'java -jar CheckEnv.jar '");
System.out.println(" e.g. 'java -jar CheckEnv.jar PATH'");
System.out.println(" 'java -jar CheckEnv.jar CLASSPATH'");
System.out.println(" 'java -jar CheckEnv.jar INCLUDE'");
System.out.println(" 'java -jar CheckEnv.jar LIB'");

envVar = args[0];

envValue = System.getenv(envVar);

System.out.println ("\nChecking for environment variable " + envVar + "\n");

if (envValue == null)
System.out.println ("Environment variable " + envVar + " doesn't exist");

envValueStrings = envValue.split(";");

for (int i = 0; i < envValueStrings.length; i++) {
envValueString = envValueStrings[i];

System.out.print("Checking " + envValueString + " ");

File file = new File(envValueString);
valid = file.exists();

if (valid) {
System.out.println("- variable exists");
} else {
System.out.println("- variable does not exist : WARNING");


Usage is 'java -jar CheckEnv.jar '

e.g. 'java -jar CheckEnv.jar PATH'
'java -jar CheckEnv.jar CLASSPATH'
'java -jar CheckEnv.jar INCLUDE'
'java -jar CheckEnv.jar LIB'

The output looks like e.g.

Checking C:\Program Files\Java\jdk1.6.0_22\jre\bin - variable exists
Checking C:\Program Files\Reflection - variable exists
Checking C:\Perl\bin\ - variable exists


Monday, November 22, 2010

JMeter : IOException: Exceeded maximum number of redirects: 5

Using the JMeter proxy server to record and playback some logins to a site and got this error.

Mr. Google to the rescue and the trick is to modify the jmeter.properties file in the JMeter bin directory.

# Maximum redirects to follow in a single sequence (default 5)

Modify the above line in that file to increase the maximum from the default of 5. In my case, I found 20 to be adequate.

You need some kind of upper limit because otherwise the trace could just get stuck in a loop.

Note that you have to restart JMeter after making this change.


Friday, November 19, 2010

Netbeans : SOAPUI plugin

Using Netbeans 6.9.

I wanted to download the SOAPUI plugin from soapUI NetBeans Plugin.

Although the description says "com-eviware-soapui-netbeans-module.nbm", when you actually download the file, you'll find it's a zip file.

Netbeans doesn't like loading zip files. A little research at Mr. Google shows that a .nbm file is essentially just a zip file with a different extension.

So I simply simply renamed

com-eviware-soapui-netbeans-module.zip to com-eviware-soapui-netbeans-module.nbm

and the plugin installed no problems at all.

It does warn you that the plugin is not signed but just ignore that and continue.


Thursday, November 18, 2010

CXF : Deploying the java_first_jaxws sample direct to Tomcat

Decided I wanted to learn a bit about CXF so downloaded the development kit and has a look at the java_first_jaxws project in the \samples directory.

Before you try and do anything, ensure you have the environment set up correctly.

I created a bat file (as per README) which looks like:

set CXF_HOME=x:\apache-cxf-2.3.0
set JAVA_HOME=x:\Program Files\Java\jdk1.6.0_22
set ANT_HOME=C:\apache-ant-1.8.1

set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%CXF_HOME%\bin;%PATH%
set CLASSPATH=.;%CXF_HOME%\lib\cxf-manifest.jar;.\build\classes

set CATALINA_HOME=x:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26

which also serves as a useful list of the file versions I have.

One level up from the project you will find a useful file i.e.


which is worth looking through.

In the actual project directory you will find a build.xml which calls the above.

ant -p


Main targets:

build build demo client and server
client run demo client
client-servlet run demo client hitting servlet
deploy deploy the application into the container
server run demo server
undeploy undeploy the application from the container
Default target: build

so we first do:

ant build

which builds both the client and the server.

Then we run:

ant server


ant client

Note that the client and server run in two separate command prompts.

The client then sends some canned messages to the server:

[java] Hello World
[java] Hello World
[java] Hello Galaxy
[java] Hello Universe
[java] Users:
[java] 1: World
[java] 2: Galaxy
[java] 3: Universe

and the server receives:

[java] Starting Server
[java] Server ready...
[java] sayHi called
[java] sayHiToUser called
[java] sayHiToUser called
[java] sayHiToUser called
[java] getUsers called

Note that this is running is a "built-in" Jetty server and the URL the client calls is:


OK, that sets the scene for the main thrust of this article which is how to deploy this client to a real instance of Tomcat.

So start up the Tomcat server as usual by running "startup.bat" in the \bin directory.

My installation of Tomcat runs on port 8080 so we need to change Client.java as follows:

//String endpointAddress = "http://localhost:9000/helloWorld";
String endpointAddress = "http://localhost:8080/helloworld/services/hello_world";

Now we run the normal "ant build" and then we run "ant deploy".

This builds the war file and then deploys it to Tomcat (which is where the CATALINA_HOME environment variable comes in.)

Then we run the normal "ant client" and this time, the server output messages will appear in the Tomcat window.

Note that the WSDL can be found at:


Where on earth does this URL come from?

As per Creating a WSDL-first web service with Apache CXF or GlassFish Metro, scroll down to Point 2 in the "Additional notes".

Adapting for our project, we get:


"localhost:8080" is the host and port of the servlet container.
"helloworld" is the name of the war file.
"services" comes from the url-pattern element in the web.xml file.
"hello_world" comes from the address attribute in the cxf-servlet.xml file (for CXF).

If we look into the web.xml file (you'll need to look at the war file in the ...\samples\java_first_jaxws\build\war directory), we find:

servlet-name = cxf
url-pattern = /services/*

If we look into the cxf-servlet.xml file (in the wsdl directory), we find:

jaxws:server id="jaxwsService" serviceClass="demo.hw.server.HelloWorld" address="/hello_world"


Tuesday, November 16, 2010

Metro : Jax WS incompatibilities with Netbeans

Using Netbeans 6.9 and Tomcat 6 with JAX WS via Metro and Java JDK 6 on Windows.

The Tomcat installation is the one that is loaded as part of Netbeans.

When you try and invoke the web service, you get a string of errors e.g.

java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String

The basic problem seems to be that the versions of JAX WS bundled with Netbeans / Java / Tomcat are incompatible.

(Metro provides JAX-WS 2.2 while Java SE includes JAX-WS 2.1. If you want to run Metro applications outside Tomcat, you will need to use the endorsed standards override mechanism. For more details see:


There are literally hundreds of articles etc. all over the web about how to fix this problem with tips about installing file x into the endorsed directory, the common/endorsed directory, updating Tomcat, updating Java etc. etc.

I tried a heap of them and none of the ones I tried fixed the problem. This is Google search at it's worst - tons of articles, all different, none of which appeared to work and utter frustration.

To complicate the issue, it you don't back out the failed change, you run the risk that the next change won't work because you didn't start from a known point.

To complicate things further, some of these changes partly work which means that next time you simply get a different error message and you have to start the process all over again.

Eventually, I went back to the source i.e. Metro and JAX WS.

I came across this article:

Creating a WSDL-first web service with Apache CXF or GlassFish Metro

which pointed me to:

Using JAX-WS 2.x / Metro 1.x/2.0 with Java SE 6

So, download Metro 2 - refer Metro 2.0

Ensure Netbeans and Tomcat are shut down.

Sort the zip file by path.

You do not need to extract all the files. You only need:

metro-on-tomcat.xml and all the jar files under /metro/lib and /metro/osgi.

Extract these to a directory.

Ensure you have ant installed.

Open a command prompt and navigate to the directory that you have just extracted the files to.


...\metro>set CATALINA_HOME=x:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26

i.e. the path where Tomcat 6 is installed

where ... is the directory that the files were extracted to.

Then run:

ant -f metro-on-tomcat.xml install

which produces:

Buildfile: metro-on-tomcat.xml








[mkdir] Created dir: x:\Program Files\Apache Software Foundation\Apache Tomc
at 6.0.26\endorsed
[copy] Copying 2 files to x:\Program Files\Apache Software Foundation\Apach
e Tomcat 6.0.26\endorsed


[echo] Installing Metro 2.0 FCS for x:\Program Files\Apache Software Founda
tion\Apache Tomcat 6.0.26 ...
[mkdir] Created dir: x:\Program Files\Apache Software Foundation\Apache Tomc
at 6.0.26\shared\lib
[copy] Copying 4 files to x:\Program Files\Apache Software Foundation\Apach
e Tomcat 6.0.26\shared\lib
[echo] ... installation complete.


The two files copied to the \endorsed directory are :

jsr173_api.jar and webservices-api.jar

The four files copied to the \shared\lib directory are:

webservices-extra.jar, webservices-extra-api.jar, webservices-rt.jar and webservices-tools.jar

In addition, the script updates catalina.properties in the \conf directory. It changes:




And that, believe it or not, is that!

Problem solved!

If you want to back the change out, run:

ant -f metro-on-tomcat.xml uninstall

For completeness, if you want to enable JAX-WS 2.2 for all applications running under Java SE 6, you may run the command:

ant install-api

That command will copy the file webservices-api.jar to ${java.home}/lib/endorsed.

(The command needs to be run by a user that has the permissions to copy files into ${java.home}/lib/endorsed.)

Note that I didn't need to do this.


Thursday, November 11, 2010

Netbeans : Can't login to Tomcat as Admin or Manager

Using Netbeans 6.9 and Tomcat 6 - integrated with Netbeans.

When I go to the Tomcat server home page i.e. http://localhost:8084/

and then click on the Manager link, I am asked to login. But my login is not accepted! WTF?

The usual course of action is to go to the Tomcat installation which is usually something like:

...\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26\conf

and edit the tomcat-users.xml file adding the lines:

but this login is not accepted.

Looked through the logs and noticed:

Using CATALINA_BASE: "...\Tmp\.netbeans\6.9\apache-tomcat-6.0.26_base"
Using CATALINA_HOME: "...\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26"

where the Tmp directory is my Netbeans work directory.

You have to edit the xml file in that directory NOT the one in the "Program Files" tree.

Then found an easier way.

Click on the Server tab in Netbeans, then right click Tomcat and click Properties.

Click the Connection tab.

The credentials in that tab are what you have to use. It's normally ide and some random password which you can change.

Note that the CATALINA_BASE and CATALINA_HOME settings appear in this tab as well.


Friday, November 05, 2010

Glassfish : Moving a project from Glassfish 2 to 3

Migrated a web application project inside Netbeans from Glassfish 2 to Glassfish 3 and built it on another PC.

Obviously the paths had changed so I did a Search / Replace across all the Netbeans project files.

Then got an error:

... \nbproject\wsit-deploy.xml:12: Must set Sun app server root.

Clicking on that line showed:

unless="sjsas.root" Must set Sun app server root

For once, Mr. Google failed to come to the rescue.

Eventually, I brute force searched the actual Glassfish installation under:

\Program Files\glassfish-3.0.1

and found:

...\Program Files\glassfish-3.0.1\glassfish\domains\domain1\config\domain.xml

system-property name="sjsas.root" value="...\Program Files\glassfish-3.0.1"

Damn - wrong path.

Moral of the story. When you migrate projects across machines, you may need to update the Glassfish configuration files as well as the Netbeans project files.

Note: The ... above represents the actual directory which is different in each environment.

Aside: Because this was a Glassfish issue rather than a project issue, I got the same error when I tried using Tomcat instead of Glassfish. Maybe that should have been a hint!


Tuesday, October 26, 2010

Selenium IDE : Different examples on input

Using the excellent FireFox add-on Firebug and the ubiquitous Google search page, we get this HTML for the "Google Search" button.

There are many ways to code the IDE for this button e.g.

click btnG

click //input[@value='Google Search']

click //input[@type='submit']

click //html/body/span/center/span/center/form/table/tbody/tr/td[2]/span/span/input

The latter ones are examples of XPath and XPath knowledge is VERY useful when coding the IDE scripts.

To get the XPath construct inside Firebug, right click on the HTML segment and then select "Copy XPath".

To check your script without having to run it, load the Click command that you want to test and then select the "Find" button to the right of "Target". The "Google Search" button will be highlighted with a green border if the script works otherwise an error message will be displayed.


Selenium RC : Importing a script from Selenium IDE

As a quick start to get up and running with Selenium RC, you can get Selenium IDE to capture the session. Here's the IDE script to search Google for "Selenium RC".


New Test
open /
type q selenium rc
clickAndWait //input[@value='Google Search']


Then Options / Format / Java (JUnit)

This produces the following code:

package com.example.tests;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;

public class Untitled extends SeleneseTestCase
public void setUp() throws Exception
setUp("http://change-this-to-the-site-you-are-testing/", "*chrome");

public void testUntitled() throws Exception
selenium.type("q", "selenium rc");
selenium.click("//input[@value='Google Search']");

You can download Selenium RC from here.

Unzip the file and then start Selenium RC from a command prompt.

...\selenium-server-1.0.3>java -jar selenium-server.jar

I run JUnit inside Netbeans.

After a bit of massaging, the code above becomes:

import com.thoughtworks.selenium.*;

public class GoogleSearch extends SeleneseTestCase

Selenium browser = null;

public void setUp() throws Exception


public void testGoogleSearch() throws Exception

browser = new DefaultSelenium("localhost", 4444,


browser.type("q", "selenium rc");
browser.click("//input[@value='Google Search']");

verifyEquals("selenium rc - Google Search", browser.getTitle());


This is invoked by a JUnit test:

public void testGoogleSearch() throws Exception
GoogleSearch instance = new GoogleSearch();


Friday, October 22, 2010

Blogger : Image messes up text

Wrote a new post and then decided to add an image using Blogger's image tool.

I use the Left / Large image options.

The text that was supposed to be below the image now turned up at the right hand side of the image about half way down.

Tried br and /br and a few other things but no go.

Mr. Google to the rescue.

Between the image and the following text insert:

Now the text is below the image, just as it should be.


IE : Fixing the "Do you want to view only the web page content" popup

The most annoying part of Internet Explorer (IE) 8 is the "Do you want to view only the webpage content that was delivered securely?" popup that forces you to continually click "No".

Maybe it's useful when doing Internet banking but I get it every time I open up Blogger. Why wouldn't I want to see the whole page?

The solution is simple:

Tools / Internet Options / Security / Custom level / Miscellaneous / Display mixed content

and change the option from "Prompt" to "Enable".

Reply "Yes" to the "Do you want to change this option?" question and OK out.

Problem solved.


Thursday, October 21, 2010

Netbeans : jQuery code complete / auto complete

Need to do some jQuery work and it's a lot easier with auto complete / code complete.

See my SO answer here.


Wednesday, October 20, 2010

JMeter : Reading variables from a file

Done a lot of load testing with JMeter.

Quite often, I need to try load testing for lots of user logins. To do this you can't hard code the value in the form - you have to somehow read it from a file.

Enter JMeter's String From File

"The StringFromFile function can be used to read strings from a text file. This is useful for running tests that require lots of variable data. For example when testing a banking application, 100s or 1000s of different account numbers might be required."

For a field called userId, enter something like the following in the Value column:

${__StringFromFile(x:\Path to csv file.csv,userId,,)}

It would look something like this:

The csv file is a simple one column list of user Ids.


Thursday, October 14, 2010

Stackoverflow : Flair

Playing around with my StackExchange "flair"


profile for nzpcmad on Stack Exchange, a network of free, community-driven Q&A sites


profile for nzpcmad at Stack Overflow, Q&A for professional and enthusiast programmers

Meta Stackoverflow

profile for nzpcmad at Meta Stack Overflow, Q&A about the Stack Exchange engine powering these sites


profile for nzpcmad at Programmers, Q&A site for expert programmers interested in subjective discussions on software development


profile for nzpcmad at Server Fault, Q&A for system administrators and IT professionals

Food and Cooking

profile for nzpcmad at Cooking, Q&A for professional and amateur chefs


profile for nzpcmad at Super User, Q&A for computer enthusiasts and power users


Selenium RC : Using a spreadsheet with Selenium

Quite a lot of the work I've done with Selenium is very repetitive e.g. navigating to an application, logging in, doing some test and logging out.

It made sense to put this in some kind of spreadsheet where each line would have the application URL, login credentials (user field name, user name, password field name, password) and the name of the "Submit" button. Then do some application work perhaps and then logout.

The program could go through the spreadsheet row by row populating the values and then posting the page.

I put all the data into a csv file so I could use opencsv to read the rows.

The code looks something like:

CSVReader reader = new CSVReader(new FileReader("x.csv"));

while ((nextLine = reader.readNext()) != null)

if (!csvURL.equals("Exit"))
selenium = new DefaultSelenium( "localhost",



selenium.type(csvUserText, csvUser);
selenium.type(csvPasswordText, csvPassword);


The code runs through the spreadsheet until it finds an "Exit" in the URL field.

populateParams looks like:

public void populateParams (String nextLine[])
csvURL = nextLine[1];
csvUserText = nextLine[2];
csvUser = nextLine[3];
csvPasswordText = nextLine[4];
csvPassword = nextLine[5];
csvSubmit = nextLine[6];


JMeter : Setting up a HTTP Proxy to capture traffic

You can build up a JMeter test plan yourself but it's much easier to set up a proxy and let JMeter do all the grunt work for you.

There are some JMeter proxy Step-by-step instructions here.

If your environment has a proxy you need to tell JMeter about it via the command line e.g.

jakarta-jmeter-2.4\bin>jmeter -H yourProxy.co.nz -P yourProxyPort

The basic idea is that you change your browser settings to point to the JMeter HTTP Proxy and then the JMeter proxy forwards the packets to the real proxy configured in the command line.

To setup the JMeter proxy after you have started up JMeter, right click:


Add / Non-Test Elements / HTTP Proxy Server

Choose a spare port (in this case 9090) and configure in the Port box.

Now you need to change your browser settings. Use

Tools / Internet Options / Connections / LAN Settings / Proxy Server

Set the proxy server to localhost (or and the port number to 9090.

In JMeter, right click Test Plan / Add / Threads / Thread Group.

Doing this forces the proxy to capture the traffic inside of the plan.

Now click on HTTP Proxy Server and click Start at the bottom.

Now open your browser and browse to the URL you want to test.

In JMeter, you should see something like:

Note that it's a good idea to add a HTTP Cookie Manager as well as this enables cookies to pass between pages.


Wednesday, October 13, 2010

Selenium IDE : Input too "early"

I've seen this behavior a number of times.

You run a Selenium IDE script where you have a

type - token - text

scenario and Selenium will complain that the field "token" does not exist.

But it does - at this point, you are staring at it in the browser.

What sometimes seems to happen is that the page loads, Selenium sees the title and moves to the next line of the script but the actual fields haven't loaded yet and so can't be found.

The way around this is to look for a bit of text near the input field and then do a


That way the input field is there when the script requires it.


Selenium RC : Setting up a Firefox proxy

The normal way to use Selenium RC if your environment has a proxy installed is to use the command line e.g.

java -jar selenium-server.jar -Dhttp.proxyHost=xxxproxy.company.nz -Dhttp.proxyPort=8082

I could never quite get this to work.

I use the Firefox Profile Manager.

The command line is:

firefox -P

You need to do this from wherever Firefox is installed on your PC e.g.

x:\Program Files\Mozilla Firefox

When the "User Profile" box pops up, choose "Create Profile" and follow the wizard.

Run the command line again and select the new profile and then select "Start Firefox"

Configure Firefox to use a manual proxy:

Tools / Options / Advanced / Network / Settings

Configure the manual proxy to point to the proxy in your environment.

The Selenium RC command line you need to use this is:

java -jar selenium-server.jar -firefoxProfileTemplate "Path to profile created above"

GOTCHA: Remember to run the Profile manager again and select "default" to return to your normal profile otherwise any new changes will be mode to the wrong profile.


Tuesday, September 28, 2010

Excel : Pesky hyperlinks

I hate the fact that Excel automatically changes a URL to a hyperlink when you click on it or want to cut and paste.

To get round this abysmal behaviour (I have Excel 2003):

Tools / AutoCorrect Options / "AutoFormat as you type" / Uncheck "Internet and network paths with hyperlinks".

Another way is to simply type an apostrophe in front of the URL.

If you already have the damn things, you can right click and "Remove Hyperlink".

For multiple ones (as per the Help file):

Type the number 1 in a blank cell, and right-click the cell.
Click Copy on the shortcut menu.
While pressing CTRL, select each hyperlink you want to deactivate.

No more damn hyperlinks!


Wednesday, August 18, 2010

Visual Studio: Fiddler and Team Test web test

Noticed that the amazing Fiddler has the capacity to generate Team Test web tests for you.

See here.

Aside: Note the comment further down the page:

"Please see http://blogs.msdn.com/slumley/pages/how-to-debug-a-web-test.aspx for information on how to troubleshoot problems with WebTests".

Very useful link!


Visual Studio

I've been playing around with Team Test 2008 running on Windows 7.

When I try and capture a web test, the browser would lock up with the comment:

"The web test recorder must be launched from within Visual Studio".

WTF, I am within Visual Studio!

Mr. Google to the rescue and the solution is that you have to run VS with administrator rights.

Right-click on the shortcut / Properties / Compatibility / Check "Run this program as an administrator".

Problem solved.


Friday, July 30, 2010

XP : Profile keeps filling up with Sun cache

Had a problem with my profile always being fill with Sun cache files i.e. files under:

\Documents and Settings\\Application Data\Sun\Java\Deployment\cache

The easy way to clear these out is to click on the Java Control Panel in Control Panel.

Under the General tab / "Temporary Internet Files" / Settings / "Delete Files"

You can also vary the amount of space these files use by adjusting the slider on that page.

Yup - tons more profile space.


Thursday, June 24, 2010

Misc : Let me Google that for you

"This is for all those people that find it more convenient to bother you with their question rather than google it for themselves."

Go to the site

Type your question and click the "Google Search" button.

Then you can share the link that's generated on the page.

e.g. searching for "Java for loop" generates:


Go to the link and watch what happens! :-) Now you send that link to the person who bothered you with the question in the first place.

If you hover your mouse over the link on the lmgtfy page, you see a button for "tinyurl" and "go". The first generates a tinyurl as you would expect and the second shows you what happens when the user clicks on the generated link.

Clicking the "Live Stream" at the bottom shows you what other people are searching for and if you click the dropdown at the bottom you can generate the page in a number of languages.

Now bug off and do your own searches!


Tuesday, June 22, 2010

Java : FizzBuzz

I regularly read Jeff Atwood's blog and renewed my acquaintance for an old post: Why Can't Programmers.. Program?.

It talks about the Fizz-Buzz question i.e.

"Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". "

So I took up the challenge and knocked this out in Java using Netbeans in about 4 minutes.

for (int i = 1; i < 101; i++)
int j = i % 3;
int k = i % 5;
System.out.print("Number is " + i);
if (j == 0 && k == 0)
System.out.print(" FizzBuzz ");
if (j == 0)
System.out.print(" Fizz ");
if (k == 0)
System.out.print(" Buzz ");


So there!


Wednesday, May 12, 2010

Mercurial : A tutorial

Have been using Subversion for some time but am looking to move to something that handles merges with a little less pain.

I refactored a whole lot of code, moved tons of stuff around and merging this was a pain!

Came across this tutorial by Joel Spolsky. He writes really well as regular readers of his blog will know. Nothing wrong with a bit of humour and it's not often that I LOL reading tutorials :-)

There's also a "Red Bean" book here.


Wednesday, May 05, 2010

Misc : Tools I use

These are the ones I use almost every day. These all run on Windows XP.

Free unless otherwise stated.

Not quite as large as Scott Hanselman's Ultimate Developer And Power Users Tool List For Windows though !

Notepad ++ - really useful text editor with language syntax - multiple tabs and multi-file search.

Winmerge - text compare and merge utility - I use it every day!

Beyond Compare - file compare which also works across FTP sites - really useful for testing if deployments etc. are up to date. Not free.

Paint.Net - graphics manipulation program. use it all the time for inserting screen shots into specs. etc.

Feeddemon - Windows RSS aggregator. Synchronises with Google Reader.

Wireshark - protocol analyser and LAN sniffer.

7-zip - handles zip files, jar files and just about everything else.

Passwordsafe - keeps my millions of passwords safe and sound.

Printscreen - allows you to print / copy / save screens or portions of them.

Google toolbar - especially the Spell check.

Sysinternals - excellent range of utilities - I user "Process Explorer", "Process Monitor", "ZoomIt" and "TcpView" a lot but have a look.

Putty - Telnet / SSH client.


XP : Clearing out and freeing up disk space

The old XP warhorse was seriously low on disk space so a bit of TLC was required.

Warning: This worked for me - you're on your own! Backup important stuff first!

Run CCleaner.

Just get it dude!

Then run PC Decrapifier. This didn't do much in my case but then I'm quite strict on what I install in the first place.

Then, using Explorer Search, I searched for *.log, *.tmp and *.bak and deleted all the junk.

Then I searched for all files greater than 10 Mb and deleted all the junk.

Advice: If in doubt , don't delete.

Then I deleted the old "Windows Update" files. These are the ones in the /Windows folder in folders like "$NtUninstallKB842773$". Again, Google this if you're not sure.

Then I deleted the files in the /Windows/Prefetch folder. Again, Google this if you're not sure.

If you have SQL server installed, you can clear out most of the files on the C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\LOG folder. Again, Google this if you're not sure.

And then run Windirstat. This gives a graphical representation of who is using what. Poke around a bit.

Man, I had a ton of crap on my PC and now it's gone!


Tuesday, March 23, 2010

StackOverflow : There goes my rep!

Before the big recalculation:

(That's 4595 !)
and after:

(That's 3636 !)

Misc : Can't login to Stack Overflow with Blogger OpenID

Suddenly couldn't login to Stack Overflow or it's "family" (Meta, ServerFault, SuperUser etc.) using my Blogger OpenID. (Cue: Major panic).

Mr. Google to the rescue - the answer is here in this article How to upgrade your Blogger OpenID to a decent one.

Note: I did not get the length error reported in some posts but the above sorted out my problem.

Tip: To ensure this doesn't happen again, get an alternate OpenID - I used Google. Just click on your user name at the top of the StackOverflow screen and then click "Change OpenID" (next to the "Edit" hyperlink). You then get an "openid" and a "alt openid" and you can swap the two around using the "swap" hyperlink.


Wednesday, March 10, 2010

Preventing Cross-Site scripting in Java

You can read about XSS here: Cross-site scripting

Been trying to figure out how to disable it using html encoding and what Java libraries are available.

OWASP's site has an article on this: http://www.owasp.org/index.php/How_to_perform_HTML_entity_encoding_in_Java

To quote:

"Injection attacks rely on the fact that interpreters take data and execute it as commands. If an attacker can modify the data that's sent to an interpreter, they may be able to make it misbehave. One way to help prevent this from happening is to encode the attacker's data in such a way that the interpreter will not get confused. HTML entity encoding is just such an encoding mechanism for many interpreters."

There are two ways to encode the data viz. entity reference and numeric reference:

From Wikipedia:

An entity reference uses the "&" symbol:

& quot; (double) quotation mark
& amp; ampersand
& apos; apostrophe (= apostrophe-quote)
& lt; less-than sign
& gt; greater-than sign

A numeric character reference refers to a character by its Universal Character Set/Unicode code point, and uses the format


where nnnn is the code point in decimal form, and hhhh is the code point in hexadecimal form

Although the OWASP article mentioned above talks about entity references, the code sample enclosed actually uses numeric entity encoding i.e.


encodes as:


where "hash" = the "#" character

Some further research around this issue leads to:
AntiXSS for Java which is a port to Java of the Microsoft Anti-Cross Site Scripting (AntiXSS) library for .NET applications

and to:
Open Web Application Security Project (OWASP)

which has a:
Enterprise Security API (ESAPI)

Click on the "Java EE" tab. There are two ways to invoke the functionality. One uses the classes directly:

import org.owasp.esapi.codecs.HTMLEntityCodec;

public static StringBuilder esapiCodecHtml (String s)
HTMLEntityCodec hec = new HTMLEntityCodec();
StringBuilder b = new StringBuilder(s.length());
char[] immune = { ',', '.', '-', '_', ' ' };
String returnStr = "";

String clean = ESAPI.encoder().canonicalize(s);
System.out.println ("Cleaned result is " + clean);

for (int i = 0; i < s.length(); i++)
char ch = s.charAt(i);
returnStr = hec.encodeCharacter(immune, ch);

return b;

Note: ESAPI canonicalizes input before validation to prevent bypassing filters with encoded attacks. Failure to canonicalize input is a very common mistake when implementing validation schemes. Canonicalization is automatic when using the ESAPI Validator.

and the other uses the wrapper:

import org.owasp.esapi.ESAPI;

public static String esapiEncodeForHTML (String s)
String returnStr = "";

String clean = ESAPI.encoder().canonicalize(s);
System.out.println ("Cleaned result is " + clean);
returnStr = ESAPI.encoder().encodeForHTML(s);

return returnStr;

They both convert <script></script> to andlt;scriptandgt;andlt;&hashx2f;scriptandgt;

where "and" is the "&" character.

Interestingly, this is a combination of both reference types.

Just to note: The example at the top converted the "/" to &hash47; whereas ESAPI converts it to &hashx2f; This is because one is decimal and one is hex!


Refer to:

XSS (Cross Site Scripting) Prevention Cheat Sheet

Refer to my SO question:

Java - XSS - HTML encoding - Character entity reference vs. Numeric entity reference


Thursday, March 04, 2010

IE : Enter won't submit the form

Wasted hours trying to fix this problem with IE. Firefox works A-OK.

Using JSP and if you have a form with one input field and the Submit button is not labelled Submit, then IE will not submit the form data on Enter. You have to click the "Submit" button to get it to work.

So jumped into Stack Overflow and here's the answer to my question


Thursday, February 25, 2010

XP : PC resumes from hibernation on it's own

Had this problem on my XP PC. Trying to be clean and green so I put the PC into hibernation when I'm away for any length of time. (To do this, just press the power switch and then choose the Hibernation option.)

It stayed in hibernation for about 10 minutes and then came out of it on it's own accord.

Mr. Google to the rescue and some research showed the answer here.

The trick is to select the "Only allow management stations to bring the computer out of standby check box" option as described in the article. Problem solved.

Note: The title of the article i.e. "The computer may unexpectedly resume from standby or hibernation and then automatically return to standby or hibernation after two minutes" is somewhat misleading because my PC didn't return to hibernation but the fix still worked.


Friday, February 12, 2010

Vista : No Audio Output Device is installed

The Compaq laptop with Vista Home Premium that we have always battles to play sounds through the headphones.

Somehow, we manged to disable the laptop sound while trying to get the headphones to work and got the message "No Audio Output Device is installed".

Control panel / Device manager / Sound, video and game controllers shows "High Definition Audio Codec". Tried updating the driver - Nix. Tried checking for new hardware - Nix.

Tried disabling - enabling - Nix.

You need to uninstall the device and then check for new hardware. Vista will find the "new" sound card and re-enable the audio device.

Problem solved.


Monday, February 08, 2010

Java : Sending a HTTP OPTIONS command

The HTTP OPTIONS command is documented here.

I needed to do this programmatically and thought I would document the code.

import java.net.HttpURLConnection;
import java.net.URL;


try {
String type = "text/plain;charset=UTF-8";
URL url = new URL("http://xxx/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestProperty("Content-Type", type);

System.out.println(String.format("HTTP %d: %s",
conn.getResponseCode(), conn.getResponseMessage()));

for(String header : conn.getHeaderFields().keySet() ){
System.out.println(String.format("%s : %s",
header, conn.getHeaderFields().get(header)));

String rMessage = conn.getResponseMessage();
System.out.println ("Response " + rMessage);

} catch (Exception e) {

Running this against Sun Java System Application Server 9.1 returns:

HTTP 200: OK
X-Powered-By : [Servlet/2.5]
Content-Length : [0]
null : [HTTP/1.1 200 OK]
Date : [Sun, 07 Feb 2010 19:11:57 GMT]
Server : [Sun Java System Application Server 9.1]
Content-Type : [text/html; charset=iso-8859-1]
Response OK

This sends something like "OPTIONS / HTTP/1.0". There is another version of the command that sends "OPTIONS * HTTP/1.0".

The "*" is actually part of the URI. However, "java.net.HttpURLConnection" has no facility which allows this. Some research suggests that this could be done by using "Apache Commons HttpClient".


Thursday, January 28, 2010

Metro : Printing / dumping out the contents of a SOAP packet

I've used Metro a lot and I've always battled to have decent logging.

In the web service, I normally log all the inputs and the outputs and all the exceptions. Wouldn't it be easier if you could just log all the requests and responses which would guarantee that you had all the information all of the time?

I just couldn't figure out how.

Until I came across "MessageDumpingFeature". You find this in the Glassfish \lib directory in the webservices-rt.jar file.

If you've generated web services using Metro, you find the code below very familiar. All you really need to do is replace:




The code looks like:


import com.sun.xml.ws.assembler.MessageDumpingFeature;

... snip ...

messageDumper = new MessageDumpingFeature();

ServiceName service = new ServiceName();
WebServiceName port = service.getWebServiceName(messageDumper);
// TODO initialize WS operation arguments here
java.lang.String xxx = "yyy";
java.lang.String yyy = "zzz"
// TODO process result here
ResultName result = port.doWebService(xxx, yyy);

String request = messageDumper.nextMessage();
String response = messageDumper.nextMessage();

System.out.println (request);
System.out.println (response);

... snip ...

} catch (Exception ex) {
String request = messageDumper.nextMessage();
String response = messageDumper.nextMessage();

System.out.println (request);
System.out.println (response);

It prints out both normal responses and SOAP Faults.

A request would be dumped like:

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<ns2:doWebService xmlns:ns2="http://namespace/">

A valid response would be dumped like:

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<ns2:doWebService xmlns:ns2="http://namespace/">

A SOAP fault would be dumped like:

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
<ns2:SomeException xmlns:ns2="http://namespace/">

Of course, instead of dumping out the request / response, it could be written to a file instead.


Thursday, January 07, 2010

SOAPUI : Adding a wsdl

Assume a WSDL like:


Sometimes when you are adding a WSDL like the above you get an error:

SOAPUIException: Error inporting wsdl

Try qualifying the URL i.e.



Wednesday, January 06, 2010

SOAPUI : NoClassDefFoundError

Using SOAPUI 3.0.1 to test web services created using Netbeans, JAX-WS and Metro.

When I try and run the TestRunner, I get:

java.lang.NoClassDefFoundError: org/apache/commons/cli/CommandLineParser

My solution was to edit soapui.bat (in the /bin directory) and add:

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_16

at the top.

Then, instead of running soapui.exe from the desktop shortcut, I open a command prompt and run soapui.bat from there manually.

Problem solved.


Tuesday, January 05, 2010

Metro : Sniffing the traffic with JAX-WS, Netbeans and Metro

I often use Fiddler to view / log browser traffic.

From the web site: "Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect all HTTP(S) traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language."

However, it doesn't work when you want to look at Java web service (SOAP) traffic generated by the JAX-WS support in Netbeans (i.e. Metro).

I have a number of command line tools that I use to generate various types of traffic with a command line like:

java -jar SomeProgram.jar

To get Fiddler to work, you need to change the command line to:

java -DproxySet=true -DproxyHost= -DproxyPort=8888 -jar SomeProgram.jar

Fiddler uses port 8888 as default.