Search in sources :

Example 66 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project iaf by ibissource.

the class TestServiceListener method getServiceListeners.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/test-servicelistener")
@Relation("servicelistener")
@Produces(MediaType.APPLICATION_JSON)
public Response getServiceListeners() throws ApiException {
    if (getIbisManager() == null) {
        throw new ApiException("Config not found!");
    }
    Map<String, Object> returnData = new HashMap<String, Object>();
    @SuppressWarnings("rawtypes") Iterator it = ServiceDispatcher.getInstance().getRegisteredListenerNames();
    List<String> services = new ArrayList<String>();
    while (it.hasNext()) {
        services.add((String) it.next());
    }
    returnData.put("services", services);
    return Response.status(Response.Status.CREATED).entity(returnData).build();
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 67 with RolesAllowed

use of javax.annotation.security.RolesAllowed 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 68 with RolesAllowed

use of javax.annotation.security.RolesAllowed 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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) NamingException(javax.naming.NamingException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) WebApplicationException(javax.ws.rs.WebApplicationException) XMLStreamException(javax.xml.stream.XMLStreamException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) NamingException(javax.naming.NamingException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) IAdapter(nl.nn.adapterframework.core.IAdapter) WsdlGenerator(nl.nn.adapterframework.soap.WsdlGenerator) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 69 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project iaf by ibissource.

the class BrowseQueue method getBrowseQueue.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("jms")
@Produces(MediaType.APPLICATION_JSON)
public Response getBrowseQueue() throws ApiException {
    Map<String, Object> returnMap = new HashMap<String, Object>();
    JndiConnectionFactoryFactory connectionFactoryFactory = getIbisContext().getBean("connectionFactoryFactory", JndiConnectionFactoryFactory.class);
    Set<String> connectionFactories = new LinkedHashSet<String>();
    // connection factories used in configured jmsSenders etc.
    connectionFactories.addAll(connectionFactoryFactory.getConnectionFactoryNames());
    // configured jms realm
    connectionFactories.addAll(JmsRealmFactory.getInstance().getConnectionFactoryNames());
    if (connectionFactories.size() == 0)
        connectionFactories.add("no connection factories found");
    returnMap.put("connectionFactories", connectionFactories);
    return Response.status(Response.Status.OK).entity(returnMap).build();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JndiConnectionFactoryFactory(nl.nn.adapterframework.jndi.JndiConnectionFactoryFactory) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 70 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project iaf by ibissource.

the class BrowseQueue method putBrowseQueue.

@POST
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("jms/browse")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response putBrowseQueue(LinkedHashMap<String, Object> json) throws ApiException {
    Map<String, Object> returnMap = new HashMap<String, Object>();
    String connectionFactory = null, destination = null;
    boolean rowNumbersOnly = false, showPayload = false, lookupDestination = false;
    DestinationType type = null;
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        if (key.equalsIgnoreCase("connectionFactory")) {
            connectionFactory = entry.getValue().toString();
        }
        if (key.equalsIgnoreCase("destination")) {
            destination = entry.getValue().toString();
        }
        if (key.equalsIgnoreCase("type")) {
            type = EnumUtils.parse(DestinationType.class, entry.getValue().toString());
        }
        if (key.equalsIgnoreCase("rowNumbersOnly")) {
            rowNumbersOnly = Boolean.parseBoolean(entry.getValue().toString());
        }
        if (key.equalsIgnoreCase("payload")) {
            showPayload = Boolean.parseBoolean(entry.getValue().toString());
        }
        if (key.equalsIgnoreCase("lookupDestination")) {
            lookupDestination = Boolean.parseBoolean(entry.getValue().toString());
        }
    }
    if (connectionFactory == null)
        throw new ApiException("No connection factory provided");
    if (destination == null)
        throw new ApiException("No destination provided");
    if (type == null)
        throw new ApiException("No type provided");
    try {
        JmsBrowser<javax.jms.Message> jmsBrowser = getIbisContext().createBeanAutowireByName(JmsBrowser.class);
        jmsBrowser.setName("BrowseQueueAction");
        if (type == DestinationType.QUEUE) {
            jmsBrowser.setQueueConnectionFactoryName(connectionFactory);
        } else {
            jmsBrowser.setTopicConnectionFactoryName(connectionFactory);
        }
        jmsBrowser.setDestinationName(destination);
        jmsBrowser.setDestinationType(type);
        jmsBrowser.setLookupDestination(lookupDestination);
        List<Map<String, Object>> messages = new ArrayList<Map<String, Object>>();
        try (IMessageBrowsingIterator it = jmsBrowser.getIterator()) {
            while (it.hasNext()) {
                IMessageBrowsingIteratorItem item = it.next();
                Map<String, Object> message = new HashMap<String, Object>();
                message.put("comment", item.getCommentString());
                message.put("correlationId", item.getCorrelationId());
                try {
                    message.put("expiryDate", item.getExpiryDate());
                } catch (Exception e) {
                    log.warn("Could not get expiryDate", e);
                }
                message.put("host", item.getHost());
                message.put("id", item.getId());
                try {
                    message.put("insertDate", item.getInsertDate());
                } catch (Exception e) {
                    log.warn("Could not get insertDate", e);
                }
                if (showPayload && item instanceof JmsMessageBrowserIteratorItem) {
                    message.put("text", ((JmsMessageBrowserIteratorItem) item).getText());
                }
                messages.add(message);
            }
        }
        log.debug("Browser returned " + messages.size() + " messages");
        returnMap.put("numberOfMessages", messages.size());
        if (!rowNumbersOnly) {
            returnMap.put("messages", messages);
        }
    } catch (Exception e) {
        throw new ApiException("Error occured browsing messages", e);
    }
    return Response.status(Response.Status.OK).entity(returnMap).build();
}
Also used : JmsMessageBrowserIteratorItem(nl.nn.adapterframework.jms.JmsMessageBrowserIteratorItem) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IMessageBrowsingIteratorItem(nl.nn.adapterframework.core.IMessageBrowsingIteratorItem) ArrayList(java.util.ArrayList) IMessageBrowsingIterator(nl.nn.adapterframework.core.IMessageBrowsingIterator) DestinationType(nl.nn.adapterframework.jms.JMSFacade.DestinationType) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Aggregations

RolesAllowed (javax.annotation.security.RolesAllowed)191 Path (javax.ws.rs.Path)127 Produces (javax.ws.rs.Produces)110 Consumes (javax.ws.rs.Consumes)55 GET (javax.ws.rs.GET)54 POST (javax.ws.rs.POST)40 PUT (javax.ws.rs.PUT)35 HashMap (java.util.HashMap)34 ArrayList (java.util.ArrayList)32 IOException (java.io.IOException)30 ApiOperation (io.swagger.annotations.ApiOperation)29 ApiResponses (io.swagger.annotations.ApiResponses)29 Response (javax.ws.rs.core.Response)28 Adapter (nl.nn.adapterframework.core.Adapter)21 DELETE (javax.ws.rs.DELETE)19 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)19 LinkedHashMap (java.util.LinkedHashMap)16 Locale (java.util.Locale)16 Map (java.util.Map)12 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)12