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

Tuesday, November 8, 2011

JSP charset usage for security fixing

JSP encoding usage:

===============================================
Посмотрел JSP login.jsp и т.д. страницы. И вот в чем заключается проблема невозможности залогинится в паролем/именем заданым не в латинской кодировке.

1. Очень хорошая привычка начинать любую JSP станицу примено так:
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
В проекте так начинается только одна страница error.jsp, а та страница для которой это критично такой строки не имеет!
Тогда строка становится не нужной (она почему-то тоже есть только в одной из JSP страниц).

2. Из-за особенностей передачи данных в HTML форме нужно правильно настроить аутентикация в tomcat.
В контекстном файле приложения, в случае c site.war/META-INF/context.xml нужно указать такое:


Если выполнить эти пункта то аутентикация будет работать правильно для любых символов в пароле или имени.
===============================================

Saturday, October 1, 2011

Solved two mysql+tomcat problems

Solved two mysql+tomcat problems:

1. The web application registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web.
2. The web application appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed.


1. The web application registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web.

PROBLEM:
org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/rest] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web


SOLUTION:
http://stackoverflow.com/questions/3320400/jdbc-driver-unregisted-when-the-web-application-stops

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class JdbcListener implements ServletContextListener
{
private static final Logger LOG = Logger.getLogger(JdbcListener.class);

public void contextDestroyed(ServletContextEvent sce)
{
deregisterJdbcDriver();
}

public void contextInitialized(ServletContextEvent sce)
{

}

private void deregisterJdbcDriver()
{
// This manually deregisters JDBC driver, which prevents Tomcat 7 from complaining about memory leaks
Enumeration drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements())
{
Driver driver = drivers.nextElement();
try
{
DriverManager.deregisterDriver(driver);
LOG.info(String.format("Deregistering jdbc driver: %s", driver));
}
catch (SQLException e)
{
LOG.info(String.format("Error deregistering driver %s", driver), e);
}
}
}

}




2. The web application appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed.

PROBLEM:
org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/rest] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed


SOLUTION:
http://bugs.mysql.com/bug.php?id=36565
To upgrage mysql connector jar.
http://dev.mysql.com/downloads/connector/j/

     
mysql
mysql-connector-java
5.1.17

Friday, September 30, 2011

JMX jconsole

Configure Tomcat
Add those params to the server JVM options :
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3456 -Dcom.sun.management.jmxremote.authenticate=false 


Run jconsole
Go to JAVA_HOME/bin
run ./jconsole
Connect to the console

Wednesday, December 1, 2010

RepositoryCreationSynchronizer - Waiting to be released by the coordinator

PROBLEM:
2010-12-01 17:54:24,684 [main] INFO exo.jcr.component.core.RepositoryCreationSynchronizer - Waiting to be released by the coordinator
Tomcat HANGS

SOLUTION:
commented out the RPCService component within
cl***-multi***-1.0-Alpha07-SNAPSHOT.jar#uzip/conf/portal/configuration.xml

Friday, January 30, 2009

Tomcat slowly starts in a debug mode

When tomcat starts slowly if you use remote debug with a tomcat and an Eclipse...
remove "watch expressions" in the Eclipse.
That should fixed it.

If no click at "skip all breakpoints"
Try to start.

NOTE:
Start tomcat in debug mode in a linux:
****************************
REMOTE_DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y"
JAVA_OPTS="$JAVA_OPTS $REMOTE_DEBUG"

export JAVA_OPTS
****************************

Thanks to Sergey.

Tuesday, January 27, 2009

[SOLVED] IOException while loading persisted sessions: java.io.InvalidClassException

PROBLEM:
SEVERE: IOException while loading persisted sessions: java.io.InvalidClassException: org.exoplatform.services.wsrp2.consumer.impl.helpers.UserSessionImpl; no valid constructor
java.io.InvalidClassException: org.exoplatform.services.wsrp2.consumer.impl.helpers.UserSessionImpl; no valid constructor
at java.io.ObjectStreamClass.(ObjectStreamClass.java:455)
at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:297)
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:531)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1552)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1699)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1439)
...

