Search in sources :

Example 86 with ServiceException

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;
}
Also used : ServiceException(com.adaptris.core.ServiceException) ByteTranslator(com.adaptris.util.text.ByteTranslator) HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator) SimpleByteTranslator(com.adaptris.util.text.SimpleByteTranslator) CharsetByteTranslator(com.adaptris.util.text.CharsetByteTranslator) CharsetByteTranslator(com.adaptris.util.text.CharsetByteTranslator) HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator) SimpleByteTranslator(com.adaptris.util.text.SimpleByteTranslator) ServiceException(com.adaptris.core.ServiceException)

Example 87 with ServiceException

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;
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException)

Example 88 with ServiceException

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);
    }
}
Also used : XmlTransformer(com.adaptris.util.text.xml.XmlTransformer) Transformer(javax.xml.transform.Transformer) XmlTransformer(com.adaptris.util.text.xml.XmlTransformer) ServiceException(com.adaptris.core.ServiceException) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ServiceException(com.adaptris.core.ServiceException)

Example 89 with ServiceException

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;
}
Also used : Pattern(java.util.regex.Pattern) ServiceException(com.adaptris.core.ServiceException) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 90 with ServiceException

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);
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) ServiceException(com.adaptris.core.ServiceException) NamespaceContext(javax.xml.namespace.NamespaceContext) SimpleNamespaceContext(com.adaptris.util.text.xml.SimpleNamespaceContext) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) XmlHelper.createDocument(com.adaptris.core.util.XmlHelper.createDocument) Document(org.w3c.dom.Document) ContentValidation(com.adaptris.transform.validate.ContentValidation) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException) ValidationStage(com.adaptris.transform.validate.ValidationStage)

Aggregations

ServiceException (com.adaptris.core.ServiceException)236 Test (org.junit.Test)172 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)161 CoreException (com.adaptris.core.CoreException)45 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)26 StandaloneProducer (com.adaptris.core.StandaloneProducer)18 MetadataElement (com.adaptris.core.MetadataElement)17 ValidationStage (com.adaptris.transform.validate.ValidationStage)16 Cache (com.adaptris.core.cache.Cache)15 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)13 TimeInterval (com.adaptris.util.TimeInterval)13 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 Connection (java.sql.Connection)10 File (java.io.File)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)9 SQLException (java.sql.SQLException)9 InputStream (java.io.InputStream)8 Document (org.w3c.dom.Document)8 Channel (com.adaptris.core.Channel)7