io.undertow.attribute.SubstituteEmptyWrapper Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including
all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and
JMS 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).
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);
}
}
}