Java Code Examples for javax.servlet.http.HttpServletResponse#SC_METHOD_NOT_ALLOWED
The following examples show how to use
javax.servlet.http.HttpServletResponse#SC_METHOD_NOT_ALLOWED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NamespacesHandler.java From cumulusrdf with Apache License 2.0 | 6 votes |
@Override public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response) throws Exception { String reqMethod = request.getMethod(); if (METHOD_GET.equals(reqMethod)) { _logger.info("GET namespace list"); return getExportNamespacesResult(repository, request, response); } if (METHOD_HEAD.equals(reqMethod)) { _logger.info("HEAD namespace list"); return getExportNamespacesResult(repository, request, response); } else if ("DELETE".equals(reqMethod)) { _logger.info("DELETE namespaces"); return getClearNamespacesResult(repository, request, response); } throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); }
Example 2
Source File: TransactionStartController.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView result; Repository repository = RepositoryInterceptor.getRepository(request); String reqMethod = request.getMethod(); if (METHOD_POST.equals(reqMethod)) { logger.info("POST transaction start"); result = startTransaction(repository, request, response); logger.info("transaction started"); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } return result; }
Example 3
Source File: NamespacesController.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String reqMethod = request.getMethod(); if (METHOD_GET.equals(reqMethod)) { logger.info("GET namespace list"); return getExportNamespacesResult(request, response); } if (METHOD_HEAD.equals(reqMethod)) { logger.info("HEAD namespace list"); return getExportNamespacesResult(request, response); } else if ("DELETE".equals(reqMethod)) { logger.info("DELETE namespaces"); return getClearNamespacesResult(request, response); } throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); }
Example 4
Source File: MCRSwordMediaHandler.java From mycore with GNU General Public License v3.0 | 6 votes |
public void replaceMediaResource(String derivateId, String requestFilePath, Deposit deposit) throws SwordError, SwordServerException { if (!MCRAccessManager.checkPermission(derivateId, MCRAccessManager.PERMISSION_WRITE)) { throw new SwordError(UriRegistry.ERROR_METHOD_NOT_ALLOWED, "You dont have the right to write to the derivate!"); } MCRPath path = MCRPath.getPath(derivateId, requestFilePath); if (!Files.exists(path)) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_NOT_FOUND, "Cannot replace a not existing file."); } final boolean pathIsDirectory = Files.isDirectory(path); if (pathIsDirectory) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_METHOD_NOT_ALLOWED, "replaceMediaResource is not supported with directories"); } // TODO: replace file }
Example 5
Source File: GraphHandler.java From cumulusrdf with Apache License 2.0 | 5 votes |
@Override public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response) throws Exception { ModelAndView result; String reqMethod = request.getMethod(); if (METHOD_GET.equals(reqMethod)) { _logger.info("GET graph"); result = getExportStatementsResult(repository, request, response); _logger.info("GET graph request finished."); } else if (METHOD_HEAD.equals(reqMethod)) { _logger.info("HEAD graph"); result = getExportStatementsResult(repository, request, response); _logger.info("HEAD graph request finished."); } else if (METHOD_POST.equals(reqMethod)) { _logger.info("POST data to graph"); result = getAddDataResult(repository, request, response, false); _logger.info("POST data request finished."); } else if ("PUT".equals(reqMethod)) { _logger.info("PUT data in graph"); result = getAddDataResult(repository, request, response, true); _logger.info("PUT data request finished."); } else if ("DELETE".equals(reqMethod)) { _logger.info("DELETE data from graph"); result = getDeleteDataResult(repository, request, response); _logger.info("DELETE data request finished."); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } return result; }
Example 6
Source File: StatementHandler.java From cumulusrdf with Apache License 2.0 | 5 votes |
@Override public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response) throws Exception { ModelAndView result; String reqMethod = request.getMethod(); if (METHOD_GET.equals(reqMethod)) { _logger.info("GET statements"); result = getExportStatementsResult(repository, request, response); } else if (METHOD_HEAD.equals(reqMethod)) { _logger.info("HEAD statements"); result = getExportStatementsResult(repository, request, response); } else if (METHOD_POST.equals(reqMethod)) { String mimeType = HttpServerUtil.getMIMEType(request.getContentType()); if (Protocol.TXN_MIME_TYPE.equals(mimeType)) { _logger.info("POST transaction to repository"); result = getTransactionResultResult(repository, request, response); } else if (request.getParameterMap().containsKey(Protocol.UPDATE_PARAM_NAME)) { _logger.info("POST SPARQL update request to repository"); result = getSparqlUpdateResult(repository, request, response); } else { _logger.info("POST data to repository"); result = getAddDataResult(repository, request, response, false); } } else if ("PUT".equals(reqMethod)) { _logger.info("PUT data in repository"); result = getAddDataResult(repository, request, response, false); } else if ("DELETE".equals(reqMethod)) { _logger.info("DELETE data from repository"); result = getDeleteDataResult(repository, request, response); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } return result; }
Example 7
Source File: Jersey1WebApplicationExceptionHandlerListenerTest.java From backstopper with Apache License 2.0 | 5 votes |
@DataProvider public static Object[][] dataProviderForShouldHandleException() { return new Object[][] { { new NotFoundException(), testProjectApiErrors.getNotFoundApiError() }, { mock(ParamException.URIParamException.class), testProjectApiErrors.getNotFoundApiError() }, { mock(ParamException.class), testProjectApiErrors.getMalformedRequestApiError() }, { new WebApplicationException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE), testProjectApiErrors.getUnsupportedMediaTypeApiError() }, { new WebApplicationException(HttpServletResponse.SC_METHOD_NOT_ALLOWED), testProjectApiErrors.getMethodNotAllowedApiError() }, { new WebApplicationException(HttpServletResponse.SC_UNAUTHORIZED), testProjectApiErrors.getUnauthorizedApiError() }, { new WebApplicationException(HttpServletResponse.SC_NOT_ACCEPTABLE), testProjectApiErrors.getNoAcceptableRepresentationApiError() }, { mock(JsonProcessingException.class), testProjectApiErrors.getMalformedRequestApiError() } }; }
Example 8
Source File: JaxRsWebApplicationExceptionHandlerListenerTest.java From backstopper with Apache License 2.0 | 5 votes |
@DataProvider public static Object[][] dataProviderForShouldHandleException() { return new Object[][] { { new NotFoundException(), testProjectApiErrors.getNotFoundApiError() }, { new WebApplicationException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE), testProjectApiErrors.getUnsupportedMediaTypeApiError() }, { new WebApplicationException(HttpServletResponse.SC_METHOD_NOT_ALLOWED), testProjectApiErrors.getMethodNotAllowedApiError() }, { new WebApplicationException(HttpServletResponse.SC_UNAUTHORIZED), testProjectApiErrors.getUnauthorizedApiError() }, { new WebApplicationException(HttpServletResponse.SC_NOT_ACCEPTABLE), testProjectApiErrors.getNoAcceptableRepresentationApiError() }, { mock(JsonProcessingException.class), testProjectApiErrors.getMalformedRequestApiError() } }; }
Example 9
Source File: GraphController.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView result; Repository repository = RepositoryInterceptor.getRepository(request); String reqMethod = request.getMethod(); if (METHOD_GET.equals(reqMethod)) { logger.info("GET graph"); result = getExportStatementsResult(repository, request, response); logger.info("GET graph request finished."); } else if (METHOD_HEAD.equals(reqMethod)) { logger.info("HEAD graph"); result = getExportStatementsResult(repository, request, response); logger.info("HEAD graph request finished."); } else if (METHOD_POST.equals(reqMethod)) { logger.info("POST data to graph"); result = getAddDataResult(repository, request, response, false); logger.info("POST data request finished."); } else if ("PUT".equals(reqMethod)) { logger.info("PUT data in graph"); result = getAddDataResult(repository, request, response, true); logger.info("PUT data request finished."); } else if ("DELETE".equals(reqMethod)) { logger.info("DELETE data from graph"); result = getDeleteDataResult(repository, request, response); logger.info("DELETE data request finished."); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } return result; }
Example 10
Source File: JaxRsWebApplicationExceptionHandlerListener.java From backstopper with Apache License 2.0 | 4 votes |
@Override public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) { ApiExceptionHandlerListenerResult result; SortedApiErrorSet handledErrors = null; List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>(); if (ex instanceof NotFoundException) { handledErrors = singletonSortedSetOf(projectApiErrors.getNotFoundApiError()); } else if (ex instanceof WebApplicationException) { utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging); WebApplicationException webex = (WebApplicationException) ex; Response webExResponse = webex.getResponse(); if (webExResponse != null) { int webExStatusCode = webExResponse.getStatus(); if (webExStatusCode == HttpServletResponse.SC_NOT_ACCEPTABLE) { handledErrors = singletonSortedSetOf(projectApiErrors.getNoAcceptableRepresentationApiError()); } else if (webExStatusCode == HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE) { handledErrors = singletonSortedSetOf(projectApiErrors.getUnsupportedMediaTypeApiError()); } else if (webExStatusCode == HttpServletResponse.SC_METHOD_NOT_ALLOWED) { handledErrors = singletonSortedSetOf(projectApiErrors.getMethodNotAllowedApiError()); } else if (webExStatusCode == HttpServletResponse.SC_UNAUTHORIZED) { handledErrors = singletonSortedSetOf(projectApiErrors.getUnauthorizedApiError()); } } } else if (ex instanceof JsonProcessingException) { utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging); handledErrors = singletonSortedSetOf(projectApiErrors.getMalformedRequestApiError()); } // Return an indication that we will handle this exception if handledErrors got set if (handledErrors != null) { result = ApiExceptionHandlerListenerResult.handleResponse(handledErrors, extraDetailsForLogging); } else { result = ApiExceptionHandlerListenerResult.ignoreResponse(); } return result; }
Example 11
Source File: StatementsController.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView result; Repository repository = RepositoryInterceptor.getRepository(request); String reqMethod = request.getMethod(); if (METHOD_GET.equals(reqMethod)) { logger.info("GET statements"); result = getExportStatementsResult(repository, request, response); } else if (METHOD_HEAD.equals(reqMethod)) { logger.info("HEAD statements"); result = getExportStatementsResult(repository, request, response); } else if (METHOD_POST.equals(reqMethod)) { String mimeType = HttpServerUtil.getMIMEType(request.getContentType()); if (Protocol.TXN_MIME_TYPE.equals(mimeType)) { logger.info("POST transaction to repository"); result = getTransactionResultResult(repository, request, response); } else if (Protocol.SPARQL_UPDATE_MIME_TYPE.equals(mimeType) || request.getParameterMap().containsKey(Protocol.UPDATE_PARAM_NAME)) { logger.info("POST SPARQL update request to repository"); result = getSparqlUpdateResult(repository, request, response); } else { logger.info("POST data to repository"); result = getAddDataResult(repository, request, response, false); } } else if ("PUT".equals(reqMethod)) { logger.info("PUT data in repository"); result = getAddDataResult(repository, request, response, true); } else if ("DELETE".equals(reqMethod)) { logger.info("DELETE data from repository"); result = getDeleteDataResult(repository, request, response); } else { throw new ClientHTTPException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + reqMethod); } return result; }
Example 12
Source File: Jersey1WebApplicationExceptionHandlerListener.java From backstopper with Apache License 2.0 | 4 votes |
@Override public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) { ApiExceptionHandlerListenerResult result; SortedApiErrorSet handledErrors = null; List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>(); if (ex instanceof NotFoundException) { handledErrors = singletonSortedSetOf(projectApiErrors.getNotFoundApiError()); } else if (ex instanceof ParamException.URIParamException) { utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging); // Returning a 404 is intentional here. // The Jersey contract for URIParamException states it should map to a 404. handledErrors = singletonSortedSetOf(projectApiErrors.getNotFoundApiError()); } else if (ex instanceof ParamException) { utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging); handledErrors = singletonSortedSetOf(projectApiErrors.getMalformedRequestApiError()); } else if (ex instanceof WebApplicationException) { utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging); WebApplicationException webex = (WebApplicationException) ex; Response webExResponse = webex.getResponse(); if (webExResponse != null) { int webExStatusCode = webExResponse.getStatus(); if (webExStatusCode == HttpServletResponse.SC_NOT_ACCEPTABLE) { handledErrors = singletonSortedSetOf(projectApiErrors.getNoAcceptableRepresentationApiError()); } else if (webExStatusCode == HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE) { handledErrors = singletonSortedSetOf(projectApiErrors.getUnsupportedMediaTypeApiError()); } else if (webExStatusCode == HttpServletResponse.SC_METHOD_NOT_ALLOWED) { handledErrors = singletonSortedSetOf(projectApiErrors.getMethodNotAllowedApiError()); } else if (webExStatusCode == HttpServletResponse.SC_UNAUTHORIZED) { handledErrors = singletonSortedSetOf(projectApiErrors.getUnauthorizedApiError()); } } } else if (ex instanceof JsonProcessingException) { utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging); handledErrors = singletonSortedSetOf(projectApiErrors.getMalformedRequestApiError()); } // Return an indication that we will handle this exception if handledErrors got set if (handledErrors != null) { result = ApiExceptionHandlerListenerResult.handleResponse(handledErrors, extraDetailsForLogging); } else { result = ApiExceptionHandlerListenerResult.ignoreResponse(); } return result; }
Example 13
Source File: ManagementException.java From qpid-broker-j with Apache License 2.0 | 4 votes |
public static ManagementException createNotAllowedManagementException(final String message, final Map<String, String> headers) { return new ManagementException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, headers); }
Example 14
Source File: HttpException.java From nomulus with Apache License 2.0 | 4 votes |
public MethodNotAllowedException() { super(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed", null); }
Example 15
Source File: UnsupportedMethodException.java From tus-java-server with MIT License | 4 votes |
public UnsupportedMethodException(String message) { super(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message); }
Example 16
Source File: PostOnInvalidRequestURIException.java From tus-java-server with MIT License | 4 votes |
public PostOnInvalidRequestURIException(String message) { super(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message); }
Example 17
Source File: ControllerArgumentException.java From n2o-framework with Apache License 2.0 | 4 votes |
@Override public int getHttpStatus() { return HttpServletResponse.SC_METHOD_NOT_ALLOWED; }