Search in sources :

Example 1 with WebServer

use of net.sourceforge.processdash.net.http.WebServer in project processdash by dtuma.

the class TinyCGIBase method getRequestURLBase.

/**
     * Return the base URL of the dashboard web server, as it was accessed
     * during the HTTP request that invoked this script.  The result will
     * include the protocol, the hostname, and the port.  It will not include
     * a trailing slash.
     * 
     * Examples: http://localhost:2468 or http://somehostname:3000
     * 
     * @since 1.14.3.1
     */
protected String getRequestURLBase() {
    WebServer ws = getTinyWebServer();
    // get the host that was used to make this request from the http headers
    String fullHostAndPort = (String) env.get("HTTP_HOST");
    if (StringUtils.hasValue(fullHostAndPort))
        return "http://" + fullHostAndPort;
    // if the http request did not contain a host header, reconstruct the
    // host and port from other values at our disposal.
    String host = (String) env.get("SERVER_ADDR");
    if (!StringUtils.hasValue(host))
        host = ws.getHostName(true);
    // get the port number that the server is listening on
    int port = ws.getPort();
    // return the appropriate value
    return "http://" + host + ":" + port;
}
Also used : WebServer(net.sourceforge.processdash.net.http.WebServer)

Example 2 with WebServer

use of net.sourceforge.processdash.net.http.WebServer in project processdash by dtuma.

the class TinyCGIBase method parseInputFile.

/* Read name=value pairs from the given URI. If the URI is not
     * absolute (e.g. "/reports/foo"), it is interpreted relative
     * to the current request. */
protected void parseInputFile(String scriptPath, String filename) throws IOException {
    if (filename == null || filename.length() == 0)
        return;
    WebServer t = getTinyWebServer();
    String origFilename = filename;
    try {
        filename = resolveRelativeURI(scriptPath, filename);
        parseInput(filename, t.getRequestAsString(filename));
        // values from it as well.
        try {
            String bundleName = filename;
            int pos = bundleName.indexOf("//");
            if (pos != -1)
                bundleName = bundleName.substring(pos + 1);
            pos = bundleName.lastIndexOf('.');
            if (pos != -1 && bundleName.indexOf('/', pos) == -1)
                bundleName = bundleName.substring(0, pos);
            Resources bundle = Resources.getTemplateBundle(bundleName);
            parameters.putAll(bundle.asMap());
        } catch (Exception e) {
        // it is not an error if no companion bundle was found.
        }
    } catch (IOException ioe) {
        System.out.println("Couldn't read file: " + filename);
        System.out.println("(Specified as '" + origFilename + "' from '" + scriptPath + "')");
    }
}
Also used : WebServer(net.sourceforge.processdash.net.http.WebServer) Resources(net.sourceforge.processdash.i18n.Resources) IOException(java.io.IOException) TinyCGIException(net.sourceforge.processdash.net.http.TinyCGIException) MalformedURLException(java.net.MalformedURLException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException)

Example 3 with WebServer

use of net.sourceforge.processdash.net.http.WebServer in project processdash by dtuma.

the class SnippetInvoker method invoke.

/** Invoke a single snippet.
     *
     * @param snippet the snippet to run
     * @return the content generated by the snippet
     * @throws IOException if an error was encountered
     */
