Search in sources :

Example 51 with JSONObject

use of org.json.simple.JSONObject in project jaggery by wso2.

the class TomcatJaggeryWebappsDeployer method addServlets.

private static void addServlets(Context ctx, JSONObject jaggeryConfig) {
    if (jaggeryConfig != null) {
        JSONArray arrServlets = (JSONArray) jaggeryConfig.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS);
        JSONArray arrServletMappings = (JSONArray) jaggeryConfig.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLET_MAPPINGS);
        if (arrServlets != null) {
            for (Object servletObj : arrServlets) {
                JSONObject servlet = (JSONObject) servletObj;
                String name = (String) servlet.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS_NAME);
                String clazz = (String) servlet.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS_CLASS);
                Wrapper servletWrapper = Tomcat.addServlet(ctx, name, clazz);
                JSONArray arrParams = (JSONArray) servlet.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS_PARAMS);
                if (arrParams != null) {
                    for (Object paramObj : arrParams) {
                        JSONObject param = (JSONObject) paramObj;
                        String paramName = (String) param.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS_PARAMS_NAME);
                        String paramValue = (String) param.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLETS_PARAMS_VALUE);
                        servletWrapper.addInitParameter(paramName, paramValue);
                    }
                }
            }
        }
        if (arrServletMappings != null) {
            for (Object servletMappingObj : arrServletMappings) {
                JSONObject mapping = (JSONObject) servletMappingObj;
                String name = (String) mapping.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLET_MAPPINGS_NAME);
                String url = (String) mapping.get(JaggeryCoreConstants.JaggeryConfigParams.SERVLET_MAPPINGS_URL);
                ctx.addServletMapping(url, name);
            }
        }
    }
}
Also used : Wrapper(org.apache.catalina.Wrapper) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject)

Example 52 with JSONObject

use of org.json.simple.JSONObject in project jaggery by wso2.

the class TomcatJaggeryWebappsDeployer method addContextParams.

private static void addContextParams(Context ctx, JSONObject jaggeryConfig) {
    if (jaggeryConfig != null) {
        JSONArray arrContextParams = (JSONArray) jaggeryConfig.get(JaggeryCoreConstants.JaggeryConfigParams.CONTEXT_PARAMS);
        if (arrContextParams != null) {
            for (Object contextParamObj : arrContextParams) {
                JSONObject contextParam = (JSONObject) contextParamObj;
                String name = (String) contextParam.get(JaggeryCoreConstants.JaggeryConfigParams.CONTEXT_PARAMS_NAME);
                String value = (String) contextParam.get(JaggeryCoreConstants.JaggeryConfigParams.CONTEXT_PARAMS_VALUE);
                ctx.addParameter(name, value);
            }
        }
    }
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject)

Example 53 with JSONObject

use of org.json.simple.JSONObject in project jaggery by wso2.

the class TomcatJaggeryWebappsDeployer method handleWebappDeployment.

/**
     * Deployment procedure of Jaggery apps
     *
     * @param webappFile                The Jaggery app file to be deployed
     * @param contextStr                jaggery app context string
     * @param webContextParams          context-params for this Jaggery app
     * @param applicationEventListeners Application event listeners
     * @throws CarbonException If a deployment error occurs
     */
