| 1 |
|
/*
|
|
|
|
|
|
|
|
|
| 2 |
|
* License
d to the A
pache Soft
ware Found
ation (ASF
) under on
e or more
|
|
|
|
|
|
|
|
|
| 3 |
|
* contrib
utor licen
se agreeme
nts. See
the NOTICE
file dist
ributed wi
th
|
|
|
|
|
|
|
|
|
| 4 |
|
* this wo
rk for add
itional in
formation
regarding
copyright
ownership.
|
|
|
|
|
|
|
|
|
| 5 |
|
* The ASF
licenses
this file
to You und
er the Apa
che Licens
e, Version
2.0
|
|
|
|
|
|
|
|
|
| 6 |
|
* (the "L
icense");
you may no
t use this
file exce
pt in comp
liance wit
h
|
|
|
|
|
|
|
|
|
| 7 |
|
* the Lic
ense. You
may obtai
n a copy o
f the Lice
nse at
|
|
|
|
|
|
|
|
|
| 8 |
|
*
|
|
|
|
|
|
|
|
|
| 9 |
|
* ht
tp://www.a
pache.org/
licenses/L
ICENSE-2.0
|
|
|
|
|
|
|
|
|
| 10 |
|
*
|
|
|
|
|
|
|
|
|
| 11 |
|
* Unless
required b
y applicab
le law or
agreed to
in writing
, software
|
|
|
|
|
|
|
|
|
| 12 |
|
* distrib
uted under
the Licen
se is dist
ributed on
an "AS IS
" BASIS,
|
|
|
|
|
|
|
|
|
| 13 |
|
* WITHOUT
WARRANTIE
S OR CONDI
TIONS OF A
NY KIND, e
ither expr
ess or imp
lied.
|
|
|
|
|
|
|
|
|
| 14 |
|
* See the
License f
or the spe
cific lang
uage gover
ning permi
ssions and
|
|
|
|
|
|
|
|
|
| 15 |
|
* limitat
ions under
the Licen
se.
|
|
|
|
|
|
|
|
|
| 16 |
|
*/
|
|
|
|
|
|
|
|
|
| 17 |
|
|
|
|
|
|
|
|
|
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
|
package or
g.apache.c
atalina.co
met;
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
|
import jav
a.io.IOExc
eption;
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
|
import jav
ax.servlet
.Filter;
|
|
|
|
|
|
|
|
|
| 24 |
|
import jav
ax.servlet
.ServletEx
ception;
|
|
|
|
|
|
|
|
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
|
/**
|
|
|
|
|
|
|
|
|
| 27 |
|
* A Comet
filter, s
imilar to
regular fi
lters, per
forms filt
ering task
s on eithe
r
|
|
|
|
|
|
|
|
|
| 28 |
|
* the req
uest to a
resource (
a Comet se
rvlet), or
on the re
sponse fro
m a resour
ce, or bot
h.
|
|
|
|
|
|
|
|
|
| 29 |
|
* <br><br
>
|
|
|
|
|
|
|
|
|
| 30 |
|
* Filters
perform f
iltering i
n the <cod
e>doFilter
Event</cod
e> method.
Every Fil
ter has ac
cess to
|
|
|
|
|
|
|
|
|
| 31 |
|
* a Filte
rConfig ob
ject from
which it c
an obtain
its initia
lization p
arameters,
a
|
|
|
|
|
|
|
|
|
| 32 |
|
* referen
ce to the
ServletCon
text which
it can us
e, for exa
mple, to l
oad resour
ces
|
|
|
|
|
|
|
|
|
| 33 |
|
* needed
for filter
ing tasks.
|
|
|
|
|
|
|
|
|
| 34 |
|
* <p>
|
|
|
|
|
|
|
|
|
| 35 |
|
* Filters
are confi
gured in t
he deploym
ent descri
ptor of a
web applic
ation
|
|
|
|
|
|
|
|
|
| 36 |
|
* <p>
|
|
|
|
|
|
|
|
|
| 37 |
|
* Example
s that hav
e been ide
ntified fo
r this des
ign are<br
>
|
|
|
|
|
|
|
|
|
| 38 |
|
* 1) Auth
entication
Filters <
br>
|
|
|
|
|
|
|
|
|
| 39 |
|
* 2) Logg
ing and Au
diting Fil
ters <br>
|
|
|
|
|
|
|
|
|
| 40 |
|
* 3) Imag
e conversi
on Filters
<br>
|
|
|
|
|
|
|
|
|
| 41 |
|
* 4) Data
compressi
on Filters
<br>
|
|
|
|
|
|
|
|
|
| 42 |
|
* 5) Encr
yption Fil
ters <br>
|
|
|
|
|
|
|
|
|
| 43 |
|
* 6) Toke
nizing Fil
ters <br>
|
|
|
|
|
|
|
|
|
| 44 |
|
* 7) Filt
ers that t
rigger res
ource acce
ss events
<br>
|
|
|
|
|
|
|
|
|
| 45 |
|
* 8) XSL/
T filters
<br>
|
|
|
|
|
|
|
|
|
| 46 |
|
* 9) Mime
-type chai
n Filter <
br>
|
|
|
|
|
|
|
|
|
| 47 |
|
* <br>
|
|
|
|
|
|
|
|
|
| 48 |
|
*
|
|
|
|
|
|
|
|
|
| 49 |
|
* @author
Remy Mauc
herat
|
|
|
|
|
|
|
|
|
| 50 |
|
*/
|
|
|
|
|
|
|
|
|
| 51 |
|
public int
erface Com
etFilter e
xtends Fil
ter {
|
|
|
|
|
|
|
|
|
| 52 |
|
|
|
|
|
|
|
|
|
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
|
/**
|
|
|
|
|
|
|
|
|
| 55 |
|
* The
<code>doF
ilterEvent
</code> me
thod of th
e CometFil
ter is cal
led by the
container
|
|
|
|
|
|
|
|
|
| 56 |
|
* eac
h time a r
equest/res
ponse pair
is passed
through t
he chain d
ue
|
|
|
|
|
|
|
|
|
| 57 |
|
* to
a client e
vent for a
resource
at the end
of the ch
ain. The C
ometFilter
Chain pass
ed in to t
his
|
|
|
|
|
|
|
|
|
| 58 |
|
* met
hod allows
the Filte
r to pass
on the eve
nt to the
next entit
y in the
|
|
|
|
|
|
|
|
|
| 59 |
|
* cha
in.<p>
|
|
|
|
|
|
|
|
|
| 60 |
|
* A t
ypical imp
lementatio
n of this
method wou
ld follow
the follow
ing patter
n:- <br>
|
|
|
|
|
|
|
|
|
| 61 |
|
* 1.
Examine th
e request<
br>
|
|
|
|
|
|
|
|
|
| 62 |
|
* 2.
Optionally
wrap the
request ob
ject conta
ined in th
e event wi
th a custo
m implemen
tation to
|
|
|
|
|
|
|
|
|
| 63 |
|
* fil
ter conten
t or heade
rs for inp
ut filteri
ng and pas
s a CometE
vent insta
nce contai
ning
|
|
|
|
|
|
|
|
|
| 64 |
|
* the
wrapped r
equest to
the next f
ilter<br>
|
|
|
|
|
|
|
|
|
| 65 |
|
* 3.
Optionally
wrap the
response o
bject cont
ained in t
he event w
ith a cust
om impleme
ntation to
|
|
|
|
|
|
|
|
|
| 66 |
|
* fil
ter conten
t or heade
rs for out
put filter
ing and pa
ss a Comet
Event inst
ance conta
ining
|
|
|
|
|
|
|
|
|
| 67 |
|
* the
wrapped r
equest to
the next f
ilter<br>
|
|
|
|
|
|
|
|
|
| 68 |
|
* 4.
a) <strong
>Either</s
trong> inv
oke the ne
xt entity
in the cha
in using t
he CometFi
lterChain
object (<c
ode>chain.
doFilterEv
ent()</cod
e>), <br>
|
|
|
|
|
|
|
|
|
| 69 |
|
* 4.
b) <strong
>or</stron
g> not pas
s on the r
equest/res
ponse pair
to the ne
xt entity
in the fil
ter chain
to block t
he event p
rocessing<
br>
|
|
|
|
|
|
|
|
|
| 70 |
|
* 5.
Directly s
et fields
on the res
ponse afte
r invocati
on of the
next entit
y in the f
ilter chai
n.
|
|
|
|
|
|
|
|
|
| 71 |
|
*
|
|
|
|
|
|
|
|
|
| 72 |
|
* @pa
ram event
the event
that is be
ing proces
sed. Anoth
er event m
ay be pass
ed along t
he chain.
|
|
|
|
|
|
|
|
|
| 73 |
|
* @pa
ram chain
|
|
|
|
|
|
|
|
|
| 74 |
|
* @th
rows IOExc
eption
|
|
|
|
|
|
|
|
|
| 75 |
|
* @th
rows Servl
etExceptio
n
|
|
|
|
|
|
|
|
|
| 76 |
|
*/
|
|
|
|
|
|
|
|
|
| 77 |
|
public
void doFi
lterEvent(
CometEvent
event, Co
metFilterC
hain chain
)
|
|
|
|
|
|
|
|
|
| 78 |
|
th
rows IOExc
eption, Se
rvletExcep
tion;
|
|
|
|
|
|
|
|
|
| 79 |
|
|
|
|
|
|
|
|
|
|
| 80 |
|
|
|
|
|
|
|
|
|
|
| 81 |
|
}
|
|
|
|
|
|
|
|
|