Example usage for javax.servlet ServletRequestWrapper getServerPort

List of usage examples for javax.servlet ServletRequestWrapper getServerPort

Introduction

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

Prototype

public int getServerPort() 

Source Link

Document

The default behavior of this method is to return getServerPort() 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 {//w  ww. j ava2  s  . c  o m
            String export = exporter.export(group, id, url);
            JsonUtils.buildJsonResult(out, export != null, export);
        }
    }
}