001/******************************************************************************* 002 * Copyright 2017 The MIT Internet Trust Consortium 003 * 004 * Portions copyright 2011-2013 The MITRE Corporation 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 *******************************************************************************/ 018/** 019 * 020 */ 021package org.mitre.openid.connect.view; 022 023import java.util.Map; 024 025import javax.servlet.http.HttpServletRequest; 026import javax.servlet.http.HttpServletResponse; 027 028import org.springframework.http.HttpStatus; 029import org.springframework.stereotype.Component; 030import org.springframework.web.servlet.view.AbstractView; 031 032/** 033 * An empty view that simply returns an HTTP code set in the model 034 * @author jricher 035 * 036 */ 037@Component(HttpCodeView.VIEWNAME) 038public class HttpCodeView extends AbstractView { 039 040 public static final String VIEWNAME = "httpCodeView"; 041 042 public static final String CODE = "code"; 043 044 @Override 045 protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { 046 HttpStatus code = (HttpStatus) model.get(CODE); 047 if (code == null) { 048 code = HttpStatus.OK; // default to 200 049 } 050 051 response.setStatus(code.value()); 052 053 } 054 055}