/**
  * Adds status field to a representation of a site configuration.
  *
  * @param siteConfigJson The JSONObject representing a single site configuration.
  * @param user The user making the request.
  * @param resource The original request passed to the decorator.
  */
 private void addStatus(
     HttpServletRequest req, JSONObject siteConfigJson, WebUser user, URI resource)
     throws JSONException {
   String id = siteConfigJson.getString(ProtocolConstants.KEY_ID);
   SiteConfiguration siteConfiguration = SiteConfiguration.fromId(id);
   IHostedSite site =
       HostingActivator.getDefault().getHostingService().get(siteConfiguration, user);
   JSONObject hostingStatus = new JSONObject();
   if (site != null) {
     hostingStatus.put(
         SiteConfigurationConstants.KEY_HOSTING_STATUS_STATUS, "started"); // $NON-NLS-1$
     String portSuffix = ":" + req.getLocalPort(); // $NON-NLS-1$
     // Whatever scheme was used to access the resource, assume it's used for the sites too
     // Hosted site also shares same contextPath
     String hostedUrl =
         resource.getScheme()
             + "://"
             + site.getHost()
             + portSuffix
             + req.getContextPath(); // $NON-NLS-1$
     hostingStatus.put(SiteConfigurationConstants.KEY_HOSTING_STATUS_URL, hostedUrl);
   } else {
     hostingStatus.put(
         SiteConfigurationConstants.KEY_HOSTING_STATUS_STATUS, "stopped"); // $NON-NLS-1$
   }
   siteConfigJson.put(SiteConfigurationConstants.KEY_HOSTING_STATUS, hostingStatus);
 }
 @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);
   }
 }