unicon.matthews.xapi.endpoint.XAPIRequestValidationFilter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 10
eloc 14
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A doFilterInternal(HttpServletRequest,HttpServletResponse,FilterChain) 0 14 2
1
/**
2
 * Copyright 2014 Unicon (R) Licensed under the
3
 * Educational Community License, Version 2.0 (the "License"); you may
4
 * not use this file except in compliance with the License. You may
5
 * obtain a copy of the License at
6
 *
7
 * http://www.osedu.org/licenses/ECL-2.0
8
9
 * Unless required by applicable law or agreed to in writing,
10
 * software distributed under the License is distributed on an "AS IS"
11
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12
 * or implied. See the License for the specific language governing
13
 * permissions and limitations under the License.
14
 *
15
 */
16
package unicon.matthews.xapi.endpoint;
17
18
import java.io.IOException;
19
20
import javax.servlet.FilterChain;
21
import javax.servlet.ServletException;
22
import javax.servlet.http.HttpServletRequest;
23
import javax.servlet.http.HttpServletResponse;
24
25
import org.apache.commons.lang3.StringUtils;
26
import org.apache.log4j.Logger;
27
import org.springframework.stereotype.Component;
28
import org.springframework.web.filter.OncePerRequestFilter;
29
30
/**
31
 * @author ggilbert
32
 *
33
 */
34
@Component
35
public class XAPIRequestValidationFilter extends OncePerRequestFilter {
36
37
	private Logger log = Logger.getLogger(XAPIRequestValidationFilter.class);
38
	
39
	@Override
40
	protected void doFilterInternal(HttpServletRequest request,
41
			HttpServletResponse response, FilterChain filterChain)
42
			throws ServletException, IOException {
43
		String versionHeader = request.getHeader(XApiConstants.XAPI_VERSION_HEADER);
44
		log.debug(String.format("versionHeader {}",versionHeader));
0 ignored issues
show
Comprehensibility Code Smell introduced by
String contains no format specifiers.
Loading history...
45
		if (StringUtils.isNotBlank(versionHeader)) {
46
			// for now we are just checking for the header
47
			// in the future we'll deal with specific versioning checking
48
			filterChain.doFilter(request, response);
49
		}
50
		else {
51
			log.warn("Request missing XAPI VERSION HEADER");
52
			response.sendError(400, "Missing "+XApiConstants.XAPI_VERSION_HEADER+" Header");
53
		}
54
		
55
	}
56
57
}
58