Search in sources :

Example 1 with HttpContextWeb

use of com.genexus.webpanels.HttpContextWeb in project JavaClasses by genexuslabs.

the class GxRestService method init.

public void init(String requestMethod, IHttpServletRequest myServletRequest, IHttpServletResponse myServletResponse, IServletContext myContext) {
    initLogger(myContext);
    try {
        String gxcfg = myContext.getInitParameter("gxcfg");
        Class gxcfgClass = getClass();
        if (gxcfg != null) {
            gxcfgClass = Class.forName(gxcfg);
            ApplicationContext appContext = ApplicationContext.getInstance();
            appContext.setServletEngine(true);
            Application.init(gxcfgClass);
        }
        restHttpContext = new HttpContextWeb(requestMethod, myServletRequest, myServletResponse, myContext);
        restHttpContext.doNotCompress(true);
        restHttpContext.setRestService();
        ModelContext.deleteThreadContext();
        super.init(restHttpContext, gxcfgClass);
        ModelContext modelContext = ModelContext.getModelContext(getClass());
        modelContext.setHttpContext(restHttpContext);
    } catch (Throwable e) {
        logger.error("Could not initialize Rest Service", e);
    }
}
Also used : HttpContextWeb(com.genexus.webpanels.HttpContextWeb)

Example 2 with HttpContextWeb

use of com.genexus.webpanels.HttpContextWeb in project JavaClasses by genexuslabs.

the class HttpClientJavaLib method SetCookieAtr.

