Search in sources :

Example 11 with IbisManager

use of nl.nn.adapterframework.configuration.IbisManager in project iaf by ibissource.

the class Webservices method doGet.

private String doGet(IPipeLineSession session) throws PipeRunException {
    IbisManager ibisManager = RestListenerUtils.retrieveIbisManager(session);
    String uri = (String) session.get("uri");
    String indent = (String) session.get("indent");
    String useIncludes = (String) session.get("useIncludes");
    if (StringUtils.isNotEmpty(uri) && (uri.endsWith(getWsdlExtention()) || uri.endsWith(".zip"))) {
        String adapterName = StringUtils.substringBeforeLast(StringUtils.substringAfterLast(uri, "/"), ".");
        IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName);
        if (adapter == null) {
            throw new PipeRunException(this, getLogPrefix(session) + "adapter [" + adapterName + "] doesn't exist");
        }
        try {
            if (uri.endsWith(getWsdlExtention())) {
                RestListenerUtils.setResponseContentType(session, "application/xml");
                wsdl((Adapter) adapter, session, indent, useIncludes);
            } else {
                RestListenerUtils.setResponseContentType(session, "application/octet-stream");
                zip((Adapter) adapter, session);
            }
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on retrieving wsdl", e);
        }
        return "";
    } else {
        return list(ibisManager);
    }
}
Also used : IbisManager(nl.nn.adapterframework.configuration.IbisManager) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IAdapter(nl.nn.adapterframework.core.IAdapter) PipeRunException(nl.nn.adapterframework.core.PipeRunException) NamingException(javax.naming.NamingException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 12 with IbisManager

use of nl.nn.adapterframework.configuration.IbisManager 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 13 with IbisManager

use of nl.nn.adapterframework.configuration.IbisManager in project iaf by ibissource.

the class CleanupDatabaseJobTest method setup.

@Override
@Before
public void setup() throws Exception {
    super.setup();
    System.setProperty("tableName", tableName);
    runMigrator(TEST_CHANGESET_PATH);
    configuration = new TestConfiguration();
    Adapter adapter = setupAdapter();
    configuration.registerAdapter(adapter);
    jobDef = new CleanupDatabaseJob() {

        @Override
        protected Set<String> getAllLockerDatasourceNames(IbisManager ibisManager) {
            return Collections.singleton(getDataSourceName());
        }
    };
    configuration.autowireByName(jobDef);
}
Also used : Set(java.util.Set) IbisManager(nl.nn.adapterframework.configuration.IbisManager) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Adapter(nl.nn.adapterframework.core.Adapter) CleanupDatabaseJob(nl.nn.adapterframework.scheduler.job.CleanupDatabaseJob) Before(org.junit.Before)

Example 14 with IbisManager

use of nl.nn.adapterframework.configuration.IbisManager in project iaf by ibissource.

the class ConfiguredJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    String ctName = Thread.currentThread().getName();
    try {
        JobDataMap dataMap = context.getJobDetail().getJobDataMap();
        IbisManager ibisManager = (IbisManager) dataMap.get(MANAGER_KEY);
        IJob jobDef = (IJob) dataMap.get(JOBDEF_KEY);
        Thread.currentThread().setName(jobDef.getName() + "[" + ctName + "]");
        log.info(getLogPrefix(jobDef) + "executing");
        jobDef.executeJob(ibisManager);
        log.debug(getLogPrefix(jobDef) + "completed");
    } catch (Exception e) {
        log.error("JobExecutionException while running " + getLogPrefix(context), e);
        throw new JobExecutionException(e, false);
    } finally {
        Thread.currentThread().setName(ctName);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) JobExecutionException(org.quartz.JobExecutionException) IbisManager(nl.nn.adapterframework.configuration.IbisManager) IJob(nl.nn.adapterframework.scheduler.job.IJob) JobExecutionException(org.quartz.JobExecutionException)

Aggregations

IbisManager (nl.nn.adapterframework.configuration.IbisManager)14 IAdapter (nl.nn.adapterframework.core.IAdapter)6 Configuration (nl.nn.adapterframework.configuration.Configuration)5 IOException (java.io.IOException)4 IbisContext (nl.nn.adapterframework.configuration.IbisContext)3 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 ZipInputStream (java.util.zip.ZipInputStream)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 Adapter (nl.nn.adapterframework.core.Adapter)2 TestConfiguration (nl.nn.adapterframework.testutil.TestConfiguration)2 Before (org.junit.Before)2