com.terracotta.management.resource.services.validator.TSARequestValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache Show documentation
Show all versions of ehcache Show documentation
Ehcache is an open source, standards-based cache used to boost performance,
offload the database and simplify scalability. Ehcache is robust, proven and full-featured and
this has made it the most widely-used Java-based cache.
package com.terracotta.management.resource.services.validator;
import java.util.List;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.terracotta.management.resource.Representable;
import org.terracotta.management.resource.exceptions.ResourceRuntimeException;
import org.terracotta.management.resource.services.Utils;
import org.terracotta.management.resource.services.validator.RequestValidator;
/**
* @author Ludovic Orban
*/
public class TSARequestValidator implements RequestValidator {
@Override
public void validateSafe(UriInfo info) {
validateAgentSegment(info.getPathSegments());
}
@Override
public void validate(UriInfo info) {
validateAgentSegment(info.getPathSegments());
}
private void validateAgentSegment(List pathSegments) {
String ids = pathSegments.get(0).getMatrixParameters().getFirst("ids");
if (Utils.trimToNull(ids) != null && !Representable.EMBEDDED_AGENT_ID.equals(ids)) {
throw new ResourceRuntimeException(String.format("Agent ID must be '%s'.", Representable.EMBEDDED_AGENT_ID),
Response.Status.BAD_REQUEST.getStatusCode());
}
}
}