Apache Tomcat 7 by Filip Hanik

58
© 2009 VMware Inc. All rights reserved Upgrading to Apache Tomcat 7 Filip Hanik, Systems Engineer

description

Introduction to Tomcat 7 & WebSockets

Transcript of Apache Tomcat 7 by Filip Hanik

Page 1: Apache Tomcat 7 by Filip Hanik

© 2009 VMware Inc. All rights reserved

Upgrading to Apache Tomcat 7

Filip Hanik, Systems Engineer

Page 2: Apache Tomcat 7 by Filip Hanik

2

Agenda

Introduction

Specification changes (Servlet 3.0)

New features (Incl. WebSocket Deep Dive)

Current status

Future plans

Useful resources

Questions

Page 3: Apache Tomcat 7 by Filip Hanik

3

Introduction

Apache Tomcat committer & PMC member

Vmware Employee and Sales Engineer

Weekend Warrior with US Army Reserve

Page 4: Apache Tomcat 7 by Filip Hanik

4

What about you?

Who’s running Apache Tomcat 6?

Who’s running Apache Tomcat 5 or older?

Page 5: Apache Tomcat 7 by Filip Hanik

5

What do the version numbers mean?

7.0.22

• 7 major version

• 0 minor version

• 22 build number

Major

• New JSRs / Specifications for Servlets/JSPs

• Side effect – New Java Version

Page 6: Apache Tomcat 7 by Filip Hanik

6

What do the version numbers mean?

7.0.22

• 7 major version

• 0 minor version

• 22 build number

Minor

• 4.0 vs 4.1

• 5.0 vs 5.5

• Refactor of code base

• Possible changes to config files

• Possible changes to internal APIs

Page 7: Apache Tomcat 7 by Filip Hanik

7

What do the version numbers mean?

7.0.22

• 7 major version

• 0 minor version

• 22 build number

Build Number

• Incremented with each build/SVN tag

• Not all builds become release

• Historically .18 has been the magic number

• Stability

• Bug fixes

• Ready for enterprises

Page 8: Apache Tomcat 7 by Filip Hanik

8

When to upgrade?

Starts with application developers

Need new features in Java

Need new features in Servlet specification

Need new features in a framework built for later versions

Page 9: Apache Tomcat 7 by Filip Hanik

9

So what changed?

Page 10: Apache Tomcat 7 by Filip Hanik

10

Specification Changes

Page 11: Apache Tomcat 7 by Filip Hanik

11

New version of Java

Less invasive as technology matures

1.5 to 1.6 should be seamless

Moving to 1.6 is beneficial from performance perspective

Page 12: Apache Tomcat 7 by Filip Hanik

12

Asynchronous Servlets

No more thread per request model

Servlet API still uses blocking programming model

• Async is more complex, non blocking would have made it too complex

Well suited for ‘Web 2.0’ applications

API for developers, does not affect operations teams

Page 13: Apache Tomcat 7 by Filip Hanik

13

Annotations

Alternative to XML configuration

Requires scanning of libraries

Will slow down startup time

• Performance can be improved by documenting JAR files not to be scanned

• tomcat.util.scan.DefaultJarScanner.jarsToSkip system property

• Defined in conf/catalina.properties

Page 14: Apache Tomcat 7 by Filip Hanik

14

Web Fragments

Libraries can ship with its partial web.xml configuration

• Eases including frameworks

Requires scanning of libraries

Will slow down startup time

• Performance can be improved by documenting JAR files not to be scanned

• tomcat.util.scan.DefaultJarScanner.jarsToSkip system property

• Defined in conf/catalina.properties

Page 15: Apache Tomcat 7 by Filip Hanik

15

Session Management

Session tracking

• Cookie, URL or SSL ID

Session cookie can be configured

• name

• domain

• path

• comment

• secure

• httpOnly

Page 16: Apache Tomcat 7 by Filip Hanik

