org.springframework.web.bind.MissingRequestCookieException Java Examples

The following examples show how to use org.springframework.web.bind.MissingRequestCookieException. 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: GlobalExceptionHandler.java    From dk-foundation with GNU Lesser General Public License v2.1 5 votes vote down vote up
@ExceptionHandler({MissingRequestCookieException.class})
public @ResponseBody
StandResponse exception(MissingRequestCookieException e, HttpServletRequest request, HttpServletResponse response) {
    logger.error("#######ERROR#######", e);
    StandResponse standResponse = new StandResponse();
    standResponse.setSuccess(false);
    standResponse.setCode(StandResponse.COOKIE_MISSING);
    standResponse.setMsg("缺少cookie");
    return standResponse;
}
 
Example #3
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 #4
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 #5
Source File: AbstractCookieValueMethodArgumentResolver.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 MissingRequestCookieException(name, parameter);
}
 
Example #6
Source File: AbstractCookieValueMethodArgumentResolver.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 MissingRequestCookieException(name, parameter);
}
 
Example #7
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;
}