How to find true cause of com.sun.star.uno.RuntimeException?

I’m stuck with OpenOffice. I’m hoping somebody can help me with this. I’ve also posted the question to the OpenOffice.org forums and to StackOverflow, but so far no luck.

I’m trying to replace a field in an openoffice document using the OpenOffice java api. I’m using the insertString method:

  xText.insertString(((XTextField) fieldMaster).getAnchor(), value.toString(), false);

The stacktrace is as follows:

com.sun.star.uno.RuntimeException:
	at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:182)
	at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:148)
	at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:344)
	at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:313)
	at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:101)
	at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:652)
	at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:154)
	at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:136)
	at $Proxy14.insertString(Unknown Source)
...

If i interpret this correctly, it’s telling me that it connected to a different process from java, something in the other process failed, but it’s not telling me what.

I found that there are some environment variables (PROT_REMOTE…) that would let me log messages from these remote (different process, same computer, btw) processes, but only if i run an OpenOffice version with debugging enabled? I’m using an openoffice version from an deb repository on ubuntu, and have to interest in compiling my own openoffice version.

Is there any way i can get some useful error messages from the remote process to help me understand why my code is failing?

Targetting different environments with Grails

Mainly as a reminder to myself, here’s how you target different environments with grails.

Grails knows about three environments out of the box: development, test, production. When you create a war file you can specify the environment after the grails command:

grails test war

Sometimes, (actually quite often), you have more environments. For example a user acceptance testing environment. You can easily add configuration information for a new environement in your grails apps. Here are some lines of code from DataSource.groovy, to define the datasource for the acceptance environment:

	acceptance {
		dataSource {
			dbCreate = "update"
			jndiName = "jdbc/myAppPool"
		}
	}

If you want to create a war file for this environment, you need to run grails as follows:

grails -Dgrails.env=acceptance war

Btw, if you want to write code for a specific environment, for example to automatically create some test data in your development environment, you can do this as follows. In BootStrap.groovy you’d write:

class BootStrap {
  def init = { servletContext ->
    if (GrailsUtil.environment == "development"){
      def employee = new Employee(...)
      employee.save()
    }
  }
}

One last remark: i really don’t like targetting different environments when building the software. I think you should be able to ship one and the same war file to 100 customers, without having to change the war file. I also think you should be able to install one and the same war file on all your environments without rebuilding the file. Otherwise your build might introduce bugs that you though you’d fixed.

Ivy support in Grails 1.1

I was just going through the Grails 1.1 beta 3 release notes and found that Grails 1.1 is not only going to support Maven but also has Ivy support for those who prefer using Ant.

Good news in my opinion. I still use Ant quite a bit, on projects that are not standard enough to be handled by Maven. Also i think that once you’ve created a library with standardized ant macro’s the need for Maven gets quite low. But library dependency management is one of the things i really value on projects. Ivy is a really good solution for dependency management on Ant projects. Good to see it included in Grails.

Using google talk from java example

Sending and receiving messages to and from google talk accounts is actually very easy. Google uses the xmpp (jabber) protocol. The Smack library enables you to use the xmpp protocol in java.

I was actually trying to use xmpp in apache camel, but couldn’t get it working with google accounts, just with other accounts, so i decided to do some basic smack testing. Smack doesn’t have any problems with google accounts. Here’s a basic example i wrote to test it


// connect to gtalk server
ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection connection = new XMPPConnection(connConfig);
connection.connect();

// login with username and password
connection.login("camel.test.1", "secret");

// set presence status info
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);

// send a message to somebody
Message msg = new Message("camel.test.2@gmail.com", Message.Type.chat);
msg.setBody("hello");
connection.sendPacket(msg);

// receive msg
PacketListener pl = new PacketListener() {
@Override
public void processPacket(Packet p) {
System.out.println(p.getFrom() + ": " + p.toString());
if (p instanceof Message) {
Message msg = (Message) p;
System.out.println(msg.getFrom() + ": " + msg.getBody());
}
}
};
connection.addPacketListener(pl, null);

// wait for user to end program
System.in.read();

// set presence status to unavailable
presence = new Presence(Presence.Type.unavailable);
connection.sendPacket(presence);

This is a very basic example, you’d normally create a chat session, and listen for messages part of the chat. More info on the smack site.

Devoxx day 4

