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);
}
}
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();
}
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);
}
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);
}
}
Aggregations