WorkflowModelDataSourceServlet extends SlingSafeMethodsServlet { @Override protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws ServletException, IOException { try { WorkflowSession workflowSession = request.getResourceResolver().adaptTo(WorkflowSession.class); ArrayList<Resource> resources = new ArrayList<>(); if (workflowSession != null) { WorkflowModel[] models = workflowSession.getModels(); for (WorkflowModel model : models) { resources.add(new WorkflowModelResource(model, request.getResourceResolver())); } } SimpleDataSource dataSource = new SimpleDataSource(resources.iterator()); request.setAttribute(DataSource.class.getName(), dataSource); } catch (WorkflowException e) { throw new ServletException(e); } }   final static String RESOURCE_TYPE; }
@Test public void testDataSource() throws Exception { context.currentResource("/apps/workflowdatasource"); WorkflowModelDataSourceServlet dataSourceServlet = new WorkflowModelDataSourceServlet(); dataSourceServlet.doGet(context.request(), context.response()); DataSource dataSource = (DataSource) context.request().getAttribute(DataSource.class.getName()); assertNotNull(dataSource); Resource resource = dataSource.iterator().next(); assertEquals("Workflow Title", resource.getValueMap().get("text", String.class)); assertEquals("test/workflow", resource.getValueMap().get("value", String.class)); }