public String invoke(SnippetInstanceTO snippet) throws IOException {
    if (!test(snippet))
        return null;
    SnippetDefinition defn = snippet.getDefinition();
    if (XMLUtils.hasValue(mode) && !"view".equalsIgnoreCase(mode) && !defn.getModes().contains(mode)) {
        snippet.setStatus(SnippetInvoker.UNSUPPORTED_MODE);
        return null;
    }
    String uri = defn.getUri(mode, action);
    if (uri == null) {
        snippet.setStatus(SnippetInvoker.UNSUPPORTED_MODE);
        return null;
    }
    String namespace = snippet.getNamespace();
    Map extraEnvironment = new HashMap();
    extraEnvironment.put(SNIPPET_ID, snippet.getSnippetID());
    extraEnvironment.put(SNIPPET_VERSION, snippet.getSnippetVersion());
    extraEnvironment.put(PERSISTED_TEXT, snippet.getPersistedText());
    extraEnvironment.put(RESOURCES, defn.getResources());
    extraEnvironment.put(HTMLPreprocessor.REPLACEMENTS_PARAM, Collections.singletonMap("$$$_", namespace));
    for (int i = 0; i < PROPAGATE_TO_ENV.length; i++) extraEnvironment.put(PROPAGATE_TO_ENV[i], parentParameters.get(PROPAGATE_TO_ENV[i]));
    StringBuffer queryString = new StringBuffer(this.queryString);
    addNamespacedParameters(parentParameters, namespace, queryString);
    if (defn.shouldParsePersistedText())
        addParsedParameters(snippet.getPersistedText(), queryString);
    StringBuffer fullUri = new StringBuffer();
    fullUri.append(WebServer.urlEncodePath(prefix)).append("/").append(uri);
    HTMLUtils.appendQuery(fullUri, queryString.toString());
    WebServer webServer = (WebServer) parentEnv.get(TinyCGI.TINY_WEB_SERVER);
    try {
        String results = webServer.getRequestAsString(fullUri.toString(), extraEnvironment);
        snippet.setStatus(SnippetInvoker.STATUS_OK);
        snippet.setUri(fullUri.toString());
        return results;
    } catch (IOException ioe) {
        snippet.setStatus(SnippetInvoker.STATUS_INTERNAL_ERROR);
        snippet.setInvocationException(ioe);
        throw ioe;
    }
}
Also used : HashMap(java.util.HashMap) WebServer(net.sourceforge.processdash.net.http.WebServer) IOException(java.io.IOException) SnippetDefinition(net.sourceforge.processdash.ui.snippet.SnippetDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with WebServer

use of net.sourceforge.processdash.net.http.WebServer in project processdash by dtuma.

the class DataExtractionScaffold method init.

public void init() throws Exception {
    DashController.setDataDirectory(dataDirectory);
    String dataDirPath = dataDirectory.getAbsolutePath() + System.getProperty("file.separator");
    // load and initialize settings
    String settingsFilename = dataDirPath + InternalSettings.getSettingsFilename();
    InternalSettings.initialize(settingsFilename);
    InternalSettings.setReadOnly(true);
    InternalSettings.set(SCAFFOLD_MODE_SETTING, "true");
    InternalSettings.set("templates.disableSearchPath", "true");
    InternalSettings.set("export.disableAutoExport", "true");
    InternalSettings.set("slowNetwork", "true");
    for (Map.Entry<String, String> e : extraSettings.entrySet()) {
        InternalSettings.set(e.getKey(), e.getValue());
    }
    extraSettings = null;
    // reset the template loader search path
    TemplateLoader.resetTemplateURLs();
    // setup the defect analyzer
    DefectAnalyzer.setDataDirectory(dataDirPath);
    // possibly initialize external resource mappings
    if (useExternalResourceMappingFile)
        ExternalResourceManager.getInstance().initializeMappings(dataDirectory, ExternalResourceManager.INITIALIZATION_MODE_ARCHIVE);
    // create the data repository.
    data = new DataRepository();
    DashHierarchy templates = TemplateLoader.loadTemplates(data);
    data.setDatafileSearchURLs(TemplateLoader.getTemplateURLs());
    // open and load the the user's work breakdown structure
    hierarchy = new DashHierarchy(null);
    String hierFilename = dataDirPath + Settings.getFile("stateFile");
    hierarchy.loadXML(hierFilename, templates);
    data.setNodeComparator(hierarchy);
    // create the time log
    timeLog = new WorkingTimeLog(dataDirectory);
    DashboardTimeLog.setDefault(timeLog);
    // open all the datafiles that were specified in the properties file.
    data.startInconsistency();
    openDataFiles(dataDirPath, PropertyKey.ROOT);
    data.openDatafile("", dataDirPath + "global.dat");
    // import data files
    DataImporter.setDynamic(false);
    ImportManager.init(data);
    data.finishInconsistency();
    // configure the task dependency resolver
    EVTaskDependencyResolver.init(this);
    EVTaskDependencyResolver.getInstance().setDynamic(false);
    if (createWebServer) {
        DashboardURLStreamHandlerFactory.disable();
        try {
            webServer = new WebServer();
            webServer.setDashboardContext(this);
            webServer.setData(data);
            webServer.setProps(hierarchy);
            webServer.setRoots(TemplateLoader.getTemplateURLs());
            WebServer.setOutputCharset(getWebCharset());
        } catch (IOException ioe) {
        }
    }
}
Also used : WebServer(net.sourceforge.processdash.net.http.WebServer) DashHierarchy(net.sourceforge.processdash.hier.DashHierarchy) DataRepository(net.sourceforge.processdash.data.repository.DataRepository) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) WorkingTimeLog(net.sourceforge.processdash.log.time.WorkingTimeLog)

