Search in sources :

Example 1 with Resource

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;
}
Also used : HashMap(java.util.HashMap) MissingResourceException(java.util.MissingResourceException) Resource(org.onehippo.cms7.crisp.api.resource.Resource) ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker) MissingResourceException(java.util.MissingResourceException)

Example 2 with 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;
}
Also used : JacksonResource(org.onehippo.cms7.crisp.core.resource.jackson.JacksonResource) Matcher(java.util.regex.Matcher)

Example 3 with Resource

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;
}
Also used : Subscriber(uk.nhs.digital.common.forms.model.Subscriber) HashMap(java.util.HashMap) ExchangeHint(org.onehippo.cms7.crisp.api.exchange.ExchangeHint) Resource(org.onehippo.cms7.crisp.api.resource.Resource) ResourceException(org.onehippo.cms7.crisp.api.resource.ResourceException) ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ResourceException(org.onehippo.cms7.crisp.api.resource.ResourceException)

Example 4 with Resource

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);
}
Also used : Resource(org.onehippo.cms7.crisp.api.resource.Resource) ResourceServiceBroker(org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker) HystrixCommand(com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand)

Example 5 with Resource

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);
}
Also used : Resource(org.onehippo.cms7.crisp.api.resource.Resource)

Aggregations

Resource (org.onehippo.cms7.crisp.api.resource.Resource)7 ResourceServiceBroker (org.onehippo.cms7.crisp.api.broker.ResourceServiceBroker)5 HashMap (java.util.HashMap)4 MissingResourceException (java.util.MissingResourceException)2 ExchangeHint (org.onehippo.cms7.crisp.api.exchange.ExchangeHint)2 ResourceException (org.onehippo.cms7.crisp.api.resource.ResourceException)2 ResourceResolver (org.onehippo.cms7.crisp.api.resource.ResourceResolver)2 MockResourceServiceBroker (org.onehippo.cms7.crisp.mock.broker.MockResourceServiceBroker)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HystrixCommand (com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand)1 ErrorMessage (com.onehippo.cms7.eforms.hst.model.ErrorMessage)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Before (org.junit.Before)1 ResourceCollection (org.onehippo.cms7.crisp.api.resource.ResourceCollection)1 JacksonResource (org.onehippo.cms7.crisp.core.resource.jackson.JacksonResource)1 SimpleJacksonRestTemplateResourceResolver (org.onehippo.cms7.crisp.core.resource.jackson.SimpleJacksonRestTemplateResourceResolver)1 MockJdomResourceResolverAdapter (org.onehippo.cms7.crisp.mock.resource.MockJdomResourceResolverAdapter)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 MockEnvironment (org.springframework.mock.env.MockEnvironment)1