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

io.undertow.attribute.SubstituteEmptyWrapper Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

The newest version!
package io.undertow.attribute;

import io.undertow.server.HttpServerExchange;

/**
 * @author Stuart Douglas
 */
public class SubstituteEmptyWrapper implements ExchangeAttributeWrapper {

    private final String substitute;

    public SubstituteEmptyWrapper(String substitute) {
        this.substitute = substitute;
    }

    @Override
    public ExchangeAttribute wrap(final ExchangeAttribute attribute) {
        return new SubstituteEmptyAttribute(attribute, substitute);
    }

    public static class SubstituteEmptyAttribute implements ExchangeAttribute {
        private final ExchangeAttribute attribute;
        private final String substitute;

        public SubstituteEmptyAttribute(ExchangeAttribute attribute, String substitute) {
            this.attribute = attribute;
            this.substitute = substitute;
        }

        @Override
        public String readAttribute(HttpServerExchange exchange) {
            String val = attribute.readAttribute(exchange);
            if(val == null || val.isEmpty()) {
                return substitute;
            }
            return val;
        }

        @Override
        public void writeAttribute(HttpServerExchange exchange, String newValue) throws ReadOnlyAttributeException {
            attribute.writeAttribute(exchange, newValue);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy