Skip to content

Instantly share code, notes, and snippets.

@Espenhh
Created September 4, 2011 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Espenhh/1193046 to your computer and use it in GitHub Desktop.
Save Espenhh/1193046 to your computer and use it in GitHub Desktop.
public class DatoVerifikasjonsFilter implements ContainerRequestFilter {
@Override
public ContainerRequest filter(final ContainerRequest request) {
String dato = request.getHeaderValue(Headers.Date);
if (dato != null) {
sjekkDato(dato);
} else {
// Kast feil - datoheader mangler!
}
return request;
}
private void sjekkDato(final String dateOnRFC1123Format) {
try {
Date date = DateUtil.parseDate(dateOnRFC1123Format); // Parser datoen (med Apache commons)
sjekkAtDatoHeaderIkkeErForGammel(date); // Kast feil om den er for gammel
sjekkAtDatoHeaderIkkeErForNy(date); // Kast feil om den er for ny
} catch (DateParseException e) {
// Kast feil - dato ikke parsebar
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment