Wednesday, May 21, 2008

Installing VMware Server Console in Hardy Heron 8.04

Here are the steps I followed while trying to install VMware Server Console on Hardy:
  • Install some prerequisitives: sudo apt-get install build-essential linux-headers-`uname -r` xinetd
  • Download the VMware Server Linux client package, which is a zip that contains the following components components:
    - Linux VMware Server Console (.tar and .rpm)
    - Perl scripting API for Linux (.tar)
    - Programming API (.tar)
  • Unzip the downloaded file.
  • Extract the file VMware-server-console-1.0.4-56528.tar.gz.
  • Enter the directory it was extracted into and run sudo ./vmware-install.pl
  • The installer will ask some questions. Choose the default answer on all of them.
  • Running vmware-server-console will fail with the following error messages:
    /usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_3.4' not found (required by /usr/lib/libcairo.so.2)
    /usr/lib/vmware-server-console/lib/libpng12.so.0/libpng12.so.0: no version information available (required by /usr/lib/libcairo.so.2)
    /usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/libstdc++.so.6)
    /usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_3.4' not found (required by /usr/lib/libcairo.so.2)
    /usr/lib/vmware-server-console/lib/libpng12.so.0/libpng12.so.0: no version information available (required by /usr/lib/libcairo.so.2)
    /usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/libstdc++.so.6)
    /usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_3.4' not found (required by /usr/lib/libcairo.so.2)
    /usr/lib/vmware-server-console/lib/libpng12.so.0/libpng12.so.0: no version information available (required by /usr/lib/libcairo.so.2)
    /usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/libstdc++.so.6)
  • Create the following links:
    sudo ln -sf /lib/libgcc_s.so.1 /usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1
    sudo ln -sf  /usr/lib/libpng12.so.0 /usr/lib/vmware-server-console/lib/libpng12.so.0/libpng12.so.0
    

Monday, May 5, 2008

Installing, configuring and using ODBC on ubuntu

I wanted to use an ODBC-MySQL bridge on my linux box. Here are the steps I followed.
  • First of all, unixodbc comes installed on ubuntu. Otherwise you can install the package called unixodbc.
  • I downloaded and installed the ODBC connector from the MySQL website. I downloaded the rpm package, converted it to a deb with alien and installed it with dpkg.
  • I also found and installed these packages in the ubuntu repositories: mysql-connector-odbc and libmyodbc. There is probably some redundancy in this step and the previous one, but at least I didn't have any conflict issues and everything worked in the end.
  • Now, unixodbc relies on two files: /etc/odbcinst.ini and ~/.odbc.ini. The first one holds a registry with ODBC drivers for different database systems. The installer for the MySQL driver (the one from the MySQL website) registers the driver with this file, so you don't need to do that manually. The file should look like this:
    [MySQL]
    DRIVER          = /usr/lib/libmyodbc3.so
    SETUP           = /usr/lib/libmyodbc3S.so
    UsageCount              = 1
    
    Make sure the location of the drivers is the correct one.
  • The .odbc.ini is used for declaring datasources. Actually this file declares datasources on a per-user basis. Global datasources can be configured in the file /etc/odbc.ini. An entry on these files should look like this:
    [test]
    DRIVER = MySQL
    SERVER = localhost
    DATABASE = mysql
    USER        =root 
    PASSWORD    =
    PORT        = 3306
    SOCKET = /var/run/mysqld/mysqld.sock
    
    Needless to say that the DRIVER name should must the name of the driver, as it was declared on /etc/odbcinst.ini.
  • As you can see I also had to explicitly define the mysql socket. This was because the location of the mysql socket in ubuntu is different than in other linux systems. By default, unixodbc uses the location /tmp/mysql.sock, so you can either explicitly specify the socket location as above, or just create a link:
    sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
  • Now you can test the connection using
    isql -v test
    You should get a message like this:
    +---------------------------------------+
    | Connected!                            |
    |                                       |
    | sql-statement                         |
    | help [tablename]                      |
    | quit                                  |
    |                                       |
    +---------------------------------------+
    followed by an SQL prompt.
  • Finally this is some java code that uses this datasource:
    // There are two ways we can address a datasource: 
    // either with the DNS of a correctly configured ODBC datasource, 
    // or by providing all the database information.
         Connection conn = java.sql.DriverManager.getConnection(
                 //"jdbc:odbc:;DRIVER={MySQL};SERVER=localhost;DATABASE=mysql;",
                 "jdbc:odbc:test",
                 "root",
                 "");
       

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.