SOLUTION:
Author: G R (http://www.jguru.com/guru/viewbio.jsp?EID=999272), Sep 14, 2002
Just wanted to correct that if the super class does not have a no argument constructor, then following exception is thrown when you try to deserialize the class. java.io.InvalidClassException: no valid constructor

Serialization FAQ From jGuru
wikipedia Serialization Java

Monday, October 27, 2008

Tomcat JAAS. Фраза дня :)

логин конфиг в веб-хмл описывает реалм, для реалма прописан логин модуль, который обращается к нашему сервису, а в контексте описан класс приципала, который логин модуль поставит в сабджект

Monday, August 11, 2008

Номер процесса по номеру порта

Know process id with a port

Как узнать имя процесса по номеру порта?
Найти и обезвредить! =)

alexey@alexey:~$ sudo lsof -iTCP:8080
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
java 635 alexey 13u IPv6 10169721 TCP *:webcache (LISTEN)

alexey@alexey:~$ sudo ps 635
PID TTY STAT TIME COMMAND
635 pts/1 Sl+ 0:20 /home/alexey/java/jdk1.5/bin/java -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog -Djava.security.auth.

alexey@alexey:~$ sudo ps -p 635 -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 1000 635 611 1 85 0 - 194938 383196 pts/1 00:00:20 java

alexey@alexey:~$ sudo kill -9 635

Tuesday, May 27, 2008

Tomcat for Eclipse

Tomcat launcher Eclipse plugin for debud
Home page
Download page
Direct download (ver. 3.2.1) !
Comments for tomcat plugin
Tomcat Tutorial: HelloWorld for Complete Fools
Documentation (translated with google)

Read before, note: replace my tomcat home "/home/alexey/java/exo-working/exo-tomcat" with your's.

1. Install
Unpack it to eclipse/plugins dir.
Start or restart Eclipse.
Be sure that you see the new tomcat panel.

2. Configure
Configure plugin under eclipse
Window -> Preferences... -> Tomcat:
2.1
Set version of your tomcat (e.g.: 5.x)
Set tomcat home (e.g.: /home/alexey/java/exo-working/exo-tomcat)
Context declaration mode: Server.xml

2.2 Advanced
Set tomcat base (e.g.: /home/alexey/java/exo-working/exo-tomcat)
Check projects for "Add java projects to tomcat classspath" (e.g.: Select All)
2.3 JVMSettings
In section "Append to JVM Parameters" add both:
"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog"
"-Djava.security.auth.login.config=/home/alexey/java/exo-working/exo-tomcat/conf/jaas.conf"


2.4 Source Path
Manually select or check "Automatically compute source path"
Click "Apply" and "OK".

3. Use
Set launch configuration.
"Run" -> "Open Debug Dialog..." -> Double click on "Java Application" for creating new configuration.
Tabs:
3.1 Main
Type in the field "Name" launch configuration name (e.g.: Tomcat5).
Choose "Project" (e.g. Portal)
Set in the "Main class" value "org.apache.catalina.startup.Bootstrap"
3.2 Arguments
Program arguments:
-config "/home/alexey/java/exo-working/exo-tomcat/conf/server.xml" start
VM arguments:
-Dcatalina.home="/home/alexey/java/exo-working/exo-tomcat"
-Djava.endorsed.dirs="/home/alexey/java/exo-working/exo-tomcat/common/endorsed"
-Dcatalina.base="/home/alexey/java/exo-working/exo-tomcat"
-Djava.io.tmpdir="/home/alexey/java/exo-working/exo-tomcat/temp"
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
-Djava.security.auth.login.config=/home/alexey/java/exo-working/exo-tomcat/conf/jaas.conf


3.3 JRE
Skip
3.4 Classpath
Remove user entries projects jars to avoid some strange exceptions while the tomcat is starting.
Add two jars to the "User Entries"
"tools.jar" from JAVA_HOME/lib
"bootstrap.jar" from TOMCAT_HOME/bin

3.5 Source
Skip

Click "Apply" and "Debug"

Wednesday, February 6, 2008

Application servers

Application servers (AS)
wiki

