use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class HexSequenceConfiguredReplacementSource method obtainValue.
public String obtainValue(AdaptrisMessage msg) throws ServiceException {
String result = null;
ByteTranslator hexToBytes = new HexStringByteTranslator();
ByteTranslator bytesToString = new SimpleByteTranslator();
if (!isEmpty(charset)) {
bytesToString = new CharsetByteTranslator(charset);
}
try {
result = bytesToString.translate(hexToBytes.translate(this.getValue()));
} catch (Exception e) {
throw new ServiceException(e);
}
return result;
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class ServiceExceptionHandler method throwExceptionAsRequired.
@Override
public void throwExceptionAsRequired() throws ServiceException {
Throwable e = getFirstThrowableException();
if (e != null) {
log.error("One or more services failed: {}", e.getMessage());
ServiceException wrappedException = ExceptionHelper.wrapServiceException(e);
for (Throwable t : exceptionList) {
if (t != e) {
wrappedException.addSuppressed(t);
}
}
clearExceptions();
throw wrappedException;
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class MultiPayloadXmlTransformService method doTransform.
private void doTransform(MultiPayloadAdaptrisMessage msg, String urlToUse) throws ServiceException {
XmlTransformer xmlTransformerImpl = new XmlTransformer();
Transformer transformer;
try {
if (cacheTransforms()) {
transformer = cacheAndGetTransformer(urlToUse, getXmlTransformerFactory());
} else {
transformer = getXmlTransformerFactory().createTransformer(urlToUse);
}
getXmlTransformerFactory().configure(xmlTransformerImpl);
} catch (Exception ex) {
throw new ServiceException(ex);
}
try (InputStream input = msg.getInputStream(sourcePayloadId);
OutputStream output = msg.getOutputStream(outputPayloadId)) {
Map<Object, Object> parameters = getParameterBuilder().createParameters(msg, null);
xmlTransformerImpl.transform(transformer, input, output, urlToUse, parameters);
if (!StringUtils.isBlank(getOutputMessageEncoding())) {
msg.setContentEncoding(outputPayloadId, getOutputMessageEncoding());
}
} catch (Exception e) {
throw new ServiceException("Failed to transform message", e);
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class ObjectMetadataParameter method createParameters.
@Override
public Map createParameters(AdaptrisMessage msg, Map existingParams) throws ServiceException {
if (isEmpty(getObjectMetadataKeyRegexp())) {
throw new ServiceException("Object Metadata Key regexp is empty");
}
Pattern pattern = Pattern.compile(getObjectMetadataKeyRegexp());
Map params = existingParams == null ? new HashMap() : new HashMap(existingParams);
Map objMetadata = msg.getObjectHeaders();
for (Object key : objMetadata.keySet()) {
if (pattern.matcher(key.toString()).matches()) {
params.put(key.toString(), objMetadata.get(key));
log.trace("Adding object metadata against [{}]", key.toString());
}
}
return params;
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class XmlRuleValidator method validate.
@Override
public void validate(AdaptrisMessage msg) throws CoreException {
try {
NamespaceContext namespaceCtx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(namespaceCtx);
Document doc = createDocument(msg, builder);
XPath xp = XPath.newXPathInstance(builder, namespaceCtx);
for (int stageIndex = 0; stageIndex < validationStages.size(); stageIndex++) {
ValidationStage v = validationStages.get(stageIndex);
NodeList n = xp.selectNodeList(doc, v.getIterationXpath());
validate(n, v.getIterationXpath(), v.failOnIteratorFailure());
for (int i = 0; i < n.getLength(); i++) {
Node node = n.item(i);
String contents = xp.selectSingleTextItem(node, v.getElementXpath());
for (ContentValidation cv : v.getRules()) {
if (!cv.isValid(contents)) {
throw new ServiceException(ERR_MSG.replaceAll(I_COUNT, "" + i).replaceAll(I_XP, Matcher.quoteReplacement(v.getIterationXpath())).replaceAll(E_XP, Matcher.quoteReplacement(v.getElementXpath())).replaceAll(CONTENTS, Matcher.quoteReplacement(contents)).replaceAll(VALIDATION_MSG, Matcher.quoteReplacement(cv.getMessage())));
}
}
}
}
} catch (Exception e) {
ExceptionHelper.rethrowCoreException(e);
}
}
Aggregations