/** Starts the server for end-to-end tests. */ private Server createServer(int port) throws Exception { Server newServer = new Server(port); // Attach the test resources in /endtoend as static content for the test ResourceHandler resources = new ResourceHandler(); URL resource = EndToEndTest.class.getResource("/endtoend"); resources.setBaseResource(Resource.newResource(resource)); newServer.addHandler(resources); Context context = new Context(newServer, "/", Context.SESSIONS); context.addEventListener(new GuiceServletContextListener()); Map<String, String> initParams = Maps.newHashMap(); String modules = Joiner.on(":") .join( SampleModule.class.getName(), DefaultGuiceModule.class.getName(), PropertiesModule.class.getName(), OAuthModule.class.getName()); initParams.put(GuiceServletContextListener.MODULES_ATTRIBUTE, modules); context.setInitParams(initParams); // Attach the gadget rendering servlet ServletHolder gadgetServletHolder = new ServletHolder(new GadgetRenderingServlet()); context.addServlet(gadgetServletHolder, GADGET_BASE); // Attach DataServiceServlet, wrapped in a proxy to fake errors ServletHolder restServletHolder = new ServletHolder(new ForceErrorServlet(new DataServiceServlet())); restServletHolder.setInitParameter("handlers", "org.apache.shindig.social.handlers"); context.addServlet(restServletHolder, REST_BASE); context.addFilter(AuthenticationServletFilter.class, REST_BASE, 0); // Attach JsonRpcServlet, wrapped in a proxy to fake errors ServletHolder rpcServletHolder = new ServletHolder(new ForceErrorServlet(new JsonRpcServlet())); rpcServletHolder.setInitParameter("handlers", "org.apache.shindig.social.handlers"); context.addServlet(rpcServletHolder, JSON_RPC_BASE); context.addFilter(AuthenticationServletFilter.class, JSON_RPC_BASE, 0); // Attach the ConcatProxyServlet - needed for rewritten JS ServletHolder concatHolder = new ServletHolder(new ConcatProxyServlet()); context.addServlet(concatHolder, CONCAT_BASE); // Attach the JsServlet - needed for rewritten JS ServletHolder jsHolder = new ServletHolder(new JsServlet()); context.addServlet(jsHolder, JS_BASE); // Attach MakeRequestServlet ServletHolder makeRequestHolder = new ServletHolder(new MakeRequestServlet()); context.addServlet(makeRequestHolder, MAKE_REQUEST_BASE); // Attach an EchoServlet, used to test proxied rendering ServletHolder echoHolder = new ServletHolder(new EchoServlet()); context.addServlet(echoHolder, "/echo"); return newServer; }
private Set<File> getDependencyFiles() { List<Resource> overlays = new ArrayList<Resource>(); Set<File> dependencies = getClasspath().getFiles(); logger.debug("Adding dependencies {} for WEB-INF/lib ", dependencies); // todo incorporate overlays when our resolved dependencies provide type information // if (artifact.getType().equals("war")) { // try { // Resource r = Resource.newResource("jar:" + // artifact.getFile().toURL().toString() + "!/"); // overlays.add(r); // getExtraScanTargets().add(artifact.getFile()); // } // catch (Exception e) { // throw new RuntimeException(e); // } // continue; // } if (!overlays.isEmpty()) { try { Resource resource = getWebAppConfig().getBaseResource(); ResourceCollection rc = new ResourceCollection(); if (resource == null) { // nothing configured, so we automagically enable the overlays int size = overlays.size() + 1; Resource[] resources = new Resource[size]; resources[0] = Resource.newResource(getWebAppSourceDirectory().toURI().toURL()); for (int i = 1; i < size; i++) { resources[i] = overlays.get(i - 1); logger.info("Adding overlay: " + resources[i]); } rc.setResources(resources); } else { if (resource instanceof ResourceCollection) { // there was a preconfigured ResourceCollection ... append the artifact wars Resource[] old = ((ResourceCollection) resource).getResources(); int size = old.length + overlays.size(); Resource[] resources = new Resource[size]; System.arraycopy(old, 0, resources, 0, old.length); for (int i = old.length; i < size; i++) { resources[i] = overlays.get(i - old.length); logger.info("Adding overlay: " + resources[i]); } rc.setResources(resources); } else { // baseResource was already configured w/c could be src/main/webapp if (!resource.isDirectory() && String.valueOf(resource.getFile()).endsWith(".war")) { // its a war resource = Resource.newResource("jar:" + resource.getURL().toString() + "!/"); } int size = overlays.size() + 1; Resource[] resources = new Resource[size]; resources[0] = resource; for (int i = 1; i < size; i++) { resources[i] = overlays.get(i - 1); logger.info("Adding overlay: " + resources[i]); } rc.setResources(resources); } } getWebAppConfig().setBaseResource(rc); } catch (Exception e) { throw new RuntimeException(e); } } return dependencies; }