com.nike.backstopper.apierror.projectspecificinfo.ProjectApiErrors Java Examples

The following examples show how to use com.nike.backstopper.apierror.projectspecificinfo.ProjectApiErrors. 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: BackstopperSpringboot2ContainerErrorController.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
public BackstopperSpringboot2ContainerErrorController(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull UnhandledServletContainerErrorHelper unhandledServletContainerErrorHelper,
    @NotNull ServerProperties serverProperties
) {
    if (projectApiErrors == null) {
        throw new NullPointerException("ProjectApiErrors cannot be null.");
    }

    if (unhandledServletContainerErrorHelper == null) {
        throw new NullPointerException("UnhandledServletContainerErrorHelper cannot be null.");
    }

    if (serverProperties == null) {
        throw new NullPointerException("ServerProperties cannot be null.");
    }

    this.projectApiErrors = projectApiErrors;
    this.unhandledServletContainerErrorHelper = unhandledServletContainerErrorHelper;
    this.errorPath = serverProperties.getError().getPath();
}
 
Example #2
Source File: BackstopperSpringboot1ContainerErrorController.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
public BackstopperSpringboot1ContainerErrorController(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull UnhandledServletContainerErrorHelper unhandledServletContainerErrorHelper,
    @NotNull ServerProperties serverProperties
) {
    if (projectApiErrors == null) {
        throw new NullPointerException("ProjectApiErrors cannot be null.");
    }

    if (unhandledServletContainerErrorHelper == null) {
        throw new NullPointerException("UnhandledServletContainerErrorHelper cannot be null.");
    }

    if (serverProperties == null) {
        throw new NullPointerException("ServerProperties cannot be null.");
    }

    this.projectApiErrors = projectApiErrors;
    this.unhandledServletContainerErrorHelper = unhandledServletContainerErrorHelper;
    this.errorPath = serverProperties.getError().getPath();
}
 
Example #3
Source File: RiposteApiExceptionHandlerTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@Test
public void constructorWorksIfPassedValidValues() {
    // when
    RiposteApiExceptionHandler
        myAdapter = new RiposteApiExceptionHandler(projectApiErrors, validListenerList, utils);

    // then
    List<ApiExceptionHandlerListener> actualListeners =
        (List<ApiExceptionHandlerListener>) Whitebox.getInternalState(myAdapter, "apiExceptionHandlerListenerList");
    ProjectApiErrors actualProjectApiErrors =
        (ProjectApiErrors) Whitebox.getInternalState(myAdapter, "projectApiErrors");
    ApiExceptionHandlerUtils actualUtils = (ApiExceptionHandlerUtils) Whitebox.getInternalState(myAdapter, "utils");
    assertThat(actualListeners, is(validListenerList));
    assertThat(actualProjectApiErrors, is(projectApiErrors));
    assertThat(actualUtils, is(utils));
}
 
Example #4
Source File: BaseSpringEnabledValidationTestCase.java    From backstopper with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that the given MvcResult's {@link org.springframework.test.web.servlet.MvcResult#getResponse()} has the
 * expected HTTP status code, that its contents can be converted to the appropriate {@link DefaultErrorContractDTO} with the
 * expected errors (as per the default error handling contract), and that the MvcResult's {@link
 * org.springframework.test.web.servlet.MvcResult#getResolvedException()} matches the given expectedExceptionType.
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
protected void verifyErrorResponse(MvcResult result, ProjectApiErrors projectApiErrors,
                                   List<ApiError> expectedErrors, Class<? extends Exception> expectedExceptionType)
    throws IOException {
    Integer expectedStatusCode = projectApiErrors.determineHighestPriorityHttpStatusCode(expectedErrors);
    expectedErrors = projectApiErrors.getSublistContainingOnlyHttpStatusCode(expectedErrors, expectedStatusCode);
    MockHttpServletResponse response = result.getResponse();
    assertThat(response.getStatus(), is(expectedStatusCode));
    DefaultErrorContractDTO details =
        objectMapper.readValue(response.getContentAsString(), DefaultErrorContractDTO.class);
    assertNotNull(details);
    assertNotNull(details.error_id);
    assertNotNull(details.errors);
    assertThat(details.errors.size(), is(expectedErrors.size()));
    List<Pair<String, String>> expectedErrorsAsPairs = convertToCodeAndMessagePairs(expectedErrors);
    for (DefaultErrorDTO errorView : details.errors) {
        assertTrue(expectedErrorsAsPairs.contains(Pair.of(errorView.code, errorView.message)));
    }
    assertNotNull(result.getResolvedException());
    Assertions.assertThat(result.getResolvedException()).isInstanceOf(expectedExceptionType);
}
 
