All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wildfly.clustering.web.undertow.routing.DistributableSessionIdentifierCodec Maven / Gradle / Ivy

Go to download

This module adapts an implementation of wildfly-clustering-web-spi to the Undertow servlet container.

There is a newer version: 34.0.0.Final
Show newest version
/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.clustering.web.undertow.routing;

import org.jboss.as.web.session.RoutingSupport;
import org.jboss.as.web.session.SessionIdentifierCodec;
import org.wildfly.clustering.web.routing.RouteLocator;

/**
 * {@link SessionIdentifierCodec} that encodes the route determined by a {@link RouteLocator}.
 * @author Paul Ferraro
 */
public class DistributableSessionIdentifierCodec implements SessionIdentifierCodec {

    private final RouteLocator locator;
    private final RoutingSupport routing;

    public DistributableSessionIdentifierCodec(RouteLocator locator, RoutingSupport routing) {
        this.locator = locator;
        this.routing = routing;
    }

    @Override
    public CharSequence encode(CharSequence sessionId) {
        String route = this.locator.locate(sessionId.toString());
        return (route != null) ? this.routing.format(sessionId, route) : sessionId;
    }

    @Override
    public CharSequence decode(CharSequence encodedSessionId) {
        return this.routing.parse(encodedSessionId).getKey();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy