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 . These examples are extracted from open source projects. 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
@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 2
@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 3
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 4
Source Project: cumulusrdf   File: NamespacesHandler.java    License: Apache License 2.0 6 votes vote down vote up
@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 5
@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 6
@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 7
@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 Project: cumulusrdf   File: StatementHandler.java    License: Apache License 2.0 5 votes vote down vote up
@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 9
Source Project: cumulusrdf   File: GraphHandler.java    License: Apache License 2.0 5 votes vote down vote up
@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 10
@Override
public int getHttpStatus() {
    return HttpServletResponse.SC_METHOD_NOT_ALLOWED;
}
 
Example 11
public PostOnInvalidRequestURIException(String message) {
    super(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);
}
 
Example 12
public UnsupportedMethodException(String message) {
    super(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);
}
 
Example 13
public static ManagementException createNotAllowedManagementException(final String message,
                                                                      final Map<String, String> headers)
{
    return new ManagementException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, headers);
}
 
Example 14
@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 15
@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 16
@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 17
Source Project: nomulus   File: HttpException.java    License: Apache License 2.0 4 votes vote down vote up
public MethodNotAllowedException() {
  super(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed", null);
}