Another good day at devoxx, more surprises: keynotes don’t have to be boring marketing talks. The day started with 2 good keynotes by sun. The first by Joshua Bloch, containing lots of code and good tips from his book: Effective Java. The next keynote presented the plans to modularize Java starting with Java 7. You can find more info here Java SE: Project Jigsaw: Modularizing JDK 7, and on Mark Reinhold’s blog

Paul Fremantle did a presentation on Event Driven Architecture and Complex Event Processing, showing examples using Apache Synapse and Esper. CEP seems very usefull in situations where you have to find informations in a large number of events. Currently Esper can be used in Synapse. Not sure how easy it integrates with other ESBs. Would be nice to have it available as an OSGi bundle, which can be used in Spring DM, ServiceMix 4, and Glassfish 3.

Next up: a talk about using Geospatial Software to create a website for kitesurfers. I do a lot of kitesurfing and windsurfing myself, so i had to see this presentation. After a short introduction, the presenter demoed how you can build geospatial websites using open source software. It was interesting to see, but not really about programming. You can achieve most of what you want using existing software, it’s mostly about configuring the software and loading the data.

Paul Sandoz did a talk on JAX-RS and the Jersey implementation. I haven’t used JAXRS yet, as i’ve been doing most of my REST stuff using Grails, which is dead easy. But Jax-RS seems like a pretty good way to do it in java. Also, i learned that they have support for JSON in JAXB, which i wasn’t aware off.

Client-Server 2.0 using JQuery and Grails

Last week gave a presentation on JQuery and Grails for a group of java freelancers called Java-Knights. In this presentation i demonstrated that it’s not only possible to build single page web applications using JQuery and Grails, but that it’s also very productive and easy.

I’ve uploaded the presentation to slideshare in case anybody is interested. There’s not much text on the slides, so they might not be very useful, but i’ll be doing the same presentation during JFall on november 12th: Waarom renderen we de view laag eigenlijk nog op de server?.

View SlideShare presentation or Upload your own. (tags: javascript jquery)

More info on client-server 2.0 can be found on the IT-eye weblog: What is Client-Server 2.0

Btw, although i like grails very much as a way to implement REST services, i do think that in the future i more dedicated SOA container might be usefull. For example, something like ServiceMix kernel combined with Apache Camel. But i haven’t found a way to create REST-services in ServiceMix that is as easy as doing it with Grails.

Simple Camel DSL OSGi Bundle example

Here’s a simple example how you can create a Camel Route using it’s DSL, and deploy it as an OSGi bundle in the ServiceMix Kernel.

I’ll start with the java class that builds the camel routes. The following class, nl.iteye.camelbundle1.FileRouteBuilder configures a route that will copy any file from /tmp/src to /tmp/dest.


package nl.iteye.camelbundle1;

import org.apache.camel.builder.RouteBuilder;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class FileRouteBuilder extends RouteBuilder {
private static final transient Log LOG = LogFactory.getLog(FileRouteBuilder.class);

public void configure() {
LOG.info("configuring routes");
from("file:///tmp/src").to("file:///tmp/dest");
}
}

I’m going to create an OSGi bundle which can be deployed in the Servicemix kernel. An OSGi bundle is basically a jar file with a special manifest file. The following code shows the META-INF/manifest.mf file.


Manifest-Version: 1.0
Bundle-Name: camel-bundle-1
Bundle-SymbolicName: camel-bundle-1
Bundle-Version: 1.0.0
Bundle-Description: Camel Bundle 1
Bundle-Vendor: IT-eye
Bundle-Category: example
Import-Package: org.osgi.framework, org.apache.commons.logging, org.apache.camel.builder, org.apache.camel.model

