Glassfish Error – java.lang.ClassCastException: org.glassfish.grizzly.config.ContextRootInfo cannot be cast to org.apache.catalina.Context

This error appeared for me because I set a default web module previously to a different enterprise application archive (ear) project while trying to run a new one in the development environment.

The solution for me was to empty the Default Web Module field shown below and restart the server. After you do that you can deploy your application successfully.

Glassfish Configuration

How to install SSL/TLS certificate on Glassfish

Introduction
It seems that build isn’t that important, as long as you are using a recent version of Glassfish and Ubuntu it should be fine. I will setup a guide on how to setup glassfish server soon. In the meantime, check the reference for nabisoft at the end of the article, it was my best reference for that part.

This tutorial is mainly directed to StartSSL user’s in the file naming convention but can work for anyone.

My Build

  • Ubuntu 16.04 Server (64 bits)
  • Glassfish 4.1
  • StartSSL certificate

You will have 3 public keys after correctly filing your certificate signing request (.csr) file to your certificate authority (CA). They will be named as such:

  • 1_Intermediate.crt
  • 2_yourdomainname.com.crt
  • root.crt

You would have had a private key which you used when you generated your CSR file. For the sake of this tutorial we will call this yourdomain.com.key .

Move to your glassfish domain’s config directory and store all your files there. I am assuming you are using the default domain, domain1.
cd /path_to_glassfish_directory/glassfish/domains/domain1/config

Step 1
Mash up our three certificated into one file using this command. Remember: don’t forget to change the values!
cat 2_yourdomainname.com.crt 1_Intermediate.crt root.crt > all.crt

Step 2
Now we import these certificates into our cacerts keystore. The keystore names I am going to assume are those shipped by default with glassfish 4.1 . Fill in ‘yourAlias’ with any non-conflicting name you wish but keep note of it for later.
keytool -import -trustcacerts -alias yourAlias -file all.crt -keystore cacerts.jks

Step 3
We are now going to decrypt the (.key) file and make a (.p12) file which will be installed into the server. The default password is ‘changeit’ and I shouldn’t have to mention… you should change it!
openssl pkcs12 -export -in all.crt -inkey yourdomain.com.key -out yourdomain.com.p12 -name yourAlias -CAfile 1_Intermediate.crt -caname immed
keytool -importkeystore -deststorepass changeit -destkeypass changeit -destkeystore keystore.jks -srckeystore yourdomain.com.p12 -srcstoretype PKCS12 -srcstorepass changeit -alias yourAlias

Step 4
Ensure that all the certificates installed correctly. Check both keystores using the following two commands:
keytool -list -keystore keystore.jks
keytool -list -keystore cacerts.jks

You should see a listing of your alias in one of them in both with the text ‘trustedCaCert’ in the cacerts.jks keystore.
In the keystore.jks file you should see your private key the alias you gave it listed in one of the entries.

Step 5
In order to use these keys on the domain you will need to configure domain.xml there are two ways to do this. BACKUP domains.xml before proceeding.

Method 1: terminal / command line
Replace every instance of the default s1asin the domain.xml file with yourAlias.

Method 2: Glassfish Admin Console
(Will be added later with pictures)

Step 5
Restart the domain

asadmin restart-domain domain1

If you haven’t loaded asadmin to your environment path then
/path_to_glassfish_directory/bin/asadmin restart-domain domain

References:

Ubuntu14 Redirected back to login screen after entering correct credentials

I wanted to discuss one issue I ran into today and how I fixed it, in case someone runs across the same issue.

The Problem
I was prompted to do an update after logging in. In the middle of the update I was prompted whether to update various configuration files for fglrx, I accidently pressed ‘no’ for the first option and ‘yes’ for all subsequent options. That ruined my configuration. After starting the computer later, I tried to login with the correct credentials and it would just return to the login page (playing the same sound you would hear once you land on the login page).

The Solution
Options:

  • Reinstall your graphics driver
  • Return to default setup when you install ubuntu desktop

To reinstall your graphics driver:
You can access terminal as if you are running the server addition by pressing ctrl+alt+f4.

If you ever need to go back (though you shouldn’t for these instructions) you would press ctrl+alt+f7.

My video card is from AMD so that is what I will talk about for this article. First you had to remove everything pertaining to fglrx with the following command:
sudo apt-get purge "fglrx.*"

Then install it again as you would have the first time
sudo apt-get install fglrx

Then what I did (which I’m not sure if its necessary or not) is remove the .XAuthority file found in /home/username using the following command
rm .XAuthority

Then reboot Ubuntu, which I’m pretty sure is the following command
sudo reboot