org.springframework.web.bind.MissingMatrixVariableException Java Examples

The following examples show how to use org.springframework.web.bind.MissingMatrixVariableException. 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: MissingRequestParametersWebErrorHandlerTest.java    From errors-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
private Object[] provideParamsForHandle() {
    return p(
        p(
            new MissingRequestHeaderException("Authorization", getParameter()),
            MISSING_HEADER,
            BAD_REQUEST,
            singletonMap(MISSING_HEADER, asList(arg("name", "Authorization"), arg("expected", "boolean")))
        ),
        p(
            new MissingRequestCookieException("sessionId", getParameter()),
            MISSING_COOKIE,
            BAD_REQUEST,
            singletonMap(MISSING_COOKIE, asList(arg("name", "sessionId"), arg("expected", "boolean")))
        ),
        p(
            new MissingMatrixVariableException("name", getParameter()),
            MISSING_MATRIX_VARIABLE,
            BAD_REQUEST,
            singletonMap(MISSING_MATRIX_VARIABLE, asList(arg("name", "name"), arg("expected", "boolean")))
        )
    );
}
 
Example #2
Source File: MissingRequestParametersWebErrorHandler.java    From errors-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Handles the given exception by selecting the appropriate error code, status code and
 * to-be-exposed arguments conditionally.
 *
 * @param exception The exception to handle.
 * @return The handled exception.
 */
@NonNull
@Override
public HandledException handle(Throwable exception) {
    List<Argument> arguments = new ArrayList<>();
    String errorCode = "unknown_error";

    if (exception instanceof MissingRequestHeaderException) {
        MissingRequestHeaderException headerException = (MissingRequestHeaderException) exception;
        arguments.add(arg("name", headerException.getHeaderName()));
        arguments.add(arg("expected", getType(headerException.getParameter())));

        errorCode = MISSING_HEADER;
    } else if (exception instanceof MissingRequestCookieException) {
        MissingRequestCookieException cookieException = (MissingRequestCookieException) exception;
        arguments.add(arg("name", cookieException.getCookieName()));
        arguments.add(arg("expected", getType(cookieException.getParameter())));

        errorCode = MISSING_COOKIE;
    } else if (exception instanceof MissingMatrixVariableException) {
        MissingMatrixVariableException variableException = (MissingMatrixVariableException) exception;
        arguments.add(arg("name", variableException.getVariableName()));
        arguments.add(arg("expected", getType(variableException.getParameter())));

        errorCode = MISSING_MATRIX_VARIABLE;
    }

    return new HandledException(errorCode, BAD_REQUEST, singletonMap(errorCode, arguments));
}
 
Example #3
Source File: MissingRequestParametersWebErrorHandlerTest.java    From errors-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
private Object[] provideParamsForCanHandle() {
    return p(
        p(null, false),
        p(new RuntimeException(), false),
        p(new MissingPathVariableException("name", getParameter()), false),
        p(new MissingRequestHeaderException("name", getParameter()), true),
        p(new MissingRequestCookieException("name", getParameter()), true),
        p(new MissingMatrixVariableException("name", getParameter()), true)
    );
}
 
Example #4
Source File: MatrixVariableMethodArgumentResolver.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException {
	throw new MissingMatrixVariableException(name, parameter);
}
 
Example #5
Source File: MatrixVariableMethodArgumentResolver.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException {
	throw new MissingMatrixVariableException(name, parameter);
}
 
Example #6
Source File: MissingRequestParametersWebErrorHandler.java    From errors-spring-boot-starter with Apache License 2.0 3 votes vote down vote up
/**
 * Only can handle exceptions about missing required headers, cookies or matrix variables.
 *
 * @param exception The exception to examine.
 * @return {@code true} when the exception is related to missing required headers, cookies or
 * matrix variables, {@code false} otherwise.
 */
@Override
public boolean canHandle(Throwable exception) {
    return exception instanceof MissingRequestHeaderException ||
        exception instanceof MissingRequestCookieException ||
        exception instanceof MissingMatrixVariableException;
}