use of com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException in project hub-alert by blackducksoftware.
the class LoginHandler method authenticateUser.
public ResponseEntity<String> authenticateUser(final HttpServletRequest request, final HttpServletResponse response, final LoginRestModel loginRestModel) {
final IntLogger logger = new PrintStreamIntLogger(System.out, LogLevel.INFO);
try {
if (loginActions.authenticateUser(loginRestModel, logger)) {
final CsrfToken token = csrfTokenRepository.generateToken(request);
csrfTokenRepository.saveToken(token, request, response);
response.setHeader(token.getHeaderName(), token.getToken());
return createResponse(HttpStatus.OK, "{\"message\":\"Success\"}");
}
return createResponse(HttpStatus.UNAUTHORIZED, "User not administrator");
} catch (final IntegrationRestException e) {
logger.error(e.getMessage(), e);
return createResponse(HttpStatus.valueOf(e.getHttpStatusCode()), e.getHttpStatusMessage() + " : " + e.getMessage());
} catch (final AlertFieldException e) {
logger.error(e.getMessage(), e);
final ResponseBodyBuilder responseBodyBuilder = new ResponseBodyBuilder(0L, e.getMessage());
responseBodyBuilder.putErrors(e.getFieldErrors());
final String responseBody = responseBodyBuilder.build();
return createResponse(HttpStatus.BAD_REQUEST, responseBody);
} catch (final Exception e) {
logger.error(e.getMessage(), e);
return createResponse(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException in project hub-alert by blackducksoftware.
the class DistributionChannel method sendAuditedMessage.
public void sendAuditedMessage(final E event, final C config) throws IntegrationException {
try {
sendMessage(event, config);
setAuditEntrySuccess(event.getAuditEntryId());
} catch (final Exception e) {
setAuditEntryFailure(event.getAuditEntryId(), e.getMessage(), e);
if (e instanceof IntegrationRestException) {
logger.error(((IntegrationRestException) e).getHttpStatusCode() + ":" + ((IntegrationRestException) e).getHttpStatusMessage());
}
logger.error(e.getMessage(), e);
throw new AlertException(e.getMessage());
}
}
use of com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException in project hub-alert by blackducksoftware.
the class CommonConfigHandlerTest method testConfigWithRestExceptionTest.
@Test
public void testConfigWithRestExceptionTest() throws Exception {
final CommonDistributionConfigActions configActions = Mockito.mock(CommonDistributionConfigActions.class);
final CommonConfigHandler<CommonDistributionConfigEntity, CommonDistributionConfigRestModel, CommonDistributionRepositoryWrapper> handler = new CommonConfigHandler<>(CommonDistributionConfigEntity.class, CommonDistributionConfigRestModel.class, configActions, objectTransformer);
final int responseCode = HttpStatus.BAD_GATEWAY.value();
Mockito.when(configActions.testConfig(Mockito.any())).thenThrow(new IntegrationRestException(responseCode, "", ""));
Mockito.when(configActions.getObjectTransformer()).thenReturn(objectTransformer);
final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
final ResponseEntity<String> response = handler.testConfig(restModel);
assertEquals(HttpStatus.BAD_GATEWAY, response.getStatusCode());
}
use of com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException in project hub-alert by blackducksoftware.
the class HubDataHandlerTest method testGetHubGroupsThrowIntegrationRestException.
@Test
public void testGetHubGroupsThrowIntegrationRestException() throws Exception {
final ObjectTransformer objectTransformer = new ObjectTransformer();
final Gson gson = new Gson();
final HubDataActions hubDataActions = Mockito.mock(HubDataActions.class);
Mockito.when(hubDataActions.getHubGroups()).thenThrow(new IntegrationRestException(402, "StatusMessage", "ErrorMessage"));
final HubDataHandler hubDataHandler = new HubDataHandler(objectTransformer, gson, hubDataActions);
final ResponseEntity<String> responseEntity = hubDataHandler.getHubGroups();
assertEquals(HttpStatus.PAYMENT_REQUIRED, responseEntity.getStatusCode());
assertEquals("{\"id\":-1,\"message\":\"StatusMessage : ErrorMessage: 402: StatusMessage\"}", responseEntity.getBody());
}
use of com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException in project hub-alert by blackducksoftware.
the class HubDataHandlerTest method testGetHubProjectsThrowIntegrationRestException.
@Test
public void testGetHubProjectsThrowIntegrationRestException() throws Exception {
final ObjectTransformer objectTransformer = new ObjectTransformer();
final Gson gson = new Gson();
final HubDataActions hubDataActions = Mockito.mock(HubDataActions.class);
Mockito.when(hubDataActions.getHubProjects()).thenThrow(new IntegrationRestException(402, "StatusMessage", "ErrorMessage"));
final HubDataHandler hubDataHandler = new HubDataHandler(objectTransformer, gson, hubDataActions);
final ResponseEntity<String> responseEntity = hubDataHandler.getHubProjects();
assertEquals(HttpStatus.PAYMENT_REQUIRED, responseEntity.getStatusCode());
assertEquals("{\"id\":-1,\"message\":\"StatusMessage : ErrorMessage: 402: StatusMessage\"}", responseEntity.getBody());
}
Aggregations