List of application server from google directory search here.

JSR 154: JavaTM Servlet 2.4 Specification
http://jcp.org/en/jsr/detail?id=154

JSR 53: JavaTM Servlet 2.3 and JavaServer PagesTM 1.2 Specifications
http://jcp.org/en/jsr/detail?id=53

The J2EE 1.4 Tutorial here
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletRequest.html
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletResponse.html

http://java.sun.com/dtd/web-app_2_3.dtd

Writing Web Application Deployment Descriptors

The eXo-Portlet-Container was tested on different AS, look here

The content of element type "web-app" must match
"(
icon?,display-name?,description?,distributable?,
context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,
session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,
resource-env-ref*,resource-ref*,
security-constraint*,login-config?,security-role*,
env-entry*,ejb-ref*,ejb-local-ref*
)"
http://download-llnw.oracle.com/docs/cd/E13222_01/wls/docs61/webapp/web_xml.html

The list of servers which I know:

  • Apache Tomcat 6.0.14
official or wiki
Default port: 8080
Start: %TOMCAT_HOME%\bin\catalina.bat start
Stop:
%TOMCAT_HOME%\bin\catalina.bat stop
Log: console or %TOMCAT_HOME%\logs\catalina.YYYY-MM-DD.log
NOTE: For Tomcat prefer to cut jar's files from all war's/WEB-INF/lib to %
TOMCAT_HOME%/commons/lib. And delete war's/WEB-INF/lib directory.

Apache Tomcat Configuration Reference - The HTTP Connector
  • ObjectWeb JOnAS 4.8.4
official or wiki
Default
port: 9000

Download form wiki on objectweb
Download from objectweb file repository
Download from forge.objectweb.org

  • JBoss 4.2.2 GA
official or wiki
Default port: 8080
Jboss Download
Jboss Forum
Jboss JIRA
Jboss wiki
Jboss 4.2.2 Documentation
http://wiki.jboss.org/wiki/ClassLoadingConfiguration
jboss classloading
  • BEA Weblogic 9.2
official or wiki
Default
port: 7001
  • IBM WebSphere 6.1.0.7
official or wiki
Default
port: 9080
Start: %WebSphere_home%\AppServer\profiles\AppSrv01\bin\startServer.bat server1
Stop:
%WebSphere_home%\AppServer\profiles\AppSrv01\bin\stopServer.bat server1
Log: AppServer\profiles\AppSrv01\logs\server1\SystemOut.log
Web control: http://localhost:8888/em/
Maintenance Download Wizard
Fix list for IBM WebSphere
FTP
Verify Java SDK version shipped with IBM WebSphere Application Server fix packs
e-books
infocenter wasinfo v6.1
http://www-306.ibm.com/software/webservers/appserv/express/requirements
http://www.ibm.com/developerworks/downloads/ws/was/
http://www-306.ibm.com/software/webservers/appserv/community/
What's new in Version 6.1
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=forum&f=46
http://saloon.javaranch.com/forums/forum-046.html

  • Oracle AS 10.1.3.1.0
official or wiki
Default
port: 8888
Start:
%oracle_home%\opnm\bin\opmnctl.exe startall
Stop: %oracle_home%\opnm\bin\opmnctl.exe stopall
Log: opmn\logs\default_group~home~default_group~1.log

  • Sun Java System AS 9.0
official or wiki
  • Jetty 6.1
official or wiki
  • Geronimo 1.1.1, 1.2-beta, 2.0-M2 with Jetty or Tomcat
official or wiki

Don't forget delete cookie in your browser when you faced with strange behave of your application while test it on other AS !!!

http://docs.sun.com/source/816-6884-10/appendixb.html

All comments are appreciated.

Tuesday, October 2, 2007

[SOLVED] eclipse tomcat debug ClassNotFoundException URLClassLoader

Need to add jars.

In the Eclipse to the "Run" -> "Open Debug Dialog..." -> Java Application -> your launch configuration -> "Classpath" Tab -> User Entries

Add two jars:
"tools.jar" from JAVA_HOME/lib
"bootstrap.jar" from TOMCAT_HOME/bin