Posts

Showing posts with the label J2EE

Cargo-itest extended

I have been doing some work on the cargo-itest project and extended it with the following features: - JOnas support - Jetty support - Auto detection of configuration files for JBoss - Extended logging information to be able to detect problems in an easier way These changes will be in the next release 1.2.0. The auto detection is a nice one since it automatically picks up .properties files and -ds.xml (Data source files) from a preconfigured location so you don't have to copy them selves to the correct location. :-) In the future we will try to implement configuration by annotation since some users prefer doing configuration through annotation instead of an XML file. In this case a Spring context file.

Shared configuration on Tomcat 6

In Tomcat 5 there was the famous ${catalina.home}/shared/classes which you could use for sharing class files, properties files etc. Tomcat 6 by default doesn't come with this directory. In a first glance it seems that you can't do it anymore :-(.. But that's not true :-).. You need to configure Tomcat to point to a directory which you want to be shared location so applications can pick up resources from the classpath. The configuration is very simple. Just go to ${catalina.home}/conf and open catalina.properties. Add the path to the  shared.loader property. It will look something like this: # # List of comma-separated paths defining the contents of the "shared"  # classloader. Prefixes should be used to define what is the repository type. # Path may be relative to the CATALINA_BASE path or absolute. If left as blank, # the "common" loader will be used as Catalina's "shared" loader. # Examples: #     "foo": Add this folder as a cla...

Fastest XML parser

In most applications you need to do some XML parsing to either provide XML to external systems or parse XML from external systems or of course both. Since the systems I work on use a lot of XML and they need to be as fast as possible I did some tests on several XML parsers. I tested the following parsers/XML frameworks: JDom Piccolo StaxMate XStream JAXB 2.1 All parsers were tested in isolation with the following parameters: 25 threads running simultaniously Every thread calls the parser 100 times The results are as follows. JDom Avg. parsing time: 325.24 ms Avg. memory usage: 307 KB Piccolo Avg. parsing time: 88.08 ms Avg. memory usage: 454 KB StaxMate Avg. parsing time: 96.16 ms Avg. memory usage: 203 KB XStream Avg. parsing time: 77.04 ms Avg. memory usage: 319 KB Jaxb 2.1 Avg. parsing time: 1778.12 ms Avg. memory usage: 618 KB As you can see XStream is the fastest one of them all. The total ranking of the parsers you can find below: XStream Piccolo StaxMate JDom JAXB 2.1 ...

Cargo-itest continues

The 0.3 version of my cargo-itest project now also supports Tomcat. So now Tomcat users can also write integration tests with fairly little effort. I am also extending it with an AbstractDefaultHibernateDeploymentTest which can be used to easily generate your database schema from your annotated classes. Before it wasn't possible to execute SQL scripts for test data. Now I added the functionality to enable you to execute SQL scripts before the deployment tests are run and also after. The execution of the SQL scripts will be before and after transaction so it will not be rolled back by the test case itself. Internally it uses the AbstractTransactionalJUnit4SpringContextTests but you only need to configure a list of file names in your itest-context.xml file which in turn will automatically be picked up by the test. Also added support for applications that don't use a database at all with the AbstractDefaultNoDbDeploymentTest class. In the near future I will also implement containe...

Cargo-itest open source project

I recently started an open source project called cargo-itest. This was started up because when I worked on several projects I needed to create integration tests for them which all had similarities. I was previously doing it with the maven2 cargo plug-in but wasn't really fond of it because it most of the times didn't work and when it worked it stopped working after editing the configuration. In other words it was very unstable. This initiated me to start to use the java API of Cargo instead of the maven plugin. By using the java API it already removes the dependency from your build system in this case Maven. Having no dependency on the build system gives you a couple of advantages: You can run it in any IDE that supports JUnit. You can switch easily to another build system without changing your tests and test configuration. These are general advantages of just using the API but also part of using my open source project cargo-itest. This project enables you to easily start creat...

Specify context name in Tomcat

When developing web applications that are distributed as WAR files running in Tomcat most of the times you want to be able to specify the context name to a nicer name than Tomcat provides by default. Which is the name of the WAR file itself. When i.e. you are keeping the version within the name of the WAR this will result in some weird name like myapp-1.2. This is most of the times not what you want. Most of the times you want a nice context name like myapp without the version in it. According to the Tomcat documentation you can do it in 3 ways: Edit the server.xml Add a context.xml to the $CATALINA_HOME/conf/Catalina/localhost with the name of your context. Add a context.xml to your META-INF directory in your WAR file The first two options just work fine only the last one doesn't do the job for you for some reason. Personally the second option is the best option since it's not intrusive to your application and also not to Tomcat since you leave the server.xml alone. This way y...

Remotely debugging JBoss

When working with JBoss sometimes it's needed to debug your code while running instead of running your application in a lightweight servlet container like Jetty or Tomcat. This can be done by adding the following line to your run.bat or run.sh: -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 You need to add this to your JAVA_OPTS variable so it will be used when JBoss starts up. When starting up now you can attach a debugger i.e. in Eclipse to the port you specified. :-)