]> git.mxchange.org Git - jcore-utils.git/blob - src/org/mxchange/jcoreee/filter/servlet/utf8/Utf8ServletFilter.java
More cleanup
[jcore-utils.git] / src / org / mxchange / jcoreee / filter / servlet / utf8 / Utf8ServletFilter.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcoreee.filter.servlet.utf8;
18
19 import java.io.IOException;
20 import java.text.MessageFormat;
21 import javax.servlet.Filter;
22 import javax.servlet.FilterChain;
23 import javax.servlet.ServletException;
24 import javax.servlet.ServletRequest;
25 import javax.servlet.ServletResponse;
26 import org.mxchange.jcoreee.filter.servlet.BaseServletFilter;
27
28 /**
29  * A HTTP filter for setting UTF-8 character encoding.
30  *
31  * @author Roland Haeder
32  */
33 public class Utf8ServletFilter extends BaseServletFilter implements Filter {
34         /**
35          * Filter to set UTF-8 encoding
36          *
37          * @param request ServletRequest instance
38          * @param response ServletResponse instance
39          * @param chain FilterChain instance
40          * @throws IOException
41          * @throws ServletException
42          */
43         @Override
44         public void doFilter (final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
45                 // Trace message
46                 this.getLogger().logTrace(MessageFormat.format("request={0},response={1},chain={2} - CALLED!", request, response, chain)); //NOI18N
47
48                 // Call super method
49                 chain.doFilter(request, response);
50
51                 // Set response/request both to UTF-8
52                 request.setCharacterEncoding("UTF-8"); //NOI18N
53                 response.setCharacterEncoding("UTF-8"); //NOI18N
54
55                 // Trace message
56                 this.getLogger().logTrace("EXIT!"); //NOI18N
57         }
58 }