Tuesday, January 15, 2008

Programmatically adding a jenia4faces Popup component to a Netbeans 6.0 VWP project

This post describes how you can programmatically add a jenia4faces PopupFrame component to a Netbeans 6.0 Visual Web project.

There are various reasons why you would need to do that. In my case the requirement was that we needed a link in each row of a dynamically-created table that brings up a popup frame that is used for editing the database entry for this table row. Since the table is created dynamically, the same must be done with the PopupFrame component.

First you need to add the Jenia servlet in your web.xml file. This is a required step for using any Jenia component, no matter whether you add it to your page through JSP or from within Java code.

<servlet>
   <servlet-name>Jenia servlet</servlet-name>
   <servlet-class>org.jenia.faces.util.Servlet</servlet-class>
   <load-on-startup>
   </load-on-startup>
</servlet>
<servlet-mapping>
   <servlet-name>Jenia servlet</servlet-name>
   <url-pattern>/jenia4faces/*</url-pattern>
</servlet-mapping>
You also need the component jars in your project classpath.

Next you need to import the appropriate Java class in your Page bean. In the case of the PopupFrame this is

import org.jenia.faces.popup.component.html.HtmlPopupFrame;
If you want to dynamically add a different Jenia component, you can easily find the fully qualified name of the appropriate class by either browsing the Jenia jar files, or simply by using the Netbeans auto-completion function.

Now you can initialize the component and set its basic properties.

// Create the popup component
  HtmlPopupFrame popup = new HtmlPopupFrame();
// Set its properties
  popup.setId("editPopup");
  popup.setCenter("true");
  popup.setWidth("550px");
  popup.setHeight("400px");
  popup.setTitle("Edit Task");
  popup.setResizable("false");
  popup.setImmediate(true);
Again, you can use the auto-completion function in order to browse the supported properties and set any of those as required for your project.

Now it's the most tricky part: setting the method bindings for the actionOpen and actionClose properties. First we get a reference to the EL Expression Factory and create a MethodExpression.

  FacesContext fc = FacesContext.getCurrentInstance();
  ELContext elctx = fc.getELContext();
  ExpressionFactory elFactory = fc.getApplication().getExpressionFactory();
  MethodExpression openExpression = elFactory.createMethodExpression(elctx,
          "#{Staff.fireEditPopup}", String.class, new Class[]{});
Then we create a method binding using this expression and bind the actionOpen property.
   MethodBindingMethodExpressionAdapter bind1 = new MethodBindingMethodExpressionAdapter(openExpression);
   popup.setActionOpen(bind1);
Repeat the steps above for the actionClose attribute.

The PopupFrame component renders as a <a>. It can accept either plain text or an image as a child, so that it displays as a simple (text) hyperlink or an image hyperlink. This leaves us with an option to use either a StaticText or am ImageComponent in Netbeans. If you are not using Netbeans, you can add the respective standard JSF components (eg. <h:outputText>).

 // Create an image component
   ImageComponent edit = new ImageComponent();
   edit.setId("editLink");
   edit.setUrl("resources/edit.png");
   edit.setHeight(16);
   edit.setWidth(16);

   // Add the image to the popup (as a child)
   popup.getChildren().add(edit);

The Popup component is now ready. We can add it to the component tree. (In my case, I am adding it to the tablecolumn.)

column8.getChildren().add(popup);

Friday, January 11, 2008

awk: Simple and combined patterns

A simple usage for the awk command is to find lines in a file or a stream match given patterns. The command
awk '/pattern/' filename
is equivalent to
grep pattern filename

But awk is more powerful than grep, in that we can display only specific fields from the matching lines. The command

awk '/pattern/ {print $2}' filename
will only print the second field of the matching lines.

Patterns can be combined with the &&, || and ! operators.

awk '/foo/ && /bar/ {print $2}' example.txt awk '/foo/ && !/bar/ {print $2}' example.txt
The first command above will print the second field of the lines in example.txt that contain both 'foo' and 'bar', while the second one will only match the lines that contain 'foo' but not 'bar'.