Example #5
Source File: BackstopperSpringWebFluxComponentTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Bean
@Primary
public SpringWebfluxApiExceptionHandler springWebfluxApiExceptionHandler(
    ProjectApiErrors projectApiErrors,
    SpringWebFluxApiExceptionHandlerListenerList apiExceptionHandlerListeners,
    ApiExceptionHandlerUtils generalUtils,
    SpringWebfluxApiExceptionHandlerUtils springUtils,
    ObjectProvider<ViewResolver> viewResolversProvider,
    ServerCodecConfigurer serverCodecConfigurer
) {
    return new SpringWebfluxApiExceptionHandler(
        projectApiErrors, apiExceptionHandlerListeners, generalUtils, springUtils, viewResolversProvider,
        serverCodecConfigurer
    ) {
        @Override
        protected ApiExceptionHandlerListenerResult shouldHandleApiException(
            Throwable ex
        ) {
            exceptionSeenByNormalBackstopperHandler = ex;
            normalBackstopperHandlingResult = super.shouldHandleApiException(ex);
            return normalBackstopperHandlingResult;
        }
    };
}
 
Example #6
Source File: ApiExceptionHandlerBase.java    From backstopper with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance with the given arguments.
 *
 * @param projectApiErrors The {@link ProjectApiErrors} used for this project - cannot be null.
 * @param apiExceptionHandlerListenerList
 *          The list of {@link ApiExceptionHandlerListener}s that will be used for this project to analyze
 *          exceptions and see if they should be handled (and how they should be handled if so). These will be
 *          executed in list order. This cannot be null (pass in an empty list if you really don't have any
 *          listeners for your project, however this should never be the case in practice - you should always
 *          include {@link com.nike.backstopper.handler.listener.impl.GenericApiExceptionHandlerListener}
 *          at the very least).
 * @param utils The {@link ApiExceptionHandlerUtils} that should be used by this instance. You can pass in
 *              {@link ApiExceptionHandlerUtils#DEFAULT_IMPL} if you don't need custom logic. Cannot be null.
 */
public ApiExceptionHandlerBase(ProjectApiErrors projectApiErrors,
                               List<ApiExceptionHandlerListener> apiExceptionHandlerListenerList,
                               ApiExceptionHandlerUtils utils) {
    if (projectApiErrors == null)
        throw new IllegalArgumentException("projectApiErrors cannot be null.");

    if (apiExceptionHandlerListenerList == null)
        throw new IllegalArgumentException("apiExceptionHandlerListenerList cannot be null.");

    if (utils == null)
        throw new IllegalArgumentException("apiExceptionHandlerUtils cannot be null.");

    this.projectApiErrors = projectApiErrors;
    this.apiExceptionHandlerListenerList = apiExceptionHandlerListenerList;
    this.utils = utils;
}
 
Example #7
Source File: ServerConfig.java    From riposte with Apache License 2.0 6 votes vote down vote up
/**
 * @return The error handler that should be used for this application for handling unknown/unexpected/unhandled
 * errors. Known/handled errors will be processed by {@link #riposteErrorHandler()}.
 *
 * <p>NOTE: The default implementation returned if you don't override this method is a very basic Backstopper impl -
 * it will not know about your application's {@link ProjectApiErrors} and will instead create a dummy {@link
 * ProjectApiErrors} that only supports the {@link com.nike.backstopper.apierror.sample.SampleCoreApiError} values.
 * This method should be overridden for most real applications to return a real implementation tailored for your
 * app. In practice this usually means copy/pasting this method and simply supplying the correct {@link
 * ProjectApiErrors} for the app. The rest is usually fine for defaults.
 */
default @NotNull RiposteUnhandledErrorHandler riposteUnhandledErrorHandler() {
    ProjectApiErrors projectApiErrors = new SampleProjectApiErrorsBase() {
        @Override
        protected List<ApiError> getProjectSpecificApiErrors() {
            return null;
        }

        @Override
        protected ProjectSpecificErrorCodeRange getProjectSpecificErrorCodeRange() {
            return null;
        }
    };
    return BackstopperRiposteConfigHelper
        .defaultUnhandledErrorHandler(projectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL);
}
 
Example #8
Source File: SpringWebfluxUnhandledExceptionHandler.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Inject
public SpringWebfluxUnhandledExceptionHandler(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull ApiExceptionHandlerUtils generalUtils,
    @NotNull SpringWebfluxApiExceptionHandlerUtils springUtils,
    @NotNull ObjectProvider<ViewResolver> viewResolversProvider,
    @NotNull ServerCodecConfigurer serverCodecConfigurer
) {
    super(projectApiErrors, generalUtils);

    //noinspection ConstantConditions
    if (springUtils == null) {
        throw new NullPointerException("springUtils cannot be null.");
    }
    
    //noinspection ConstantConditions
    if (viewResolversProvider == null) {
        throw new NullPointerException("viewResolversProvider cannot be null.");
    }

    //noinspection ConstantConditions
    if (serverCodecConfigurer == null) {
        throw new NullPointerException("serverCodecConfigurer cannot be null.");
    }

    this.singletonGenericServiceError = Collections.singleton(projectApiErrors.getGenericServiceError());
    this.genericServiceErrorHttpStatusCode = projectApiErrors.getGenericServiceError().getHttpStatusCode();

    this.springUtils = springUtils;
    this.viewResolvers = viewResolversProvider.orderedStream().collect(Collectors.toList());
    this.messageReaders = serverCodecConfigurer.getReaders();
    this.messageWriters = serverCodecConfigurer.getWriters();
}
 
Example #9
Source File: AppGuiceModuleTest.java    From riposte-microservice-template with Apache License 2.0 5 votes vote down vote up
@Test
public void projectApiErrors_returns_ProjectApiErrorsImpl() {
    ProjectApiErrors projectApiErrors = injector.getInstance(ProjectApiErrors.class);
    assertThat(projectApiErrors)
        .isNotNull()
        .isInstanceOf(ProjectApiErrorsImpl.class);
}
 
Example #10
Source File: ApiExceptionHandlerServletApiBaseTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
      instanceSpy = spy(new ApiExceptionHandlerServletApiBase<Object>(mock(ProjectApiErrors.class),
                                                                      Collections.<ApiExceptionHandlerListener>emptyList(),
                                                                      ApiExceptionHandlerUtils.DEFAULT_IMPL) {
          @Override
          protected Object prepareFrameworkRepresentation(DefaultErrorContractDTO errorContractDTO, int httpStatusCode, Collection<ApiError> filteredClientErrors,
                                                          Throwable originalException, RequestInfoForLogging request) {
              return null;
          }
      });
    servletRequestMock = mock(HttpServletRequest.class);
    servletResponseMock = mock(HttpServletResponse.class);
}
 