protected void handleWebappDeployment(File webappFile, String contextStr, List<WebContextParameter> webContextParams, List<Object> applicationEventListeners) throws CarbonException {
    String filename = webappFile.getName();
    ArrayList<Object> listeners = new ArrayList<Object>(1);
    // listeners.add(new CarbonServletRequestListener());
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setAuthConstraint(true);
    SecurityCollection securityCollection = new SecurityCollection();
    securityCollection.setName("ConfigDir");
    securityCollection.setDescription("Jaggery Configuration Dir");
    securityCollection.addPattern("/" + JaggeryCoreConstants.JAGGERY_CONF_FILE);
    securityConstraint.addCollection(securityCollection);
    WebApplicationsHolder webApplicationsHolder = WebAppUtils.getWebappHolder(webappFile.getAbsolutePath(), configurationContext);
    try {
        JSONObject jaggeryConfigObj = readJaggeryConfig(webappFile);
        Tomcat tomcat = DataHolder.getCarbonTomcatService().getTomcat();
        Context context = DataHolder.getCarbonTomcatService().addWebApp(contextStr, webappFile.getAbsolutePath(), new JaggeryDeployerManager.JaggeryConfListener(jaggeryConfigObj, securityConstraint));
        //deploying web app for url mapping inside virtual host
        if (DataHolder.getHotUpdateService() != null) {
            List<String> hostNames = DataHolder.getHotUpdateService().getMappigsPerWebapp(contextStr);
            for (String hostName : hostNames) {
                Host host = DataHolder.getHotUpdateService().addHost(hostName);
                /*                    ApplicationContext.getCurrentApplicationContext().putUrlMappingForApplication(hostName, contextStr);
  */
                Context contextForHost = DataHolder.getCarbonTomcatService().addWebApp(host, "/", webappFile.getAbsolutePath(), new JaggeryDeployerManager.JaggeryConfListener(jaggeryConfigObj, securityConstraint));
                log.info("Deployed JaggeryApp on host: " + contextForHost);
            }
        }
        Manager manager = context.getManager();
        if (isDistributable(context, jaggeryConfigObj)) {
            //Clusterable manager implementation as DeltaManager
            context.setDistributable(true);
            // Using clusterable manager
            CarbonTomcatClusterableSessionManager sessionManager;
            if (manager instanceof CarbonTomcatClusterableSessionManager) {
                sessionManager = (CarbonTomcatClusterableSessionManager) manager;
                sessionManager.setOwnerTenantId(tenantId);
            } else {
                sessionManager = new CarbonTomcatClusterableSessionManager(tenantId);
                context.setManager(sessionManager);
            }
            Object alreadyinsertedSMMap = configurationContext.getProperty(CarbonConstants.TOMCAT_SESSION_MANAGER_MAP);
            if (alreadyinsertedSMMap != null) {
                ((Map<String, CarbonTomcatClusterableSessionManager>) alreadyinsertedSMMap).put(context.getName(), sessionManager);
            } else {
                sessionManagerMap.put(context.getName(), sessionManager);
                configurationContext.setProperty(CarbonConstants.TOMCAT_SESSION_MANAGER_MAP, sessionManagerMap);
            }
        } else {
            if (manager instanceof CarbonTomcatSessionManager) {
                ((CarbonTomcatSessionManager) manager).setOwnerTenantId(tenantId);
            } else if (manager instanceof CarbonTomcatSessionPersistentManager) {
                ((CarbonTomcatSessionPersistentManager) manager).setOwnerTenantId(tenantId);
                log.debug(manager.getInfo() + " enabled Tomcat HTTP Session Persistent mode using " + ((CarbonTomcatSessionPersistentManager) manager).getStore().getInfo());
            } else {
                context.setManager(new CarbonTomcatSessionManager(tenantId));
            }
        }
        context.setReloadable(false);
        JaggeryApplication webapp = new JaggeryApplication(this, context, webappFile);
        webapp.setServletContextParameters(webContextParams);
        webapp.setState("Started");
        webApplicationsHolder.getStartedWebapps().put(filename, webapp);
        webApplicationsHolder.getFaultyWebapps().remove(filename);
        registerApplicationEventListeners(applicationEventListeners, context);
        log.info("Deployed webapp: " + webapp);
    } catch (Throwable e) {
        //catching a Throwable here to avoid web-apps crashing the server during startup
        StandardContext context = new StandardContext();
        context.setName(webappFile.getName());
        context.addParameter(WebappsConstants.FAULTY_WEBAPP, "true");
        JaggeryApplication webapp = new JaggeryApplication(this, context, webappFile);
        webapp.setProperty(WebappsConstants.WEBAPP_FILTER, JaggeryConstants.JAGGERY_WEBAPP_FILTER_PROP);
        String msg = "Error while deploying webapp: " + webapp;
        log.error(msg, e);
        webapp.setFaultReason(new Exception(msg, e));
        webApplicationsHolder.getFaultyWebapps().put(filename, webapp);
        webApplicationsHolder.getStartedWebapps().remove(filename);
        throw new CarbonException(msg, e);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) Tomcat(org.apache.catalina.startup.Tomcat) JaggeryDeployerManager(org.jaggeryjs.jaggery.core.manager.JaggeryDeployerManager) ArrayList(java.util.ArrayList) CarbonException(org.wso2.carbon.CarbonException) Host(org.apache.catalina.Host) CarbonTomcatClusterableSessionManager(org.wso2.carbon.core.session.CarbonTomcatClusterableSessionManager) Manager(org.apache.catalina.Manager) JaggeryDeployerManager(org.jaggeryjs.jaggery.core.manager.JaggeryDeployerManager) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) CarbonException(org.wso2.carbon.CarbonException) JSONObject(org.json.simple.JSONObject) CarbonTomcatClusterableSessionManager(org.wso2.carbon.core.session.CarbonTomcatClusterableSessionManager) StandardContext(org.apache.catalina.core.StandardContext) JSONObject(org.json.simple.JSONObject) Map(java.util.Map) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Example 54 with JSONObject

