use of nl.nn.adapterframework.soap.WsdlGenerator 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.soap.WsdlGenerator 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.soap.WsdlGenerator in project iaf by ibissource.
the class Webservices method getWsdl.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/webservices/{resourceName}")
@Relation("webservices")
@Produces(MediaType.APPLICATION_XML)
public Response getWsdl(@PathParam("resourceName") String resourceName, @DefaultValue("true") @QueryParam("indent") boolean indent, @DefaultValue("false") @QueryParam("useIncludes") boolean useIncludes) throws ApiException {
String adapterName;
boolean zip;
int dotPos = resourceName.lastIndexOf('.');
if (dotPos >= 0) {
adapterName = resourceName.substring(0, dotPos);
zip = resourceName.substring(dotPos).equals(".zip");
} else {
adapterName = resourceName;
zip = false;
}
if (StringUtils.isEmpty(adapterName)) {
return Response.status(Response.Status.BAD_REQUEST).entity("<error>no adapter specified</error>").build();
}
IAdapter adapter = getIbisManager().getRegisteredAdapter(adapterName);
if (adapter == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("<error>adapter not found</error>").build();
}
try {
String servletName = getServiceEndpoint(adapter);
String generationInfo = "by FrankConsole";
WsdlGenerator wsdl = new WsdlGenerator(adapter.getPipeLine(), generationInfo);
wsdl.setIndent(indent);
wsdl.setUseIncludes(useIncludes || zip);
wsdl.init();
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException, WebApplicationException {
try {
if (zip) {
wsdl.zip(out, servletName);
} else {
wsdl.wsdl(out, servletName);
}
} catch (ConfigurationException | XMLStreamException | NamingException e) {
throw new WebApplicationException(e);
}
}
};
ResponseBuilder responseBuilder = Response.ok(stream);
if (zip) {
responseBuilder.type(MediaType.APPLICATION_OCTET_STREAM);
responseBuilder.header("Content-Disposition", "attachment; filename=\"" + adapterName + ".zip\"");
}
return responseBuilder.build();
} catch (Exception e) {
throw new ApiException("exception on retrieving wsdl", e);
}
}
use of nl.nn.adapterframework.soap.WsdlGenerator in project iaf by ibissource.
the class WsdlGeneratorPipe method doPipe.
@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
String result = null;
Adapter adapter;
try {
if ("input".equals(getFrom())) {
String adapterName = message.asString();
adapter = getAdapter().getConfiguration().getIbisManager().getRegisteredAdapter(adapterName);
if (adapter == null) {
throw new PipeRunException(this, "Could not find adapter: " + adapterName);
}
} else {
adapter = getPipeLine().getAdapter();
}
} catch (IOException e) {
throw new PipeRunException(this, "Could not determine adapter name", e);
}
try {
String generationInfo = "at " + RestListenerUtils.retrieveRequestURL(session);
WsdlGenerator wsdl = new WsdlGenerator(adapter.getPipeLine(), generationInfo);
wsdl.init();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
wsdl.wsdl(outputStream, null);
result = outputStream.toString(StreamUtil.DEFAULT_INPUT_STREAM_ENCODING);
} catch (Exception e) {
throw new PipeRunException(this, "Could not generate WSDL for adapter [" + adapter.getName() + "]", e);
}
return new PipeRunResult(getSuccessForward(), result);
}
Aggregations