use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class GBFOrderService method parseShippingConfirmations.
ShippingConfirmations parseShippingConfirmations(HttpResponse response) {
String responseXml;
try {
ConfirmShippingResponse responseObj = jsonMapper.readValue(response.getEntity().getContent(), ConfirmShippingResponse.class);
responseXml = responseObj.XML;
} catch (IOException e) {
LOG.error("parseShippingConfirmations failed to read Json from remote response", e);
throw new BridgeServiceException("Error parsing response Json.");
}
return parseShippingConfirmations(responseXml);
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class SendMailViaAmazonService method sendEmail.
@Override
public void sendEmail(MimeTypeEmailProvider provider) {
String senderEmail = provider.getPlainSenderEmail();
if (!emailVerificationService.isVerified(senderEmail)) {
throw new BridgeServiceException(UNVERIFIED_EMAIL_ERROR);
}
try {
String fullSenderEmail = provider.getMimeTypeEmail().getSenderAddress();
MimeTypeEmail email = provider.getMimeTypeEmail();
for (String recipient : email.getRecipientAddresses()) {
sendEmail(fullSenderEmail, recipient, email, provider.getApp().getIdentifier());
}
} catch (MessageRejectedException ex) {
// This happens if the sender email is not verified in SES. In general, it's not useful to app users to
// receive a 500 Internal Error when this happens. Plus, if this exception gets thrown, the user session
// won't be updated properly, and really weird things happen. The best course of option is to log an error
// and swallow the exception.
logger.error("SES rejected email: " + ex.getMessage(), ex);
} catch (MessagingException | AmazonServiceException | IOException e) {
throw new BridgeServiceException(e);
}
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class OAuthProviderService method executeInternal.
private OAuthProviderService.Response executeInternal(HttpPost client) {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
CloseableHttpResponse response = httpclient.execute(client);
int statusCode = response.getStatusLine().getStatusCode();
JsonNode body;
try {
body = BridgeObjectMapper.get().readTree(response.getEntity().getContent());
} catch (JsonParseException ex) {
// Log the error and the status code. Set body to a null node, so we don't break any callers.
LOG.error("OAuth call failed with invalid JSON, status code " + statusCode);
body = NullNode.getInstance();
}
return new Response(statusCode, body);
} catch (IOException e) {
LOG.error(SERVICE_ERROR_MSG, e);
throw new BridgeServiceException(SERVICE_ERROR_MSG);
}
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class OAuthService method retrieveAccessToken.
private OAuthAccessToken retrieveAccessToken(App app, String vendorId, String healthCode, OAuthAuthorizationToken authToken) {
checkNotNull(app);
checkNotNull(vendorId);
checkNotNull(healthCode);
OAuthProvider provider = app.getOAuthProviders().get(vendorId);
if (provider == null) {
throw new EntityNotFoundException(OAuthProvider.class);
}
OAuthAccessGrant grant = null;
try {
// If client has submitted an authorization token, we always refresh the grant
if (authToken != null && authToken.getAuthToken() != null) {
grant = providerService.requestAccessGrant(provider, authToken);
} else {
// If not, start first by seeing if a grant has been saved
grant = grantDao.getAccessGrant(app.getIdentifier(), vendorId, healthCode);
}
// If no grant was saved or successfully returned from a grant, it's not found.
if (grant == null) {
throw new EntityNotFoundException(OAuthAccessGrant.class);
} else if (getDateTime().isAfter(grant.getExpiresOn())) {
// If there's a grant record, but it has expired, attempt to refresh it
grant = providerService.refreshAccessGrant(provider, vendorId, grant.getRefreshToken());
}
} catch (BridgeServiceException e) {
// It is in an unknown state.
if (e.getStatusCode() < 502 || e.getStatusCode() > 504) {
grantDao.deleteAccessGrant(app.getIdentifier(), vendorId, healthCode);
}
throw e;
}
grant.setVendorId(vendorId);
grant.setHealthCode(healthCode);
grantDao.saveAccessGrant(app.getIdentifier(), grant);
return getTokenForGrant(grant);
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class DynamoSchedulePlan method setData.
public void setData(ObjectNode data) {
if (data != null) {
String typeName = JsonUtils.asText(data, "type");
try {
String className = BridgeConstants.SCHEDULE_STRATEGY_PACKAGE + typeName;
Class<?> clazz = Class.forName(className);
strategy = (ScheduleStrategy) BridgeObjectMapper.get().treeToValue(data, clazz);
} catch (ClassCastException | ClassNotFoundException e) {
throw new BadRequestException("Invalid type " + typeName);
} catch (JsonProcessingException e) {
throw new BridgeServiceException(e);
}
}
}
Aggregations