Monday, April 28, 2008

Hide partition icons from your ubuntu desktop

http://tombuntu.com/index.php/2007/10/25/hide-partition-icons-from-your-ubuntu-desktop/

Changing the looks of the input boxes and button on Firefox

Firefox 2 looks like crap on linux. The buttons and other input widgets just look so 90s... Jesse "fatsheep" Cambon has created a nice little app to change the appearance of all the input controls (buttons, textfields/textareas/dropdowns/checkboxes etc). The app can be downloaded at ubuntuforums. You just have to download the archive, extract it, run ./install and restart firefox. That's all.

Thursday, April 24, 2008

Installing MS Word 2003 on ubuntu using WINE

Although OpenOffice is a fairly decent suite, there are still some compatibility issues between OO and MSOffice. In my experience these have to do with formatting, which just gets messed up if you open a Word document on OO and save it as a .doc. I read somewhere that these problems can probably be overcome if you install some fonts on linux, but I didn't try that.

Instead, I thought I should finally give WINE a try so I could stop dual-booting. I found a very helpful guide on Sorcerer's tech. I am using Feisty Fawn 7.10, and I only installed and tested Word. At the time of writing this, the newest version on the ubuntu repositories was 0.9.46. When I tried it out with this version, I got an error message as soon as Word launched, saying something like this: "Microsoft Word has not been installed for the current user", and then it would just close. After a quick search on the Web, I found out that I had to use an older version of Wine, so I downloaded the 0.9.37 version and everything worked fine.

Note: Accordint to the Sorcerer's tech, this should work on all flavors of linux.

Tuesday, April 22, 2008

Create a custom keyboard layout in linux

This post explains how you can create a custom keyboard layout in linux.

Tuesday, April 8, 2008

Wrapping all dependencies in a jar

Yesterday I encountered this issue: I have been writing a client code that contacts a web service. I wanted to implement a modularized solution by wrapping all web service related code and dependencies in a library, so that I could jsut use this library in my client code, without having to worry about the WS specifics (ie the web service location, how to establish connection with it etc).

So I created a package that operates as a middle layer between the WS and the client code and then packaged it into a jar file. However, when I tried to use that in an applet I realised that I also had to distribute all of the jar's dependencies with the applet. (This problem wasn't obvious while running the program as a Java application, cause JVM was able to locate the dependencies in the file system.)

I made a little research and I found out that it is not possible to include other jars in a jar file, just like you can do with war files. The suggested solution is to unpackage all jars and re-package them into your own jar. Of course this isn't something that you can easily do by hand, especially if you think that the whole process has to be repeated each time you compile your project.

So this process has to be automated and ant is one way to do that. I will be demonstrating how this can be done on Netbeans.

First a few words about how Netbeans uses ant. In your project folder you will find two build files:

  • $PROJ_HOME/build.xml
  • $PROJ_HOME/nbproject/build-impl.xml
The second one is the actual build file that Netbeans automatically creates using the project properties, and is updated each time you add a new source file, or add a new JAR to the project classpath. You should not edit this file. (Actually even if you do, your changes might be overwritten when the file is automatically regenerated.) You should only edit the first one. This file defines a number of pre and post targets that are built just before or just after the basic targets of build-impl.xml.

In our case we will use the -pre-jar target. The commands of this target will extract the library jar files into the built directory just before the jar target is called, so the latter will include them when creating the project's jar file. An example of the definition of this target is shown below.

    <target name="-pre-jar">
        <unjar src="${file.reference.axis-ant.jar}" 
                  dest="${build.classes.dir}"/>
        <unjar src="${file.reference.activation.jar}"  
                  dest="${build.classes.dir}"/>
        <unjar src="${file.reference.axis.jar-1}" 
                  dest="${build.classes.dir}"/>
        <unjar src="${file.reference.commons-discovery-0.2.jar}" 
                  dest="${build.classes.dir}"/>
        <unjar src="${file.reference.commons-logging-1.0.4.jar}" 
                  dest="${build.classes.dir}"/>
        <unjar src="${file.reference.jaxrpc.jar-1}" 
                  dest="${build.classes.dir}"/>
        <unjar src="${file.reference.log4j-1.2.8.jar}"  
                  dest="${build.classes.dir}"/>
        <unjar src="${file.reference.saaj.jar-1}" 
                  dest="${build.classes.dir}"/>
        <unjar src="${file.reference.wsdl4j-1.5.1.jar}" 
                  dest="${build.classes.dir}"/>
        <unjar src="${file.reference.activation.jar}" 
                  dest="${build.classes.dir}"/>
        <unjar src="${file.reference.mail.jar}" 
                  dest="${build.classes.dir}"/>
    </target>

