Showing posts with label tomcat. Show all posts
Showing posts with label tomcat. Show all posts

Wednesday, 21 November 2012

Tomcat 7.0.32, IE & javascript comments


UPDATE: this is fixed in 7.0.33


A funny one this & one that took a while to track down.
First off the bug does not show itself in firefox or chrome (proper browsers), just IE, but sadly we have to get them all to work.

My development system was running perfectly in all tested browsers but then my tester reported an issue where a page was just displaying a blank page.

We blamed the data, his version of IE, which was 8 & I am on IE 9.

Eventually we struck on the tomcat versions. I was running 7.0.29 & he was running what is currently the latest tomcat 7.0.32

So looking further I worked out that if I swapped over the jasper jars I could get 7.0.32 to work. The issue turns out to be the javascript comments. If there is an uneven number of dashes next to the percent then the page will fail.

 So this is good.
 <%-- a good javascript comment --%>;  

& this will fail
 <%--- a dodgy javascript copmment in tomcat 7.0.32 --%>  

Thursday, 16 September 2010

tomcat IE and parse locale Exceptions

I have just done an upgrade for a customer that involved new java, tomcat as well as a new version of our application software.


The webapp was failing with the following Exception:


Caused by: javax.servlet.jsp.JspException: In &lt;parseNumber&gt;, a parse locale can not be established
at org.apache.taglibs.standard.tag.common.fmt.ParseNumberSupport.doEndTag(ParseNumberSupport.java:134)
at org.apache.jsp.tag.web.shared.paging_tag._jspx_meth_fmt_005fparseNumber_005f0(paging_tag.java:598)
at org.apache.jsp.tag.web.shared.paging_tag.doTag(paging_tag.java:241)
at org.apache.jsp.pages.jsp.type3Footer_jsp._jspx_meth_tag_005fpaging_005f0(type3Footer_jsp.java:220)
at org.apache.jsp.pages.jsp.type3Footer_jsp._jspService(type3Footer_jsp.java:114)
... 73 more


Some googling pointed me to adding locale java options:
This just shifted the problem to Oracle Exceptions complaining about NLS_LANG and suggesting
After all the application worked fine before.

So what was my final solution.

Very simple. In IE go to Tools->Internet Options->General/Languages.
  • found out there were no languages set
  • Add the appropriate one
  • English (United Kingdom) [en-gb] in my case.



Monday, 5 July 2010

Getting eclipse to connect to a running tomcat

Firstly tomcat needs to set up to allow a debug connection.

These instructions are for windows - sorry.

  • Go to the tomcat/bin directory and run tomcat6w.exe
  • Click on the java tab
  • To connect on port 8002 add the line:
    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8002
  • And start tomcat normally


Now go to eclipse.

  • Go the Debug perspective
  • Click on the 'bug' arrow and select 'Debug Configurations'
  • Double click 'Remote Java Application'
  • Give it a name EG 'tomcat'
  • Select the project
  • Select the server if it is not localhost (the default)
  • Select the port that you used above eg 8002
  • Click on the 'debug' button and you are now debugging the tomcat session.

If you want to save that config to use again do the following

  • Click on the 'bug' arrow and select 'organise Favourites'
  • Select 'Add'
  • Search down for the name of the debug session and tick the box
  • Select OK.

Wednesday, 3 March 2010

SSL, tomcat and self signed certificates

I have been through the process of getting an application to work via https before but I have always muddled through and never documented exactly what I have done.

I must also admit that I never quite understood exactly what I had done and why.

One problem is that I can not find one place that covers everything you need in one place.

Now I think I am pretty well there.

This post describes what I have done to get a simple client application working using HTTPS posting to tomcat server and using a self signed certificate with the help of several refereneces in particular:

The last reference has a chapter which is pretty well SSL for dummies and explains things very nicely.

The steps that need to be done are:
  1. Create a self signed certificate authority (CA)
  2. Sign a test key via the CA
  3. Add both these keys to a keystore
  4. Setup the application (client) and tomcat (the server) to use this keystore.

1) Create a self signed certificate authority (CA) and keystore

This is described in How to create a self signed certificate, but I will show the steps here

What is happening here:
you will create a CA that later will be added to your keystore file. By adding this CA to your keystore you are saying it is trusted like verisign and any certificates signed by it are then also trusted.


1.1) make a directory to hold the certs and keystore. This might be something like:
C:\ssl
1.2) generate a private key for the server
openssl genrsa -des3 -out server.key 1024
1.3) generate a CSR (Certificate Signing Request)
openssl req -new -key server.key -out server.csr
1.4) Remove the passphrasse from the key
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key

