Search in sources :

Example 66 with CoreException

use of com.adaptris.core.CoreException in project interlok by adaptris.

the class ZipAggregator method aggregate.

@Override
public void aggregate(AdaptrisMessage original, Iterable<AdaptrisMessage> messages) throws CoreException {
    try (ZipOutputStream zipOutputStream = new ZipOutputStream(original.getOutputStream())) {
        for (AdaptrisMessage m : messages) {
            if (BooleanUtils.and(new boolean[] { filter(m), m.headersContainsKey(filenameMetadata()) })) {
                zipOutputStream.putNextEntry(new ZipEntry(m.getMetadataValue(filenameMetadata())));
                try (InputStream in = m.getInputStream()) {
                    IOUtils.copy(in, zipOutputStream);
                }
                zipOutputStream.closeEntry();
            }
        }
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ZipOutputStream(java.util.zip.ZipOutputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) CoreException(com.adaptris.core.CoreException)

Example 67 with CoreException

use of com.adaptris.core.CoreException in project interlok by adaptris.

the class ConditionFunction method init.

@Override
public void init() throws CoreException {
    try {
        ScriptEngineManager manager = new ScriptEngineManager(this.getClass().getClassLoader());
        engine = Args.notNull(manager.getEngineByName("nashorn"), "nashorn engine");
        engine.eval(definition);
        Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
        bindings.put("log", log);
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    }
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) Bindings(javax.script.Bindings) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Example 68 with CoreException

use of com.adaptris.core.CoreException in project interlok by adaptris.

the class ExceptionAsXml method serialize.

@Override
public void serialize(Exception exception, AdaptrisMessage msg) throws CoreException {
    try {
        Document newDoc = exceptionGenerator().create(exception, msg.getMetadataValue(Workflow.WORKFLOW_ID_KEY), (String) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
        Document result = documentMerge().merge(XmlHelper.createDocument(msg, documentFactoryBuilder(), ignoreXmlParseExceptions()), newDoc);
        String encoding = XmlHelper.getXmlEncoding(msg, getXmlEncoding());
        XmlHelper.writeXmlDocument(result, msg, encoding);
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}
Also used : Document(org.w3c.dom.Document) CoreException(com.adaptris.core.CoreException)

Example 69 with CoreException

use of com.adaptris.core.CoreException in project interlok by adaptris.

the class XpathCacheValueTranslator method getValueFromMessage.

/**
 * @return the result of applying the configured xpath against the payload of this {@link AdaptrisMessage}
 */
@Override
public String getValueFromMessage(AdaptrisMessage msg) throws CoreException {
    NamespaceContext ctx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
    DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(ctx);
    String result = null;
    try {
        XPath xp = XPath.newXPathInstance(builder, ctx);
        Document d = XmlHelper.createDocument(msg, builder);
        result = xp.selectSingleTextItem(d, msg.resolve(getXpath()));
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    }
    return result;
}
Also used : XPath(com.adaptris.util.text.xml.XPath) SimpleNamespaceContext(com.adaptris.util.text.xml.SimpleNamespaceContext) NamespaceContext(javax.xml.namespace.NamespaceContext) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) CoreException(com.adaptris.core.CoreException)

Example 70 with CoreException

use of com.adaptris.core.CoreException in project interlok by adaptris.

the class XmlPayloadTranslatorImpl method createXmlUtils.

protected static XmlUtils createXmlUtils(AdaptrisMessage msg) {
    XmlUtils xu = null;
    try {
        NamespaceContext ctx = (NamespaceContext) msg.getObjectHeaders().get(JdbcDataQueryService.KEY_NAMESPACE_CTX);
        DocumentBuilderFactoryBuilder builder = (DocumentBuilderFactoryBuilder) msg.getObjectHeaders().get(JdbcDataQueryService.KEY_DOCBUILDER_FAC);
        xu = XmlHelper.createXmlUtils(msg, ctx, builder);
    } catch (CoreException e) {
        xu = new XmlUtils();
    }
    return xu;
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) CoreException(com.adaptris.core.CoreException) NamespaceContext(javax.xml.namespace.NamespaceContext) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder)

Aggregations

CoreException (com.adaptris.core.CoreException)186 Test (org.junit.Test)110 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)44 Adapter (com.adaptris.core.Adapter)32 ObjectName (javax.management.ObjectName)29 Channel (com.adaptris.core.Channel)27 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)20 File (java.io.File)19 ServiceException (com.adaptris.core.ServiceException)14 TimeInterval (com.adaptris.util.TimeInterval)13 Document (org.w3c.dom.Document)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)10 StandardWorkflow (com.adaptris.core.StandardWorkflow)9 URLString (com.adaptris.util.URLString)9 TimeoutException (java.util.concurrent.TimeoutException)9 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)8 Workflow (com.adaptris.core.Workflow)8 XPath (com.adaptris.util.text.xml.XPath)8