001package jmri.server.json.throttle; 002 003import com.fasterxml.jackson.databind.JsonNode; 004import com.fasterxml.jackson.databind.ObjectMapper; 005import com.fasterxml.jackson.databind.node.ArrayNode; 006import javax.servlet.http.HttpServletResponse; 007 008import jmri.server.json.JsonException; 009import jmri.server.json.JsonHttpService; 010import jmri.server.json.JsonRequest; 011 012/** 013 * @author Randall Wood Copyright 2018 014 */ 015public class JsonThrottleHttpService extends JsonHttpService { 016 017 public JsonThrottleHttpService(ObjectMapper mapper) { 018 super(mapper); 019 } 020 021 @Override 022 public JsonNode doGet(String type, String name, JsonNode data, JsonRequest request) throws JsonException { 023 throw new JsonException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, 024 Bundle.getMessage(request.locale, "GetNotAllowed", type), request.id); 025 } 026 027 @Override 028 public JsonNode doPost(String type, String name, JsonNode data, JsonRequest request) throws JsonException { 029 throw new JsonException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, 030 Bundle.getMessage(request.locale, "PostNotAllowed", type), request.id); 031 } 032 033 @Override 034 public ArrayNode doGetList(String type, JsonNode data, JsonRequest request) throws JsonException { 035 throw new JsonException(HttpServletResponse.SC_BAD_REQUEST, 036 Bundle.getMessage(request.locale, "UnlistableService", type), request.id); 037 } 038 039 @Override 040 public JsonNode doSchema(String type, boolean server, JsonRequest request) throws JsonException { 041 if (JsonThrottle.THROTTLE.equals(type)) { 042 return doSchema(type, 043 server, 044 "jmri/server/json/throttle/throttle-server.json", 045 "jmri/server/json/throttle/throttle-client.json", 046 request.id); 047 } else { 048 throw new JsonException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 049 Bundle.getMessage(request.locale, JsonException.ERROR_UNKNOWN_TYPE, type), request.id); 050 } 051 } 052 053}