List of usage examples for javax.servlet.http HttpServletResponse SC_METHOD_NOT_ALLOWED
int SC_METHOD_NOT_ALLOWED
To view the source code for javax.servlet.http HttpServletResponse SC_METHOD_NOT_ALLOWED.
Click Source Link
Request-Line
is not allowed for the resource identified by the Request-URI
. From source file:org.ednovo.gooru.web.spring.exception.GooruExceptionResolver.java
@Override public ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {/*from w ww.j av a2 s . c o m*/ ErrorObject errorObject = null; boolean isLogError = false; if (ex instanceof AccessDeniedException) { errorObject = new ErrorObject(403, ex.getMessage()); response.setStatus(403); logger.error("input parameters --- " + getRequestInfo(request).toString()); } else if (ex instanceof BadCredentialsException) { errorObject = new ErrorObject(400, ex.getMessage()); response.setStatus(400); } else if (ex instanceof BadRequestException) { errorObject = new ErrorObject(400, ((BadRequestException) ex).getErrorCode() != null ? "400-" + ((BadRequestException) ex).getErrorCode() : "400", ex.getMessage()); response.setStatus(400); } else if (ex instanceof UnauthorizedException) { errorObject = new ErrorObject(401, ((UnauthorizedException) ex).getErrorCode() != null ? "401-" + ((UnauthorizedException) ex).getErrorCode() : "401", ex.getMessage()); response.setStatus(401); } else if (ex instanceof SizeLimitExceededException) { response.setStatus(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE); errorObject = new ErrorObject(413, ex.getMessage()); } else if (ex instanceof S3ServiceException) { response.setStatus(500); errorObject = new ErrorObject(500, "Internal Server Error"); logger.info("Error in Resolver -- " + ((S3ServiceException) ex).getErrorMessage()); } else if (ex instanceof NotFoundException) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); isLogError = true; errorObject = new ErrorObject(404, ex.getMessage()); } else if (ex instanceof NotImplementedException || ex instanceof NotAllowedException) { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); errorObject = new ErrorObject(405, ex.getMessage()); } else if (ex instanceof MethodFailureException) { response.setStatus(420); errorObject = new ErrorObject(420, ex.getMessage()); logger.error("Error in Resolver -- ", ex); logger.error("input parameters --- " + getRequestInfo(request).toString()); } else { errorObject = new ErrorObject(500, "Internal Server Error"); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); logger.error("Error in Resolver -- ", ex); logger.error("input parameters --- " + getRequestInfo(request).toString()); } if (!isLogError) { logger.debug("Error in Resolver -- ", ex); logger.debug("input parameters --- " + getRequestInfo(request).toString()); } ModelAndView jsonModel = new ModelAndView("rest/model"); String errorJsonResponse = new JSONSerializer().exclude("*.class").serialize(errorObject); if (ex instanceof UnauthorizedException) { response.setHeader("Unauthorized", errorJsonResponse); } jsonModel.addObject("model", errorJsonResponse); return jsonModel; }
From source file:org.jahia.test.bin.LogWatcher.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { try {/*from ww w . j av a2 s . co m*/ if (request.getMethod().equalsIgnoreCase("GET")) { String operation = request.getParameter("op"); String appenderKey = request.getParameter("key"); if (StringUtils.isEmpty(appenderKey)) { appenderKey = DEFAULT_APPENDER_KEY; } LogExceptionExtractor logAppender = errorLogAppenders.remove(appenderKey); Logger rootLogger = Logger.getRootLogger(); if (logAppender != null) { rootLogger.removeAppender(logAppender); logger.info("Error logging (key=" + appenderKey + ") stopped"); } if ("start".equals(operation)) { logAppender = new LogExceptionExtractor(); logAppender.setName(appenderKey); errorLogAppenders.put(appenderKey, logAppender); logger.info("Error logging (key=" + appenderKey + ") started"); response.getWriter().println("OK"); rootLogger.addAppender(logAppender); } else if (logAppender != null) { response.getWriter().println(logAppender.getErrorLogs()); } } else if (request.getMethod().equals("OPTIONS")) { response.setHeader("Allow", "GET, OPTIONS"); } else { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } } catch (Exception e) { DefaultErrorHandler.getInstance().handle(e, request, response); } return null; }
From source file:org.opencastproject.capture.admin.endpoint.CaptureAgentStateRestService.java
@GET @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Path("agents/{name}.{format:xml|json}") @RestQuery(name = "getAgent", description = "Return the state of a given capture agent", pathParameters = { @RestParameter(name = "name", description = "The name of a given capture agent", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "format", description = "The output format (json or xml) of the response body.", isRequired = true, type = RestParameter.Type.STRING) }, restParameters = {}, reponses = { @RestResponse(description = "{agentState}", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "The agent {agentName} does not exist", responseCode = HttpServletResponse.SC_NOT_FOUND), @RestResponse(description = "If the {format} is not xml or json", responseCode = HttpServletResponse.SC_METHOD_NOT_ALLOWED), @RestResponse(description = "If no capture agent state service is available", responseCode = HttpServletResponse.SC_SERVICE_UNAVAILABLE) }, returnDescription = "") public Response getAgentState(@PathParam("name") String agentName, @PathParam("format") String format) throws NotFoundException { if (service == null) return Response.serverError().status(Response.Status.SERVICE_UNAVAILABLE).build(); Agent ret = service.getAgent(agentName); logger.debug("Returning agent state for {}", agentName); if ("json".equals(format)) { return Response.ok(new AgentStateUpdate(ret)).type(MediaType.APPLICATION_JSON).build(); } else {//from ww w.j av a 2s.c o m return Response.ok(new AgentStateUpdate(ret)).type(MediaType.APPLICATION_XML).build(); } }
From source file:com.imaginary.home.cloud.api.call.RelayCall.java
@Override public void put(@Nonnull String requestId, @Nullable String userId, @Nonnull String[] path, @Nonnull HttpServletRequest req, @Nonnull HttpServletResponse resp, @Nonnull Map<String, Object> headers, @Nonnull Map<String, Object> parameters) throws RestException, IOException { try {/*from w ww .j a va 2s .c o m*/ if (path.length < 2) { throw new RestException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, RestException.INVALID_OPERATION, "No PUT on /relay"); } ControllerRelay relay = ControllerRelay.getRelay(path[1]); if (relay == null) { throw new RestException(HttpServletResponse.SC_NOT_FOUND, RestException.NO_SUCH_OBJECT, "Relay " + path[1] + " not found"); } BufferedReader reader = new BufferedReader(new InputStreamReader(req.getInputStream())); StringBuilder source = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { source.append(line); source.append(" "); } JSONObject object = new JSONObject(source.toString()); String action; if (object.has("action") && !object.isNull("action")) { action = object.getString("action"); } else { throw new RestException(HttpServletResponse.SC_BAD_REQUEST, RestException.INVALID_ACTION, "An invalid action was specified (or not specified) in the PUT"); } if (action.equalsIgnoreCase("update")) { if (userId != null) { throw new RestException(HttpServletResponse.SC_FORBIDDEN, RestException.USER_NOT_ALLOWED, "This API call may be called only by controller relays"); } update(relay, object, resp); } else if (action.equalsIgnoreCase("modify")) { if (object.has("relay")) { object = object.getJSONObject("relay"); } else { object = null; } if (object == null) { throw new RestException(HttpServletResponse.SC_BAD_REQUEST, RestException.INVALID_PUT, "No location was specified in the PUT"); } String name; if (object.has("name") && !object.isNull("name")) { name = object.getString("name"); } else { name = relay.getName(); } relay.modify(name); resp.setStatus(HttpServletResponse.SC_NO_CONTENT); } else { throw new RestException(HttpServletResponse.SC_BAD_REQUEST, RestException.INVALID_ACTION, "The action " + action + " is not a valid action."); } } catch (JSONException e) { throw new RestException(HttpServletResponse.SC_BAD_REQUEST, RestException.INVALID_JSON, "Invalid JSON in body"); } catch (PersistenceException e) { e.printStackTrace(); throw new RestException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, RestException.INTERNAL_ERROR, "Internal database error"); } }
From source file:ch.entwine.weblounge.dispatcher.impl.handler.RobotsRequestHandlerImpl.java
/** * {@inheritDoc}/* w ww . ja va 2 s .c om*/ * * @see ch.entwine.weblounge.dispatcher.RequestHandler#service(ch.entwine.weblounge.common.request.WebloungeRequest, * ch.entwine.weblounge.common.request.WebloungeResponse) */ public boolean service(WebloungeRequest request, WebloungeResponse response) { WebUrl url = request.getUrl(); String path = url.getPath(); // Is the request intended for this handler? if (!URI_PREFIX.equals(path)) { logger.debug("Skipping request for {}, request path does not start with {}", URI_PREFIX); return false; } // Check the request method. Only GET is supported right now. String requestMethod = request.getMethod().toUpperCase(); if ("OPTIONS".equals(requestMethod)) { String verbs = "OPTIONS,GET"; logger.trace("Answering options request to {} with {}", url, verbs); response.setHeader("Allow", verbs); response.setContentLength(0); return true; } else if (!"GET".equals(requestMethod)) { logger.debug("Robots request handler does not support {} requests", requestMethod); DispatchUtils.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, request, response); return true; } // Decide on which directives to send String robotsDirective = null; if (Environment.Production.equals(request.getEnvironment())) { // TODO: Get hold of the site bundle and check for an existing robots.txt robotsDirective = allowRobotsTxt; } else { robotsDirective = disallowRobotsTxt; } // Send the response try { response.setContentType("text/plain"); response.setContentLength(robotsDirective.length()); response.setModificationDate(modificationDate); IOUtils.write(robotsDirective, response.getOutputStream(), "UTF-8"); } catch (IOException e) { logger.warn("Error sending robots.txt to client: {}", e.getMessage()); } return true; }
From source file:com.jaspersoft.jasperserver.rest.RESTAbstractService.java
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { log.error("Method PUT is not supported for this object type - request params: Path: " + req.getPathInfo()); restUtils.setStatusAndBody(HttpServletResponse.SC_METHOD_NOT_ALLOWED, resp, "Method not supported for this object type"); }
From source file:com.amazonaws.services.dynamodbv2.replication.server.ReplicationGroupHandler.java
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { switch (target) { case ADD_TABLES_TARGET: case ADD_TABLES_TARGET_: addTables(target, baseRequest, request, response); break;/*from w ww .j a v a2s . co m*/ case REMOVE_REGIONS_TARGET: case REMOVE_REGIONS_TARGET_: removeRegions(target, baseRequest, request, response); break; case REMOVE_TABLES_TARGET: case REMOVE_TABLES_TARGET_: removeTables(target, baseRequest, request, response); break; case DESCRIBE_REPLICATION_COORDINATOR_TARGET: case DESCRIBE_REPLICATION_COORDINATOR_TARGET_: switch (request.getMethod().toUpperCase()) { case "GET": break; default: sendError(response, HttpServletResponse.SC_METHOD_NOT_ALLOWED, "DescribeReplicationCoordinator only supports GET"); return; } describeReplicationCoordinator(target, baseRequest, request, response); break; case DESCRIBE_REPLICATION_GROUP: case DESCRIBE_REPLICATION_GROUP_: switch (request.getMethod().toUpperCase()) { case "GET": break; default: sendError(response, HttpServletResponse.SC_METHOD_NOT_ALLOWED, "DescribeReplicationGroup only supports GET"); return; } describeReplicationGroup(target, baseRequest, request, response); break; case DESCRIBE_TABLES: case DESCRIBE_TABLES_: switch (request.getMethod().toUpperCase()) { case "GET": break; default: sendError(response, HttpServletResponse.SC_METHOD_NOT_ALLOWED, "DescribeTables only supports GET"); return; } describeTables(target, baseRequest, request, response); break; case DESCRIBE_REGIONS: case DESCRIBE_REGIONS_: switch (request.getMethod().toUpperCase()) { case "GET": break; default: sendError(response, HttpServletResponse.SC_METHOD_NOT_ALLOWED, "DescribeRegions only supports GET"); return; } describeRegions(target, baseRequest, request, response); break; case START_REPLICATION_TARGET: case START_REPLICATION_TARGET_: switch (request.getMethod().toUpperCase()) { case "POST": break; default: sendError(response, HttpServletResponse.SC_METHOD_NOT_ALLOWED, "StartReplication only supports POST"); return; } startReplication(target, baseRequest, request, response); break; case STOP_REPLICATION_TARGET: case STOP_REPLICATION_TARGET_: switch (request.getMethod().toUpperCase()) { case "POST": break; default: sendError(response, HttpServletResponse.SC_METHOD_NOT_ALLOWED, "StopReplication only supports POST"); return; } stopReplication(target, baseRequest, request, response); break; default: setHelpResponse(target, baseRequest, request, response); break; } baseRequest.setHandled(true); }
From source file:org.gss_project.gss.server.rest.SharedHandler.java
/** * Serve the 'shared' namespace for the user. *//from w w w .j a v a2 s.co m * @param req The servlet request we are processing * @param resp The servlet response we are processing * @throws IOException if an input/output error occurs */ void serveShared(HttpServletRequest req, HttpServletResponse resp) throws IOException { String path = getInnerPath(req, PATH_SHARED); if (path.equals("")) path = "/"; if (path.equals("/")) try { User user = getUser(req); User owner = getOwner(req); if (!owner.equals(user)) throw new InsufficientPermissionsException("User " + user.getUsername() + " does not have permission to view the resources shared by " + owner.getUsername()); JSONObject json = new JSONObject(); List<JSONObject> subfolders = new ArrayList<JSONObject>(); List<Folder> folders = getService().getSharedRootFolders(owner.getId()); for (Folder f : folders) { JSONObject j = new JSONObject(); j.put("name", f.getName()).put("uri", getApiRoot() + f.getURI()); if (f.getParent() != null) j.put("parent", getApiRoot() + f.getParent().getURI()).put("shared", f.getShared()); ; subfolders.add(j); } json.put("folders", subfolders); List<FileHeader> fileHeaders = getService().getSharedFilesNotInSharedFolders(owner.getId()); List<JSONObject> files = new ArrayList<JSONObject>(); for (FileHeader f : fileHeaders) { JSONObject j = new JSONObject(); j.put("name", f.getName()).put("owner", f.getOwner().getUsername()) .put("deleted", f.isDeleted()).put("version", f.getCurrentBody().getVersion()) .put("size", f.getCurrentBody().getFileSize()) .put("content", f.getCurrentBody().getMimeType()).put("path", f.getFolder().getPath()) .put("shared", f.getShared()).put("versioned", f.isVersioned()) .put("creationDate", f.getAuditInfo().getCreationDate().getTime()) .put("modificationDate", f.getAuditInfo().getModificationDate().getTime()) .put("uri", getApiRoot() + f.getURI()); JSONObject jf = new JSONObject(); jf.put("uri", getApiRoot() + f.getFolder().getURI()).put("name", URLEncoder.encode(f.getFolder().getName(), "UTF-8")); j.put("folder", jf); files.add(j); } json.put("files", files); sendJson(req, resp, json.toString()); // Workaround for IE's broken caching behavior. resp.setHeader("Expires", "-1"); } catch (ObjectNotFoundException e) { logger.error("User not found", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (RpcException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (JSONException e) { logger.error("", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (InsufficientPermissionsException e) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, e.getMessage()); } else resp.sendError(HttpServletResponse.SC_NOT_FOUND); }
From source file:com.haulmont.cuba.web.controllers.StaticContentController.java
@RequestMapping(method = RequestMethod.HEAD) public String handleHeadRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { try {//from w w w .ja v a2 s . c om lookup(request).respondHead(request, response); } catch (UnsupportedOperationException e) { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } return null; }
From source file:org.apache.wookie.controller.WidgetInstancesController.java
@Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!WidgetKeyManager.isValidRequest(request)) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } else {//from ww w . j ava 2 s . c o m try { String requestId = request.getParameter("requestid"); //$NON-NLS-1$ if (requestId == null || requestId.equals("")) { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } else { if (requestId.equals("stopwidget")) { //$NON-NLS-1$ doStopWidget(request, response); } else if (requestId.equals("resumewidget")) { //$NON-NLS-1$ doResumeWidget(request, response); } else if (requestId.equals("clone")) { //$NON-NLS-1$ cloneSharedData(request, response); } else { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } } } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } }