use of nl.nn.adapterframework.receivers.Receiver in project iaf by ibissource.
the class WsdlGeneratorPipe method doPipe.
@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
Message fileInSession = session.getMessage(getSessionKey());
if (fileInSession == null) {
throw new PipeRunException(this, getLogPrefix(session) + "got null value from session under key [" + getSessionKey() + "]");
}
File tempDir;
String fileName;
try (InputStream inputStream = fileInSession.asInputStream()) {
tempDir = FileUtils.createTempDir(null, "WEB-INF" + File.separator + "classes");
fileName = session.getMessage(getFilenameSessionKey()).asString();
if (FileUtils.extensionEqualsIgnoreCase(fileName, "zip")) {
FileUtils.unzipStream(inputStream, tempDir);
} else {
File file = new File(tempDir, fileName);
Misc.streamToFile(inputStream, file);
file.deleteOnExit();
}
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on uploading and unzipping/writing file", e);
}
File propertiesFile = new File(tempDir, getPropertiesFileName());
PipeLine pipeLine;
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
// A DirectoryClassloader is used to create a new 'dummy' pipeline, see createPipeLineFromPropertiesFile(String)
// This method reads a properties file and xsd's (when present) to programmatically 'create' a pipeline.
// The pipeline will then be used to generate a new WSDL file.
DirectoryClassLoader directoryClassLoader = new DirectoryClassLoader(originalClassLoader);
directoryClassLoader.setDirectory(tempDir.getPath());
directoryClassLoader.setBasePath(".");
directoryClassLoader.configure(getAdapter().getConfiguration().getIbisManager().getIbisContext(), "dummy");
Thread.currentThread().setContextClassLoader(directoryClassLoader);
if (propertiesFile.exists()) {
pipeLine = createPipeLineFromPropertiesFile(propertiesFile);
} else {
File xsdFile = FileUtils.getFirstFile(tempDir);
pipeLine = createPipeLineFromXsdFile(xsdFile);
}
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
} finally {
if (originalClassLoader != null) {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
Object result = null;
OutputStream zipOut = null;
OutputStream fullWsdlOut = null;
try {
Adapter adapter = new Adapter();
Configuration configuration = new Configuration();
configuration.setClassLoader(getConfigurationClassLoader());
adapter.setConfiguration(configuration);
String fileBaseName = FileUtils.getBaseName(fileName).replaceAll(" ", "_");
adapter.setName(fileBaseName);
Receiver receiver = new Receiver();
EsbJmsListener esbJmsListener = new EsbJmsListener();
esbJmsListener.setQueueConnectionFactoryName("jms/qcf_" + fileBaseName);
esbJmsListener.setDestinationName("jms/dest_" + fileBaseName);
receiver.setListener(esbJmsListener);
adapter.registerReceiver(receiver);
adapter.setPipeLine(pipeLine);
WsdlGenerator wsdl = null;
String generationInfo = "at " + RestListenerUtils.retrieveRequestURL(session);
wsdl = new WsdlGenerator(pipeLine, generationInfo);
wsdl.setIndent(true);
wsdl.init();
File wsdlDir = FileUtils.createTempDir(tempDir);
// zip (with includes)
File zipOutFile = new File(wsdlDir, wsdl.getFilename() + ".zip");
zipOutFile.deleteOnExit();
zipOut = new FileOutputStream(zipOutFile);
wsdl.setUseIncludes(true);
wsdl.zip(zipOut, null);
// full wsdl (without includes)
File fullWsdlOutFile = new File(wsdlDir, wsdl.getFilename() + ".wsdl");
fullWsdlOutFile.deleteOnExit();
fullWsdlOut = new FileOutputStream(fullWsdlOutFile);
wsdl.setUseIncludes(false);
wsdl.wsdl(fullWsdlOut, null);
Dir2Xml dx = new Dir2Xml();
dx.setPath(wsdlDir.getPath());
result = dx.getDirList();
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
} finally {
try {
if (zipOut != null) {
zipOut.close();
}
if (fullWsdlOut != null) {
fullWsdlOut.close();
}
} catch (IOException e1) {
log.warn("exception closing outputstream", e1);
}
}
return new PipeRunResult(getSuccessForward(), result);
}
use of nl.nn.adapterframework.receivers.Receiver in project iaf by ibissource.
the class FxfListener method warn.
private void warn(String msg, Throwable t) {
log.warn(msg, t);
Receiver receiver = getReceiver();
if (receiver != null) {
IAdapter iAdapter = receiver.getAdapter();
if (iAdapter != null) {
iAdapter.getMessageKeeper().add("WARNING: " + msg + (t != null ? ": " + t.getMessage() : ""), MessageKeeperLevel.WARN);
}
}
}
use of nl.nn.adapterframework.receivers.Receiver in project iaf by ibissource.
the class Webservices method getWebServices.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/webservices")
@Relation("webservices")
@Produces(MediaType.APPLICATION_JSON)
public Response getWebServices() throws ApiException {
Map<String, Object> returnMap = new HashMap<String, Object>();
List<Map<String, Object>> webServices = new ArrayList<Map<String, Object>>();
for (Adapter adapter : getIbisManager().getRegisteredAdapters()) {
for (Receiver receiver : adapter.getReceivers()) {
IListener listener = receiver.getListener();
if (listener instanceof RestListener) {
RestListener rl = (RestListener) listener;
Map<String, Object> service = new HashMap<String, Object>();
service.put("name", adapter.getName() + " " + receiver.getName());
service.put("method", rl.getMethod());
service.put("view", rl.isView());
service.put("uriPattern", rl.getUriPattern());
webServices.add(service);
}
}
}
returnMap.put("services", webServices);
List<Map<String, Object>> wsdls = new ArrayList<Map<String, Object>>();
for (Adapter adapter : getIbisManager().getRegisteredAdapters()) {
Map<String, Object> wsdlMap = null;
try {
if (WsdlGeneratorUtils.canProvideWSDL(adapter)) {
// check eligibility
wsdlMap = new HashMap<String, Object>(2);
WsdlGenerator wsdl = new WsdlGenerator(adapter.getPipeLine());
wsdlMap.put("name", wsdl.getName());
wsdlMap.put("extension", getWsdlExtension());
}
} catch (Exception e) {
wsdlMap.put("name", adapter.getName());
if (e.getMessage() != null) {
wsdlMap.put("error", e.getMessage());
} else {
wsdlMap.put("error", e.toString());
}
}
if (wsdlMap != null) {
wsdls.add(wsdlMap);
}
}
returnMap.put("wsdls", wsdls);
// ApiListeners
List<Map<String, Object>> apiListeners = new LinkedList<Map<String, Object>>();
SortedMap<String, ApiDispatchConfig> patternClients = ApiServiceDispatcher.getInstance().getPatternClients();
for (Entry<String, ApiDispatchConfig> client : patternClients.entrySet()) {
ApiDispatchConfig config = client.getValue();
Set<HttpMethod> methods = config.getMethods();
for (HttpMethod method : methods) {
ApiListener listener = config.getApiListener(method);
Receiver receiver = listener.getReceiver();
IAdapter adapter = receiver == null ? null : receiver.getAdapter();
Map<String, Object> endpoint = new HashMap<>();
String uriPattern = listener.getUriPattern();
endpoint.put("uriPattern", uriPattern);
endpoint.put("method", method);
if (adapter != null)
endpoint.put("adapter", adapter.getName());
if (receiver != null)
endpoint.put("receiver", receiver.getName());
String schemaResource = uriPattern.substring(1).replace("/", "_") + "_" + method + "_" + "openapi.json";
endpoint.put("schemaResource", schemaResource);
apiListeners.add(endpoint);
}
}
returnMap.put("apiListeners", apiListeners);
return Response.status(Response.Status.OK).entity(returnMap).build();
}
use of nl.nn.adapterframework.receivers.Receiver in project iaf by ibissource.
the class Webservices method getServiceEndpoint.
private String getServiceEndpoint(IAdapter adapter) {
String endpoint = "external address of ibis";
Iterator it = adapter.getReceivers().iterator();
while (it.hasNext()) {
IListener listener = ((Receiver) it.next()).getListener();
if (listener instanceof WebServiceListener) {
String address = ((WebServiceListener) listener).getAddress();
if (StringUtils.isNotEmpty(address)) {
endpoint = address;
} else {
endpoint = "rpcrouter";
}
String protocol = request.isSecure() ? "https://" : "http://";
int port = request.getServerPort();
String restBaseUrl = protocol + request.getServerName() + (port != 0 ? ":" + port : "") + request.getContextPath() + "/services/";
endpoint = restBaseUrl + endpoint;
// what if there are more than 1 WebServiceListener
break;
}
}
return endpoint;
}
use of nl.nn.adapterframework.receivers.Receiver in project iaf by ibissource.
the class SlotIdRecord method getSlotmap.
private Map<String, SlotIdRecord> getSlotmap() {
Map<String, SlotIdRecord> slotmap = new HashMap<String, SlotIdRecord>();
for (Adapter adapter : getIbisManager().getRegisteredAdapters()) {
for (Receiver receiver : adapter.getReceivers()) {
ITransactionalStorage errorStorage = receiver.getErrorStorage();
if (errorStorage != null) {
String slotId = errorStorage.getSlotId();
if (StringUtils.isNotEmpty(slotId)) {
SlotIdRecord sir = new SlotIdRecord(adapter.getName(), receiver.getName(), null);
String type = errorStorage.getType();
slotmap.put(type + "/" + slotId, sir);
}
}
ITransactionalStorage messageLog = receiver.getMessageLog();
if (messageLog != null) {
String slotId = messageLog.getSlotId();
if (StringUtils.isNotEmpty(slotId)) {
SlotIdRecord sir = new SlotIdRecord(adapter.getName(), receiver.getName(), null);
String type = messageLog.getType();
slotmap.put(type + "/" + slotId, sir);
}
}
}
PipeLine pipeline = adapter.getPipeLine();
if (pipeline != null) {
for (int i = 0; i < pipeline.getPipeLineSize(); i++) {
IPipe pipe = pipeline.getPipe(i);
if (pipe instanceof MessageSendingPipe) {
MessageSendingPipe msp = (MessageSendingPipe) pipe;
ITransactionalStorage messageLog = msp.getMessageLog();
if (messageLog != null) {
String slotId = messageLog.getSlotId();
if (StringUtils.isNotEmpty(slotId)) {
SlotIdRecord sir = new SlotIdRecord(adapter.getName(), null, msp.getName());
String type = messageLog.getType();
slotmap.put(type + "/" + slotId, sir);
slotmap.put(slotId, sir);
}
}
}
}
}
}
return slotmap;
}
Aggregations