Search in sources :

Example 6 with HttpContext

use of com.genexus.internet.HttpContext in project JavaClasses by genexuslabs.

the class GXWebObjectStub method callExecute.

protected void callExecute(String method, IHttpServletRequest req, IHttpServletResponse res) throws ServletException {
    initialize(req, res);
    HttpContext httpContext = null;
    try {
        String gxcfg = getWrappedServletContext().getInitParameter("gxcfg");
        if (gxcfg != null) {
            Class gxcfgClass = Class.forName(gxcfg);
            ModelContext.gxcfgPackageClass = gxcfgClass;
            ApplicationContext appContext = ApplicationContext.getInstance();
            appContext.setServletEngine(true);
            Application.init(gxcfgClass);
        }
        httpContext = new HttpContextWeb(method, req, res, getWrappedServletContext());
        if (logger.isDebugEnabled())
            dumpRequestInfo(httpContext);
        boolean useAuthentication = IntegratedSecurityEnabled();
        if (!useAuthentication) {
            callDoExecute(httpContext);
        } else {
            init(httpContext);
            if (IntegratedSecurityLevel() == SECURITY_GXOBJECT) {
                httpContext.doNotCompress(true);
            }
            new WebApplicationStartup().init(getClass(), httpContext);
            boolean[] flag = new boolean[] { false };
            boolean[] permissionFlag = new boolean[] { false };
            String reqUrl = req.getRequestURL().toString();
            if (req.getMethod().equals("POST")) {
                if (EncryptURLParameters().equals("SESSION"))
                    reqUrl = "";
                else
                    reqUrl = req.getHeader("Referer");
            } else {
                String queryString = req.getQueryString();
                if (queryString != null) {
                    reqUrl += "?" + queryString;
                }
            }
            ModelContext modelContext = ModelContext.getModelContext(getClass());
            modelContext.setHttpContext(httpContext);
            ApplicationContext.getInstance().setPoolConnections(!Namespace.createNamespace(modelContext).isRemoteGXDB());
            String loginObject = Application.getClientContext().getClientPreferences().getProperty("IntegratedSecurityLoginWeb", "");
            loginObject = GXutil.getClassName(loginObject);
            String loginObjectURL = URLRouter.getURLRoute(loginObject.toLowerCase(), new String[] {}, new String[] {}, httpContext.getRequest().getContextPath(), modelContext.getPackageName());
            String permissionPrefix = IntegratedSecurityPermissionPrefix();
            if (IntegratedSecurityLevel() == SECURITY_GXOBJECT) {
                String token = req.getHeader("Authorization");
                if (token != null && token.length() > 0) {
                    token = token.replace("OAuth ", "");
                    GXResult result = GXSecurityProvider.getInstance().checkaccesstoken(-2, modelContext, token, flag);
                } else {
                    token = "";
                    GXSecurityProvider.getInstance().checksession(-2, modelContext, reqUrl, flag);
                }
                if (!flag[0]) {
                    String OauthRealm = "OAuth realm=\"" + httpContext.getRequest().getServerName() + "\"";
                    httpContext.getResponse().addHeader("WWW-Authenticate", OauthRealm);
                    httpContext.sendResponseStatus(401, "Not Authorized");
                } else {
                    callDoExecute(httpContext);
                }
            } else if (IntegratedSecurityLevel() == SECURITY_LOW) {
                GXSecurityProvider.getInstance().checksession(-2, modelContext, reqUrl, flag);
                if (!flag[0]) {
                    httpContext.redirect(loginObjectURL, true);
                } else {
                    callDoExecute(httpContext);
                }
            } else {
                GXSecurityProvider.getInstance().checksessionprm(-2, modelContext, reqUrl, permissionPrefix, flag, permissionFlag);
                if (permissionFlag[0]) {
                    callDoExecute(httpContext);
                } else {
                    String notAuthorizedObject = Application.getClientContext().getClientPreferences().getProperty("IntegratedSecurityNotAuthorizedWeb", "");
                    notAuthorizedObject = GXutil.getClassName(notAuthorizedObject);
                    String notAuthorizedObjectURL = URLRouter.getURLRoute(notAuthorizedObject.toLowerCase(), new String[] {}, new String[] {}, httpContext.getRequest().getContextPath(), modelContext.getPackageName());
                    if (flag[0]) {
                        httpContext.redirect(notAuthorizedObjectURL, true);
                    } else {
                        httpContext.redirect(loginObjectURL, true);
                    }
                }
            }
        }
        httpContext.setResponseCommited();
        httpContext.flushStream();
    } catch (Throwable e) {
        if (!res.isCommitted())
            res.reset();
        logger.error("Web Execution Error", e);
        if (logger.isDebugEnabled() && httpContext != null)
            dumpRequestInfo(httpContext);
        throw new ServletException(com.genexus.PrivateUtilities.getStackTraceAsString(e));
    }
}
Also used : ServletException(com.genexus.servlet.ServletException) GXResult(com.genexus.security.GXResult) HttpContext(com.genexus.internet.HttpContext)

