Ejemplo n.º 1
0
 @Override
 public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
   try {
     Object entity = response.getEntity();
     if (entity != null) {
       if (entity
           instanceof TopicType) { // Note: type matches both, must take precedence over topic
         firePreSend((TopicType) entity);
       } else if (entity instanceof Topic) {
         firePreSend((Topic) entity);
       } else if (entity instanceof Association) {
         firePreSend((Association) entity);
       } else if (entity instanceof Directives) {
         firePreSend((Directives) entity);
       } else if (isIterable(response, TopicType.class)) {
         firePreSendTopicTypes(DeepaMehtaUtils.<Iterable<TopicType>>cast(entity));
       } else if (isIterable(response, Topic.class)) {
         firePreSendTopics(DeepaMehtaUtils.<Iterable<Topic>>cast(entity));
       }
     }
     return response;
   } catch (Exception e) {
     throw new WebApplicationException(
         new RuntimeException("Jersey response filtering failed", e));
   }
 }
Ejemplo n.º 2
0
 @Override
 public ContainerResponse filter(ContainerRequest req, ContainerResponse res) {
   Object entity = res.getEntity();
   if (entity instanceof PaginatedIterable) {
     PaginatedIterable<?> p = (PaginatedIterable) entity;
     if (p.isPaginated()) {
       insertLinks(p, req, res);
     }
   }
   return res;
 }
Ejemplo n.º 3
0
 private boolean isIterable(ContainerResponse response, Class<?> elementType) {
   Type genericType = response.getEntityType();
   if (genericType instanceof ParameterizedType) {
     Type[] typeArgs = ((ParameterizedType) genericType).getActualTypeArguments();
     Class<?> type = response.getEntity().getClass();
     // FIX FOO CHECK THIS OUT!!!!
     if (typeArgs.length == 1
         && Iterable.class.isAssignableFrom(type)
         && elementType.isAssignableFrom((Class<?>) typeArgs[0])) {
       return true;
     }
   }
   return false;
 }