use of org.onehippo.cms7.crisp.api.exchange.ExchangeHint 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.exchange.ExchangeHint in project hippo by NHS-digital-website.
the class SubscriptionResourceTest method setUp.
@Before
public void setUp() {
final Map<String, ResourceResolver> resourceResolverMap = new HashMap<>();
resourceResolverMap.put("govDeliveryApi", new MockJdomResourceResolverAdapter() {
@Override
public Resource resolve(String absPath, Map<String, Object> pathVariables, ExchangeHint exchangeHint) throws ResourceException {
return urlToResource(SubscriptionResourceTest.class.getResource("/subscriber-output.xml"));
}
});
final ResourceServiceBroker mockBroker = new MockResourceServiceBroker(resourceResolverMap);
MockCrispHstServices.setDefaultResourceServiceBroker(mockBroker);
}
Aggregations