Example 7 with HttpContext

use of com.genexus.internet.HttpContext in project JavaClasses by genexuslabs.

the class GXWebRow method AddColumnProperties.

public void AddColumnProperties(int valueIndex, boolean valueWithProps, Object[] props) {
    Iterator it = this.initializePptyIterator();
    // ColProps Reversed
    JSONArray colPropsRev = new JSONArray();
    Object value = "";
    JSONArray colProps = new JSONArray();
    boolean equal = it != null && !((HttpContext) context.getHttpContext()).isAjaxCallMode();
    Object current = null;
    for (int i = props.length - 1; i >= 0; i--) {
        Object prop = props[i];
        if (IGxJSONAble.class.isAssignableFrom(prop.getClass()))
            prop = ((IGxJSONAble) prop).GetJSONObject();
        if (i != valueIndex) {
            equal = equal && it.hasNext();
            if (equal)
                current = it.next();
            if (!(equal && (current.equals(prop)))) {
                equal = false;
                try {
                    colProps.putIndex(0, prop);
                } catch (JSONException e) {
                }
                if (it == null)
                    colPropsRev.put(prop);
            }
        } else if (valueWithProps)
            value = prop;
        else {
            CommonUtil.strReplace(prop.toString(), "'", "\'");
            _Values.put(prop);
        }
    }
    if (// If is the first Row.
    this._parentGrid != null && it == null) {
        this._parentGrid.GetColsPropsCommon().add(colPropsRev);
    }
    if (valueWithProps)
        colProps.put(value);
    else if (valueIndex < 0)
        _Values.put("");
    _Columns.put(colProps);
    _Count++;
}
Also used : IGxJSONAble(com.genexus.internet.IGxJSONAble) Iterator(java.util.Iterator) JSONArray(json.org.json.JSONArray) HttpContext(com.genexus.internet.HttpContext) JSONException(json.org.json.JSONException) JSONObject(json.org.json.JSONObject)

Example 8 with HttpContext

use of com.genexus.internet.HttpContext in project JavaClasses by genexuslabs.

the class GXWebStdMethods method callMethod.