1.5) Generate the self signed certificate
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

2) Create a certificate for tomcat and add both to the keystore

2.1) cd to where the keystore is held. This might be something like:
C:\ssl

2.2) Create a keypair for 'tomcat'
keytool -genkey -alias tomcat  -keyalg RSA -keystore tomcat.ks

2.3) Generate a CSR (Certificate Signing Request) for tomcat
keytool -keystore tomcat.ks -alias tomcat -certreq -file tomcat.csr

2.4) create unique serial number
echo 02 > serial.txt

2.5) Sign the tomcat CSR
openssl x509 -CA server.crt -CAkey server.key -CAserial serial.txt -req -in tomcat.csr -out tomcat.cer -days 365

2.6) Import the server CA certificate into the keystore
keytool -import -alias serverCA -file server.crt -keystore tomcat.ks

2.7) add the tomcat certificate to the keystore
keytool -import -alias tomcat -file tomcat.cer -keystore tomcat.ks

3) Tomcat configuration
3.1) Tomcat needs to be configured to use SSL
This is described in more detail at Tomcat SSL Configuration How-To
However all that is needed here is to edit the server.xml to enable SSL
This section is already in the server.xml but commented out.
NB that the location of the keystore has been added.

<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
keystoreFile="C:\ssl\tomcat.ks"
keystorePass="changeit"
clientAuth="false" sslProtocol="TLS" />

3.2) test tomcat
start tomcat and go to https://localhost:8443/

your browser will return an error such as "sites certificate is not trusted"

3.3) import the CA certificate server.crt into your browser's tructed root certificates

3.4) test again at https://localhost:8443/

this time you should see the tomcat home page

4) Test your application

4.1) I have a unit test run from eclipse that I have been using to post off to my test server. This produces the error;
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:289)

4.2) The reason for this is that eclipse is not referring to the keystore that we have created. At the time of writing I have not sussed out how to make eclipse use this - Do you know ?
So instead I have added the same two certs to javas keystore

4.3) cd to the directory where java's keystore is held. This might be something like:
C:\java\jdk1.6.0_18\jre\lib\security

4.4) the keystore is a file called cacerts

4.5) copy the files c:\ssl\server.crt and c:\ssl\tomcat.cer to this directory

4.6) import the server CA into the java keystore
keytool -import -alias serverCA -file server.crt -keystore cacerts
4.7 import tomcats cert into the java keystore
keytool -import -alias tomcat -file tomcat.cer -keystore cacerts

5) Test your app again.
Hopefully all will be hunkdory. Enjoy.

6) Caveats:

6.1) the passwords for all keystores and certs are 'changeit'. this is the default keystore password
and I suggest you change this for a production system

6.2) Using a self signed cert is great for a test environment of for a private system but not for a commercial released application. For this you will need to get & pay for a signed certificate from an approved authority such as Verisign.

Tuesday, 17 March 2009

org.hibernate.DuplicateMappingException and tomcat

There are probably many reasons why you might get a DuplicateMappingException from an application using hibernate. Not least because you have a mapping defined twice.

However I have just found this reason and it is new to me.

In the tomcat logs I found this:
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping uk.co.formfill.dfcommon.domain.dfwv.Action
at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:154)
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.hibernate.cfg.Configuration.addFile(Configuration.java:267)

Looking further up the tomcat logs to just before the first Exception stack trace there was this:
17-03-2009 10:44:22 [Thread-1] INFO  - Reading mappings from file: D:\apache-tomcat-6.0.14\work\Catalina\localhost\dfweb\loader\uk\co\formfill\dfcommon\hibernate\mappings\dfwv\actions.hbm.xml
17-03-2009 10:44:22 [Thread-1] INFO - duplicate import: uk.co.formfill.dfcommon.domain.dfwv.Action->uk.co.formfill.dfcommon.domain.dfwv.Action
17-03-2009 10:44:22 [Thread-1] INFO - duplicate import: uk.co.formfill.dfcommon.domain.dfwv.Action->Action
17-03-2009 10:44:22 [Thread-1] INFO - Mapping class: uk.co.formfill.dfcommon.domain.dfwv.Action -> ACTIONS

So I looked in D:\apache-tomcat-6.0.14\work\Catalina\localhost\dfweb and that was empty. Strange.

The same war worked fine on a different installation and the cause was in the tomcat configuration.

The offending line was in tomcat's context.xml with the problem being the overriding of the antiJARLocking property which had been done beacuse of some historical apps..
<Context antiJARLocking="true">

Removing this and all is fine. Looking at the tomcat documentation I can not see why this problem might occurr but hey ho, it is fixed.