本文整理汇总了Java中javax.ws.rs.ext.WriterInterceptorContext.getEntity方法的典型用法代码示例。如果您正苦于以下问题:Java WriterInterceptorContext.getEntity方法的具体用法?Java WriterInterceptorContext.getEntity怎么用?Java WriterInterceptorContext.getEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.ext.WriterInterceptorContext
的用法示例。
在下文中一共展示了WriterInterceptorContext.getEntity方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
if (!isVersioningSupported(context)) {
context.proceed();
return;
}
String targetVersion = Version.get(context);
Object source = context.getEntity();
if (source instanceof Collection) {
context.setEntity(convertCollectionToLowerVersion(targetVersion, (Collection<?>)source));
} else {
mapper.map(source);
context.setEntity(converter.convertToLowerVersion(targetVersion, source));
}
Type targetType = getVersionType(context.getGenericType(), targetVersion);
context.setType(toClass(targetType));
context.setGenericType(targetType);
context.proceed();
Version.unset(context);
}
示例2: applyStreaming
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
/**
* <p>applyStreaming.</p>
*
* @param requestContext a {@link javax.ws.rs.container.ContainerRequestContext} object.
* @param context a {@link javax.ws.rs.ext.WriterInterceptorContext} object.
* @throws java.io.IOException if any.
*/
protected void applyStreaming(ContainerRequestContext requestContext, WriterInterceptorContext context)
throws IOException {
Object entity = context.getEntity();
StreamingProcess<Object> process = MessageHelper.getStreamingProcess(context.getEntity(), manager);
if (process != null) {
ContainerResponseContext responseContext =
(ContainerResponseContext) requestContext.getProperty(RESP_PROP_N);
responseContext.setStatusInfo(Response.Status.PARTIAL_CONTENT);
context.getHeaders().putSingle(ACCEPT_RANGES, BYTES_RANGE);
context.setType(StreamingOutput.class);
context.setEntity(new MediaStreaming(
entity,
requestContext.getHeaderString(MediaStreaming.RANGE),
process,
context.getMediaType(),
context.getHeaders()
)
);
}
}
示例3: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
if (!context.getHeaders().containsKey(HttpHeaders.CONTENT_LENGTH)) {
Object entity = context.getEntity();
StreamingProcess<Object> process = MessageHelper.getStreamingProcess(entity, manager);
if (process != null) {
long length = process.length(entity);
if (length != -1)
context.getHeaders().putSingle(HttpHeaders.CONTENT_LENGTH, length);
}
}
context.proceed();
}
示例4: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@Override
public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
final Object entity = context.getEntity();
if (entity instanceof Viewable) {
User user = (User) securityContext.getUserPrincipal();
if ( ((Viewable) entity).getModel() instanceof ViewData) {
ViewData model = ((ViewData) ((Viewable) entity).getModel());
model.set("authUser", user);
String templateName = ((Viewable) entity).getTemplateName();
context.setEntity(new Viewable(templateName, model.getData()));
}
}
context.proceed();
}
示例5: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
if (context.getEntity() != null && context.getEntity() instanceof Viewable) {
final Viewable viewable = (Viewable) context.getEntity();
Object model = viewable.getModel();
if (!(model instanceof Map)) {
model = new HashMap<String, Object>() {
private static final long serialVersionUID = 1L;
{
put("model", viewable.getModel());
}
};
}
((Map) model).put("context", getContextMap());
((Map) model).put("session", getSessionMap());
if (servletRequest.getAttribute(RepositoryContext.ATTR_NAME) != null) {
RepositoryContext repoContext = (RepositoryContext) servletRequest.getAttribute(RepositoryContext.ATTR_NAME);
((Map) model).put("repo", repoContext);
}
context.setEntity(new Viewable(viewable.getTemplateName(), model));
}
context.proceed();
}
示例6: isWritable
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
/**
* <p>isWritable.</p>
*
* @param context a {@link javax.ws.rs.ext.WriterInterceptorContext} object.
* @return a boolean.
*/
protected boolean isWritable(WriterInterceptorContext context) {
return context.getEntity() != null
&& !Boolean.FALSE.equals(requestProvider.get().getProperty(MessageHelper.STREAMING_RANGE_ENABLED))
&& context.getHeaders().containsKey(HttpHeaders.CONTENT_LENGTH)
&& !(context.getEntity() instanceof MediaStreaming);
}
示例7: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
Object entity = context.getEntity();
if (entity instanceof Images.Captcha || entity instanceof Captcha) {
context.setMediaType(IMG_TYPE);
context.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, IMG_TYPE);
if (entity instanceof Captcha) {
Captcha captcha = (Captcha) entity;
context.setType(BufferedImage.class);
context.setEntity(captcha.getImage());
}
}
context.proceed();
}
示例8: aroundWriteTo
import javax.ws.rs.ext.WriterInterceptorContext; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
final Object entity = context.getEntity();
if (!(entity instanceof Viewable) && resourceInfoProvider.get().getResourceMethod() != null) {
final Template template = TemplateHelper.getTemplateAnnotation(context.getAnnotations());
if (template != null) {
context.setType(Viewable.class);
context.setEntity(new Viewable(template.name(), entity));
}
}
context.proceed();
}