Search in sources :

Example 1 with MessageEventListener

use of nl.nn.adapterframework.lifecycle.MessageEventListener in project iaf by ibissource.

the class IbisContextTest method nullClassLoader.

@Test
public void nullClassLoader() {
    String configurationName = "ConfigWithNullClassLoader";
    try (IbisContext context = new IbisTestContext(configurationName, TestClassLoader.class)) {
        context.init(false);
        assertEquals("TestConfiguration", context.getApplicationName());
        assertEquals(0, context.getIbisManager().getConfigurations().size());
        MessageEventListener events = context.getBean("MessageEventListener", MessageEventListener.class);
        MessageKeeperMessage message = events.getMessageKeeper().getMessage(events.getMessageKeeper().size() - 2);
        assertNotNull("unable to find MessageKeeperMessage", message);
        assertThat(message.getMessageText(), Matchers.endsWith("error configuring ClassLoader for configuration [ConfigWithNullClassLoader]: (ClassLoaderException) test-exception"));
    }
}
Also used : MessageEventListener(nl.nn.adapterframework.lifecycle.MessageEventListener) MessageKeeperMessage(nl.nn.adapterframework.util.MessageKeeperMessage) Test(org.junit.Test)

Example 2 with MessageEventListener

use of nl.nn.adapterframework.lifecycle.MessageEventListener in project iaf by ibissource.

the class ApiTestBase method setUp.

@Before
public void setUp() throws Exception {
    // Remove old instance if present
    ApplicationWarnings.removeInstance();
    M resource = createJaxRsResource();
    checkContextFields(resource);
    jaxRsResource = spy(resource);
    MockServletContext servletContext = new MockServletContext();
    MockServletConfig servletConfig = new MockServletConfig(servletContext, "JAX-RS-MockDispatcher");
    jaxRsResource.servletConfig = servletConfig;
    jaxRsResource.securityContext = mock(SecurityContext.class);
    IbisContext ibisContext = mock(IbisContext.class);
    configuration = new TestConfiguration();
    IbisManager ibisManager = configuration.getIbisManager();
    ibisManager.setIbisContext(ibisContext);
    doReturn(ibisManager).when(ibisContext).getIbisManager();
    doReturn(ibisContext).when(jaxRsResource).getIbisContext();
    doReturn(configuration.getBean("applicationWarnings")).when(ibisContext).getBean(eq("applicationWarnings"), any());
    // we don't test the messages
    doReturn(new MessageEventListener()).when(ibisContext).getBean(eq("MessageEventListener"), any());
    registerAdapter(configuration);
    dispatcher.register(jaxRsResource);
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) IbisManager(nl.nn.adapterframework.configuration.IbisManager) MessageEventListener(nl.nn.adapterframework.lifecycle.MessageEventListener) SecurityContext(javax.ws.rs.core.SecurityContext) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) MockServletConfig(org.springframework.mock.web.MockServletConfig) MockServletContext(org.springframework.mock.web.MockServletContext) Before(org.junit.Before)

Example 3 with MessageEventListener

use of nl.nn.adapterframework.lifecycle.MessageEventListener in project iaf by ibissource.

the class ServerStatistics method getServerConfiguration.

