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

aspectran / aspectran / #4014

25 Jan 2025 04:30PM CUT coverage: 35.455% (+0.008%) from 35.447%
#4014

push

github

topframe
Update

24 of 52 new or added lines in 13 files covered. (46.15%)

2 existing lines in 2 files now uncovered.

14289 of 40302 relevant lines covered (35.45%)

0.35 hits per line

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

23.68
/with-undertow/src/main/java/com/aspectran/undertow/server/session/TowSession.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.undertow.server.session;
17

18
import com.aspectran.core.component.session.NonPersistentValue;
19
import com.aspectran.core.component.session.Session;
20
import com.aspectran.utils.Assert;
21
import com.aspectran.utils.annotation.jsr305.NonNull;
22
import com.aspectran.utils.annotation.jsr305.Nullable;
23
import io.undertow.server.HttpServerExchange;
24
import io.undertow.server.session.SessionConfig;
25
import io.undertow.server.session.SessionManager;
26

27
import java.util.Set;
28

29
/**
30
 * Class that bridges between Aspectran native session and Undertow one.
31
 *
32
 * <p>Created: 2019-08-11</p>
33
 */
34
public final class TowSession implements io.undertow.server.session.Session {
35

36
    private final TowSessionManager sessionManager;
37

38
    private final Session session;
39

40
    TowSession(TowSessionManager sessionManager, Session session) {
1✔
41
        this.sessionManager = sessionManager;
1✔
42
        this.session = session;
1✔
43
    }
1✔
44

45
    @Override
46
    public String getId() {
47
        return session.getId();
×
48
    }
49

50
    void requestStarted(@NonNull HttpServerExchange exchange) {
51
        if (sessionManager.checkFirstAccess(exchange)) {
×
52
            session.access();
×
53
        }
54
    }
×
55

56
    @Override
57
    public void requestDone(@NonNull HttpServerExchange exchange) {
58
        if (sessionManager.hasBeenAccessed(exchange)) {
1✔
59
            session.complete();
1✔
60
        }
61
    }
1✔
62

63
    @Override
64
    public long getCreationTime() {
65
        return session.getCreationTime();
×
66
    }
67

68
    @Override
69
    public long getLastAccessedTime() {
70
        return session.getLastAccessedTime();
×
71
    }
72

73
    @Override
74
    public void setMaxInactiveInterval(int interval) {
75
        session.setMaxInactiveInterval(interval);
×
76
    }
×
77

78
    @Override
79
    public int getMaxInactiveInterval() {
80
        return session.getMaxInactiveInterval();
1✔
81
    }
82

83
    @Override
84
    public Object getAttribute(String name) {
85
        return session.getAttribute(name);
1✔
86
    }
87

88
    @Override
89
    public Set<String> getAttributeNames() {
90
        return session.getAttributeNames();
×
91
    }
92

93
    @Override
94
    public Object setAttribute(String name, Object value) {
95
        Assert.notNull(name, "name must not be null");
×
NEW
96
        if (value != null && isNonPersistent(name)) {
×
97
            return session.setAttribute(name, NonPersistentValue.wrap(value));
×
98
        } else {
99
            return session.setAttribute(name, value);
×
100
        }
101
    }
102

103
    @Override
104
    public Object removeAttribute(String name) {
UNCOV
105
        return session.removeAttribute(name);
×
106
    }
107

108
    @Override
109
    public void invalidate(HttpServerExchange exchange) {
110
        session.invalidate();
×
111
        if (exchange != null) {
×
112
            sessionManager.clearSession(exchange, session.getId());
×
113
        }
114
    }
×
115

116
    @Override
117
    public SessionManager getSessionManager() {
118
        return sessionManager;
×
119
    }
120

121
    @Override
122
    @Nullable
123
    public String changeSessionId(HttpServerExchange exchange, SessionConfig config) {
124
        synchronized (session) {
×
125
            if (!session.isValid()) {
×
126
                return null;
×
127
            }
128
            String oldId = session.getId();
×
129
            String newId = sessionManager.createSessionId(hashCode());
×
130
            String newIdToUse = sessionManager.renewSessionId(oldId, newId);
×
131
            if (newIdToUse != null) {
×
132
                config.setSessionId(exchange, newIdToUse);
×
133
            }
134
            return newIdToUse;
×
135
        }
136
    }
137

138
    private boolean isNonPersistent(@NonNull String name) {
139
        return name.startsWith("io.undertow.");
×
140
    }
141

142
}
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