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
here.

Enjoy!

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.

Enjoy.

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.

Enjoy!

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.setDoOutput(true);
conn.setRequestMethod("OPTIONS");
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) {
e.printStackTrace();
}
}


Running this against Sun Java System Application Server 9.1 returns:

HTTP 200: OK
X-Powered-By : [Servlet/2.5]
Content-Length : [0]
Allow : [GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS]
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".

Enjoy!

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:

service.getWebServiceName();

with

service.getWebServiceName(messageDumper);

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/">
<S:Body>
<ns2:doWebService xmlns:ns2="http://namespace/">
<xxx>yyy</xxx>
<yyy>zzz</yyy>
</ns2:doWebService>
</S:Body>
</S:Envelope>


A valid response would be dumped like:

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


A SOAP fault would be dumped like:

 
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>SomeErrorString</faultstring>
<detail>
<ns2:SomeException xmlns:ns2="http://namespace/">
<message>SomeErrorMessage</message>
</ns2:SomeException>
</detail>
</S:Fault>
</S:Body>
</S:Envelope>


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

Enjoy!

Thursday, January 07, 2010

SOAPUI : Adding a wsdl

Assume a WSDL like:

http://host:port/ApplicationServer/Service

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

SOAPUIException: Error inporting wsdl

Try qualifying the URL i.e.

http://host:port/ApplicationServer/Service?wsdl

Enjoy!

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.

Enjoy!

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=127.0.0.1 -DproxyPort=8888 -jar SomeProgram.jar


Fiddler uses port 8888 as default.

Enjoy!

Tuesday, October 20, 2009

Blogger : Syntax highlighting for code

I hate the way Blogger displays code , XML etc, inside the "blockqoute" construct.

Then I came across this:

How to add syntax highlight to Blogger.

This uses Syntax Highlighter.

Just to add:

You don't need to host the files. You can use:

http://syntaxhighlighter.googlecode.com/svn/trunk/

e.g. the link in the article would become:
http://syntaxhighlighter.googlecode.com/svn/trunk/Styles/SyntaxHighlighter.css

Update: As per the comment:

More info. available here:
http://mlawire.blogspot.com/2009/07/blogger-syntax-highlighting.html

Warning: There are a number of posts around on how to do this - all slightly different - use at your own risk.

Enjoy!

Log4J : Path to properties file

For Glassfish, we normally put the log4j.properties in the "domain / config" directory.

To enable Glassfish to find it, add the following to the Glassfish JVM settings. Easiest way is to use the Admin console i.e. Application Server / JVM Settings / JVM Options.

Add this line:

-Dlog4j.configuration=file:///${com.sun.aas.instanceRoot}/config/log4j.properties

Enjoy!

Netbeans : Generating getters and setters for a Java class

Using Netbeans 6.5.

Unlike Eclipse (where the link to do this is obvious), in Netbeans you will find this under:

Refactor / Encapsulate Fields

Enjoy!

Metro : JAX WS catalogue

One of the problems with using Netbeans to generate web services using Glassfish / Metro is that when you want to create a new Web service client, you are asked to select the web service which is normally on your local machine.

This means that the web service has an address like http://localhost:8080 and it then becomes a problem when you deploy to other environments.

One way around this is to use a catalog to resolve the addresses at run time. The file is called jax-ws-catalog.xml and it's placed in the META-INF directory.

It looks like e.g.

 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
<rewriteSystem
systemIdStartString="http://localhost:8080/"
rewritePrefix="http://some url:some port/"/>
<rewriteURI
uriStartString="http://localhost:8080/"
rewritePrefix="http://some url:some port/" />
</catalog>


This searches for any URL that starts with "http://localhost:8080/" and replaces this with "http://some url:some port/" e.g.

http://localhost:8080/webserver/WebService

becomes

http://some url:some port/webserver/WebService

The ant build files in Netbeans use the -catalog option to point to a file called catalog.xml in the project root directory. You can apply the same principles to this file to resolve addresses at compile time.

Some useful links:

Using a JAX-WS Catalog

How to write an XML catalog file

Global URI re-writing with jax-ws-catalog

Enjoy!