Search in sources :

Example 81 with CoreException

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;
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 82 with CoreException

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;
            }
        }
    }
}
Also used : InputFieldHint(com.adaptris.annotation.InputFieldHint) IOException(java.io.IOException) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) CoreException(com.adaptris.core.CoreException)

Example 83 with CoreException

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;
    }
}
Also used : CoreException(com.adaptris.core.CoreException) Channel(com.adaptris.core.Channel) CoreException(com.adaptris.core.CoreException) ManagedThreadFactory(com.adaptris.core.util.ManagedThreadFactory)

Example 84 with CoreException

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);
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) CoreException(com.adaptris.core.CoreException)

Example 85 with CoreException

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);
            }
        });
    }
}
Also used : CoreException(com.adaptris.core.CoreException) Channel(com.adaptris.core.Channel) ExecutorService(java.util.concurrent.ExecutorService)

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