Hashtable<String, String[]> properties3 = new Hashtable<String, String[]>();
properties3.put(URLConstants.URL_CONTENT_MIMETYPE, new String[]{"text/javascript"});
context.registerService(ContentHandler.class.getName(), new TextJavascriptHandler(),
properties3);
final HttpService httpService = getHttpService();
Dictionary<String, String> initparams = new Hashtable<String, String>();
initparams.put("servlet-name", "TilesServlet");
initparams.put("definitions-config", "/WEB-INF/tiles/main_defs.xml");
initparams.put("org.apache.tiles.context.TilesContextFactory",
"org.apache.tiles.context.enhanced.EnhancedContextFactory");
initparams.put("org.apache.tiles.factory.TilesContainerFactory.MUTABLE", "true");
initparams.put("org.apache.tiles.definition.DefinitionsFactory",
"org.wso2.carbon.tiles.CarbonUrlDefinitionsFactory");
String webContext = "carbon"; // The subcontext for the Carbon Mgt Console
String serverURL = CarbonUIUtil.getServerURL(serverConfig);
String indexPageURL = CarbonUIUtil.getIndexPageURL(serverConfig);
if (indexPageURL == null) {
indexPageURL = "/carbon/admin/index.jsp";
}
RegistryService registryService = getRegistryService();
Registry registry = registryService.getLocalRepository();
UIBundleDeployer uiBundleDeployer = new UIBundleDeployer();
UIResourceRegistry uiResourceRegistry = new UIResourceRegistry();
uiResourceRegistry.initialize(bundleContext);
uiResourceRegistry.setDefaultUIResourceProvider(
uiBundleDeployer.getBundleBasedUIResourcePrvider());
// BundleResourcePathRegistry resourcePathRegistry = uiBundleDeployer.getBundleResourcePathRegistry();
HttpContext commonContext =
new CarbonSecuredHttpContext(context.getBundle(), "/web", uiResourceRegistry, registry);
//Registering filedownload servlet
Servlet fileDownloadServlet = new ContextPathServletAdaptor(new FileDownloadServlet(
context, getConfigurationContextService()), "/filedownload");
httpService.registerServlet("/filedownload", fileDownloadServlet, null, commonContext);
fileDownloadServlet.getServletConfig().getServletContext().setAttribute(
CarbonConstants.SERVER_URL, serverURL);
fileDownloadServlet.getServletConfig().getServletContext().setAttribute(
CarbonConstants.INDEX_PAGE_URL, indexPageURL);
//Registering fileupload servlet
Servlet fileUploadServlet;
if (isLocalTransportMode) {
fileUploadServlet = new ContextPathServletAdaptor(new FileUploadServlet(
context, serverConfigContext, webContext), "/fileupload");
} else {
fileUploadServlet = new ContextPathServletAdaptor(new FileUploadServlet(
context, clientConfigContext, webContext), "/fileupload");
}
httpService.registerServlet("/fileupload", fileUploadServlet, null, commonContext);
fileUploadServlet.getServletConfig().getServletContext().setAttribute(
CarbonConstants.SERVER_URL, serverURL);
fileUploadServlet.getServletConfig().getServletContext().setAttribute(
CarbonConstants.INDEX_PAGE_URL, indexPageURL);
uiBundleDeployer.deploy(bundleContext, commonContext);
context.addBundleListener(uiBundleDeployer);
httpService.registerServlet("/", new org.apache.tiles.web.startup.TilesServlet(),
initparams,
commonContext);
httpService.registerResources("/" + webContext, "/", commonContext);
adaptedJspServlet = new ContextPathServletAdaptor(
new TilesJspServlet(context.getBundle(), uiResourceRegistry), "/" + webContext);
httpService.registerServlet("/" + webContext + "/*.jsp", adaptedJspServlet, null,
commonContext);
ServletContext jspServletContext =
adaptedJspServlet.getServletConfig().getServletContext();
jspServletContext.setAttribute("registry", registryService);