Passa ai contenuti principali


Visualizzazione dei post da Maggio, 2014

Tomcat mod_proxy configuration

Configuring Tomcat with mod_proxy  mod_proxy configuration is the simplest way to integrate Apache tomcat with Apache server. In order to do that,we need to add the module and redirect the URL to a virtual host.
Open the httpd.conf:
1. Place the following lines of code after the other LoadModule directives:

LoadModule proxy_module modules/ LoadModule proxy_http_module modules/ 2. Place the following lines of code with your other VirtualHost, or at the bottom of the file:

NameVirtualHost *<VirtualHost *>ServerName ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ <Location/> Order allow,deny Allow from all</Location></VirtualHost> Save the configuration file and restart Apache Web server in order to test the integration using mod_proxy.
[root@localhost bin]# ./apachectl stop
[root@root@localhost bin]# ./apachectl start

How to configure Tomcat JVM parameters

How to increase JVM size in Tomcat In order to change the JVM heap size for Tomcat, we need to pickup the file and modify the value for the JAVA_OPTS parameter. For example, suppose we want to change the max heap size from 256 MB to 512 MB while setting the Perm Gen = 256 MB.
Here's how to modify the JAVA_OPTS:
JAVA_OPTS="-Xms128m -Xmx512m -XX:MaxPermSize=256m" The changes in the JVM settings will take effect on the server restart. You can verify the change done in the JVM parameter by running the jmap command that is part of the JDK distribution. This tool requires passing the processId of Tomcat. Example:

C:\Users\tomcat>jmap -heap 3860
Attaching to process ID 3860, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.51-b03

using thread-local object allocation.
Parallel GC with 4 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 2122317824 (2024.0MB)
   NewSize   …

Tomcat Context Path configuration

Tomcat context path configuration Every time we deploy an application we need to setup a context path for the application. The context path will be used for accessing the application from a browser:
Even if it's actually possible to deploy an application on the Root Context Path ("/") this is usually reserved in special cases, for example if you need to provide a welcome page for your server or in other circumstances.

Enabling a context path The context path in Tomcat can be enabled in two ways:

GUI using the Tomcat Web Application ManagerCommand-line configuration in server.xml
In order to enable Context Path using the GUI interface, login into the Tomcat Application Manager:

You can create the context path using the Deploy tab.

Click on Browse and select the required WAR file. Then click on Deploy. It will take some seconds seconds to deploy the application (based on the application size) .
The following screenshot shows the appl…

Tomcat Manager Configuration

This tutorial shows how to configure the tomcat manager application that can be used to administrate Tomcat. We will also show how to enable the default user and password and how to grant the roles required to run the manager application.
The Tomcat Manager is a very powerful tool for Tomcat administration. It allows you to use the following features:

Remote application deployment Cleanup of Idle sessionApplication undeployment and redeploymentAnalysis of memory leaksJVM statusServer status
The Tomcat Manager by default is disabled in Tomcat 7. In order to enable it, pickup the tomcat-users.xml in the conf folder of Tomcat 7. This file contains two users: tomcat and role1. These roles however are not enabled to use the manager gui, as you need an user with the "manager-gui" roles. So change the file so that it look like this:

<tomcat-users><role rolename="manager-gui"/><user username="tomcat" password="s3cret" roles="manager-gu…

Tomcat Websocket example

A WebSocket is a full-duplex communication mechanism that allows both textual and binary messages to be sent between clients and servers, without the HTTP request/response life cycle. WebSockets allow either the client or the server to send a message at any time, providing an asynchronous solution for working with data while the user is performing a task.
Websockets API are included in Tomcat 7 Web server distribution so you don't have to download any extra library:

In this tutorial we will show how to create a WebSocket example using Apache Tomcat and Eclipse.
Start by creating on Eclipse a new Dynamic project named websocket-example:
We will now create a server side class named WebSocketDemo that is going to echo messages from a Javascript client:
package com.sample;import;import java.nio.ByteBuffer;import javax.websocket.OnMessage;import javax.websocket.Session;import javax.websocket.server.ServerEndpoint; @ServerEndpoint("/echo") publicclass WebSoc…