added empty http code view

pull/210/head
Justin Richer 2012-08-28 13:00:26 -04:00
parent 8ae1b376fe
commit b462d6dd96
2 changed files with 56 additions and 19 deletions

View File

@ -0,0 +1,34 @@
/**
*
*/
package org.mitre.openid.connect.view;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.AbstractView;
/**
* An empty view that simply returns an HTTP code set in the model
* @author jricher
*
*/
@Component("httpCodeView")
public class HttpCodeView extends AbstractView {
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
HttpStatus code = (HttpStatus) model.get("code");
if (code == null) {
code = HttpStatus.OK; // default to 200
}
response.setStatus(code.value());
}
}

View File

@ -10,6 +10,7 @@ import org.mitre.oauth2.model.ClientDetailsEntity;
import org.mitre.openid.connect.model.WhitelistedSite;
import org.mitre.openid.connect.service.WhitelistedSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
@ -90,15 +91,16 @@ public class WhitelistApi {
WhitelistedSite oldWhitelist = whitelistService.getById(id);
if (oldWhitelist == null) {
// TODO: throw new "entity not found"
m.put("code", HttpStatus.NOT_FOUND);
return "httpCodeView";
} else {
WhitelistedSite newWhitelist = whitelistService.update(oldWhitelist, whitelist);
m.put("entity", newWhitelist);
return "jsonEntityView";
}
WhitelistedSite newWhitelist = whitelistService.update(oldWhitelist, whitelist);
m.put("entity", newWhitelist);
return "jsonEntityView";
}
/**
@ -110,13 +112,12 @@ public class WhitelistApi {
WhitelistedSite whitelist = whitelistService.getById(id);
if (whitelist == null) {
// TODO: throw new "entity not found"
}
m.put("code", HttpStatus.NOT_FOUND);
} else {
whitelistService.remove(whitelist);
}
whitelistService.remove(whitelist);
// TODO: not really an entity view, more of an empty view w/code
return "jsonEntityView";
return "httpCodeView";
}
/**
@ -126,12 +127,14 @@ public class WhitelistApi {
public String getWhitelistedSite(@PathVariable("id") Long id, ModelMap m) {
WhitelistedSite whitelist = whitelistService.getById(id);
if (whitelist == null) {
// TODO: throw new "entity not found"
m.put("code", HttpStatus.NOT_FOUND);
return "httpCodeView";
} else {
m.put("entity", whitelist);
return "jsonEntityView";
}
m.put("entity", whitelist);
return "jsonEntityView";
}
}