• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aspectran / aspectran / #4050

08 Feb 2025 09:05AM CUT coverage: 35.31% (-0.003%) from 35.313%
#4050

push

github

topframe
Update

0 of 21 new or added lines in 1 file covered. (0.0%)

14252 of 40363 relevant lines covered (35.31%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/web/src/main/java/com/aspectran/web/servlet/filter/URLSessionTrackingFilter.java
1
/*
2
 * Copyright (c) 2008-2025 The Aspectran Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.aspectran.web.servlet.filter;
17

18
import com.aspectran.utils.ObjectUtils;
19
import com.aspectran.utils.StringUtils;
20
import com.aspectran.utils.ToStringBuilder;
21
import com.aspectran.utils.annotation.jsr305.NonNull;
22
import com.aspectran.utils.logging.Logger;
23
import com.aspectran.utils.logging.LoggerFactory;
24
import jakarta.servlet.Filter;
25
import jakarta.servlet.FilterChain;
26
import jakarta.servlet.FilterConfig;
27
import jakarta.servlet.ServletException;
28
import jakarta.servlet.ServletRequest;
29
import jakarta.servlet.ServletResponse;
30
import jakarta.servlet.http.HttpServletRequest;
31
import jakarta.servlet.http.HttpServletRequestWrapper;
32

33
import java.io.IOException;
34
import java.util.Locale;
35

36
/**
37
 * <p>Created: 2025. 2. 8.</p>
38
 */
NEW
39
public class URLSessionTrackingFilter implements Filter {
×
40

NEW
41
    private static final Logger logger = LoggerFactory.getLogger(URLSessionTrackingFilter.class);
×
42

43
    private static final String DEFAULT_DELIMITER = ";jsessionid=";
44

NEW
45
    private String delimiter = DEFAULT_DELIMITER;
×
46

47
    @Override
48
    public void init(@NonNull FilterConfig filterConfig) {
NEW
49
        String name = filterConfig.getServletContext().getSessionCookieConfig().getName();
×
NEW
50
        if (StringUtils.hasText(name)) {
×
NEW
51
            delimiter = ";" + name.toLowerCase(Locale.ENGLISH) + "=";
×
52
        }
NEW
53
        if (logger.isDebugEnabled()) {
×
NEW
54
            String myName = ObjectUtils.simpleIdentityToString(this, filterConfig.getFilterName());
×
NEW
55
            ToStringBuilder tsb = new ToStringBuilder(myName);
×
NEW
56
            tsb.append("delimiter", delimiter);
×
57
        }
NEW
58
    }
×
59

60
    @Override
61
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
62
            throws IOException, ServletException {
NEW
63
        if (request instanceof HttpServletRequest httpRequest) {
×
NEW
64
            String requestURI = httpRequest.getRequestURI();
×
NEW
65
            if (requestURI.contains(delimiter)) {
×
NEW
66
                final String requestURItoUse = StringUtils.divide(httpRequest.getRequestURI(), delimiter)[0];
×
NEW
67
                HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(httpRequest) {
×
68
                    @Override
69
                    public String getRequestURI() {
NEW
70
                        return requestURItoUse;
×
71
                    }
72
                };
NEW
73
                chain.doFilter(requestWrapper, response);
×
NEW
74
                return;
×
75
            }
76
        }
NEW
77
        chain.doFilter(request, response);
×
NEW
78
    }
×
79

80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc