Search in sources :

Example 51 with IAdapter

use of nl.nn.adapterframework.core.IAdapter in project iaf by ibissource.

the class ShowConfiguration method getConfigurationHealth.

@GET
@PermitAll
@Path("/configurations/{configuration}/health")
@Produces(MediaType.APPLICATION_JSON)
public Response getConfigurationHealth(@PathParam("configuration") String configurationName) throws ApiException {
    Configuration configuration = getIbisManager().getConfiguration(configurationName);
    if (configuration == null) {
        throw new ApiException("Configuration not found!");
    }
    if (!configuration.isActive()) {
        throw new ApiException("Configuration not active", configuration.getConfigurationException());
    }
    Map<String, Object> response = new HashMap<>();
    Map<RunState, Integer> stateCount = new HashMap<>();
    List<String> errors = new ArrayList<>();
    for (IAdapter adapter : configuration.getRegisteredAdapters()) {
        // Let's not make it difficult for ourselves and only use STARTED/ERROR enums
        RunState state = adapter.getRunState();
        if (state == RunState.STARTED) {
            for (Receiver<?> receiver : adapter.getReceivers()) {
                RunState rState = receiver.getRunState();
                if (rState != RunState.STARTED) {
                    errors.add("receiver[" + receiver.getName() + "] of adapter[" + adapter.getName() + "] is in state[" + rState.toString() + "]");
                    state = RunState.ERROR;
                }
            }
        } else {
            errors.add("adapter[" + adapter.getName() + "] is in state[" + state.toString() + "]");
            state = RunState.ERROR;
        }
        int count;
        if (stateCount.containsKey(state))
            count = stateCount.get(state);
        else
            count = 0;
        stateCount.put(state, ++count);
    }
    Status status = Response.Status.OK;
    if (stateCount.containsKey(RunState.ERROR))
        status = Response.Status.SERVICE_UNAVAILABLE;
    if (!errors.isEmpty())
        response.put("errors", errors);
    response.put("status", status);
    return Response.status(status).entity(response).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) RunState(nl.nn.adapterframework.util.RunState) IAdapter(nl.nn.adapterframework.core.IAdapter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Example 52 with IAdapter

use of nl.nn.adapterframework.core.IAdapter in project iaf by ibissource.

the class TestPipeline method postTestPipeLine.

@POST
@RolesAllowed("IbisTester")
@Path("/test-pipeline")
@Relation("pipeline")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postTestPipeLine(MultipartBody inputDataMap) throws ApiException {
    Map<String, Object> result = new HashMap<>();
    IbisManager ibisManager = getIbisManager();
    if (ibisManager == null) {
        throw new ApiException("Config not found!");
    }
    String message = null;
    InputStream file = null;
    boolean isZipFile = false;
    String adapterName = resolveStringFromMap(inputDataMap, "adapter");
    // Make sure the adapter exists!
    IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName);
    if (adapter == null) {
        throw new ApiException("Adapter [" + adapterName + "] not found");
    }
    // resolve session keys
    String sessionKeys = resolveTypeFromMap(inputDataMap, "sessionKeys", String.class, "");
    Map<String, String> sessionKeyMap = null;
    if (StringUtils.isNotEmpty(sessionKeys)) {
        try {
            sessionKeyMap = Stream.of(new ObjectMapper().readValue(sessionKeys, PostedSessionKey[].class)).collect(Collectors.toMap(item -> item.key, item -> item.value));
        } catch (Exception e) {
            throw new ApiException("An exception occurred while parsing session keys", e);
        }
    }
    String fileEncoding = resolveTypeFromMap(inputDataMap, "encoding", String.class, StreamUtil.DEFAULT_INPUT_STREAM_ENCODING);
    Attachment filePart = inputDataMap.getAttachment("file");
    if (filePart != null) {
        String fileName = filePart.getContentDisposition().getParameter("filename");
        if (StringUtils.endsWithIgnoreCase(fileName, ".zip")) {
            try {
                isZipFile = true;
                file = filePart.getObject(InputStream.class);
                processZipFile(result, file, fileEncoding, adapter, sessionKeyMap, secLogMessage);
            } catch (Exception e) {
                throw new ApiException("An exception occurred while processing zip file", e);
            }
        } else {
            message = resolveStringWithEncoding(inputDataMap, "file", fileEncoding);
        }
    } else {
        message = resolveStringWithEncoding(inputDataMap, "message", fileEncoding);
    }
    if (!isZipFile) {
        result.put("message", message);
        try {
            PipeLineResult plr = processMessage(adapter, message, sessionKeyMap, secLogMessage);
            try {
                result.put(PIPELINE_RESULT_STATE, plr.getState());
                result.put(PIPELINE_RESULT, plr.getResult().asString());
            } catch (Exception e) {
                String msg = "An exception occurred while extracting the result of the PipeLine with exit state [" + plr.getState() + "]";
                log.warn(msg, e);
                result.put(PIPELINE_RESULT_STATE, PIPELINE_RESULT_STATE_ERROR);
                result.put(PIPELINE_RESULT, msg + ": (" + e.getClass().getTypeName() + ") " + e.getMessage());
            }
        } catch (Exception e) {
            String msg = "An exception occurred while processing the message";
            log.warn(msg, e);
            result.put(PIPELINE_RESULT_STATE, PIPELINE_RESULT_STATE_ERROR);
            result.put(PIPELINE_RESULT, msg + ": (" + e.getClass().getTypeName() + ") " + e.getMessage());
        }
    }
    return Response.status(Response.Status.CREATED).entity(result).build();
}
Also used : IbisManager(nl.nn.adapterframework.configuration.IbisManager) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) IOException(java.io.IOException) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) IAdapter(nl.nn.adapterframework.core.IAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 53 with IAdapter

use of nl.nn.adapterframework.core.IAdapter in project iaf by ibissource.

the class JmxNamingStrategyTest method testAdapterWithAStupidName.

@Test
public void testAdapterWithAStupidName() throws Exception {
    IAdapter adapter = new Adapter();
    // adapters should always have a name otherwise it wont be instantiated by the AdapterService
    adapter.setName("H#llo =; [i]<3u, \"have an adapter N4m3 :)");
    ObjectName name = namingStrategy.getObjectName(adapter, null);
    assertNull("an adapter without configuration should not exist", name.getKeyProperty("type"));
    // this defaults to the className
    assertEquals("H#llo _; [i]<3u_ \"have an adapter N4m3 _)", name.getKeyProperty("name"));
    // for non Adapters this defaults to the package name
    assertEquals("defaultDomain", name.getDomain());
}
Also used : IAdapter(nl.nn.adapterframework.core.IAdapter) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 54 with IAdapter

use of nl.nn.adapterframework.core.IAdapter in project iaf by ibissource.

the class TibetView method isOpenReportAllowedViaAdapter.

public String isOpenReportAllowedViaAdapter(Object StorageId) {
    Echo2Application app = getEcho2Application();
    IAdapter adapter = ibisManager.getRegisteredAdapter(AUTHORISATION_CHECK_ADAPTER);
    if (adapter == null) {
        return "Not allowed. Could not find adapter " + AUTHORISATION_CHECK_ADAPTER;
    } else {
        PipeLineSession pipeLineSession = new PipeLineSession();
        if (app.getUserPrincipal() != null)
            pipeLineSession.put("principal", app.getUserPrincipal().getName());
        pipeLineSession.put("StorageId", StorageId);
        pipeLineSession.put("View", getName());
        PipeLineResult processResult = adapter.processMessage(null, new Message("<dummy/>"), pipeLineSession);
        if (processResult.isSuccessful()) {
            return ReportsComponent.OPEN_REPORT_ALLOWED;
        } else {
            return "Not allowed. Result of adapter " + AUTHORISATION_CHECK_ADAPTER + ": " + processResult.getResult();
        }
    }
}
Also used : Message(nl.nn.adapterframework.stream.Message) Echo2Application(nl.nn.testtool.echo2.Echo2Application) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IAdapter(nl.nn.adapterframework.core.IAdapter)

Aggregations

IAdapter (nl.nn.adapterframework.core.IAdapter)54 Adapter (nl.nn.adapterframework.core.Adapter)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 Iterator (java.util.Iterator)13 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)11 Configuration (nl.nn.adapterframework.configuration.Configuration)10 List (java.util.List)9 IReceiver (nl.nn.adapterframework.core.IReceiver)9 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)9 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)8 LinkedList (java.util.LinkedList)7 IListener (nl.nn.adapterframework.core.IListener)7 PipeRunException (nl.nn.adapterframework.core.PipeRunException)7 HashMap (java.util.HashMap)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 IbisManager (nl.nn.adapterframework.configuration.IbisManager)6 Message (nl.nn.adapterframework.stream.Message)6 RolesAllowed (javax.annotation.security.RolesAllowed)5