Search in sources :

Example 1 with ApiDispatchConfig

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();
}
Also used : HashMap(java.util.HashMap) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Receiver(nl.nn.adapterframework.receivers.Receiver) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) NamingException(javax.naming.NamingException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) WebApplicationException(javax.ws.rs.WebApplicationException) LinkedList(java.util.LinkedList) RestListener(nl.nn.adapterframework.http.RestListener) ApiListener(nl.nn.adapterframework.http.rest.ApiListener) ApiDispatchConfig(nl.nn.adapterframework.http.rest.ApiDispatchConfig) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) WsdlGenerator(nl.nn.adapterframework.soap.WsdlGenerator) IAdapter(nl.nn.adapterframework.core.IAdapter) HttpMethod(nl.nn.adapterframework.http.rest.ApiListener.HttpMethod) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ApiDispatchConfig

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();
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) IListener(nl.nn.adapterframework.core.IListener) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) Wsdl(nl.nn.adapterframework.soap.Wsdl) PipeRunException(nl.nn.adapterframework.core.PipeRunException) NamingException(javax.naming.NamingException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) RestListener(nl.nn.adapterframework.http.RestListener) IReceiver(nl.nn.adapterframework.core.IReceiver) ApiListener(nl.nn.adapterframework.http.rest.ApiListener) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) ApiDispatchConfig(nl.nn.adapterframework.http.rest.ApiDispatchConfig) IAdapter(nl.nn.adapterframework.core.IAdapter)

Aggregations

IOException (java.io.IOException)2 NamingException (javax.naming.NamingException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 Adapter (nl.nn.adapterframework.core.Adapter)2 IAdapter (nl.nn.adapterframework.core.IAdapter)2 IListener (nl.nn.adapterframework.core.IListener)2 RestListener (nl.nn.adapterframework.http.RestListener)2 ApiDispatchConfig (nl.nn.adapterframework.http.rest.ApiDispatchConfig)2 ApiListener (nl.nn.adapterframework.http.rest.ApiListener)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1