use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.
the class InMemoryWebSessionStoreTests method startsSessionExplicitly.
@Test
public void startsSessionExplicitly() {
WebSession session = this.store.createWebSession().block();
assertThat(session).isNotNull();
session.start();
assertThat(session.isStarted()).isTrue();
}
use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.
the class InMemoryWebSessionStoreTests method lastAccessTimeIsUpdatedOnRetrieve.
@Test
public void lastAccessTimeIsUpdatedOnRetrieve() {
WebSession session1 = this.store.createWebSession().block();
assertThat(session1).isNotNull();
String id = session1.getId();
Instant time1 = session1.getLastAccessTime();
session1.start();
session1.save().block();
// Fast-forward a few seconds
this.store.setClock(Clock.offset(this.store.getClock(), Duration.ofSeconds(5)));
WebSession session2 = this.store.retrieveSession(id).block();
assertThat(session2).isNotNull();
assertThat(session2).isSameAs(session1);
Instant time2 = session2.getLastAccessTime();
assertThat(time1.isBefore(time2)).isTrue();
}
use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.
the class InMemoryWebSessionStore method createWebSession.
@Override
public Mono<WebSession> createWebSession() {
// Opportunity to clean expired sessions
Instant now = this.clock.instant();
this.expiredSessionChecker.checkIfNecessary(now);
return Mono.<WebSession>fromSupplier(() -> new InMemoryWebSession(now)).subscribeOn(Schedulers.boundedElastic()).publishOn(Schedulers.parallel());
}
use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.
the class WebSessionMethodArgumentResolver method resolveArgument.
@Override
public Mono<Object> resolveArgument(MethodParameter parameter, BindingContext context, ServerWebExchange exchange) {
Mono<WebSession> session = exchange.getSession();
ReactiveAdapter adapter = getAdapterRegistry().getAdapter(parameter.getParameterType());
return (adapter != null ? Mono.just(adapter.fromPublisher(session)) : Mono.from(session));
}
use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.
the class WebSessionMethodArgumentResolverTests method resolverArgument.
@Test
public void resolverArgument() {
BindingContext context = new BindingContext();
WebSession session = mock(WebSession.class);
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
ServerWebExchange exchange = MockServerWebExchange.builder(request).session(session).build();
MethodParameter param = this.testMethod.arg(WebSession.class);
Object actual = this.resolver.resolveArgument(param, context, exchange).block();
assertThat(actual).isSameAs(session);
param = this.testMethod.arg(Mono.class, WebSession.class);
actual = this.resolver.resolveArgument(param, context, exchange).block();
assertThat(actual).isNotNull();
assertThat(Mono.class.isAssignableFrom(actual.getClass())).isTrue();
assertThat(((Mono<?>) actual).block()).isSameAs(session);
param = this.testMethod.arg(Single.class, WebSession.class);
actual = this.resolver.resolveArgument(param, context, exchange).block();
assertThat(actual).isNotNull();
assertThat(Single.class.isAssignableFrom(actual.getClass())).isTrue();
assertThat(((Single<?>) actual).blockingGet()).isSameAs(session);
}
Aggregations