2017-06-28 97 views
1

我想啓用澤西島上的壓縮功能。我有一個web服務,必須返回json格式的事件列表。 對於爲例:gzip與澤西壓縮問題

{ 
    "page": 1, 
    "pageCount": 1, 
    "list": [ 
    { 
     "pk": 1, 
     "state": "ACTIVE", 
     "locationType": "ADDRESS", 
     "title": "titre", 
     "description": "hello", 
     "country": "osef", 
     "city": "osef", 
     "address": "osef", 
     "inAgendaCount": 0, 
     "dateBeginning": 1498734400758 
    } 
    ] 
} 

但是,當我使用gzip壓縮檔,反應是這樣的:

{ 
    "page": 1, 
    "pageCount": 1, 
    "list": [ 
    { 
    } 
    ] 
} 

列表中的所有事件被切斷。 這裏是我的web服務:

@Component 
@Path("/") 
public class EventSearchWebService { 

    @Autowired 
    private EventSearchController controller; 

    @GET 
    @Path("/event/search") 
    @Produces(MediaType.APPLICATION_JSON) 
    @JsonView(SmallView.class) 
    public Response search(@QueryParam("keywords") String keywords, @DefaultValue("1") @QueryParam("page") Long page) { 

     if (keywords != null && !keywords.trim().isEmpty()) { 
      return Response.status(200).entity(controller.search(keywords, page)).build(); 
     } else { 
      return Response.status(200).entity(controller.search(page)).build(); 
     } 
    } 
} 

我resourceConfig與壓縮:

@Configuration 
@ApplicationPath("/rest") 
public class JerseyConfig extends ResourceConfig { 

    public JerseyConfig() { 
     // Compression 
     register(EntityFilteringFeature.class); 
     EncodingFilter.enableFor(this, GZipEncoder.class); 

     register(EventSearchWebService.class); 

     register(MultiPartFeature.class); 
     register(ValidationFeature.class); 
     register(ValidationExceptionMapper.class); 
     register(CrossDomainContainerResponseFilter.class); 

     registerClasses(AccessDeniedExceptionMapper.class, 
       GeneralUserExceptionMapper.class, 
       NoResultExceptionMapper.class, 
       UnknowExceptionMapper.class, 
       ValidationExceptionMapper.class); 
    } 
} 

而且我pageableList類:

public class PageableList<E> { 

    @Getter 
    @Setter 
    @JsonView(value = {SmallView.class, FullView.class}) 
    private long page; 

    @Getter 
    @Setter 
    @JsonView(value = {SmallView.class, FullView.class}) 
    private long pageCount; 

    @Getter 
    @Setter 
    @JsonView(value = {SmallView.class, FullView.class}) 
    private List<E> list; 

    public PageableList() { 
     super(); 
    } 

    public PageableList(List<E> list) { 
     super(); 
     this.list = list; 
    } 
} 

有一個在日誌中沒有任何錯誤。有人對發生的事情有了線索嗎?

謝謝

編輯:經過進一步調查,我發現,如果我直接發我的活動清單不PageableList,我有錯誤:

Can not resolve PropertyFilter with id 'org.vagrant.server.entity.EventEntity'; no FilterProvider configured (through reference chain: java.util.ArrayList[0]) 

回答

0

的問題是在ResourceConfig。 此行:

register(EntityFilteringFeature.class); 

是無用的,並導致錯誤。