org.jetrs.server.container.InterceptorContextImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of server Show documentation
Show all versions of server Show documentation
A fast and lightweight implementation of Java's JAX-RS 2.1 server specification built to run in a servlet container.
/* Copyright (c) 2016 OpenJAX
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* You should have received a copy of The MIT License (MIT) along with this
* program. If not, see .
*/
package org.jetrs.server.container;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.InterceptorContext;
import org.jetrs.common.ext.delegate.DateHeaderDelegate;
import org.jetrs.common.util.MediaTypes;
abstract class InterceptorContextImpl implements InterceptorContext {
private final Locale locale;
protected final Map properties;
private Annotation[] annotations;
private Class> type;
private Type genericType;
protected InterceptorContextImpl(final Locale locale, final Map properties) {
this.locale = locale;
this.properties = properties;
}
abstract MultivaluedMap getStringHeaders();
public final String getHeaderString(final String name) {
return getStringHeaders().getFirst(name);
}
public final Date getDate() {
final String date = getStringHeaders().getFirst(HttpHeaders.DATE);
return date == null ? null : DateHeaderDelegate.parse(date);
}
public final Locale getLanguage() {
return locale;
}
@Override
public final Object getProperty(final String name) {
return properties.get(name);
}
@Override
public final Collection getPropertyNames() {
return properties.keySet();
}
@Override
public final void setProperty(final String name, final Object object) {
properties.put(name, object);
}
@Override
public final void removeProperty(final String name) {
properties.remove(name);
}
@Override
public final Annotation[] getAnnotations() {
return annotations;
}
@Override
public final void setAnnotations(final Annotation[] annotations) {
this.annotations = annotations;
}
@Override
public final Class> getType() {
return type;
}
@Override
public final void setType(final Class> type) {
this.type = type;
}
@Override
public final Type getGenericType() {
return genericType;
}
@Override
public final void setGenericType(final Type genericType) {
this.genericType = genericType;
}
@Override
public final MediaType getMediaType() {
final String mediaType = getStringHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
return mediaType == null ? MediaType.WILDCARD_TYPE : MediaTypes.parse(mediaType);
}
@Override
public final void setMediaType(final MediaType mediaType) {
getStringHeaders().putSingle(HttpHeaders.CONTENT_TYPE, mediaType.toString());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy