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:com.novartis.pcs.ontology.rest.servlet.OntologiesServlet.java
@Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); resp.setContentLength(0);/*w w w. j a va 2 s . co m*/ }
From source file:org.eclipse.rdf4j.http.server.repository.transaction.TransactionController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView result;/*from w ww .j ava 2s . c om*/ String reqMethod = request.getMethod(); UUID transactionId = getTransactionID(request); logger.debug("transaction id: {}", transactionId); logger.debug("request content type: {}", request.getContentType()); Transaction transaction = ActiveTransactionRegistry.INSTANCE.getTransaction(transactionId); if (transaction == null) { logger.warn("could not find transaction for transaction id {}", transactionId); throw new ClientHTTPException(SC_BAD_REQUEST, "unable to find registerd transaction for transaction id '" + transactionId + "'"); } // if no action is specified in the request, it's a rollback (since it's // the only txn operation that does not require the action parameter). final String actionParam = request.getParameter(Protocol.ACTION_PARAM_NAME); final Action action = actionParam != null ? Action.valueOf(actionParam) : Action.ROLLBACK; switch (action) { case QUERY: // TODO SES-2238 note that we allow POST requests for backward // compatibility reasons with earlier // 2.8.x releases, even though according to the protocol spec only // PUT is allowed. if ("PUT".equals(reqMethod) || METHOD_POST.equals(reqMethod)) { logger.info("{} txn query request", reqMethod); result = processQuery(transaction, request, response); logger.info("{} txn query request finished", reqMethod); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } break; case GET: if ("PUT".equals(reqMethod) || METHOD_POST.equals(reqMethod)) { logger.info("{} txn get/export statements request", reqMethod); result = getExportStatementsResult(transaction, request, response); logger.info("{} txn get/export statements request finished", reqMethod); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } break; case SIZE: if ("PUT".equals(reqMethod) || METHOD_POST.equals(reqMethod)) { logger.info("{} txn size request", reqMethod); result = getSize(transaction, request, response); logger.info("{} txn size request finished", reqMethod); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } break; default: // TODO Action.ROLLBACK check is for backward compatibility with // older 2.8.x releases only. It's not in the protocol spec. if ("DELETE".equals(reqMethod) || (action.equals(Action.ROLLBACK) && ("PUT".equals(reqMethod) || METHOD_POST.equals(reqMethod)))) { logger.info("transaction rollback"); try { transaction.rollback(); } finally { ActiveTransactionRegistry.INSTANCE.deregister(transaction); } result = new ModelAndView(EmptySuccessView.getInstance()); logger.info("transaction rollback request finished."); } else if ("PUT".equals(reqMethod) || METHOD_POST.equals(reqMethod)) { // TODO filter for appropriate PUT operations logger.info("{} txn operation", reqMethod); result = processModificationOperation(transaction, action, request, response); logger.info("PUT txn operation request finished."); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } break; } return result; }
From source file:com.novartis.pcs.ontology.rest.servlet.OntologiesServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); resp.setContentLength(0);/*from www . j av a2 s . c om*/ }
From source file:org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.java
public ModelAndView handleURI(String uri, GrailsWebRequest webRequest, Map params) { if (uri == null) { throw new IllegalArgumentException("Controller URI [" + uri + "] cannot be null!"); }/*from w w w . ja v a 2 s .com*/ HttpServletRequest request = webRequest.getCurrentRequest(); HttpServletResponse response = webRequest.getCurrentResponse(); configureStateForWebRequest(webRequest, request); if (uri.endsWith("/")) { uri = uri.substring(0, uri.length() - 1); } // if the id is blank check if its a request parameter // Step 2: lookup the controller in the application. GrailsControllerClass controllerClass = getControllerClassByURI(uri); if (controllerClass == null) { throw new UnknownControllerException("No controller found for URI [" + uri + "]!"); } actionName = controllerClass.getClosurePropertyName(uri); webRequest.setActionName(actionName); if (LOG.isDebugEnabled()) { LOG.debug("Processing request for controller [" + controllerName + "], action [" + actionName + "], and id [" + id + "]"); } controllerActionURI = SLASH + controllerName + SLASH + actionName + SLASH; // Step 3: load controller from application context. GroovyObject controller = getControllerInstance(controllerClass); if (!controllerClass.isHttpMethodAllowedForAction(controller, request.getMethod(), actionName)) { try { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return null; } catch (IOException e) { throw new ControllerExecutionException("I/O error sending 403 error", e); } } request.setAttribute(GrailsApplicationAttributes.CONTROLLER, controller); // Step 4: Set grails attributes in request scope request.setAttribute(GrailsApplicationAttributes.REQUEST_SCOPE_ID, this.grailsAttributes); // Step 5: get the view name for this URI. String viewName = controllerClass.getViewByURI(uri); boolean executeAction = invokeBeforeInterceptor(controller, controllerClass); // if the interceptor returned false don't execute the action if (!executeAction) return null; ModelAndView mv = executeAction(controller, controllerClass, viewName, request, response, params); boolean returnModelAndView = invokeAfterInterceptor(controllerClass, controller, mv) && !response.isCommitted(); return returnModelAndView ? mv : null; }
From source file:io.github.gsteckman.rpi_rest.SubscriptionManager.java
/** * Processes a UPnP UNSUBSCRIBE request and removes a subscription. * /*from w ww.j a v a 2 s .c o m*/ * @param key * The key identifies the resource to which the subscription applies. * @param req * HTTP request * @param res * Response to the request * @throws IOException * Thrown by HttpServletResponse.sendError if an error occurs writing the response. */ public void processUnsubscribe(String key, HttpServletRequest req, HttpServletResponse res) throws IOException { String timeoutHdr = req.getHeader("TIMEOUT"); String callbackHdr = req.getHeader("CALLBACK"); String sidHdr = req.getHeader("SID"); // Perform error checking: // 1. Method must be UNSUBSCRIBE // 2. SID header must be present // 3. NT and CALLBACK headers not present if (!"UNSUBSCRIBE".equalsIgnoreCase(req.getMethod())) { // Return 405 status res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method " + req.getMethod() + " not allowed for this resource."); return; } if (sidHdr == null || sidHdr.length() == 0) { res.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, "SID header field is missing or empty."); } if (timeoutHdr != null || callbackHdr != null) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "An SID header field and one of NT or CALLBACK header fields are present."); return; } Map<UUID, SubscriptionInfo> m = subscriptions.get(key); if (m == null) { res.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, "SID doesn't correspond to a known subscription."); return; } // parse SID & remove subscription String ss = sidHdr.substring(5).trim(); UUID sid = new UUID(ss); if (m.remove(sid) == null) { res.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, "SID doesn't correspond to a known subscription."); return; } }
From source file:csiro.pidsvc.servlet.info.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response)// ww w . j a v a2 s.c o m */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); }
From source file:org.openrdf.http.server.repository.transaction.TransactionController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView result;//from w ww . j a va 2s .c o m String reqMethod = request.getMethod(); UUID transactionId = getTransactionID(request); logger.debug("transaction id: {}", transactionId); logger.debug("request content type: {}", request.getContentType()); RepositoryConnection connection = ActiveTransactionRegistry.INSTANCE .getTransactionConnection(transactionId); if (connection == null) { logger.warn("could not find connection for transaction id {}", transactionId); throw new ClientHTTPException(SC_BAD_REQUEST, "unable to find registerd connection for transaction id '" + transactionId + "'"); } // if no action is specified in the request, it's a rollback (since it's // the only txn operation that does not require the action parameter). final String actionParam = request.getParameter(Protocol.ACTION_PARAM_NAME); final Action action = actionParam != null ? Action.valueOf(actionParam) : Action.ROLLBACK; switch (action) { case QUERY: // TODO SES-2238 note that we allow POST requests for backward // compatibility reasons with earlier // 2.8.x releases, even though according to the protocol spec only // PUT is allowed. if ("PUT".equals(reqMethod) || METHOD_POST.equals(reqMethod)) { logger.info("{} txn query request", reqMethod); result = processQuery(connection, transactionId, request, response); logger.info("{} txn query request finished", reqMethod); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } break; case GET: if ("PUT".equals(reqMethod) || METHOD_POST.equals(reqMethod)) { logger.info("{} txn get/export statements request", reqMethod); result = getExportStatementsResult(connection, transactionId, request, response); logger.info("{} txn get/export statements request finished", reqMethod); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } break; case SIZE: if ("PUT".equals(reqMethod) || METHOD_POST.equals(reqMethod)) { logger.info("{} txn size request", reqMethod); result = getSize(connection, transactionId, request, response); logger.info("{} txn size request finished", reqMethod); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } break; default: // modification operations - we can process these and then // immediately release the connection back to the registry. try { // TODO Action.ROLLBACK check is for backward compatibility with // older 2.8.x releases only. It's not in the protocol spec. if ("DELETE".equals(reqMethod) || (action.equals(Action.ROLLBACK) && ("PUT".equals(reqMethod) || METHOD_POST.equals(reqMethod)))) { logger.info("transaction rollback"); try { connection.rollback(); } finally { ActiveTransactionRegistry.INSTANCE.deregister(transactionId); connection.close(); } result = new ModelAndView(EmptySuccessView.getInstance()); logger.info("transaction rollback request finished."); } else if ("PUT".equals(reqMethod) || METHOD_POST.equals(reqMethod)) { // TODO filter for appropriate PUT operations logger.info("{} txn operation", reqMethod); result = processModificationOperation(connection, action, request, response); logger.info("PUT txn operation request finished."); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } } finally { ActiveTransactionRegistry.INSTANCE.returnTransactionConnection(transactionId); } break; } return result; }
From source file:org.eclipse.orion.server.servlets.PreferencesServlet.java
/** * Returns the metadata object associated with this request. This method controls * exactly what metadata objects are exposed via this service. If there is no matching * metadata object for the request, this method handles the appropriate response * and returns <code>null</code>. * @param req/*from ww w . j a va2s . c o m*/ * @param resp */ private MetadataInfo getNode(HttpServletRequest req, HttpServletResponse resp) throws ServletException { String pathString = req.getPathInfo(); if (pathString == null) pathString = ""; //$NON-NLS-1$ IPath path = new Path(pathString); int segmentCount = path.segmentCount(); String scope = path.segment(0); try { if ("user".equalsIgnoreCase(scope)) { //$NON-NLS-1$ String username = req.getRemoteUser(); if (username == null) { resp.setStatus(HttpServletResponse.SC_FORBIDDEN); return null; } return OrionConfiguration.getMetaStore().readUser(username); } else if ("workspace".equalsIgnoreCase(scope) && segmentCount > 1) { //$NON-NLS-1$ //format is /workspace/{workspaceId} return OrionConfiguration.getMetaStore().readWorkspace(path.segment(1)); } else if ("project".equalsIgnoreCase(scope) && segmentCount > 2) { //$NON-NLS-1$ //format is /project/{workspaceId}/{projectName} return OrionConfiguration.getMetaStore().readProject(path.segment(1), path.segment(2)); } } catch (CoreException e) { handleException(resp, "Internal error obtaining preferences", e, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } //invalid prefix handleNotFound(req, resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED); return null; }
From source file:org.sakaiproject.kernel.rest.RestPatchProvider.java
/** * {@inheritDoc}/*from w w w .j a v a 2s .com*/ * * @see org.sakaiproject.kernel.api.rest.RestProvider#dispatch(java.lang.String[], * javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) */ public void dispatch(String[] elements, HttpServletRequest request, HttpServletResponse response) { try { if (elements.length >= 1) { // the URL is the path to the resource. Map<String, Object> map = null; if (PRIVATE.equals(elements[1]) && "POST".equals(request.getMethod())) { map = doPatchPrivate(elements, request, response); } else if (SHARED.equals(elements[1]) && "POST".equals(request.getMethod())) { map = doPatchShared(elements, request, response); } else { throw new RestServiceFaultException(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } if (map != null) { String responseBody = beanConverter.convertToString(map); response.setContentType(RestProvider.CONTENT_TYPE); response.getOutputStream().print(responseBody); } } } catch (AccessDeniedException ex) { throw new RestServiceFaultException(HttpServletResponse.SC_FORBIDDEN, ex.getMessage(), ex); } catch (SecurityException ex) { throw ex; } catch (RestServiceFaultException ex) { throw ex; } catch (Exception ex) { throw new RestServiceFaultException(ex.getMessage(), ex); } }