When you deploy a bundle in Servicemix, Spring looks for META-INF/spring/*.xml files which can contain camel routes. In the following file i’m telling spring to look in the package nl.iteye.camelbundle1 for classes. This way my FileRouteBuilder class will automatically be run when the bundle is started.


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

http://activemq.apache.org/camel/schema/spring

http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

<camelContext xmlns="http://activemq.apache.org/camel/schema/spring" >
<package>nl.iteye.camelbundle1</package>
</camelContext>
</beans>

Next I’m using a simple ant script to compile and jar the above files. The resulting jar can be installed in ServiceMix.

Before you can install the bundle, you need to install some required bundles, as is described here: Apache ServiceMix Kernel and Camel. You can verify the bundles installed correctly using osgi list command in ServiceMix kernel. The result should show the following modules:


[  29] [Active     ] [   50] camel-core (1.4.0)
[  30] [Active     ] [   50] camel-spring (1.4.0)
[  31] [Active     ] [   50] spring-tx (2.5.5)

Now i can install the bundle i’ve created as follows:


servicemix> osgi install file:///tmp/osgi/camel-bundle-1.jar
Bundle ID: 68
servicemix> osgi start 68

Test it by creating a file in /tmp/src.

Jwebunit, untrusted certificates, https and proxies

Jwebunit is an excellent tool for testing webpages. It’s part of our build process in cruisecontrol. In the build script we deploy all ear files to an Oracle Application Server and then we use jwebunit to test all the webpages.

Getting jwebunit to work over https, using an untrusted certificate (eg, a self signed certificate), behind a proxy requires some configuration. First some code. The following is a simple jwebunit test:

import net.sourceforge.jwebunit.WebTestCase;

public class Test1 extends WebTestCase {
    public Test1() {
    }

    protected void setUp() throws Exception {
        super.setUp();

        // configuration for http proxy use
        System.setProperty("proxyHost", "10.0.0.1");
        System.setProperty("proxyPort", "8080");
        System.setProperty("proxySet", "true");
        System.setProperty("http.nonProxyHosts", "mywebserver");

        // configuration for https proxy use
        System.setProperty("https.proxyHost", "10.0.0.1");
        System.setProperty("https.proxyPort", "8080");
        System.setProperty("https.proxySet", "true");
        System.setProperty("https.nonProxyHosts", "mywebserver");

        // configure which keystore to use to validate certificate
        System.setProperty("javax.net.ssl.trustStore",
            "d:\\projects\\tests\\jwebunit\\dev.keystore");
        System.setProperty("javax.net.ssl.trustStorePassword", "secret");

        // specify base url of the web application
        getTestContext().setBaseUrl("https://mywebserver/app1/");
        beginAt("/");
    }

    public void test1() {
        // test the title of the default page
        assertTitleEquals("App1 title");
    }
}

The setup method first specifies which proxy to use for http connections. It then specifies the proxy for https connections. The last configuration step specifies a keystore which can be used to validate certificates. This is required if the web server you are using, uses certificates issued by an untrusted party for the https encryption. This might be the case if you create your own certificate, for example using java’s keytool.

You have to tell java that the untrusted certificate used by the webserver can be trusted, otherwise your jwebunit test will fail with the following error:

Caused by: javax.net.ssl.SSLHandshakeException:
  sun.security.validator.ValidatorException: No trusted certificate found

To avoid this you provide the certificate used by the webserver in a keystore. The easiest way to save the certificate used by the webserver is to open your website with internet explorer. MSIE will show a ‘Security Alert’ popup window. If you select ‘View Certificate’, choose the ‘Details’ tab, andthen ‘copy to file’, you can save the certificate on your development pc.

After you’ve saved the certificate you can display the contents of the certificate using keytool:

D:\projects\tests\jwebunit>keytool -printcert -file dev.cer
Owner: CN=dvlp.iteye.nl, O=IT-eye, L=Nieuwegein, ST=Utrecht, C=NL
Issuer: O=IT-eye, C=NL
Serial number: 6
Valid from: Mon Mar 14 15:06:35 CET 2005 until: Sat Mar 13 15:06:35 CET 2010
Certificate fingerprints:
         MD5:  7B:26:F0:67:48:4C:1C:35:52:C4:BC:32:50:72:49:CE
         SHA1: 94:44:33:18:59:66:BB:71:9F:5B:7C:FE:C3:A6:A8:04:2F:9B:DB:1D

Next, import the certificate into a keystore as follows:

D:\projects\tests\jwebunit>keytool -import -v -file dev.cer  -storepass secret -keystore dev.keystore -alias dev
Owner: CN=dvlp.iteye.nl, O=IT-eye, L=Nieuwegein, ST=Utrecht, C=NL
Issuer: O=IT-eye, C=NL
Serial number: 6
Valid from: Mon Mar 14 15:06:35 CET 2005 until: Sat Mar 13 15:06:35 CET 2010
Certificate fingerprints:
         MD5:  7B:26:F0:67:48:4C:1C:35:52:C4:BC:32:50:72:49:CE
         SHA1: 94:44:33:18:59:66:BB:71:9F:5B:7C:FE:C3:A6:A8:04:2F:9B:DB:1D
Trust this certificate? [no]:  yes
Certificate was added to keystore
[Saving dev.keystore]

Make sure the file is stored in the location specified in the code.