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