Clover icon

sunshower-sdk

  1. Project Clover database Sat May 12 2018 05:15:40 UTC
  2. Package io.sunshower.sdk.channel

File MediaTypeInterceptor.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
22% of files have more coverage

Code metrics

8
10
1
1
31
27
5
0.5
10
1
5

Classes

Class Line # Actions
MediaTypeInterceptor 12 10 5
0.789473778.9%
 

Contributing tests

This file is covered by 23 tests. .

Source view

1    package io.sunshower.sdk.channel;
2   
3    import org.jboss.resteasy.spi.ResteasyProviderFactory;
4   
5    import javax.ws.rs.container.ContainerRequestContext;
6    import javax.ws.rs.container.ContainerRequestFilter;
7    import javax.ws.rs.core.MediaType;
8    import javax.ws.rs.ext.Provider;
9    import java.io.IOException;
10   
11    @Provider
 
12    public class MediaTypeInterceptor implements ContainerRequestFilter {
13   
 
14  224 toggle @Override
15    public void filter(ContainerRequestContext requestContext) throws IOException {
16  224 MediaType mediaType = requestContext.getMediaType();
17  224 if (mediaType == null) {
18  156 String accept = requestContext.getHeaderString("Accept");
19  156 if (accept != null) {
20  156 String[] values = accept.split("\\s*,\\s*");
21  156 if (values.length > 0) {
22  156 mediaType = MediaType.valueOf(values[0]);
23    }
24    }
25    }
26  224 if (mediaType == null) {
27  0 mediaType = MediaType.APPLICATION_JSON_TYPE;
28    }
29  224 ResteasyProviderFactory.getContextDataMap().put(MediaType.class, mediaType);
30    }
31    }