Example #11
Source File: SpringWebfluxApiExceptionHandlerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    projectApiErrorsMock = mock(ProjectApiErrors.class);
    listenerList = new SpringWebFluxApiExceptionHandlerListenerList(
        Arrays.asList(mock(ApiExceptionHandlerListener.class), mock(ApiExceptionHandlerListener.class))
    );
    generalUtils = ApiExceptionHandlerUtils.DEFAULT_IMPL;
    springUtilsMock = mock(SpringWebfluxApiExceptionHandlerUtils.class);
    viewResolversProviderMock = mock(ObjectProvider.class);
    serverCodecConfigurerMock = mock(ServerCodecConfigurer.class);
    messageReaders = Arrays.asList(mock(HttpMessageReader.class), mock(HttpMessageReader.class));
    messageWriters = Arrays.asList(mock(HttpMessageWriter.class), mock(HttpMessageWriter.class));
    viewResolvers = Arrays.asList(mock(ViewResolver.class), mock(ViewResolver.class));
    serverWebExchangeMock = mock(ServerWebExchange.class);
    serverHttpRequestMock = mock(ServerHttpRequest.class);
    serverHttpResponseMock = mock(ServerHttpResponse.class);
    serverHttpResponseHeadersMock = mock(HttpHeaders.class);
    uri = URI.create("http://localhost:8080/foo/bar?someQuery=someValue");
    exMock = mock(Throwable.class);

    doAnswer(invocation -> viewResolvers.stream()).when(viewResolversProviderMock).orderedStream();
    doReturn(messageReaders).when(serverCodecConfigurerMock).getReaders();
    doReturn(messageWriters).when(serverCodecConfigurerMock).getWriters();

    doReturn(serverHttpRequestMock).when(serverWebExchangeMock).getRequest();
    doReturn(uri).when(serverHttpRequestMock).getURI();

    doReturn(serverHttpResponseMock).when(serverWebExchangeMock).getResponse();
    doReturn(serverHttpResponseHeadersMock).when(serverHttpResponseMock).getHeaders();

    handlerSpy = spy(new SpringWebfluxApiExceptionHandler(
        projectApiErrorsMock, listenerList, generalUtils, springUtilsMock, viewResolversProviderMock,
        serverCodecConfigurerMock
    ));
}
 