16

Programmatic Login

Easier integration with alternative authentication solutions

Calling login/logout

• Directly within an application

• Allows to retrieve credentials from alternative location

Page 17: Apache Tomcat 7 by Filip Hanik

17

Other changes

JSP 2.2

• JSP property group additions

• New omit attribute for <jsp:attribute .../>

Expression Language 2.2

• Method invocations

Page 18: Apache Tomcat 7 by Filip Hanik

18

New featuresTomcat evolves too

Page 19: Apache Tomcat 7 by Filip Hanik

19

Management

JMX remote lifecycle listener Allows JMX communication through firewall

jconsole (or JMX client) url

Page 20: Apache Tomcat 7 by Filip Hanik

20

Management

Manager application can differentiate between primary, backup and proxy sessions

Page 21: Apache Tomcat 7 by Filip Hanik

21

Performance

Limit loaded JSPs with LRU cache

GZIP compressed output streams can now be flushed

Remove bottleneck in session ID generation

Crawler session manager valve

AJP NIO connector (will be in 7.0.15 onwards)

Page 22: Apache Tomcat 7 by Filip Hanik

22

Performance

Tomcat jdbc-pool

Alternative to commons-dbcp

Well fitted for multi core machines

Documented at tomcat.apache.org

Page 23: Apache Tomcat 7 by Filip Hanik

23

Resources

New singleton attribute Create new object on JNDI lookup

New closeMethod attribute Close resources upon shutdown/undeploy

Page 24: Apache Tomcat 7 by Filip Hanik

24

Deployment

Support parallel deployment

Existing sessions go to the original applications

New users go to the new application

Defer undeployment

DEMO

Page 25: Apache Tomcat 7 by Filip Hanik

25

Deployment

Copying of /META-INF/context.xml to

$CATALINA_BASE/<engine>/<host>/contextname.xml

now optional and disabled by default

One of the most confusing features in old version

Often resulted in administrators unaware of accidental deployment

Natural behaviour is that no files get created outside of application

Page 26: Apache Tomcat 7 by Filip Hanik

26

Deployment

Improved memory leak detection and prevention

Prevents common memory leaks during undeployment

Warns on unpreventable memory leaks

Page 27: Apache Tomcat 7 by Filip Hanik

27

Security

Cross-site request forgery (CSRF) protection filter

CSRF protection added to manager application

• role names & some URLs changed

LockOutRealm used by default

Access log enabled by default

exec is disabled by default for SSI

DefaultServlet serves content from root of context by default

Page 28: Apache Tomcat 7 by Filip Hanik

28

Security

Graceful handling of users book-marking the login page

Session IDs generated using SecureRandom by default

SSL renegotiation & RFC 5746

HTTP NIO connector now supports SSL renegotiation Not having this made Apache Tomcat not be vulnerable to the man in the middle

attack recently discovered

Cookie paths end in /

Page 29: Apache Tomcat 7 by Filip Hanik

29

Embedding and Extending

New o.a.catalina.startup.Tomcat class for embedding

Binary and source JARs provided for Apache Maven

Customisable JAR scanning

Page 30: Apache Tomcat 7 by Filip Hanik

30

Embedding and Extending

New o.a.catalina.startup.Tomcat class for embedding

Adding a servlet

Page 31: Apache Tomcat 7 by Filip Hanik

31

Code clean-up

Generics

Better definition of Lifecycle interface

Comet classes have moved to o.a.catalina.comet

Expanded the unit tests

Added Checkstyle and FindBugs to the build process

Removed unused / deprecated / duplicated code

Custom components using Tomcat internals are likely to require changes

Page 32: Apache Tomcat 7 by Filip Hanik

32

Windows

Windows installer detects 32-bit or 64-bit JVM and installs correct native binaries

Windows native authentication (SPNEGO) Integration with

MS Active DirectoryandDomain Controller

Single Sign On based on Kerberos/SPNEGO

