private void startJetty() throws Exception { QueuedThreadPool jettyThreadPool = new QueuedThreadPool(jettyServerThreads); Server server = new Server(jettyThreadPool); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory()); http.setPort(jettyListenPort); server.addConnector(http); ContextHandler contextHandler = new ContextHandler(); contextHandler.setHandler(botSocketHandler); server.setHandler(contextHandler); server.start(); server.join(); }
private HandlerList getAllServices() throws Exception{ // File server & Context Handler for root, also setting the index.html // to be the "welcome file", i.e, autolink on root addresses. ContextHandler rootContext = new ContextHandler(); rootContext.setContextPath("/*"); rootContext.setHandler(getResourceHandlers()); // Possible servlet lists, for all servlets or custom services you want to access later. // Warning, it might become a little bit nested if you add to many classes. ServletHandler questionHandler = new ServletHandler(); questionHandler.addServletWithMapping(QuestionHandler.class, "/question"); // Add the ResourceHandler to the server. HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { rootContext , questionHandler, }); return handlers; }
@Test public void testGetConfigWithLocalFileAndWithRemoteConfig() throws Exception { String someKey = "someKey"; String someValue = "someValue"; String anotherValue = "anotherValue"; Properties properties = new Properties(); properties.put(someKey, someValue); createLocalCachePropertyFile(properties); ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, anotherValue)); ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig); startServerWithHandlers(handler); Config config = ConfigService.getAppConfig(); assertEquals(anotherValue, config.getProperty(someKey, null)); }
private ContextHandler mockConfigServerHandler(final int statusCode, final ApolloConfig result, final boolean failedAtFirstTime) { ContextHandler context = new ContextHandler("/configs/*"); context.setHandler(new AbstractHandler() { AtomicInteger counter = new AtomicInteger(0); @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (failedAtFirstTime && counter.incrementAndGet() == 1) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); baseRequest.setHandled(true); return; } response.setContentType("application/json;charset=UTF-8"); response.setStatus(statusCode); response.getWriter().println(gson.toJson(result)); baseRequest.setHandled(true); } }); return context; }
public static void main(String[] args) throws Exception { Server server = new Server(8080); // connector // server.getConnectors()[0].getConnectionFactory(HttpConnectionFactory.class) // .setHttpCompliance(HttpCompliance.LEGACY); // server.setHandler(new HelloHandler("Hi JettyEmbeded "," light测试")); // Add a single handler on context "/hello" ContextHandler context = new ContextHandler(); context.setContextPath( "/hello" ); context.setHandler( new HelloHandler("Hi JettyEmbeded "," light测试") ); // Can be accessed using http://localhost:8080/hello server.setHandler( context ); server.start(); server.join(); }
public static void main(String[] args) throws Exception { final ApiServer api = new ApiServer(new InetSocketAddress(9998)); PrometheusConfig cfg = createPrometheusConfig(args); final Optional<File> _cfg = cfg.getConfiguration(); if (_cfg.isPresent()) registry_ = new PipelineBuilder(_cfg.get()).build(); else registry_ = new PipelineBuilder(Configuration.DEFAULT).build(); api.start(); Runtime.getRuntime().addShutdownHook(new Thread(api::close)); Server server = new Server(cfg.getPort()); ContextHandler context = new ContextHandler(); context.setClassLoader(Thread.currentThread().getContextClassLoader()); context.setContextPath(cfg.getPath()); context.setHandler(new DisplayMetrics(registry_)); server.setHandler(context); server.start(); server.join(); }
@Override public void lifeCycleStarted(LifeCycle bean) { if (bean instanceof Server) { Server server = (Server)bean; Connector[] connectors = server.getConnectors(); if (connectors == null || connectors.length == 0) { server.dumpStdErr(); throw new IllegalStateException("No Connector"); } else if (!Arrays.stream(connectors).allMatch(Connector::isStarted)) { server.dumpStdErr(); throw new IllegalStateException("Connector not started"); } ContextHandler context = server.getChildHandlerByClass(ContextHandler.class); if (context == null || !context.isAvailable()) { server.dumpStdErr(); throw new IllegalStateException("No Available Context"); } } }
public void invalidateAll(String sessionId) { synchronized (sessionsIds) { sessionsIds.remove(sessionId); //tell all contexts that may have a session object with this id to //get rid of them Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class); for (int i = 0; contexts != null && i < contexts.length; i++) { SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof HazelcastSessionManager) { ((HazelcastSessionManager) manager).invalidateSession(sessionId); } } } } }
@Override public void renewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request) { //generate a new id String newClusterId = newSessionId(request.hashCode()); synchronized (sessionsIds) { //remove the old one from the list sessionsIds.remove(oldClusterId); //add in the new session id to the list sessionsIds.add(newClusterId); //tell all contexts to update the id Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class); for (int i = 0; contexts != null && i < contexts.length; i++) { SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof HazelcastSessionManager) { ((HazelcastSessionManager) manager). renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request)); } } } } }
@Override public void invalidateAll(String sessionId) { synchronized (sessionsIds) { sessionsIds.remove(sessionId); //tell all contexts that may have a session object with this id to //get rid of them Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class); for (int i = 0; contexts != null && i < contexts.length; i++) { SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof HazelcastSessionManager) { ((HazelcastSessionManager) manager).invalidateSession(sessionId); } } } } }
/** * * @param webapp * @return */ private static ContextHandlerCollection setupHttpsRedirect(WebAppContext webapp) { /*HANDLERS BUSINESS*/ SecuredRedirectHandler securedRedirect = new SecuredRedirectHandler(); // Establish all handlers that have a context ContextHandlerCollection contextHandlers = new ContextHandlerCollection(); webapp.setVirtualHosts(new String[]{"@secured"}); // handles requests that come through the sslConnector connector ... ContextHandler redirectHandler = new ContextHandler(); redirectHandler.setContextPath("/"); redirectHandler.setHandler(securedRedirect); redirectHandler.setVirtualHosts(new String[]{"@unsecured"}); // handls requests that come through the Connector (unsecured) ... contextHandlers.setHandlers(new Handler[]{redirectHandler, webapp}); return contextHandlers; }
private static void logStartupBanner(Server server) { Object banner = null; ContextHandler contextHandler = server.getChildHandlerByClass(ContextHandler.class); if (contextHandler != null) { Context context = contextHandler.getServletContext(); if (context != null) { banner = context.getAttribute("nexus-banner"); } } StringBuilder buf = new StringBuilder(); buf.append("\n-------------------------------------------------\n\n"); buf.append("Started ").append(banner instanceof String ? banner : "Nexus Repository Manager"); buf.append("\n\n-------------------------------------------------"); log.info(buf.toString()); }
ContextHandler jsp(String ctx, File templateDir, String descriptor) { File tempDir = new File(System.getProperty("java.io.tmpdir")); File scratchDir = new File(tempDir.toString(), "jtr"); if (!scratchDir.exists()) { if (!scratchDir.mkdirs()) { throw new RuntimeException("Unable to create scratch directory: " + scratchDir); } } final WebAppContext context = new WebAppContext(templateDir.getAbsolutePath(), ctx); final URL url = getClass().getProtectionDomain().getCodeSource().getLocation(); if (url != null) { // tld could be scanned under the META-INF/ after add shade jar context.getMetaData().addWebInfJar(Resource.newResource(url)); descriptor = descriptor == null ? "jar:" + url + "!/empty-web.xml" : descriptor; context.setDescriptor(descriptor); } context.setAttribute(INCLUDE_JAR_PATTERN, JSP_PATTERN); context.setAttribute("javax.servlet.context.tempdir", scratchDir); context.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers()); context.addBean(new ServletContainerInitializersStarter(context), true); context.setClassLoader(new URLClassLoader(new URL[0], getClass().getClassLoader())); return context; }
public static void main(String[] args) throws Exception { URI baseUri = UriBuilder.fromUri("http://localhost").port(SERVER_PORT) .build(); ResourceConfig config = new ResourceConfig(Calculator.class); Server server = JettyHttpContainerFactory.createServer(baseUri, config, false); ContextHandler contextHandler = new ContextHandler("/rest"); contextHandler.setHandler(server.getHandler()); ProtectionDomain protectionDomain = EmbeddedServer.class .getProtectionDomain(); URL location = protectionDomain.getCodeSource().getLocation(); ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setWelcomeFiles(new String[] { "index.html" }); resourceHandler.setResourceBase(location.toExternalForm()); System.out.println(location.toExternalForm()); HandlerCollection handlerCollection = new HandlerCollection(); handlerCollection.setHandlers(new Handler[] { resourceHandler, contextHandler, new DefaultHandler() }); server.setHandler(handlerCollection); server.start(); server.join(); }
@Override public ContextHandler createContextHandler(Environment environment) { String appName = environment.getApplicationName(); String docsRootPath = environment.getValue(appName + ".docs.root"); if (docsRootPath != null && containsDocumentation(Paths.get(docsRootPath))) { return createDocumentationContext(Paths.get(docsRootPath)); } Path root = environment.getApplicationRoot(); if (root != null && containsDocumentation(root.resolve(DEFAULT_DOCS_FOLDER))) { return createDocumentationContext(root.resolve(DEFAULT_DOCS_FOLDER)); } String appBasePath = environment.getValue(APPLICATION_BASE); if (appBasePath != null && Files.isDirectory(Paths.get(appBasePath)) && containsDocumentation(Paths.get(appBasePath).resolve(DEFAULT_DOCS_FOLDER))) { return createDocumentationContext(Paths.get(appBasePath).resolve(DEFAULT_DOCS_FOLDER)); } return null; }
@Override public ContextHandler createContextHandler(App app) throws IOException { URL appResource = ClassLoader.getSystemResource(app.getOriginId()); if (appResource == null) { throw new FileNotFoundException("Web application not found"); } WebAppContext contextHandler = new WebAppContext(); // Excluding some from the server classes for Weld to work. contextHandler.prependServerClass( "-org.eclipse.jetty.server.handler.ContextHandler"); contextHandler.prependServerClass( "-org.eclipse.jetty.servlet.ServletContextHandler"); contextHandler.prependServerClass( "-org.eclipse.jetty.servlet.ServletHandler"); contextHandler.setWar(appResource.toString()); return contextHandler; }
/** * do setup for the static resource handler * @return ContextHandler for the static resource handler */ private static ContextHandler setUpGuiHandler() throws MalformedURLException { ContextHandler context1 = new ContextHandler(); context1.setContextPath("/"); ResourceHandler res = new ResourceHandler(); res.setWelcomeFiles(new String[]{"index.html"}); res.setBaseResource(Resource.newResource("./resources/")); context1.setHandler(res); logger.info("<---gui handler initialised--->"); // WebAppContext webApp = new WebAppContext(); // webApp.setContextPath("/"); // webApp.setResourceBase("/home/orpheus/projects/BeSeen/BeSeenium/resources/"); // webApp.setWar("/home/orpheus/projects/BeSeen/BeSeenium/resources/quercus-4.0.18.war"); // webApp.setServer(server); // context1.setHandler(webApp); return context1; }
private ContextHandler systemRestart() { AbstractHandler system = new AbstractHandler() { @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { restartContexts(); response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); response.getWriter().println("<h1>Done</h1>"); } }; ContextHandler context = new ContextHandler(); context.setContextPath("/vraptor/restart"); context.setResourceBase("."); context.setClassLoader(Thread.currentThread().getContextClassLoader()); context.setHandler(system); return context; }
private static void startServer(String workingDir, List<String> specificWARs) throws Exception { Server server = new Server(port); List<ContextHandler> warHandlers = createWarHandlers(workingDir, specificWARs); Handler indexHandler = createIndexContext(warHandlers); List<Handler> allHandlers = new ArrayList<Handler>(); allHandlers.addAll(warHandlers); allHandlers.add(indexHandler); HandlerList handlerList = new HandlerList(); handlerList.setHandlers(allHandlers.toArray(new Handler[]{})); server.setHandler(handlerList); server.start(); info("\n##############################\n# Server up on port " + port + "!\n##############################"); server.join(); }
private static List<ContextHandler> createWarHandlers(String workingDir, List<String> specificWARsRequested) { final List<ContextHandler> warHandlers = new ArrayList<ContextHandler>(); if (specificWARsRequested != null) { warHandlers.addAll(createWarContexts(gatherSpecificWars(specificWARsRequested).toArray(new File[]{}))); } else { warHandlers.addAll(createWarContexts(findWarFiles(new File(workingDir)))); String warsDir = workingDir + "/wars"; warHandlers.addAll(createWarContexts(findWarFiles(new File(warsDir)))); String distDir = workingDir + "/dist"; warHandlers.addAll(createWarContexts(findWarFiles(new File(distDir)))); if (warHandlers.isEmpty()) { info("No WAR files found in " + workingDir + ", " + warsDir + ", or " + distDir + ". \nExiting."); System.exit(0); } } return warHandlers; }
private static List<ContextHandler> createWarContexts(File[] warFiles) { List<ContextHandler> result = new ArrayList<ContextHandler>(); for (final File warFile : warFiles) { final String contextPath = "/" + warFile.getName().replaceAll("\\.war$", ""); info("Nomcat: Serving " + warFile.getName() + " at " + contextPath); result.add(new WebAppContext() {{ setContextPath(contextPath); setWar(warFile.toURI().toString()); setThrowUnavailableOnStartupException(true); }}); } return result; }
/** * stop it and remove the context * @throws just about anything, caller would be wise to catch Throwable */ static void stopWebApp(String appName) { ContextHandler wac = getWebApp(appName); if (wac == null) return; try { // not graceful is default in Jetty 6? wac.stop(); } catch (Exception ie) {} ContextHandlerCollection server = getConsoleServer(); if (server == null) return; try { server.removeHandler(wac); server.mapContexts(); } catch (IllegalStateException ise) {} }
/** @since Jetty 6 */ static ContextHandler getWebApp(String appName) { ContextHandlerCollection server = getConsoleServer(); if (server == null) return null; Handler handlers[] = server.getHandlers(); if (handlers == null) return null; String path = '/'+ appName; for (int i = 0; i < handlers.length; i++) { if (!(handlers[i] instanceof ContextHandler)) continue; ContextHandler ch = (ContextHandler) handlers[i]; if (path.equals(ch.getContextPath())) return ch; } return null; }
@Override protected void doPreStart() { ContextHandler welcomeContext = new ContextHandler("/"); welcomeContext.setContextPath("/"); welcomeContext.setHandler(new WelcomeHandler(gpapProjectsFolder)); ContextHandler projectsListContext = new ContextHandler("/stage_gplist_download"); projectsListContext.setHandler(new ProjectListHandler(gpapProjectsFolder)); ContextHandler projectDownloadContext = new ContextHandler("/stage_gpproject_download"); projectDownloadContext.setHandler(new ProjectDownloadHandler(gpapProjectsFolder)); ContextHandler projectUploadContext = new ContextHandler("/stage_gpproject_upload"); projectUploadContext.setHandler(new ProjectUploadHandler(gpapProjectsFolder)); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[]{welcomeContext, projectDownloadContext, projectUploadContext, projectsListContext}); _server.setHandler(contexts); }
@Override public HttpServer listen(int port) throws Exception { SessionHandler sessionHandler = new SessionHandler(app.configuration(SessionManager.class)); sessionHandler.setHandler(new MiddlewareHandler(app)); ContextHandler context = new ContextHandler(); context.setContextPath("/"); context.setResourceBase("."); context.setClassLoader(Thread.currentThread().getContextClassLoader()); context.setHandler(sessionHandler); Server server = new Server(port); server.setSessionIdManager(new HashSessionIdManager()); server.setHandler(context); server.start(); server.join(); return this; }
@Test public void testCreateHandlersCoversExpectedContextPaths() { ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(); WebServer webServer = new WebServer(/* port */ 9999, projectFilesystem, "/static/"); List<ContextHandler> handlers = webServer.createHandlers(); final Map<String, ContextHandler> contextPathToHandler = Maps.newHashMap(); for (ContextHandler handler : handlers) { contextPathToHandler.put(handler.getContextPath(), handler); } Function<String, TemplateHandlerDelegate> getDelegate = new Function<String, TemplateHandlerDelegate>() { @Override public TemplateHandlerDelegate apply(String contextPath) { return ((TemplateHandler) contextPathToHandler.get(contextPath).getHandler()) .getDelegate(); } }; assertTrue(getDelegate.apply("/") instanceof IndexHandlerDelegate); assertTrue(contextPathToHandler.get("/static").getHandler() instanceof ResourceHandler); assertTrue(getDelegate.apply("/trace") instanceof TraceHandlerDelegate); assertTrue(getDelegate.apply("/traces") instanceof TracesHandlerDelegate); assertTrue(contextPathToHandler.get("/tracedata").getHandler() instanceof TraceDataHandler); }
@Test public void testCreateHandlersCoversExpectedContextPaths() { ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(); WebServer webServer = new WebServer(/* port */ 9999, projectFilesystem); ImmutableList<ContextHandler> handlers = webServer.createHandlers(); final Map<String, ContextHandler> contextPathToHandler = new HashMap<>(); for (ContextHandler handler : handlers) { contextPathToHandler.put(handler.getContextPath(), handler); } Function<String, TemplateHandlerDelegate> getDelegate = contextPath -> ((TemplateHandler) contextPathToHandler.get(contextPath).getHandler()).getDelegate(); assertTrue(getDelegate.apply("/") instanceof IndexHandlerDelegate); assertTrue(contextPathToHandler.get("/static").getHandler() instanceof StaticResourcesHandler); assertTrue(getDelegate.apply("/trace") instanceof TraceHandlerDelegate); assertTrue(getDelegate.apply("/traces") instanceof TracesHandlerDelegate); assertTrue(contextPathToHandler.get("/tracedata").getHandler() instanceof TraceDataHandler); }
public static void main(String[] args) throws Exception { Server server = new Server(8085); ContextHandler context = new ContextHandler("/"); context.setContextPath("/"); context.setHandler(new HandlerGUI("Root Hello")); ContextHandler contextFR = new ContextHandler("/fr"); contextFR.setHandler(new HandlerGUI("Bonjoir")); ContextHandler contextIT = new ContextHandler("/it"); contextIT.setHandler(new HandlerGUI("Bongiorno")); ContextHandler contextV = new ContextHandler("/"); contextV.setVirtualHosts(new String[] { "127.0.0.2" }); contextV.setHandler(new HandlerGUI("Virtual Hello")); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[] { context, contextFR, contextIT, contextV }); server.setHandler(contexts); server.start(); server.join(); }
@Override protected void configServer(Server server, int port) { ServerConnector connector = new ServerConnector(server); connector.setPort(port); server.setConnectors(new Connector[]{connector}); ResourceHandler handler = new ResourceHandler(); ContextHandler context = new ContextHandler(); context.setContextPath("/dbus/"); context.setResourceBase(SystemUtils.USER_DIR + File.separator + "html"); context.setHandler(handler); server.setHandler(context); }
public void run() { try { System.out.println("Listening on Reqs..."); Server server = new Server(Config.PORT); // Handler for the voting API ContextHandler votingContext = new ContextHandler(); votingContext.setContextPath("/vote"); votingContext.setHandler(new VoteHandler()); // Handler for the stats API ContextHandler statContext = new ContextHandler(); statContext.setContextPath("/stats"); statContext.setHandler(new StatsHandler()); // summing all the Handlers up to one ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[] { votingContext, statContext}); server.setHandler(contexts); server.start(); server.join(); } catch (Exception e) { e.printStackTrace(); } }
protected ContextHandler getUIWSHandler() { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); ServletHolder holderEvents = getServlet(); context.addServlet(holderEvents, "/dashboard/har"); return context; }
/** * onWrapServletContext Jetty的场景下需要采用一些Wrapper来替代Proxy,因为不全是接口 * * @param args */ public ContextHandler.Context onWrapServletContext(Object... args) { ServletContextHandler.Context oContext = (ServletContextHandler.Context) args[0]; ServletContextHandlerWrapper.JettyContextWrapper ctx = new ServletContextHandlerWrapper().new JettyContextWrapper( oContext); return ctx; }
public ServletContextHandler(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler,int options) { super((ContextHandler.Context)null); _options=options; _scontext = new Context(); _sessionHandler = sessionHandler; _securityHandler = securityHandler; _servletHandler = servletHandler; if (contextPath!=null) setContextPath(contextPath); if (parent instanceof HandlerWrapper) ((HandlerWrapper)parent).setHandler(this); else if (parent instanceof HandlerCollection) ((HandlerCollection)parent).addHandler(this); // Link the handlers relinkHandlers(); if (errorHandler!=null) setErrorHandler(errorHandler); this.addFilter(new FilterHolder(new HTTPAuthFilter()), "/v2/*", EnumSet.allOf(DispatcherType.class)); }
@Override public RequestDispatcher getNamedDispatcher(String name) { ContextHandler context=org.eclipse.jetty.servlet.ServletContextHandler.this; if (_servletHandler==null) return null; ServletHolder holder = _servletHandler.getServlet(name); if (holder==null || !holder.isEnabled()) return null; return new Dispatcher(context, name); }
/** * init and start a jetty server, remember to call server.stop when the task is finished * @param handlers * @throws Exception */ protected Server startServerWithHandlers(ContextHandler... handlers) throws Exception { server = new Server(PORT); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(handlers); contexts.addHandler(mockMetaServerHandler()); server.setHandler(contexts); server.start(); return server; }
protected ContextHandler mockMetaServerHandler(final boolean failedAtFirstTime) { final ServiceDTO someServiceDTO = new ServiceDTO(); someServiceDTO.setAppName(someAppName); someServiceDTO.setInstanceId(someInstanceId); someServiceDTO.setHomepageUrl(configServiceURL); final AtomicInteger counter = new AtomicInteger(0); ContextHandler context = new ContextHandler("/services/config"); context.setHandler(new AbstractHandler() { @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (failedAtFirstTime && counter.incrementAndGet() == 1) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); baseRequest.setHandled(true); return; } response.setContentType("application/json;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println(gson.toJson(Lists.newArrayList(someServiceDTO))); baseRequest.setHandled(true); } }); return context; }