@GET
@PermitAll
@Path("/server/warnings")
@Produces(MediaType.APPLICATION_JSON)
public Response getServerConfiguration() throws ApiException {
    Map<String, Object> returnMap = new HashMap<String, Object>();
    ApplicationWarnings globalConfigWarnings = getIbisContext().getBean("applicationWarnings", ApplicationWarnings.class);
    MessageEventListener eventListener = getIbisContext().getBean("MessageEventListener", MessageEventListener.class);
    long totalErrorStoreCount = 0;
    boolean showCountErrorStore = AppConstants.getInstance().getBoolean("errorStore.count.show", true);
    if (!showCountErrorStore)
        totalErrorStoreCount = -1;
    for (Configuration configuration : getIbisManager().getConfigurations()) {
        Map<String, Object> configurationsMap = new HashMap<String, Object>();
        // Configuration specific exceptions
        if (configuration.getConfigurationException() != null) {
            String message = configuration.getConfigurationException().getMessage();
            configurationsMap.put("exception", message);
        }
        if (configuration.isActive()) {
            // ErrorStore count
            if (showCountErrorStore) {
                long esr = 0;
                for (Adapter adapter : configuration.getRegisteredAdapters()) {
                    for (Receiver<?> receiver : adapter.getReceivers()) {
                        IMessageBrowser<?> errorStorage = receiver.getMessageBrowser(ProcessState.ERROR);
                        if (errorStorage != null) {
                            try {
                                esr += errorStorage.getMessageCount();
                            } catch (Exception e) {
                                // error("error occured on getting number of errorlog records for adapter ["+adapter.getName()+"]",e);
                                log.warn("Assuming there are no errorlog records for adapter [" + adapter.getName() + "]");
                            }
                        }
                    }
                }
                totalErrorStoreCount += esr;
                configurationsMap.put("errorStoreCount", esr);
            }
            // Configuration specific warnings
            ConfigurationWarnings configWarns = configuration.getConfigurationWarnings();
            if (configWarns != null && configWarns.size() > 0) {
                configurationsMap.put("warnings", configWarns.getWarnings());
            }
            // Configuration specific messages
            MessageKeeper messageKeeper = eventListener.getMessageKeeper(configuration.getName());
            if (messageKeeper != null) {
                List<Object> messages = mapMessageKeeperMessages(messageKeeper);
                if (!messages.isEmpty()) {
                    configurationsMap.put("messages", messages);
                }
            }
        }
        returnMap.put(configuration.getName(), configurationsMap);
    }
    // Total ErrorStore Count
    returnMap.put("totalErrorStoreCount", totalErrorStoreCount);
    // Global warnings
    if (globalConfigWarnings.size() > 0) {
        List<Object> warnings = new ArrayList<>();
        for (int j = 0; j < globalConfigWarnings.size(); j++) {
            warnings.add(globalConfigWarnings.get(j));
        }
        returnMap.put("warnings", warnings);
    }
    // Global messages
    MessageKeeper messageKeeper = eventListener.getMessageKeeper();
    List<Object> messages = mapMessageKeeperMessages(messageKeeper);
    if (!messages.isEmpty()) {
        returnMap.put("messages", messages);
    }
    Response.ResponseBuilder response = null;
    // Calculate the ETag on last modified date of user resource
    EntityTag etag = new EntityTag(returnMap.hashCode() + "");
    // Verify if it matched with etag available in http request
    response = rsRequest.evaluatePreconditions(etag);
    // If ETag matches the response will be non-null;
    if (response != null) {
        return response.tag(etag).build();
    }
    response = Response.status(Response.Status.OK).entity(returnMap).tag(etag);
    return response.build();
}
Also used : ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) MessageEventListener(nl.nn.adapterframework.lifecycle.MessageEventListener) ArrayList(java.util.ArrayList) MessageKeeper(nl.nn.adapterframework.util.MessageKeeper) Adapter(nl.nn.adapterframework.core.Adapter) Response(javax.ws.rs.core.Response) ApplicationWarnings(nl.nn.adapterframework.configuration.ApplicationWarnings) EntityTag(javax.ws.rs.core.EntityTag) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Aggregations

MessageEventListener (nl.nn.adapterframework.lifecycle.MessageEventListener)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PermitAll (javax.annotation.security.PermitAll)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 EntityTag (javax.ws.rs.core.EntityTag)1 Response (javax.ws.rs.core.Response)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 ApplicationWarnings (nl.nn.adapterframework.configuration.ApplicationWarnings)1 Configuration (nl.nn.adapterframework.configuration.Configuration)1 ConfigurationWarnings (nl.nn.adapterframework.configuration.ConfigurationWarnings)1 IbisContext (nl.nn.adapterframework.configuration.IbisContext)1 IbisManager (nl.nn.adapterframework.configuration.IbisManager)1 Adapter (nl.nn.adapterframework.core.Adapter)1 TestConfiguration (nl.nn.adapterframework.testutil.TestConfiguration)1 MessageKeeper (nl.nn.adapterframework.util.MessageKeeper)1 MessageKeeperMessage (nl.nn.adapterframework.util.MessageKeeperMessage)1 Before (org.junit.Before)1