Example #12
Source File: TestCaseValidationSpringConfig.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Bean
public ProjectApiErrors projectApiErrors() {
    return ProjectApiErrorsForTesting.withProjectSpecificData(
        Arrays.asList(INVALID_COUNT_VALUE, INVALID_OFFSET_VALUE),
        ProjectSpecificErrorCodeRange.ALLOW_ALL_ERROR_CODES
    );
}
 
Example #13
Source File: SpringApiExceptionHandlerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    projectApiErrorsMock = mock(ProjectApiErrors.class);
    listenerList = new ApiExceptionHandlerListenerList(Collections.<ApiExceptionHandlerListener>emptyList());
    generalUtils = ApiExceptionHandlerUtils.DEFAULT_IMPL;
    springUtils = SpringApiExceptionHandlerUtils.DEFAULT_IMPL;
    handlerSpy = spy(new SpringApiExceptionHandler(projectApiErrorsMock, listenerList, generalUtils, springUtils));
}
 
Example #14
Source File: SpringUnhandledExceptionHandler.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Inject
public SpringUnhandledExceptionHandler(ProjectApiErrors projectApiErrors,
                                       ApiExceptionHandlerUtils generalUtils,
                                       SpringApiExceptionHandlerUtils springUtils) {
    super(projectApiErrors, generalUtils);
    this.springUtils = springUtils;
    this.singletonGenericServiceError = Collections.singleton(projectApiErrors.getGenericServiceError());
    this.genericServiceErrorHttpStatusCode = projectApiErrors.getGenericServiceError().getHttpStatusCode();
}
 
Example #15
Source File: Jersey1BackstopperConfigHelper.java    From backstopper with Apache License 2.0 5 votes vote down vote up
/**
 * @return The basic set of handler listeners that are appropriate for most applications.
 */
public static List<ApiExceptionHandlerListener> defaultApiExceptionHandlerListeners(
    ProjectApiErrors projectApiErrors, ApiExceptionHandlerUtils utils
) {
    return Arrays.asList(
        new GenericApiExceptionHandlerListener(),
        new ServersideValidationErrorHandlerListener(projectApiErrors, utils),
        new ClientDataValidationErrorHandlerListener(projectApiErrors, utils),
        new DownstreamNetworkExceptionHandlerListener(projectApiErrors),
        new Jersey1WebApplicationExceptionHandlerListener(projectApiErrors, utils));
}
 
Example #16
Source File: JaxRsApiExceptionHandler.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Inject
public JaxRsApiExceptionHandler(ProjectApiErrors projectApiErrors,
                                JaxRsApiExceptionHandlerListenerList apiExceptionHandlerListeners,
                                ApiExceptionHandlerUtils apiExceptionHandlerUtils,
                                JaxRsUnhandledExceptionHandler jerseyUnhandledExceptionHandler) {

    this(projectApiErrors, apiExceptionHandlerListeners.listeners, apiExceptionHandlerUtils, jerseyUnhandledExceptionHandler);
}
 
Example #17
Source File: Jersey1WebApplicationExceptionHandlerListener.java    From backstopper with Apache License 2.0 5 votes vote down vote up
/**
 * @param projectApiErrors The {@link ProjectApiErrors} that should be used by this instance when finding {@link
 *                         ApiError}s. Cannot be null.
 * @param utils The {@link ApiExceptionHandlerUtils} that should be used by this instance.
 */
@Inject
public Jersey1WebApplicationExceptionHandlerListener(ProjectApiErrors projectApiErrors,
                                                     ApiExceptionHandlerUtils utils) {
    if (projectApiErrors == null)
        throw new IllegalArgumentException("ProjectApiErrors cannot be null");

    if (utils == null)
        throw new IllegalArgumentException("ApiExceptionHandlerUtils cannot be null");

    this.projectApiErrors = projectApiErrors;
    this.utils = utils;
}
 
