Posts

Showing posts with the label tomcat

Tomcat behind Apache HTTP server using Spring Security

Since I have been struggling with applications not working properly behind Apache HTTP server that use Spring Security I dedicated this blog to this issue. When you develop an application using Spring security this works fine when just running on a Tomcat server e.g. http://localhost:8080/app-context/. The problems start when you want to setup your environment properly by adding an Apache HTTP server in front of it using proxy AJP. You would start by adding the following to your apache config file: ProxyPass /app-context/ ajp://localhost:8009/app-context/ This works fine when trying to go to http://servername/app-context/ but when you try to login you will be redirected back to the login page everytime. To avoid this behavior you need to add the following line to your Apache configuration: ProxyPass /app-context/j_spring_security_check ajp://localhost:8009/app-context/j_spring_security_check For some reason it doesn't work without this line which seems weird to me since you basical...

Configure Tomcat as a deamon on Linux

Since I keep on forgetting how to do this I decided to put this on my blog to make it easier for me and other people that have the same issue as me. It's pretty simple actually but yesterday I caught myself forgetting how it needs to be done. Basically you need to follow to following steps to successfully. Step 1 - Creating startup deamon file You can take the following file and adjust it accordingly. You have to create this file in /etc/init.d/. #Jenkins startup script #!/bin/sh -e #Jenkins startup script #chkconfig: 2345 80 05 #description: Jenkins CI # Define some variables # Name of app APP=Jenkins # Name of the user to run as USER=tomcat # Location of application's bin directory BASE=/var/tomcat/instances/jenkins # Location of Java JDK export JAVA_HOME=/opt/java/jdk1.6.0_11 case "$1" in # Start command start) echo "Starting $APP" /bin/su -m $USER -c "cd $BASE/logs && $BASE/bin/startup.sh &> /dev/null" ;; # Stop...

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

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

Enabling GZIP compression on Tomcat

Enabling GZIP compression for your web application is a good way to accelerate your web site. This can reduce the size of data being transferred and, consequently, speed your application. Enabling compression on the web server will make data be transferred in compressed form. The browser will decompress the data on the fly, making the application faster. If your application uses Ajax, what usually increases the volume of data transferred from server to client, compression of data will significantly improve your application performance. Here is how to enable GZIP compression on Tomcat: edit file /conf/server.xml and add to the HTTP Connector configuration something like this: compression="on" compressionMinSize="2048" noCompressionUserAgents="gozilla, traviata" compressableMimeType="text/html,text/xml" An example of a HTTP Connector configuration with compression enabled could be: Connector port="8080...