public static void callMethod(ModelContext context, String controlType, Object[] parms, String GridName) {
    if (tagHasStdMethod(controlType)) {
        try {
            Class webStdFuncs = getWebStdClass(context);
            if (webStdFuncs != null) {
                HttpContext httpContext = (HttpContext) context.getHttpContext();
                if (httpContext != null) {
                    boolean addCallerPgm = true;
                    Method method = null;
                    if (controlType.equalsIgnoreCase("edit")) {
                        method = getMethod(context, "gx_single_line_edit");
                    } else if (controlType.equalsIgnoreCase("html_textarea")) {
                        method = getMethod(context, "gx_html_textarea");
                    } else if (controlType.equalsIgnoreCase("button")) {
                        // sCtrlName
                        String sCtrlName = (String) parms[1];
                        if (sCtrlName.lastIndexOf('_') > 0) {
                            String row = sCtrlName.substring(sCtrlName.lastIndexOf('_') + 1);
                            short eventType = ((Number) parms[10]).shortValue();
                            if (// execCliEvt
                            eventType == 7) {
                                // sEventName
                                parms[12] = ((String) parms[12]) + ",'" + GridName + "','" + row + '\'';
                            } else if (// serverEvt
                            eventType == 5) {
                                // sEventName
                                parms[12] = parms[12] + row;
                            }
                        }
                        method = getMethod(context, "gx_button_ctrl");
                    } else if (controlType.equalsIgnoreCase("blob")) {
                        method = getMethod(context, "gx_blob_field");
                    } else if (controlType.equalsIgnoreCase("label")) {
                        method = getMethod(context, "gx_label_ctrl");
                    } else if (controlType.equalsIgnoreCase("radio")) {
                        method = getMethod(context, "gx_radio_ctrl");
                    } else if (controlType.equalsIgnoreCase("combobox")) {
                        method = getMethod(context, "gx_combobox_ctrl1");
                    } else if (controlType.equalsIgnoreCase("listbox")) {
                        method = getMethod(context, "gx_listbox_ctrl1");
                    } else if (controlType.equalsIgnoreCase("checkbox")) {
                        addCallerPgm = false;
                        method = getMethod(context, "gx_checkbox_ctrl");
                    } else if (controlType.equalsIgnoreCase("bitmap")) {
                        method = getMethod(context, "gx_bitmap");
                    } else if (controlType.equalsIgnoreCase("table")) {
                        try {
                            method = getMethod(context, "gx_table_start");
                            String sStyleString = "";
                            if (Integer.parseInt(parms[1].toString()) == 0) /*Visible*/
                            {
                                sStyleString = "display:none;";
                            }
                            int nBorder = (parms[8].toString().equals("")) ? 0 : Integer.parseInt(parms[8].toString());
                            method.invoke(null, new Object[] { httpContext, // sCtrlName
                            parms[0], // sHTMLid
                            parms[0], // sHTMLTags
                            "", // sClassString
                            parms[2], // nBorder
                            nBorder, // sAlign
                            parms[6], // sTooltiptext
                            parms[7], // nCellpadding
                            parms[9], // nCellspacing
                            parms[10], // sStyleString
                            sStyleString, // sRules
                            parms[13], // nParentIsFreeStyle
                            0 });
                        } catch (Exception e) {
                            httpContext.writeTextNL("<table>");
                        }
                        method = null;
                    }
                    if (method != null) {
                        int parmsLen = parms.length + 1;
                        if (addCallerPgm) {
                            parmsLen++;
                        }
                        Object[] allParms = new Object[parmsLen];
                        allParms[0] = httpContext;
                        System.arraycopy(parms, 0, allParms, 1, parms.length);
                        if (addCallerPgm) {
                            // sCallerPgm
                            allParms[parms.length + 1] = "";
                        }
                        if (method.getParameterTypes().length == allParms.length) {
                            method.invoke(null, convertParms(method.getParameterTypes(), allParms));
                        }
                    }
                }
            }
        } catch (Exception e) {
        }
    } else {
        openTag(context, controlType, parms);
    }
}
Also used : HttpContext(com.genexus.internet.HttpContext) Method(java.lang.reflect.Method)

Example 9 with HttpContext

use of com.genexus.internet.HttpContext in project JavaClasses by genexuslabs.

the class GXGridStateHandler method saveGridState.

public void saveGridState() {
    WebSession session = ((HttpContext) context.getHttpContext()).getWebSession();
    state.fromJSonString(session.getValue(gridName));
    runVarsToState();
    session.setValue(gridName, state.toJSonString());
    dirty = true;
}
Also used : WebSession(com.genexus.webpanels.WebSession) HttpContext(com.genexus.internet.HttpContext)

Example 10 with HttpContext

use of com.genexus.internet.HttpContext in project JavaClasses by genexuslabs.

the class GXGridStateHandler method getState.

public SdtGridState getState() {
    try {
        if (dirty || state == null) {
            HttpContext httpContext = (HttpContext) context.getHttpContext();
            WebSession session = httpContext.getWebSession();
            state = new SdtGridState(context);
            state.fromJSonString(session.getValue(gridName));
            dirty = false;
        }
        return state;
    } catch (Exception ex) {
        logger.error("Can't create " + sdtGridStateClass, ex);
        return null;
    }
}
Also used : WebSession(com.genexus.webpanels.WebSession) HttpContext(com.genexus.internet.HttpContext)

Aggregations

HttpContext (com.genexus.internet.HttpContext)30 File (java.io.File)5 WebSession (com.genexus.webpanels.WebSession)4 IOException (java.io.IOException)4 ModelContext (com.genexus.ModelContext)3 GXFile (com.genexus.util.GXFile)3 HttpContextWeb (com.genexus.webpanels.HttpContextWeb)3 com.genexus (com.genexus)2 HttpContextNull (com.genexus.internet.HttpContextNull)2 HttpRequest (com.genexus.internet.HttpRequest)2 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 SQLException (java.sql.SQLException)2 IExtensionModelContext (com.genexus.common.interfaces.IExtensionModelContext)1 IGxJSONAble (com.genexus.internet.IGxJSONAble)1 GXResult (com.genexus.security.GXResult)1 ServletException (com.genexus.servlet.ServletException)1