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();
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
Aggregations