Page 33: Apache Tomcat 7 by Filip Hanik

33

Current status

Apache Tomcat 7 is stable as of 7.0.6 Current release is 7.0.27

Continuing to provide a release a month

All releases have passed the Servlet 3.0, JSP 2.2 and EL 2.2 TCKs

Servlet TCK is tested with the following combinations

• HTTP BIO, NIO & APR/native

• mod_jk + AJP BIO, NIO & APR/native

• mod_proxy_http + HTTP BIO, NIO & APR/native

• mod_proxy_ajp + AJP BIO, NIO & APR/native

Page 34: Apache Tomcat 7 by Filip Hanik

34

What to expect from an upgrade

Tomcat 4 to Tomcat 7

Tomcat 5 to Tomcat 7

Tomcat 6 to Tomcat 7

Page 35: Apache Tomcat 7 by Filip Hanik

35

Web SocketsNew in Tomcat 7.027

Part of HTML 5

Page 36: Apache Tomcat 7 by Filip Hanik

36

WebSockets – Bi-drectional protocol (binary/text)

Page 37: Apache Tomcat 7 by Filip Hanik

37

Event Based on both Server and Client

Page 38: Apache Tomcat 7 by Filip Hanik

38

Client - Initiating a WebSocket

Page 39: Apache Tomcat 7 by Filip Hanik

39

Client - Initiating a WebScoket

Page 40: Apache Tomcat 7 by Filip Hanik

40

Network – Opening WebSocket Request

Page 41: Apache Tomcat 7 by Filip Hanik

41

In Tomcat 7 – Extend WebSocketServlet

Page 42: Apache Tomcat 7 by Filip Hanik

42

In Tomcat 7 – Create a StreamInbound object

Page 43: Apache Tomcat 7 by Filip Hanik

43

Page 44: Apache Tomcat 7 by Filip Hanik

44

Network – Opening WebSocket - Response

Page 45: Apache Tomcat 7 by Filip Hanik

45

Socket Opened – First Event

Page 46: Apache Tomcat 7 by Filip Hanik

46

Page 47: Apache Tomcat 7 by Filip Hanik

47

Client - Send a Message

Page 48: Apache Tomcat 7 by Filip Hanik

48

In Tomcat 7 – Receive the message

Page 49: Apache Tomcat 7 by Filip Hanik

49

Page 50: Apache Tomcat 7 by Filip Hanik

50

Page 51: Apache Tomcat 7 by Filip Hanik

51

Client – Receive the Message

Page 52: Apache Tomcat 7 by Filip Hanik

52

Future Plans

Servlet 3.1 addition

Commons DBCP v2

Socket IO

Keep on top of open bugs

Continue reviewing enhancement requests

Page 53: Apache Tomcat 7 by Filip Hanik

53

Useful Resources

Page 54: Apache Tomcat 7 by Filip Hanik

54

Useful resources

http://www.tomcatexpert.com

http://tomcat.apache.org

• http://blogs.apache.org/tomcat

Mailing lists

• users

• dev

• announce

http://tomcat.markmail.org

http://svn.apache.org/repos/asf/tomcat/trunk/webapps/ docs/changelog.xml

http://ci.apache.org/projects/tomcat/tomcat7/docs/

http://s.apache.org/tomcat-7-open-issues

Page 55: Apache Tomcat 7 by Filip Hanik

55

References

Page 56: Apache Tomcat 7 by Filip Hanik

56

References

TomcatExpert.comhttp://www.tomcatexpert.com/blog/2012/04/24/websockets-tomcat-7http://www.tomcatexpert.com/blog/2012/05/01/how-apache-tomcat-implemented-websocket

Net.tutsplus.comhttp://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/

Page 57: Apache Tomcat 7 by Filip Hanik

57

Vmware Supported Platform

Page 58: Apache Tomcat 7 by Filip Hanik

58

Questions