use of org.json.simple.JSONObject in project jaggery by wso2.

the class TomcatJaggeryWebappsDeployer method addListeners.

private static void addListeners(Context ctx, JSONObject jaggeryConfig) {
    if (jaggeryConfig != null) {
        JSONArray arrListeners = (JSONArray) jaggeryConfig.get(JaggeryCoreConstants.JaggeryConfigParams.LISTENERS);
        if (arrListeners != null) {
            for (Object listenerObj : arrListeners) {
                JSONObject listener = (JSONObject) listenerObj;
                String clazz = (String) listener.get(JaggeryCoreConstants.JaggeryConfigParams.LISTENERS_CLASS);
                ctx.addApplicationListener(clazz);
            }
        }
    }
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject)

Example 55 with JSONObject

use of org.json.simple.JSONObject in project jaggery by wso2.

the class JaggeryDeployerManager method addErrorPages.

private static void addErrorPages(Context context, JSONObject obj) {
    JSONObject arr = (JSONObject) obj.get(JaggeryCoreConstants.JaggeryConfigParams.ERROR_PAGES);
    if (arr != null) {
        for (Object keys : arr.keySet()) {
            ErrorPage errPage = new ErrorPage();
            errPage.setErrorCode((String) keys);
            errPage.setLocation((String) arr.get(keys));
            context.addErrorPage(errPage);
        }
    }
}
Also used : JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) LogHostObject(org.jaggeryjs.hostobjects.log.LogHostObject)

Aggregations

JSONObject (org.json.simple.JSONObject)961 Test (org.junit.Test)312 JSONArray (org.json.simple.JSONArray)232 JSONParser (org.json.simple.parser.JSONParser)164 Map (java.util.Map)97 HashMap (java.util.HashMap)91 IOException (java.io.IOException)84 ArrayList (java.util.ArrayList)75 ParseException (org.json.simple.parser.ParseException)60 HttpClient (org.apache.commons.httpclient.HttpClient)39 File (java.io.File)38 List (java.util.List)38 BlockchainTest (org.xel.BlockchainTest)34 GetMethod (org.apache.commons.httpclient.methods.GetMethod)30 HttpURLConnection (java.net.HttpURLConnection)27 Tuple (org.apache.storm.tuple.Tuple)23 Transaction (org.xel.Transaction)23 APICall (org.xel.http.APICall)23 InputStreamReader (java.io.InputStreamReader)22 WriterConfiguration (org.apache.metron.common.configuration.writer.WriterConfiguration)22