use of com.adaptris.core.CoreException in project interlok by adaptris.
the class JettyMessageConsumer method createMessage.
@Override
public AdaptrisMessage createMessage(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
AdaptrisMessage msg = null;
try {
logHeaders(request);
if (getEncoder() != null) {
msg = getEncoder().readMessage(request);
} else {
msg = defaultIfNull(getMessageFactory()).newMessage();
try (InputStream in = request.getInputStream();
OutputStream out = msg.getOutputStream()) {
if (request.getContentLength() == -1) {
IOUtils.copy(request.getInputStream(), out);
} else {
StreamUtil.copyStream(request.getInputStream(), out, request.getContentLength());
}
}
}
checkCharsetAndApply(msg, request.getCharacterEncoding(), !checkCharset());
addParamMetadata(msg, request);
addHeaderMetadata(msg, request);
} catch (CoreException e) {
throw new IOException(e.getMessage(), e);
}
return msg;
}
use of com.adaptris.core.CoreException in project interlok by adaptris.
the class JmxConnection method doConnect.
private void doConnect() throws CoreException {
int attemptCount = 0;
while (connection == null) {
try {
attemptCount++;
if (additionalDebug()) {
log.trace("Attempting connection to [{}]", jmxServiceUrlForLogging());
}
connection = createConnection();
} catch (Exception e) {
if (logWarning(attemptCount)) {
log.warn("Connection attempt [{}] failed for {}", attemptCount, jmxServiceUrlForLogging(), e);
}
if (connectionAttempts() != -1 && attemptCount >= connectionAttempts()) {
log.error("Failed to connect to [{}]", getJmxServiceUrl(), e);
throw ExceptionHelper.wrapCoreException(e);
} else {
log.warn("Attempt [{}] failed for [{}], retrying", attemptCount, jmxServiceUrlForLogging());
log.info(createLoggingStatement(attemptCount));
LifecycleHelper.waitQuietly(connectionRetryInterval());
continue;
}
}
}
}
use of com.adaptris.core.CoreException in project interlok by adaptris.
the class BlockingChannelLifecycleStrategy method handleOperation.
private void handleOperation(List<Channel> channels, ChannelAction op, CyclicBarrier gate) throws CoreException {
ManagedThreadFactory factory = new ManagedThreadFactory(getClass().getSimpleName());
Set<Thread> myThreads = Collections.newSetFromMap(new WeakHashMap<Thread, Boolean>());
final CoreExceptionHandler exceptions = new CoreExceptionHandler();
for (int i = 0; i < channels.size(); i++) {
final Channel c = channels.get(i);
final String name = c.hasUniqueId() ? c.getUniqueId() : "Channel(" + i + ")";
Thread t = factory.newThread(new ChannelInvocationThread(name + "." + op.name(), exceptions, gate, op, c));
t.setUncaughtExceptionHandler(exceptions);
myThreads.add(t);
t.start();
}
try {
gate.await(timeoutMs(), TimeUnit.MILLISECONDS);
} catch (Exception gateException) {
CoreException e = new CoreException("Exception waiting for all channel." + op.name() + " operations to complete", gateException);
exceptions.uncaughtException(Thread.currentThread(), e);
// I've been interrupted; so interrupt children!
interrupt(myThreads);
}
CoreException e = exceptions.getFirstThrowableException();
if (e != null) {
throw e;
}
}
use of com.adaptris.core.CoreException in project interlok by adaptris.
the class FilteredSharedComponentStart method execute.
private void execute(final ConnectionAction action, final AdaptrisConnection comp) throws CoreException {
if (threadedStart()) {
ExecutorService myExecutor = getExecutor(comp.getUniqueId());
final String threadName = this.getClass().getSimpleName();
myExecutor.execute(new Runnable() {
@Override
public void run() {
Thread.currentThread().setName(threadName);
try {
action.invoke(comp);
} catch (Exception e) {
log.error("Failed to {} connection {}", action, friendlyName(comp), e);
}
}
});
} else {
action.invoke(comp);
}
}
use of com.adaptris.core.CoreException in project interlok by adaptris.
the class NonBlockingChannelStartStrategy method handleLifecycle.
private void handleLifecycle(List<Channel> channels, final String friendlyText, final ChannelLifecycle oper) {
for (int i = 0; i < channels.size(); i++) {
final Channel c = channels.get(i);
final String name = channelName(c, i);
if (!c.shouldStart()) {
continue;
}
ExecutorService es = getExecutor(name);
es.execute(() -> {
Thread.currentThread().setName(String.format("%s %s", name, friendlyText));
try {
oper.initOrStart(c);
} catch (CoreException e) {
log.error("Failed to {} channel {}", friendlyText, name, e);
}
});
}
}
Aggregations