We need an unjar element for each jar we want to repackage in our jar. The dest attributes specifies that the jars should be extracted in the project's build directory; you should leave that as it is.
Now, the value of the src attribute contains a reference to the jar file that will be unjar-ed. You can find the values you should use in the file $PROJ_HOME/nbproject/private/private.properties. This properties file contains key-value pairs with the names used by Netbeans for library files and the actual location of these files.

Thursday, April 3, 2008

SOAP attachments with AXIS

I wanted to create a Web Service that accepts a JPEG image as the input. The preferred way to send an image in a SOAP message is using SOAP attachments.

Below is a sample WSDL file for a service that accepts an image as input.


<?xml version="1.0" encoding="UTF-8"?>
<definitions name="newWSDL" targetNamespace="http://www.example.com/example"
            xmlns="http://schemas.xmlsoap.org/wsdl/"
            xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://www.example.com/example"
            xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/"
            xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
  

   <message name="isLabelAuthenticRequest">
       <part name="labelImage" type="xsd:hexBinary"/>
   </message>
   <message name="isLabelAuthenticReply">
       <part name="isAuthentic" type="xsd:boolean"/>
   </message>
  
   <portType name="isLabelAuthenticPortType">
       <operation name="isLabelAuthenticOperation">
           <input name="authenticInput" message="tns:isLabelAuthenticRequest"/>
           <output name="authenticOutput"
 message="tns:isLabelRegisteredOperationReply"/>
       </operation>
   </portType>
  
   <binding name="isLabelAuthenticBinding" type="tns:isLabelAuthenticPortType">
       <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
       <operation name="isLabelAuthenticOperation">
           <soap:operation/>
           <input name="authenticInput">
               <mime:multipartRelated>
                   <mime:part>
                       <soap:body use="encoded"    
   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.example.com/example"/>
                   </mime:part>
                   <mime:part>
                       <mime:content part="labelImage" type="image/jpeg"/>
                   </mime:part>
               </mime:multipartRelated>
           </input>
           <output name="authenticOutput">
               <soap:body use="encoded"
  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.example.com/example"/>
           </output>
       </operation>
   </binding>
  
   <service name="smartLabelDemoService">
       <port name="isLabelAuthenticPort" binding="tns:isLabelAuthenticBinding">
           <soap:address location="http://192.168.0.156:8080/Example/authentic"/>
       </port>
   </service>
  
</definitions>

The highlights of the WSDL file:

  • The following namespace for SOAP must be used to enable support for attachments:
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/
  • The message that will include an attachment is declared to be of type xsd:hexBinary
  • The actual structure of this message is specified in the binding element. It is specified as a multipart message, with the MIME type of the second part set to image/jpeg.

The WSDL2Java utility offered by Axis, should be able to parse this wsdl document and generate the stubs successfully. (I have been using version 1.4 of Axis). Of course, for WSDL2Java to work, all the axis-related jars (ie all the jars in the folder $AXIS_HOME/lib) must be present in the CLASSPATH. Furthermore, for attachment support, we also need mail.jar and activation.jar. The first one is part of the Java Mail API and the second on can be found in the JavaBeans Activation Framework.

However I was getting the following error message when I tried to implement and test the web service:

http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: Bad envelope tag:  html
  org.apache.axis.message.EnvelopeBuilder.startElement(EnvelopeBuilder.java:71)
  ...

I could only understand what was causing this when I used the tcpmon utility to monitor the TCP connections. This actually revealed that the server was returning an HTML document (rather than a SOAP message) containing an error message:

java.lang.RuntimeException: No support for attachments
  org.apache.axis.Message.setup(Message.java:372)
  ...

So, it was a matter of just enabling attachment support on the server side. This can be done by simply copying mail.jar and activation.jar under the location where axis has been deployed, ie under the directory $CATALINA_HOME/webapps/axis/lib.