use of org.onehippo.cms7.crisp.api.resource.Resource in project hippo by NHS-digital-website.
the class ReCaptchaValidationPlugin method validateReCaptcha.
private Resource validateReCaptcha(String gReCaptchaResponseCode, String recaptchaSecret) throws MissingResourceException {
Resource resource = null;
final Map<String, Object> pathVars = new HashMap<>();
pathVars.put("secret", recaptchaSecret);
pathVars.put("response", gReCaptchaResponseCode);
final ResourceServiceBroker resourceServiceBroker = CrispHstServices.getDefaultResourceServiceBroker(getComponentManager());
if (Objects.isNull(resourceServiceBroker)) {
throw new MissingResourceException("The CRISP Resource Service Broker is null!", "ResourceServiceBroker", "GoogleReCaptchaResourceResolver");
} else {
try {
resource = resourceServiceBroker.resolve("googleReCaptchaResourceResolver", "/recaptcha/api/siteverify?secret={secret}&response={response}", pathVars);
} catch (Exception e) {
log.warn("Failed to find resources from '{}' resource space for ReCaptcha validation, '{}'. The message '{}'", "googleReCaptchaResourceResolver", "/recaptcha/api/siteverify/", e.getMessage(), e);
}
}
return resource;
}
use of org.onehippo.cms7.crisp.api.resource.Resource in project hippo by NHS-digital-website.
the class SvgSimpleJacksonRestTemplateResourceResolver method isCacheable.
@Override
public boolean isCacheable(final Resource resource) {
if (this.isCacheEnabled() && resource instanceof JacksonResource) {
String data = resource.getValue("data", String.class);
if (Objects.nonNull(data)) {
byte[] decodedBytes = Base64.getDecoder().decode(data);
String decodedString = new String(decodedBytes);
Matcher regexMatcher = svgPattern.matcher(decodedString);
if (regexMatcher.find()) {
return true;
} else {
log.warn("Could not cache SVG resource. Its body contained: " + decodedString);
}
}
}
return false;
}
use of org.onehippo.cms7.crisp.api.resource.Resource in project hippo by NHS-digital-website.
the class SubscriptionResource method subscribe.
public String subscribe(final String emailAddress, final List<String> topicCodes) {
final Subscriber subscriber = SubscriberFactory.create(emailAddress, topicCodes);
try {
final ResourceServiceBroker broker = CrispHstServices.getDefaultResourceServiceBroker(HstServices.getComponentManager());
final Map<String, Object> pathVars = new HashMap<>();
pathVars.put("account", ACCOUNT);
final ExchangeHint exchangeHint = ExchangeHintBuilder.create().methodName("POST").requestHeader("Content-Type", "application/xml").requestBody(XML_MAPPER.writeValueAsString(subscriber)).build();
final Resource resource = broker.resolve("govDeliveryApi", URL, pathVars, exchangeHint);
return (String) ((Resource) resource.getValueMap().get("to-param")).getDefaultValue();
} catch (final JsonProcessingException e) {
LOGGER.error("Encountered exception when serializing XML.", e);
} catch (final ResourceException e) {
LOGGER.error("Encountered communication exception when calling the API.", e);
} catch (final Exception e) {
LOGGER.error("Encountered unexpected exception when subscribing user.", e);
}
return null;
}
use of org.onehippo.cms7.crisp.api.resource.Resource in project hippo by NHS-digital-website.
the class RemoteContentService method getContentObjectFrom.
@HystrixCommand(fallbackMethod = "getReliableFallBackObject", commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "400") })
public Object getContentObjectFrom(URL url, String resourceResolver, Class type) {
LOGGER.debug("Inside RemoteContentService ");
ResourceServiceBroker broker = CrispHstServices.getDefaultResourceServiceBroker(HstServices.getComponentManager());
LOGGER.debug("Inside RemoteContentService broker is " + broker + " URL is " + url);
Resource r = broker.resolve(resourceResolver, url.toString());
LOGGER.debug("Inside RemoteContentService Resource r is " + r);
return broker.getResourceBeanMapper(resourceResolver).map(r, type);
}
use of org.onehippo.cms7.crisp.api.resource.Resource in project hippo by NHS-digital-website.
the class ApigeeService method apiSpecificationJsonForSpecId.
@Override
public String apiSpecificationJsonForSpecId(final String specificationId) throws OpenApiSpecificationRepositoryException {
log.debug("Retrieving specification with id {}.", specificationId);
return throwServiceExceptionOnFailure(() -> {
final String singleSpecUrl = urlForSingleSpecification(specificationId);
final Resource resource = resourceAt(singleSpecUrl);
return apigeeApiSpecificationJsonFrom(resource);
}, "Failed to retrieve specification with id {0}.", specificationId);
}
Aggregations