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);
}
}
}
}
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);
}
}
}
}
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);
}
}
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);
}
}
}
}
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);
}
}
}
Aggregations