private void SetCookieAtr(CookieStore cookiesToSend) {
    if (cookiesToSend != null) {
        if (ModelContext.getModelContext().isNullHttpContext()) {
            for (Cookie c : cookiesToSend.getCookies()) cookies.addCookie(c);
        } else {
            try {
                HttpContextWeb webcontext = ((HttpContextWeb) ModelContext.getModelContext().getHttpContext());
                Header[] headers = this.response.getHeaders(SET_COOKIE);
                if (headers.length > 0) {
                    String webcontextCookieHeader = "";
                    for (Header header : headers) {
                        String[] cookieParts = header.getValue().split(";");
                        String[] cookieKeyAndValue = cookieParts[0].split("=");
                        webcontextCookieHeader += cookieKeyAndValue[0] + "=" + cookieKeyAndValue[1] + "; ";
                    }
                    // Se quita el espacio y la coma al final
                    webcontextCookieHeader = webcontextCookieHeader.trim().substring(0, webcontextCookieHeader.length() - 2);
                    webcontext.setCookie(SET_COOKIE, webcontextCookieHeader, "", CommonUtil.nullDate(), "", this.getSecure());
                }
                ModelContext.getModelContext().setHttpContext(webcontext);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Cookie(org.apache.http.cookie.Cookie) HttpContextWeb(com.genexus.webpanels.HttpContextWeb) URISyntaxException(java.net.URISyntaxException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnknownHostException(java.net.UnknownHostException)

Example 3 with HttpContextWeb

use of com.genexus.webpanels.HttpContextWeb in project JavaClasses by genexuslabs.

the class HttpResponse method addFile.

public void addFile(String fileName) {
    resetErrors();
    try {
        if (ModelContext.getModelContext() != null && !new File(fileName).isAbsolute()) {
            IHttpContext webContext = ModelContext.getModelContext().getHttpContext();
            if ((webContext != null) && (webContext instanceof HttpContextWeb) && !fileName.isEmpty()) {
                fileName = ModelContext.getModelContext().getHttpContext().getDefaultPath() + File.separator + fileName;
            }
        }
        InputStream source = new BufferedInputStream(new FileInputStream(fileName));
        int bytes_read;
        byte[] buffer = new byte[1024];
        while (true) {
            bytes_read = source.read(buffer);
            if (bytes_read == -1)
                break;
            httpContext.getOutputStream().write(buffer, 0, bytes_read);
        }
        source.close();
    } catch (FileNotFoundException e) {
        errCode = ERROR_IO;
        errDescription = e.getMessage();
    } catch (IOException e) {
        errCode = ERROR_IO;
        errDescription = e.getMessage();
    }
}
Also used : IHttpContext(com.genexus.IHttpContext) HttpContextWeb(com.genexus.webpanels.HttpContextWeb)

Example 4 with HttpContextWeb

use of com.genexus.webpanels.HttpContextWeb in project JavaClasses by genexuslabs.

the class PDFReportItext method GxSetDocName.

public void GxSetDocName(String docName) {
    this.docName = docName.trim();
    if (this.docName.indexOf('.') < 0)
        this.docName += ".pdf";
    if (!new File(docName).isAbsolute()) {
        // Si el nombre del documento es relativo, veo si hay que agregarle el outputDir
        String outputDir = props.getGeneralProperty(Const.OUTPUT_FILE_DIRECTORY, "").replace(alternateSeparator, File.separatorChar).trim();
        if (!outputDir.equalsIgnoreCase("") && !outputDir.equalsIgnoreCase(".")) {
            if (!outputDir.endsWith(File.separator)) {
                outputDir += File.separator;
            }
            new File(outputDir).mkdirs();
            this.docName = outputDir + this.docName;
        } else {
            if (ModelContext.getModelContext() != null) {
                HttpContext webContext = (HttpContext) ModelContext.getModelContext().getHttpContext();
                if ((webContext != null) && (webContext instanceof HttpContextWeb)) {
                    outputDir = com.genexus.ModelContext.getModelContext().getHttpContext().getDefaultPath() + File.separator;
                    this.docName = outputDir + this.docName;
                }
            }
        }
    }
    if (this.docName.indexOf('.') < 0)
        this.docName += ".pdf";
    if (DEBUG)
        DEBUG_STREAM.println("GxSetDocName: '" + this.docName + "'");
}
Also used : HttpContext(com.genexus.internet.HttpContext) File(java.io.File) HttpContextWeb(com.genexus.webpanels.HttpContextWeb)

Example 5 with HttpContextWeb

use of com.genexus.webpanels.HttpContextWeb in project JavaClasses by genexuslabs.

the class PDFReportItext method GxEndDocument.

public void GxEndDocument() {
    if (document.getPageNumber() == 0) {
        // Si no hay ninguna página en el documento, agrego una vacia}
        writer.setPageEmpty(false);
    }
    // Ahora proceso los comandos GeneXus {{Pages}}
    if (template != null) {
        template.beginText();
        template.setFontAndSize(templateFont, templateFontSize);
        template.setTextMatrix(0, 0);
        template.setColorFill(templateColorFill);
        template.showText(String.valueOf(pages));
        template.endText();
    }
    int copies = 1;
    try {
        copies = Integer.parseInt(printerSettings.getProperty(form, Const.COPIES));
        if (DEBUG)
            DEBUG_STREAM.println("Setting number of copies to " + copies);
        writer.addViewerPreference(PdfName.NUMCOPIES, new PdfNumber(copies));
        int duplex = Integer.parseInt(printerSettings.getProperty(form, Const.DUPLEX));
        PdfName duplexValue;
        switch(duplex) {
            case 1:
                duplexValue = PdfName.SIMPLEX;
                break;
            case 2:
                duplexValue = PdfName.DUPLEX;
                break;
            case 3:
                duplexValue = PdfName.DUPLEXFLIPSHORTEDGE;
                break;
            case 4:
                duplexValue = PdfName.DUPLEXFLIPLONGEDGE;
                break;
            default:
                duplexValue = PdfName.NONE;
        }
        if (DEBUG)
            DEBUG_STREAM.println("Setting duplex to " + duplexValue.toString());
        writer.addViewerPreference(PdfName.DUPLEX, duplexValue);
    } catch (Exception ex) {
        ex.printStackTrace(System.err);
    }
    String serverPrinting = props.getGeneralProperty(Const.SERVER_PRINTING);
    boolean fit = props.getGeneralProperty(Const.ADJUST_TO_PAPER).equals("true");
    if ((outputType == Const.OUTPUT_PRINTER || outputType == Const.OUTPUT_STREAM_PRINTER) && (httpContext instanceof HttpContextWeb && serverPrinting.equals("false"))) {
        // writer.addJavaScript("if (this.external)\n");//Specifies whether the current document is being viewed in the Acrobat application or in an external window (such as a web browser).
        // writer.addJavaScript("app.alert('SI es externa' + this.external);");
        writer.addJavaScript("var pp = this.getPrintParams();\n");
        // writer.addJavaScript("pp.interactive = pp.constants.interactionLevel.automatic;\n");
        String printerAux = printerSettings.getProperty(form, Const.PRINTER);
        String printer = replace(printerAux, "\\", "\\\\");
        if (printer != null && !printer.equals("")) {
            writer.addJavaScript("pp.printerName = \"" + printer + "\";\n");
        }
        if (fit) {
            writer.addJavaScript("pp.pageHandling = pp.constants.handling.fit;\n");
        } else {
            writer.addJavaScript("pp.pageHandling = pp.constants.handling.none;\n");
        }
        if (// Show printer dialog Never
        printerSettings.getProperty(form, Const.MODE, "3").startsWith("0")) {
            writer.addJavaScript("pp.interactive = pp.constants.interactionLevel.automatic;\n");
            // dialog is displayed and removed automatically when printing is complete.
            for (int i = 0; i < copies; i++) {
                writer.addJavaScript("this.print(pp);\n");
            }
        } else // Show printer dialog is sent directly to printer | always
        {
            writer.addJavaScript("pp.interactive = pp.constants.interactionLevel.full;\n");
            // Displays the print dialog allowing the user to change print settings and requiring
            // the user to press OK to continue. During printing a progress monitor and cancel
            // dialog is displayed and removed automatically when printing is complete.
            writer.addJavaScript("this.print(pp);\n");
        }
    }
    document.close();
    if (DEBUG)
        DEBUG_STREAM.println("GxEndDocument!");
    try {
        props.save();
    } catch (IOException e) {
        ;
    }
    // OK, ahora que ya terminamos el PDF, vemos si tenemos que mostrarlo en pantalla
    switch(outputType) {
        case Const.OUTPUT_SCREEN:
            // Cierro el archivo
            try {
                outputStream.close();
            } catch (IOException e) {
                ;
            }
            try {
                showReport(docName, modal);
            } catch (Exception e) {
                // Si no se puede mostrar el reporte
                e.printStackTrace();
            }
            // if(modal)if(new File(docName).delete())TemporaryFiles.getInstance().removeFileFromList(docName); // Intento eliminar el docName aqu\uFFFDE
            break;
        case Const.OUTPUT_PRINTER:
            // Cierro el archivo
            try {
                outputStream.close();
            } catch (IOException e) {
                ;
            }
            try {
                if (!(httpContext instanceof HttpContextWeb) || !serverPrinting.equals("false")) {
                    printReport(docName, this.printerOutputMode == 1);
                }
            } catch (Exception e) {
                // Si no se puede mostrar el reporte
                e.printStackTrace();
            }
            break;
        case Const.OUTPUT_FILE:
            // Cierro el archivo
            try {
                outputStream.close();
            } catch (IOException e) {
                ;
            }
            break;
        case Const.OUTPUT_STREAM:
        case Const.OUTPUT_STREAM_PRINTER:
        default:
            break;
    }
    outputStream = null;
}
Also used : PdfName(com.lowagie.text.pdf.PdfName) PdfNumber(com.lowagie.text.pdf.PdfNumber) IOException(java.io.IOException) HttpContextWeb(com.genexus.webpanels.HttpContextWeb) IOException(java.io.IOException) DocumentException(com.lowagie.text.DocumentException)

Aggregations

HttpContextWeb (com.genexus.webpanels.HttpContextWeb)8 HttpContext (com.genexus.internet.HttpContext)3 File (java.io.File)3 IOException (java.io.IOException)3 IHttpContext (com.genexus.IHttpContext)1 AbstractGXFile (com.genexus.common.classes.AbstractGXFile)1 DocumentException (com.lowagie.text.DocumentException)1 PdfName (com.lowagie.text.pdf.PdfName)1 PdfNumber (com.lowagie.text.pdf.PdfNumber)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Cookie (org.apache.http.cookie.Cookie)1