Showing posts with label Tomcat. Show all posts
Showing posts with label Tomcat. Show all posts

Saturday, 29 March 2014

Increase Default Size limit of WAR files in Tomcat 7+

Correct me if am wrong, ever since Tomcat 7.0.x versions and above, the minimum size for a deployable WAR file is set to 50 MB by default. So if you're WAR file exceeds 50 MB limit, you will get the IllegalStateException error.

There is a fix for this problem. This file size limit can be increased to a value higher than 50 MB.

Go to the location : TOMCAT_HOME/webapps/manager/WEB-INF folder. We need to edit the web.xml file here.

Before editing, I suggest you create a backup of the original web.xml ( cp web.xml web.xml.bkp )... Just in case...

Now open the web.xml and search for the attribute "max-file-size". You see the default value is set to 52428800 i.e 50MB. Increase it to let's say 100 MB (104857600 in bytes).

Also increase the value of the attribute "max-request-size" to 100 MB (104857600 in bytes).

Restart tomcat to bring the changes into effect.

Now you can deploy a 100 MB WAR file onto Tomcat without getting any error.

Thursday, 13 March 2014

UTF-8 Encoding in Tomcat for Hudson

If you're using Tomcat container for working with Hudson, you'll most likely see a warning on the Manage Hudson page. Something like "Your container doesn't use UTF-8 to decode URL's".

In that case, we need to tweak Tomcat a little bit. Edit the server.xml file located at $TOMCAT_HOME / conf

Locate the line where connector port is mentioned. Once located, we just have to add the following next to it - URIEncoding="UTF-8"


Refer the i18n section of the official Hudson FAQ link here.

Thursday, 27 February 2014

Tomcat Controller for Mac OS X

Folks, if you've installed Apache Tomcat on your Mac OS X machines for deploying webapps, this post will surely interest you. This quick byte is about a free small useful utility - Tomcat Controller, used for starting and stopping Apache Tomcat with a single mouse click.

Once downloaded, install it. Observe that it will add a new PrefPane in the System Preferences. It supports the newer 64-bit machines and older 32-bit machines as well. However, on newer 64-bit machines, am wondering why it closes and reopens the 32-bit System Preferences. Guys, do drop in your comments if you're aware of the reasons why it happens this way.


You simply have to mention the location pointing to the Tomcat instance. The current version 2.1 works like a charm for Tomcat 6 & 7 alike. Just click Start Tomcat Server. This comes in very handy if you have to bounce the server over and over again.


Finally, if you need some help with installing Tomcat & accessing the Tomcat manager, do refer my previous post. Bye.

Monday, 3 February 2014

Encrypt Tomcat Manager Password

In my previous post, we discussed about access to Tomcat Manager. In this post, we will discuss how to encrypt the Tomcat Manager password to make it more secure.

Recall that we had entered a plaintext password in the tomcat_users.xml file for access to Tomcat Manager. In this post we'll see how to encrypt the plaintext string using either SHA or MD5 encryption.

Go to bin folder within your Apache Tomcat home folder { eg: /usr/temp/apache-tomcat-7.0.47/bin }

Run the script digest.sh and pass your plaintext password to it in following way:

./digest.sh -a sha abc123  { For SHA encryption }  The output will give SHA encrypted password

abc123:6367c48dd193d56ea7b0baad25b19455e529f5ee

Alternatively use ./digest.sh -a md5 abc123 { If you intend to use MD5 encryption }

Note this encrypted password somewhere as you'd need this later.

Now, go to the conf folder and edit the tomcat-users.xml. Enter this encrypted password for the admin role instead of the plaintext password you entered previously for accessing tomcat manager.

Eg:

<user username="admin" password="6367c48dd193d56ea7b0baad25b19455e529f5ee" roles="admin-gui,admin-script,manager-gui,manager-script"/>

Now, lets edit the server.xml file, which also is present in the conf folder.

Search for the following text:

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

Once you locate the above code block, we just have to add digest="sha" at its end.

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase" digest="sha"/>

Check out the screenshot for reference


Restart the Tomcat server so that the changes take effect.

Monday, 13 January 2014

Changing default connector port in Tomcat

In my previous post about Tomcat manager, I said about changing the default port in Tomcat. So here's a quick small post about how we can change the default connector port 8080 in Tomcat.

Browse the apache installation folder and check for the file - server.xml. It's usually located under the conf folder.

By making a small edit in this file - server.xml, we can change the default port 8080 to some other port eg: 8081 or 8085. Scroll down till you find the tag for connector port. Check the screenshot below for reference.


Now all you have to do is modify the Connector port from default 8080 to any number like 8081, 8082, 8085 as you wish to. This is especially useful if you use any other application or web application server or service (eg: Hudson for continuous builds) which also uses port 8080.

Friday, 10 January 2014

Accessing Tomcat Manager

If you deploy your web applications to Apache Tomcat, then you may want to know about accessing the Tomcat manager page.

Let's assume you already have downloaded Apache Tomcat. If not, please download the current stable version v7.x from the official download site.

Once you have downloaded Tomcat you have to set the environment variables.

Now in order to access the Tomcat Manager, go to the tomcat_home/conf directory { For instance /usr/temp/apache-tomcat-7.0.47/conf }.

Now edit the tomcat-users.xml file in Terminal. { vi tomcat-users.xml }. Scroll down and you'll observe the tags for roles and users.

Insert the following roles as follows :

  <role rolename="admin-gui"/>
  <role rolename="admin-script"/>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-status"/>

Below the roles insert a new user named as 'admin' and define his roles in the following fashion :

<user username="admin" password="***" roles="admin-gui,manager-gui,manager-script"/>

Make sure to remove the comment tags <!-- and --> before roles and after the users block and save the file.

If you're not conversant with vi editor, I'll cover the topic about vi keyboard commands in another post.

For now, once the edits are made to the tomcat-users.xml, startup tomcat and open browser.

In the browser, type localhost:8080 { default port is 8080, but it can be modified if you want to. I'll cover this topic as well in a separate post. }. Then click the button Manager App on right. Check the below screenshot for reference.


Once you click Manager App, you'll prompted to enter the credentials. Enter the admin username and password which you specified in the tomcat-users.xml, to thereby access the manager. Here you can see the list of deployed applications. Individual applications can be started or stopped here. You can also check the server status here.


If you want to manually deploy a web application, you can choose the .war file and manually deploy it from this page. However, if you want to automate the deployment of a .war file using Apache Ant, I'll cover the topic in detail in another post. The post will contain information about copying the tomcat jars to ant home, defining tasks in build.xml to start, stop tomcat, deploy, undeploy an application. Stay tuned :)

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker