Search in sources :

Example 71 with CoreException

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

the class ServiceWorkerPool method warmup.

public void warmup(final GenericObjectPool<Worker> objectPool) throws CoreException {
    ExecutorService populator = Executors.newCachedThreadPool(new ManagedThreadFactory(this.getClass().getSimpleName()));
    try {
        log.trace("Warming up {} service-workers", maxThreads);
        final List<Future<Worker>> futures = new ArrayList<>(maxThreads);
        for (int i = 0; i < maxThreads; i++) {
            futures.add(populator.submit(new Callable<Worker>() {

                @Override
                public Worker call() throws Exception {
                    return objectPool.borrowObject();
                }
            }));
        }
        for (Worker w : waitFor(futures)) {
            objectPool.returnObject(w);
        }
        log.trace("ObjectPool contains {} (active) of {} objects", objectPool.getNumActive(), objectPool.getNumIdle());
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    } finally {
        populator.shutdownNow();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) CoreException(com.adaptris.core.CoreException) ManagedThreadFactory(com.adaptris.core.util.ManagedThreadFactory)

Example 72 with CoreException

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

the class SizeBasedSplitter method splitMessage.

public CloseableIterable<AdaptrisMessage> splitMessage(final AdaptrisMessage msg) throws CoreException {
    logR.debug("SizeBasedSplitter splits every {} bytes", splitSizeBytes());
    logExpected(msg);
    try {
        return new SplitGenerator(msg.getInputStream(), msg, selectFactory(msg));
    } catch (IOException e) {
        throw new CoreException(e);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) IOException(java.io.IOException)

Example 73 with CoreException

use of com.adaptris.core.CoreException 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)

Example 74 with CoreException

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

the class BasicXmlSchemaValidator method validate.

@Override
public void validate(AdaptrisMessage msg) throws CoreException {
    // Since we don't throw SAXParseExceptions in the collector, any exceptions
    // shouldn't be schema violations we're basically in the normal error handler chain
    CollectingSaxErrorHandler violationCollector = new CollectingSaxErrorHandler();
    try (InputStream in = msg.getInputStream()) {
        Validator validator = this.resolveSchema(msg).newValidator();
        validator.setErrorHandler(violationCollector);
        validator.validate(new SAXSource(new InputSource(in)));
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException("Failed to validate message", e);
    }
    if (violationCollector.hasErrors()) {
        violationHandler().handle(IterableUtils.chainedIterable(violationCollector.fatalErrors(), violationCollector.errors()), msg);
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) InputStream(java.io.InputStream) Validator(javax.xml.validation.Validator) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Example 75 with CoreException

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

the class AggregatingFtpConsumeServiceTest method testInit.

@Test
public void testInit() throws Exception {
    AggregatingFtpConsumeService service = new AggregatingFtpConsumeService();
    try {
        LifecycleHelper.prepare(service);
        LifecycleHelper.init(service);
        fail();
    } catch (CoreException expected) {
    }
    service = new AggregatingFtpConsumeService();
    service.setConnection(new FtpConnection());
    try {
        LifecycleHelper.prepare(service);
        LifecycleHelper.init(service);
        fail();
    } catch (CoreException expected) {
    }
    service = new AggregatingFtpConsumeService();
    service.setConsumer(new AggregatingFtpConsumer());
    try {
        LifecycleHelper.prepare(service);
        LifecycleHelper.init(service);
        fail();
    } catch (CoreException expected) {
    }
    service = new AggregatingFtpConsumeService(new FtpConnection(), createConsumer("ftp://localhost/work", null, new ReplaceWithFirstMessage()));
    LifecycleHelper.prepare(service);
    LifecycleHelper.init(service);
    LifecycleHelper.close(service);
}
Also used : CoreException(com.adaptris.core.CoreException) ReplaceWithFirstMessage(com.adaptris.core.services.aggregator.ReplaceWithFirstMessage) Test(org.junit.Test)

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