@Override protected void handlePost(HttpRequest request, String data) { String uri = request.getPath(); if (uri.startsWith(JSCOVERAGE_STORE)) { File reportDir = configuration.getReportDir(); if (uri.length() > JSCOVERAGE_STORE.length()) { reportDir = new File(reportDir, uri.substring(JSCOVERAGE_STORE.length())); } try { List<ScriptLinesAndSource> unloadJSData = null; if (configuration.isIncludeUnloadedJS()) unloadJSData = unloadedSourceProcessor.getEmptyCoverageData(uris); jsonDataSaver.saveJSONData(reportDir, data, unloadJSData); ioService.generateJSCoverFilesForWebServer(reportDir, configuration.getVersion()); sendResponse(HTTP_STATUS.HTTP_OK, MIME.TEXT_PLAIN, "Coverage data stored at " + reportDir); } catch (Throwable t) { t.printStackTrace(); String message = format("Error saving coverage data. Try deleting JSON file at %s\n", reportDir); sendResponse(HTTP_STATUS.HTTP_OK, MIME.TEXT_PLAIN, message); } } else { if (configuration.isProxy()) proxyService.handleProxyPost(request, data, os); else super.handlePost(request, data); } }
@Override protected void handleGet(HttpRequest request) throws IOException { String uri = request.getPath(); try { if (uri.equals("/jscoverage.js")) { sendResponse( HTTP_STATUS.HTTP_OK, request.getMime(), ioService.generateJSCoverageServerJS()); } else if (uri.startsWith("/jscoverage.html")) { String reportHTML = ioService.generateJSCoverageHtml(configuration.getVersion()); sendResponse(HTTP_STATUS.HTTP_OK, request.getMime(), reportHTML); } else if (uri.startsWith("/jscoverage")) { sendResponse(HTTP_STATUS.HTTP_OK, request.getMime(), ioService.getResourceAsStream(uri)); } else if (uri.endsWith(".js") && !configuration.skipInstrumentation(uri.substring(1))) { String jsInstrumented; if (configuration.isProxy()) { String originalJS = proxyService.getUrl(request.getUrl()); jsInstrumented = instrumenterService.instrumentJSForWebServer( configuration.getCompilerEnvirons(), originalJS, uri, configuration.isIncludeBranch()); } else { if (configuration.isIncludeUnloadedJS()) uris.add(uri.substring(1)); jsInstrumented = instrumenterService.instrumentJSForWebServer( configuration.getCompilerEnvirons(), new File(wwwRoot, uri), uri, configuration.isIncludeBranch()); } sendResponse(HTTP_STATUS.HTTP_OK, MIME.JS, jsInstrumented); } else { if (configuration.isProxy()) proxyService.handleProxyGet(request, os); else super.handleGet(request); } } catch (Throwable e) { StringWriter stringWriter = new StringWriter(); e.printStackTrace(new PrintWriter(stringWriter)); sendResponse( HTTP_STATUS.HTTP_INTERNAL_SERVER_ERROR, MIME.TEXT_PLAIN, stringWriter.toString()); } }
@Override protected void handleHead(HttpRequest request) { if (configuration.isProxy()) proxyService.handleProxyHead(request, os); else super.handleHead(request); }
public InstrumentingRequestHandler(Socket socket, ConfigurationForServer configuration) { super(socket, configuration.getDocumentRoot(), configuration.getVersion()); this.configuration = configuration; this.unloadedSourceProcessor = new UnloadedSourceProcessor(configuration); }