Example usage for javax.servlet ServletRequestWrapper getServerName

List of usage examples for javax.servlet ServletRequestWrapper getServerName

Introduction

In this page you can find the example usage for javax.servlet ServletRequestWrapper getServerName.

Prototype

public String getServerName() 

Source Link

Document

The default behavior of this method is to return getServerName() on the wrapped request object.

Usage

From source file:pt.webdetails.cdb.CdbContentGenerator.java

@Exposed(accessLevel = AccessLevel.PUBLIC)
public void export(OutputStream out) throws IOException, ExporterRuntimeException, ExporterNotFoundException {
    ExporterEngine engine = ExporterEngine.getInstance();
    IParameterProvider requestParams = getRequestParameters(), pathParams = getPathParameters();

    String method = requestParams.getStringParameter("method", "");

    if ("listExporters".equals(method)) {
        String exporters = engine.listExporters();
        JsonUtils.buildJsonResult(out, exporters != null, exporters);
    } else if ("export".equals(method)) {
        ServletRequestWrapper wrapper = (ServletRequestWrapper) pathParams.getParameter("httprequest");
        String exporterName = requestParams.getStringParameter("exporter", ""),
                group = requestParams.getStringParameter("group", ""),
                id = requestParams.getStringParameter("id", ""),
                url = wrapper.getScheme() + "://" + wrapper.getServerName() + ":" + wrapper.getServerPort()
                        + PentahoRequestContextHolder.getRequestContext().getContextPath();

        boolean toFile = requestParams.getStringParameter("toFile", "false").equals("true");
        Exporter exporter = engine.getExporter(exporterName);
        if (toFile) {
            HttpServletResponse response = (HttpServletResponse) pathParams.getParameter("httpresponse");
            String path = exporter.getFilename(group, id, url).replaceAll("\\\\", "\\\\").replaceAll("\"",
                    "\\\"");
            response.setHeader("content-disposition", "attachment; filename=\"" + path + "\"");
            exporter.binaryExport(group, id, url, out);
        } else {//from   w w w  .ja  va 2 s. co  m
            String export = exporter.export(group, id, url);
            JsonUtils.buildJsonResult(out, export != null, export);
        }
    }
}