use of nl.nn.adapterframework.http.rest.ApiDispatchConfig 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.http.rest.ApiDispatchConfig in project iaf by ibissource.
the class Webservices method list.
private String list(IbisManager ibisManager) {
XmlBuilder webservicesXML = new XmlBuilder("webservices");
// RestListeners
XmlBuilder restsXML = new XmlBuilder("rests");
for (IAdapter a : ibisManager.getRegisteredAdapters()) {
Adapter adapter = (Adapter) a;
Iterator recIt = adapter.getReceiverIterator();
while (recIt.hasNext()) {
IReceiver receiver = (IReceiver) recIt.next();
if (receiver instanceof ReceiverBase) {
ReceiverBase rb = (ReceiverBase) receiver;
IListener listener = rb.getListener();
if (listener instanceof RestListener) {
RestListener rl = (RestListener) listener;
if (rl.isView()) {
XmlBuilder restXML = new XmlBuilder("rest");
restXML.addAttribute("name", rb.getName());
restXML.addAttribute("uriPattern", rl.getUriPattern());
restsXML.addSubElement(restXML);
}
}
}
}
}
webservicesXML.addSubElement(restsXML);
// WSDL's
XmlBuilder wsdlsXML = new XmlBuilder("wsdls");
for (IAdapter a : ibisManager.getRegisteredAdapters()) {
XmlBuilder wsdlXML = new XmlBuilder("wsdl");
try {
Adapter adapter = (Adapter) a;
Wsdl wsdl = new Wsdl(adapter.getPipeLine());
wsdlXML.addAttribute("name", wsdl.getName());
wsdlXML.addAttribute("extention", getWsdlExtention());
} catch (Exception e) {
wsdlXML.addAttribute("name", a.getName());
XmlBuilder errorXML = new XmlBuilder("error");
if (e.getMessage() != null) {
errorXML.setCdataValue(e.getMessage());
} else {
errorXML.setCdataValue(e.toString());
}
wsdlXML.addSubElement(errorXML);
}
wsdlsXML.addSubElement(wsdlXML);
}
webservicesXML.addSubElement(wsdlsXML);
// ApiListeners
XmlBuilder apiListenerXML = new XmlBuilder("apiListeners");
SortedMap<String, ApiDispatchConfig> patternClients = ApiServiceDispatcher.getInstance().getPatternClients();
for (Entry<String, ApiDispatchConfig> client : patternClients.entrySet()) {
XmlBuilder apiXML = new XmlBuilder("apiListener");
ApiDispatchConfig config = client.getValue();
Set<String> methods = config.getMethods();
for (String method : methods) {
ApiListener listener = config.getApiListener(method);
XmlBuilder methodXML = new XmlBuilder(method);
String name = listener.getName();
if (name.contains("listener of ["))
name = name.substring(13, name.length() - 1);
methodXML.addAttribute("name", name);
methodXML.addAttribute("updateEtag", listener.getUpdateEtag());
methodXML.addAttribute("isRunning", listener.isRunning());
apiXML.addSubElement(methodXML);
}
apiXML.addAttribute("uriPattern", config.getUriPattern());
apiListenerXML.addSubElement(apiXML);
}
webservicesXML.addSubElement(apiListenerXML);
return webservicesXML.toXML();
}
Aggregations