Example #18
Source File: RiposteUnhandledExceptionHandler.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Inject
public RiposteUnhandledExceptionHandler(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull ApiExceptionHandlerUtils utils
) {
    super(projectApiErrors, utils);
    singletonGenericServiceError = Collections.singleton(projectApiErrors.getGenericServiceError());
    genericServiceErrorHttpStatusCode = projectApiErrors.getGenericServiceError().getHttpStatusCode();
}
 
Example #19
Source File: OneOffSpringWebMvcFrameworkExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void constructor_sets_projectApiErrors_and_utils_to_passed_in_args() {
    // given
    ProjectApiErrors projectErrorsMock = mock(ProjectApiErrors.class);
    ApiExceptionHandlerUtils utilsMock = mock(ApiExceptionHandlerUtils.class);

    // when
    OneOffSpringWebMvcFrameworkExceptionHandlerListener
        impl = new OneOffSpringWebMvcFrameworkExceptionHandlerListener(projectErrorsMock, utilsMock);

    // then
    assertThat(impl.projectApiErrors).isSameAs(projectErrorsMock);
    assertThat(impl.utils).isSameAs(utilsMock);
}
 
Example #20
Source File: SpringWebfluxApiExceptionHandler.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Inject
public SpringWebfluxApiExceptionHandler(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull SpringWebFluxApiExceptionHandlerListenerList apiExceptionHandlerListeners,
    @NotNull ApiExceptionHandlerUtils generalUtils,
    @NotNull SpringWebfluxApiExceptionHandlerUtils springUtils,
    @NotNull ObjectProvider<ViewResolver> viewResolversProvider,
    @NotNull ServerCodecConfigurer serverCodecConfigurer
) {
    super(projectApiErrors, apiExceptionHandlerListeners.listeners, generalUtils);

    //noinspection ConstantConditions
    if (springUtils == null) {
        throw new NullPointerException("springUtils cannot be null.");
    }

    //noinspection ConstantConditions
    if (viewResolversProvider == null) {
        throw new NullPointerException("viewResolversProvider cannot be null.");
    }

    //noinspection ConstantConditions
    if (serverCodecConfigurer == null) {
        throw new NullPointerException("serverCodecConfigurer cannot be null.");
    }

    this.springUtils = springUtils;
    this.viewResolvers = viewResolversProvider.orderedStream().collect(Collectors.toList());
    this.messageReaders = serverCodecConfigurer.getReaders();
    this.messageWriters = serverCodecConfigurer.getWriters();
}
 
Example #21
Source File: OneOffSpringWebMvcFrameworkExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void constructor_throws_IllegalArgumentException_if_passed_null_utils() {
    // when
    Throwable ex = Assertions.catchThrowable(
        () -> new OneOffSpringWebMvcFrameworkExceptionHandlerListener(mock(ProjectApiErrors.class), null)
    );

    // then
    assertThat(ex).isInstanceOf(IllegalArgumentException.class);
}
 
Example #22
Source File: BackstopperRiposteConfigHelper.java    From riposte with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link RiposteUnhandledErrorHandler} that uses the given {@link ProjectApiErrors}.
 */
public static @NotNull RiposteUnhandledErrorHandler defaultUnhandledErrorHandler(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull ApiExceptionHandlerUtils utils
) {
    return new RiposteUnhandledExceptionHandler(projectApiErrors, utils);
}
 
Example #23
Source File: ProjectApiErrorsImplTest.java    From riposte-microservice-template with Apache License 2.0 5 votes vote down vote up
@Override
protected ProjectApiErrors getProjectApiErrors() {
    if (projectErrors == null) {
        projectErrors = new ProjectApiErrorsImpl();
    }

    return projectErrors;
}
 
Example #24
Source File: JaxRsWebApplicationExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void constructor_sets_fields_to_passed_in_args() {
    // given
    ProjectApiErrors projectErrorsMock = mock(ProjectApiErrors.class);
    ApiExceptionHandlerUtils utilsMock = mock(ApiExceptionHandlerUtils.class);

    // when
    JaxRsWebApplicationExceptionHandlerListener
        impl = new JaxRsWebApplicationExceptionHandlerListener(projectErrorsMock, utilsMock);

    // then
    assertThat(impl.projectApiErrors).isSameAs(projectErrorsMock);
    assertThat(impl.utils).isSameAs(utilsMock);
}
 
