当前位置: 首页>>代码示例>>Java>>正文


Java ErrorMessage类代码示例

本文整理汇总了Java中io.dropwizard.jersey.errors.ErrorMessage的典型用法代码示例。如果您正苦于以下问题:Java ErrorMessage类的具体用法?Java ErrorMessage怎么用?Java ErrorMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ErrorMessage类属于io.dropwizard.jersey.errors包,在下文中一共展示了ErrorMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toResponse

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@Override
public Response toResponse(IllegalArgumentException e) {
   exceptions.mark();

   if (e.getMessage().matches("Resource .* not found!")) {
      return Response
            .status(Response.Status.NOT_FOUND) // 404
            .type(MediaType.APPLICATION_JSON_TYPE)
            .entity(new ErrorMessage(Response.Status.UNAUTHORIZED.getStatusCode(), e.getMessage()))
            .build();
   }

   return Response
         .status(422) // UNPROCESSABLE_ENTITY
         .type(MediaType.APPLICATION_JSON_TYPE)
         .entity(new ErrorMessage(422, e.getMessage()))
         .build();
}
 
开发者ID:acciente,项目名称:oacc-example-securetodo,代码行数:19,代码来源:IllegalArgumentExceptionMapper.java

示例2: translateResponse

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@POST
public Response translateResponse(@NotNull @Valid TranslateSamlResponseBody translateSamlResponseBody) throws IOException {
    String entityId = entityIdService.getEntityId(translateSamlResponseBody);
    try {
        TranslatedResponseBody translatedResponseBody = responseService.convertTranslatedResponseBody(
            translateSamlResponseBody.getSamlResponse(),
            translateSamlResponseBody.getRequestId(),
            translateSamlResponseBody.getLevelOfAssurance(),
            entityId
        );

        LOG.info(String.format("Translated response for entityId: %s, requestId: %s, got Scenario: %s",
                entityId,
                translateSamlResponseBody.getRequestId(),
                translatedResponseBody.getScenario()));

        return Response.ok(translatedResponseBody).build();
    } catch (SamlResponseValidationException | SamlTransformationErrorException e) {
        LOG.warn(String.format("Error translating saml response for entityId: %s, requestId: %s, got Message: %s", entityId, translateSamlResponseBody.getRequestId(), e.getMessage()));
        return Response
            .status(BAD_REQUEST)
            .entity(new ErrorMessage(BAD_REQUEST.getStatusCode(), e.getMessage()))
            .build();
    }
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:26,代码来源:TranslateSamlResponseResource.java

示例3: shouldReturnAnErrorWhenTranslatingLowerLoAThanRequested

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@Test
public void shouldReturnAnErrorWhenTranslatingLowerLoAThanRequested() {
    RequestResponseBody requestResponseBody = generateRequestService.generateAuthnRequest(application.getLocalPort());
    Map<String, String> translateResponseRequestData = ImmutableMap.of(
        "samlResponse", complianceTool.createResponseFor(requestResponseBody.getSamlRequest(), BASIC_SUCCESSFUL_MATCH_WITH_LOA1_ID),
        "requestId", requestResponseBody.getRequestId(),
        "levelOfAssurance", LEVEL_2.name()
    );

    Response response = client
        .target(String.format("http://localhost:%d/translate-response", application.getLocalPort()))
        .request()
        .buildPost(json(translateResponseRequestData))
        .invoke();

    assertThat(response.getStatus()).isEqualTo(BAD_REQUEST.getStatusCode());
    ErrorMessage errorMessage = response.readEntity(ErrorMessage.class);
    assertThat(errorMessage.getCode()).isEqualTo(BAD_REQUEST.getStatusCode());
    assertThat(errorMessage.getMessage()).isEqualTo("Expected Level of Assurance to be at least LEVEL_2, but was LEVEL_1");
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:21,代码来源:SuccessMatchAcceptanceTest.java

示例4: shouldReturnAnErrorWhenInvalidEntityIdProvided

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@Test
public void shouldReturnAnErrorWhenInvalidEntityIdProvided() {
    RequestResponseBody requestResponseBody = generateRequestService.generateAuthnRequest(application.getLocalPort());
    Map<String, String> translateResponseRequestData = ImmutableMap.of(
        "samlResponse", complianceTool.createResponseFor(requestResponseBody.getSamlRequest(), BASIC_SUCCESSFUL_MATCH_WITH_LOA2_ID),
        "requestId", requestResponseBody.getRequestId(),
        "levelOfAssurance", LEVEL_2.name(),
        "entityId", "invalidEntityId"
    );

    Response response = client
        .target(String.format("http://localhost:%d/translate-response", application.getLocalPort()))
        .request()
        .buildPost(json(translateResponseRequestData))
        .invoke();

    assertThat(response.getStatus()).isEqualTo(BAD_REQUEST.getStatusCode());
    ErrorMessage errorMessage = response.readEntity(ErrorMessage.class);
    assertThat(errorMessage.getCode()).isEqualTo(BAD_REQUEST.getStatusCode());
    assertThat(errorMessage.getMessage()).isEqualTo("Provided entityId: invalidEntityId is not listed in config");
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:22,代码来源:SuccessMatchAcceptanceTest.java

示例5: shouldReturn400IfNoEntityIdProvided

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@Test
public void shouldReturn400IfNoEntityIdProvided() {
    complianceTool.initialiseWithEntityIdAndPid(configuredEntityIdOne, "some-expected-pid");
    RequestResponseBody requestResponseBody = generateRequestService.generateAuthnRequest(application.getLocalPort(), configuredEntityIdOne);
    Map<String, String> translateResponseRequestData = ImmutableMap.of(
        "samlResponse", complianceTool.createResponseFor(requestResponseBody.getSamlRequest(), BASIC_SUCCESSFUL_MATCH_WITH_LOA2_ID),
        "requestId", requestResponseBody.getRequestId(),
        "levelOfAssurance", LEVEL_2.name()
    );

    Response response = client
        .target(String.format("http://localhost:%d/translate-response", application.getLocalPort()))
        .request()
        .buildPost(json(translateResponseRequestData))
        .invoke();

    assertThat(response.getStatus()).isEqualTo(BAD_REQUEST.getStatusCode());
    assertThat(response.readEntity(ErrorMessage.class).getMessage()).isEqualTo("No entityId was provided, and there are several in config");
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:20,代码来源:TranslateResponseMultiTenantedSetupAcceptanceTest.java

示例6: shouldReturn400IfIncorrectEntityIdProvided

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@Test
public void shouldReturn400IfIncorrectEntityIdProvided() {
    complianceTool.initialiseWithEntityIdAndPid(configuredEntityIdTwo, "some-expected-pid");
    RequestResponseBody requestResponseBody = generateRequestService.generateAuthnRequest(application.getLocalPort(), configuredEntityIdTwo);
    Map<String, String> translateResponseRequestData = ImmutableMap.of(
        "samlResponse", complianceTool.createResponseFor(requestResponseBody.getSamlRequest(), BASIC_SUCCESSFUL_MATCH_WITH_LOA2_ID),
        "requestId", requestResponseBody.getRequestId(),
        "levelOfAssurance", LEVEL_2.name(),
        "entityId", "http://incorrect-entity-id"
    );

    Response response = client
        .target(String.format("http://localhost:%d/translate-response", application.getLocalPort()))
        .request()
        .buildPost(json(translateResponseRequestData))
        .invoke();

    assertThat(response.getStatus()).isEqualTo(BAD_REQUEST.getStatusCode());
    assertThat(response.readEntity(ErrorMessage.class).getMessage()).isEqualTo("Provided entityId: http://incorrect-entity-id is not listed in config");
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:21,代码来源:TranslateResponseMultiTenantedSetupAcceptanceTest.java

示例7: shouldRespondWithErrorWhenAssertionSignedByHub

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@Test
public void shouldRespondWithErrorWhenAssertionSignedByHub() {
    RequestResponseBody requestResponseBody = generateRequestService.generateAuthnRequest(application.getLocalPort());
    Map<String, String> translateResponseRequestData = ImmutableMap.of(
        "samlResponse", complianceTool.createResponseFor(requestResponseBody.getSamlRequest(), BASIC_SUCCESSFUL_MATCH_WITH_ASSERTIONS_SIGNED_BY_HUB_ID),
        "requestId", requestResponseBody.getRequestId(),
        "levelOfAssurance", LEVEL_2.name()
    );

    Response response = client
        .target(String.format("http://localhost:%d/translate-response", application.getLocalPort()))
        .request()
        .buildPost(json(translateResponseRequestData))
        .invoke();

    ErrorMessage errorBody = response.readEntity(ErrorMessage.class);

    assertThat(response.getStatus()).isEqualTo(BAD_REQUEST.getStatusCode());
    assertThat(errorBody.getCode()).isEqualTo(BAD_REQUEST.getStatusCode());
    assertThat(errorBody.getMessage()).contains("SAML Validation Specification: Signature was not valid.");
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:22,代码来源:InvalidSamlAcceptanceTest.java

示例8: shouldReturn400WhenSamlValidationExceptionThrown

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@Test
public void shouldReturn400WhenSamlValidationExceptionThrown() throws Exception {
    JSONObject translateResponseRequest = new JSONObject().put("samlResponse", "some-saml-response")
            .put("requestId", "some-request-id")
            .put("levelOfAssurance", LEVEL_2.name());

    when(responseService.convertTranslatedResponseBody(any(), eq("some-request-id"), eq(LEVEL_2), eq(defaultEntityId)))
            .thenThrow(new SamlResponseValidationException("Some error."));

    Response response = resources.client()
            .target("/translate-response")
            .request()
            .post(json(translateResponseRequest.toString()));

    assertThat(response.getStatus()).isEqualTo(BAD_REQUEST.getStatusCode());

    ErrorMessage actualError = response.readEntity(ErrorMessage.class);
    assertThat(actualError.getCode()).isEqualTo(BAD_REQUEST.getStatusCode());
    assertThat(actualError.getMessage()).isEqualTo("Some error.");
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:21,代码来源:TranslateSamlResponseResourceTest.java

示例9: shouldReturn400WhenSamlTransformationErrorExceptionThrown

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@Test
public void shouldReturn400WhenSamlTransformationErrorExceptionThrown() throws Exception {
    JSONObject translateResponseRequest = new JSONObject().put("samlResponse", "some-saml-response")
            .put("requestId", "some-request-id")
            .put("levelOfAssurance", LEVEL_2.name());

    when(responseService.convertTranslatedResponseBody(any(), eq("some-request-id"), eq(LEVEL_2), eq(defaultEntityId)))
            .thenThrow(new SamlTransformationErrorException("Some error.", Level.ERROR));

    Response response = resources.client()
        .target("/translate-response")
        .request()
        .post(json(translateResponseRequest.toString()));

    assertThat(response.getStatus()).isEqualTo(BAD_REQUEST.getStatusCode());

    ErrorMessage actualError = response.readEntity(ErrorMessage.class);
    assertThat(actualError.getCode()).isEqualTo(BAD_REQUEST.getStatusCode());
    assertThat(actualError.getMessage()).isEqualTo("Some error.");
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:21,代码来源:TranslateSamlResponseResourceTest.java

示例10: shouldReturn400WhenCalledWithEmptyJson

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@Test
public void shouldReturn400WhenCalledWithEmptyJson() throws Exception {
    Response response = resources.client()
        .target("/translate-response")
        .request()
        .post(json("{}"));

    assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);

    ErrorMessage actualErrorMessage = response.readEntity(ErrorMessage.class);
    assertThat(actualErrorMessage.getCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);

    Set<String> expectedErrors = ImmutableSet.of("requestId may not be null", "samlResponse may not be null", "levelOfAssurance may not be null");
    Set<String> actualErrors = Arrays.stream(actualErrorMessage.getMessage().split(", ")).collect(Collectors.toSet());
    assertThat(actualErrors).isEqualTo(expectedErrors);
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:17,代码来源:TranslateSamlResponseResourceTest.java

示例11: getRun

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@GET
@Path("/{runId}")
@UnitOfWork
@ApiOperation(value = "Get a specific run")
@ApiResponses({
        @ApiResponse(code = HttpStatus.OK_200, response = RunApiEntity.class, message = "OK"),
        @ApiResponse(code = HttpStatus.NOT_FOUND_404, response = ErrorMessage.class, message = "Not found"),
        @ApiResponse(
                code = HttpStatus.CONFLICT_409,
                response = ErrorMessage.class,
                message = "Event ID and Run ID are mismatched"
        )
})
public RunApiEntity getRun(
        @PathParam("eventId") @ApiParam(value = "Event ID", required = true) String eventId,
        @PathParam("runId") @ApiParam(value = "Run ID", required = true) String runId
) throws EntityMismatchException, EntityNotFoundException {
    Run domainRun = runEntityService.getByEventIdAndRunId(eventId, runId);
    return runMapper.toApiEntity(domainRun);
}
 
开发者ID:caeos,项目名称:coner-core,代码行数:21,代码来源:EventRunsResource.java

示例12: getRegistration

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@GET
@Path("/{registrationId}")
@UnitOfWork
@ApiOperation(value = "Get a specific registration")
@ApiResponses({
        @ApiResponse(code = HttpStatus.OK_200, response = RegistrationApiEntity.class, message = "OK"),
        @ApiResponse(code = HttpStatus.NOT_FOUND_404, response = ErrorMessage.class, message = "Not found"),
        @ApiResponse(
                code = HttpStatus.CONFLICT_409,
                response = ErrorMessage.class,
                message = "Event ID and Registration ID are mismatched"
        )
})
public RegistrationApiEntity getRegistration(
        @PathParam("eventId") @ApiParam(value = "Event ID", required = true) String eventId,
        @PathParam("registrationId") @ApiParam(value = "Registration ID", required = true) String registrationId
) throws EntityMismatchException, EntityNotFoundException {
    Registration domainRegistration = eventRegistrationService.getByEventIdAndRegistrationId(
            eventId,
            registrationId
    );
    return registrationMapper.toApiEntity(domainRegistration);
}
 
开发者ID:caeos,项目名称:coner-core,代码行数:24,代码来源:EventRegistrationsResource.java

示例13: addHandicapGroupToHandicapGroupSet

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@POST
@Path("/{handicapGroupSetId}/handicapGroups/{handicapGroupId}")
@UnitOfWork
@ApiOperation(value = "Add a Handicap Group to a Handicap Group Set", response = HandicapGroupSetApiEntity.class)
@ApiResponses({
        @ApiResponse(code = HttpStatus.OK_200, response = HandicapGroupSetApiEntity.class, message = "OK"),
        @ApiResponse(code = HttpStatus.NOT_FOUND_404, response = ErrorMessage.class, message = "Not found"),
})
public HandicapGroupSetApiEntity addHandicapGroupToHandicapGroupSet(
        @PathParam("handicapGroupSetId") @ApiParam(value = "Handicap Group Set ID", required = true)
                String handicapGroupSetId,
        @PathParam("handicapGroupId") @ApiParam(value = "Handicap Group ID", required = true)
                String handicapGroupId
) throws EntityNotFoundException {
    HandicapGroupSet domainSetEntity = handicapGroupSetService.getById(handicapGroupSetId);
    HandicapGroup domainEntity = handicapGroupEntityService.getById(handicapGroupId);
    handicapGroupSetService.addToHandicapGroups(domainSetEntity, domainEntity);
    return handicapGroupSetMapper.toApiEntity(domainSetEntity);
}
 
开发者ID:caeos,项目名称:coner-core,代码行数:20,代码来源:HandicapGroupSetsResource.java

示例14: addCompetitionGroupToCompetitionGroupSet

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@POST
@Path("/{competitionGroupSetId}/competitionGroups/{competitionGroupId}")
@UnitOfWork
@ApiOperation(
        value = "Add a Competition Group to a Competition Group Set",
        response = CompetitionGroupSetApiEntity.class
)
@ApiResponses({
        @ApiResponse(code = HttpStatus.OK_200, response = CompetitionGroupSetApiEntity.class, message = "OK"),
        @ApiResponse(code = HttpStatus.NOT_FOUND_404, response = ErrorMessage.class, message = "Not found"),
})
public CompetitionGroupSetApiEntity addCompetitionGroupToCompetitionGroupSet(
        @PathParam("competitionGroupSetId") @ApiParam(value = "Competition Group Set ID", required = true)
                String competitionGroupSetId,
        @PathParam("competitionGroupId") @ApiParam(value = "Competition Group ID", required = true)
                String competitionGroupId
) throws EntityNotFoundException {
    CompetitionGroupSet domainSetEntity = competitionGroupSetService.getById(competitionGroupSetId);
    CompetitionGroup domainEntity = competitionGroupEntityService.getById(competitionGroupId);
    competitionGroupSetService.addToCompetitionGroups(domainSetEntity, domainEntity);
    return competitionGroupSetMapper.toApiEntity(domainSetEntity);
}
 
开发者ID:caeos,项目名称:coner-core,代码行数:23,代码来源:CompetitionGroupSetsResource.java

示例15: itShouldFailToAddRunWhenMapperThrowsRuntimeExceptionWrappingEntityNotFoundException

import io.dropwizard.jersey.errors.ErrorMessage; //导入依赖的package包/类
@Test
public void itShouldFailToAddRunWhenMapperThrowsRuntimeExceptionWrappingEntityNotFoundException() {
    AddRunRequest apiRequest = ApiRequestTestUtils.fullAddRun();
    Entity<AddRunRequest> requestEntity = Entity.json(apiRequest);
    when(runMapper.toDomainAddPayload(apiRequest, EVENT_ID))
            .thenThrow(new RuntimeException(new EntityNotFoundException(Event.class, EVENT_ID)));

    Response response = resources.client()
            .target(UriBuilder.fromPath("/events/{eventId}/runs").build(EVENT_ID))
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    verifyZeroInteractions(runEntityService);
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND_404);
    assertThat(response.readEntity(ErrorMessage.class))
            .extracting(ErrorMessage::getCode, ErrorMessage::getMessage)
            .containsExactly(HttpStatus.NOT_FOUND_404, "Event entity not found with id " + EVENT_ID);
}
 
开发者ID:caeos,项目名称:coner-core,代码行数:20,代码来源:EventRunsResourceTest.java


注:本文中的io.dropwizard.jersey.errors.ErrorMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。