@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { traceRequest(req); String pathInfoString = req.getPathInfo(); String queryString = getQueryString(req); IPath pathInfo = new Path( null /*don't parse host:port as device*/, pathInfoString == null ? "" : pathInfoString); // $NON-NLS-1$ if (pathInfo.segmentCount() > 0) { String hostedHost = pathInfo.segment(0); IHostedSite site = HostingActivator.getDefault().getHostingService().get(hostedHost); if (site != null) { IPath path = pathInfo.removeFirstSegments(1); IPath contextPath = new Path(req.getContextPath()); IPath contextlessPath = path.makeRelativeTo(contextPath).makeAbsolute(); URI[] mappedPaths; try { mappedPaths = getMapped(site, contextlessPath, queryString); } catch (URISyntaxException e) { handleException( resp, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Could not create target URI ", e)); return; } if (mappedPaths != null) { serve(req, resp, site, mappedPaths); } else { handleException( resp, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("No mappings matched {0}", path), null)); } } else { String msg = NLS.bind("Hosted site {0} is stopped", hostedHost); handleException( resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null)); } } else { super.doGet(req, resp); } }
// temp code for grabbing files from filesystem protected IFileStore tempGetFileStore(IPath path) { // first check if we have an alias registered if (path.segmentCount() > 0) { URI alias = aliasRegistry.lookupAlias(path.segment(0)); if (alias != null) try { return EFS.getStore(alias).getFileStore(path.removeFirstSegments(1)); } catch (CoreException e) { LogHelper.log( new Status( IStatus.WARNING, HostingActivator.PI_SERVER_HOSTING, 1, "An error occured when getting file store for path '" + path + "' and alias '" + alias + '\'', e)); //$NON-NLS-1$ //$NON-NLS-2$ // fallback is to try the same path relatively to the root } } // assume it is relative to the root try { return EFS.getStore(rootStoreURI).getFileStore(path); } catch (CoreException e) { LogHelper.log( new Status( IStatus.WARNING, HostingActivator.PI_SERVER_HOSTING, 1, "An error occured when getting file store for path '" + path + "' and root '" + rootStoreURI + '\'', e)); //$NON-NLS-1$ //$NON-NLS-2$ // fallback and return null } return null; }