Example #25
Source File: JaxRsApiExceptionHandler.java    From backstopper with Apache License 2.0 5 votes vote down vote up
public JaxRsApiExceptionHandler(ProjectApiErrors projectApiErrors,
                               List<ApiExceptionHandlerListener> apiExceptionHandlerListeners,
                               ApiExceptionHandlerUtils apiExceptionHandlerUtils,
                               JaxRsUnhandledExceptionHandler jerseyUnhandledExceptionHandler) {

   super(projectApiErrors, apiExceptionHandlerListeners, apiExceptionHandlerUtils);

  if (jerseyUnhandledExceptionHandler == null)
    throw new IllegalArgumentException("jerseyUnhandledExceptionHandler cannot be null");

  this.jerseyUnhandledExceptionHandler = jerseyUnhandledExceptionHandler;
}
 
Example #26
Source File: ProjectApiErrorsImplTest.java    From moirai with Apache License 2.0 5 votes vote down vote up
@Override
protected ProjectApiErrors getProjectApiErrors() {
    if (projectErrors == null) {
        projectErrors = new ProjectApiErrorsImpl();
    }

    return projectErrors;
}
 
Example #27
Source File: JaxRsApiExceptionHandlerListenerList.java    From backstopper with Apache License 2.0 5 votes vote down vote up
/**
 * @return The basic set of handler listeners that are appropriate for most JAX-RS applications.
 */
public static List<ApiExceptionHandlerListener> defaultApiExceptionHandlerListeners(
    ProjectApiErrors projectApiErrors, ApiExceptionHandlerUtils utils
) {
    return Arrays.asList(
        new GenericApiExceptionHandlerListener(),
        new ServersideValidationErrorHandlerListener(projectApiErrors, utils),
        new ClientDataValidationErrorHandlerListener(projectApiErrors, utils),
        new DownstreamNetworkExceptionHandlerListener(projectApiErrors),
        new JaxRsWebApplicationExceptionHandlerListener(projectApiErrors, utils));
}
 
Example #28
Source File: JaxRsWebApplicationExceptionHandlerListener.java    From backstopper with Apache License 2.0 5 votes vote down vote up
/**
 * @param projectApiErrors The {@link ProjectApiErrors} that should be used by this instance when finding {@link
 *                         ApiError}s. Cannot be null.
 * @param utils The {@link ApiExceptionHandlerUtils} that should be used by this instance.
 */
@Inject
public JaxRsWebApplicationExceptionHandlerListener(ProjectApiErrors projectApiErrors,
                                                   ApiExceptionHandlerUtils utils) {
    if (projectApiErrors == null)
        throw new IllegalArgumentException("ProjectApiErrors cannot be null");

    if (utils == null)
        throw new IllegalArgumentException("ApiExceptionHandlerUtils cannot be null");

    this.projectApiErrors = projectApiErrors;
    this.utils = utils;
}
 
Example #29
Source File: Jersey2WebApplicationExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void constructor_sets_fields_to_passed_in_args() {
    // given
    ProjectApiErrors projectErrorsMock = mock(ProjectApiErrors.class);
    ApiExceptionHandlerUtils utilsMock = mock(ApiExceptionHandlerUtils.class);

    // when
    Jersey2WebApplicationExceptionHandlerListener
        impl = new Jersey2WebApplicationExceptionHandlerListener(projectErrorsMock, utilsMock);

    // then
    assertThat(impl.projectApiErrors).isSameAs(projectErrorsMock);
    assertThat(impl.utils).isSameAs(utilsMock);
}
 
Example #30
Source File: Jersey2BackstopperConfigHelper.java    From backstopper with Apache License 2.0 5 votes vote down vote up
/**
 * @return The basic set of handler listeners that are appropriate for most Jersey 2 applications.
 */
public static List<ApiExceptionHandlerListener> defaultApiExceptionHandlerListeners(
    ProjectApiErrors projectApiErrors, ApiExceptionHandlerUtils utils
) {
    return Arrays.asList(
        new GenericApiExceptionHandlerListener(),
        new ServersideValidationErrorHandlerListener(projectApiErrors, utils),
        new ClientDataValidationErrorHandlerListener(projectApiErrors, utils),
        new DownstreamNetworkExceptionHandlerListener(projectApiErrors),
        new Jersey2WebApplicationExceptionHandlerListener(projectApiErrors, utils),
        new JaxRsWebApplicationExceptionHandlerListener(projectApiErrors, utils));
}