Example 5 with WebServer

use of net.sourceforge.processdash.net.http.WebServer in project processdash by dtuma.

the class AnalysisPage method writeChart.

protected void writeChart(HttpServletRequest req, HttpServletResponse resp, ChartData chartData, String chartId, String... chartArgs) throws ServletException, IOException {
    // retrieve the data to display in the chart. If the data for this chart
    // cannot be calculated for the given dataset, abort.
    Entry<Chart, Method> chart = getChartById(chartId);
    chartData.chartArgs = chartArgs;
    Map chartParams;
    try {
        chartParams = invokeChart(chart, chartData);
        if (chartParams == null)
            return;
    } catch (ServletException se) {
        resp.getWriter().write(//
        "<!-- Could not calculate data for chart '" + chartId + "', encountered error:\n");
        se.printStackTrace(resp.getWriter());
        resp.getWriter().write("\n -->\n");
        return;
    }
    // build query parameters that can be used to request this chart later
    Chart metadata = chart.getKey();
    StringBuffer chartDataArgs = new StringBuffer("x");
    HTMLUtils.appendQuery(chartDataArgs, "dqf", selfUri);
    HTMLUtils.appendQuery(chartDataArgs, "workflow", chartData.histData.getWorkflowID());
    HTMLUtils.appendQuery(chartDataArgs, "type", chartId);
    for (int i = 0; i < chartArgs.length; i++) {
        HTMLUtils.appendQuery(chartDataArgs, metadata.params()[i], chartArgs[i]);
    }
    // use the query parameters to build a URL for the chart details view
    String fullURL;
    if (isExporting(req))
        fullURL = "table.class";
    else {
        fullURL = "full.htm";
        HTMLUtils.appendQuery(chartDataArgs, "chart", metadata.type());
    }
    String href = fullURL + "?" + chartDataArgs.substring(2);
    chartParams.put("href", href);
    chartParams.putAll(parseFormatParams(chartData, metadata.smallFmt()));
    // make an internal request to the CGI script for the given chart,
    // and write the resulting HTML fragment to the response
    String chartHtmlUri = "/reports/" + metadata.type() + ".class" + "?qf=small.rpt&html";
    WebServer webServer = (WebServer) PDashServletUtils.buildEnvironment(req).get(TinyCGI.TINY_WEB_SERVER);
    String chartHtml = webServer.getRequestAsString(chartHtmlUri, Collections.singletonMap("REQUEST_PARAMS", chartParams));
    resp.getWriter().write(chartHtml);
    resp.getWriter().write(" \n");
}
Also used : ServletException(javax.servlet.ServletException) WebServer(net.sourceforge.processdash.net.http.WebServer) Method(java.lang.reflect.Method) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

WebServer (net.sourceforge.processdash.net.http.WebServer)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 MalformedURLException (java.net.MalformedURLException)2 Method (java.lang.reflect.Method)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 MissingResourceException (java.util.MissingResourceException)1 ServletException (javax.servlet.ServletException)1 DataRepository (net.sourceforge.processdash.data.repository.DataRepository)1 DashHierarchy (net.sourceforge.processdash.hier.DashHierarchy)1 Resources (net.sourceforge.processdash.i18n.Resources)1 WorkingTimeLog (net.sourceforge.processdash.log.time.WorkingTimeLog)1 TinyCGIException (net.sourceforge.processdash.net.http.TinyCGIException)1 SnippetDefinition (net.sourceforge.processdash.ui.snippet.SnippetDefinition)1