当前位置: 首页>>代码示例>>Java>>正文


Java WriterInterceptorContext.setEntity方法代码示例

本文整理汇总了Java中javax.ws.rs.ext.WriterInterceptorContext.setEntity方法的典型用法代码示例。如果您正苦于以下问题:Java WriterInterceptorContext.setEntity方法的具体用法?Java WriterInterceptorContext.setEntity怎么用?Java WriterInterceptorContext.setEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.ext.WriterInterceptorContext的用法示例。


在下文中一共展示了WriterInterceptorContext.setEntity方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
 
开发者ID:openknowledge,项目名称:jaxrs-versioning,代码行数:21,代码来源:MessageBodyConverter.java

示例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()
                )
        );
    }
}
 
开发者ID:icode,项目名称:ameba,代码行数:30,代码来源:StreamingWriterInterceptor.java

示例3: 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();
}
 
开发者ID:autoschool,项目名称:splinter,代码行数:17,代码来源:UserDataInterceptor.java

示例4: 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();
}
 
开发者ID:kamegu,项目名称:git-webapp,代码行数:29,代码来源:AttachContextInterceptor.java

示例5: 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();
}
 
开发者ID:icode,项目名称:ameba,代码行数:18,代码来源:CaptchaWriterInterceptor.java

示例6: 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();
}
 
开发者ID:icode,项目名称:ameba,代码行数:18,代码来源:TemplateMethodInterceptor.java


注:本文中的javax.ws.rs.ext.WriterInterceptorContext.setEntity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。