@Override public Set<String> getResourcePaths(String path) { File root = getWebApplication().getResourceFile(path); Set<String> paths = new TreeSet<String>(); File[] files = root.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { paths.add(path + file.getName() + "/"); } else { paths.add(path + file.getName()); } } } return paths; }
void shutDown() { destroyServlets(); notifyContextDestroyed(); }
private Hashtable getContextParams() { return _application.getContextParameters(); }
/** * Constructs an application spec from an XML document. */ WebApplication( Document document, File file, String contextPath ) throws MalformedURLException, SAXException { if (contextPath != null && contextPath.length() > 0 && !contextPath.startsWith( "/" )) throw new IllegalArgumentException( "Context path " + contextPath + " must start with '/'" ); _contextDir = file; _contextPath = contextPath == null ? "" : contextPath; NodeList nl = document.getElementsByTagName( "display-name" ); if (nl.getLength() > 0) _displayName = XMLUtils.getTextValue( nl.item(0) ).trim(); registerServlets( document ); registerFilters( document ); extractSecurityConstraints( document ); extractContextParameters( document ); extractLoginConfiguration( document ); extractListeners( document ); notifyContextInitialized(); _servletMapping.autoLoadServlets(); }
private URL computeEffectiveUrl( HttpServletRequest request, URL requestURL ) { if (!_application.requiresAuthorization( requestURL ) || userIsAuthorized( request, requestURL ) ) { return requestURL; } else if (request.getRemoteUser() != null) { throw new AccessDeniedException( requestURL ); } else if (_application.usesBasicAuthentication()) { throw AuthorizationRequiredException.createBasicAuthenticationRequiredException( _application.getAuthenticationRealm() ); } else if (!_application.usesFormAuthentication()) { throw new IllegalStateException( "Authorization required but no authentication method defined" ); } else { ((ServletUnitHttpSession) request.getSession()).setOriginalURL( requestURL ); return _application.getLoginURL(); } }
/** * Default constructor, which defines no servlets. */ public ServletRunner() { _application = new WebApplication(); completeInitialization( null ); }
/** * Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher * object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static. * The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext to obtain a * RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a * RequestDispatcher. **/ public javax.servlet.RequestDispatcher getRequestDispatcher( String path ) { try { URL url = new URL( "http", "localhost", _application.getContextPath() + path ); return new RequestDispatcherImpl( _application, url ); } catch (ServletException e) { return null; } catch (MalformedURLException e) { return null; } }
/** * Constructs an application spec from an XML document. */ WebApplication( Document document, File file, String contextPath ) throws MalformedURLException, SAXException { if (contextPath != null && contextPath.length() > 0 && !contextPath.startsWith( "/" )) throw new IllegalArgumentException( "Context path " + contextPath + " must start with '/'" ); _contextDir = file; _contextPath = contextPath == null ? "" : contextPath; NodeList nl = document.getElementsByTagName( "display-name" ); if (nl.getLength() > 0) _displayName = XMLUtils.getTextValue( nl.item(0) ).trim(); registerServlets( document ); registerFilters( document ); extractSecurityConstraints( document ); extractContextParameters( document ); extractLoginConfiguration( document ); extractListeners( document ); notifyContextInitialized(); _servletMapping.autoLoadServlets(); }
private URL computeEffectiveUrl( HttpServletRequest request, URL requestURL ) { if (!_application.requiresAuthorization( requestURL ) || userIsAuthorized( request, requestURL ) ) { return requestURL; } else if (request.getRemoteUser() != null) { throw new AccessDeniedException( requestURL ); } else if (_application.usesBasicAuthentication()) { throw AuthorizationRequiredException.createBasicAuthenticationRequiredException( _application.getAuthenticationRealm() ); } else if (!_application.usesFormAuthentication()) { throw new IllegalStateException( "Authorization required but no authentication method defined" ); } else { ((ServletUnitHttpSession) request.getSession()).setOriginalURL( requestURL ); return _application.getLoginURL(); } }
/** * Default constructor, which defines no servlets. */ public ServletRunner() { _application = new WebApplication(); completeInitialization( null ); }
/** * Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher * object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static. * The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext to obtain a * RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a * RequestDispatcher. **/ public javax.servlet.RequestDispatcher getRequestDispatcher( String path ) { try { URL url = new URL( "http", "localhost", _application.getContextPath() + path ); return new RequestDispatcherImpl( _application, url ); } catch (ServletException e) { return null; } catch (MalformedURLException e) { return null; } }
/** * Constructs an application spec from an XML document. */ WebApplication( Document document, File file, String contextPath ) throws MalformedURLException, SAXException { if (contextPath != null && contextPath.length() > 0 && !contextPath.startsWith( "/" )) throw new IllegalArgumentException( "Context path " + contextPath + " must start with '/'" ); _contextDir = file; _contextPath = contextPath == null ? "" : contextPath; NodeList nl = document.getElementsByTagName( "display-name" ); if (nl.getLength() > 0) _displayName = XMLUtils.getTextValue( nl.item(0) ).trim(); registerServlets( document ); registerFilters( document ); extractSecurityConstraints( document ); extractContextParameters( document ); extractLoginConfiguration( document ); extractListeners( document ); notifyContextInitialized(); _servletMapping.autoLoadServlets(); }
private URL computeEffectiveUrl( HttpServletRequest request, URL requestURL ) { if (!_application.requiresAuthorization( requestURL ) || userIsAuthorized( request, requestURL ) ) { return requestURL; } else if (request.getRemoteUser() != null) { throw new AccessDeniedException( requestURL ); } else if (_application.usesBasicAuthentication()) { throw AuthorizationRequiredException.createBasicAuthenticationRequiredException( _application.getAuthenticationRealm() ); } else if (!_application.usesFormAuthentication()) { throw new IllegalStateException( "Authorization required but no authentication method defined" ); } else { ((ServletUnitHttpSession) request.getSession()).setOriginalURL( requestURL ); return _application.getLoginURL(); } }
@Override public Set<String> getResourcePaths(String path) { File root = getWebApplication().getResourceFile(path); Set<String> paths = new TreeSet<String>(); File[] files = root.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { paths.add(path + file.getName() + "/"); } else { paths.add(path + file.getName()); } } } return paths; }
/** * Default constructor, which defines no servlets. */ public ServletRunner() { _application = new WebApplication(); completeInitialization( null ); }
void shutDown() { destroyServlets(); notifyContextDestroyed(); }
private Hashtable getContextParams() { return _application.getContextParameters(); }
/** * Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher * object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static. * The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext to obtain a * RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a * RequestDispatcher. **/ public javax.servlet.RequestDispatcher getRequestDispatcher( String path ) { try { URL url = new URL( "http", "localhost", _application.getContextPath() + path ); return new RequestDispatcherImpl( _application, url ); } catch (ServletException e) { return null; } catch (MalformedURLException e) { return null; } }
/** * Returns a String containing the real path for a given virtual path. For example, the virtual path "/index.html" has a real path of * whatever file on the server's filesystem would be served by a request for "/index.html". * * The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, * including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for * any reason (such as when the content is being made available from a .war archive). **/ public String getRealPath( String path ) { return _application.getResourceFile( path ).getAbsolutePath(); }
/** * Constructor which expects a File object representing the web.xml for the * application and a context path under which to mount it. * * @param webXml the web.xml file * @param contextPath the context path * @since 1.6 */ public ServletRunner( File webXml, String contextPath ) throws IOException, SAXException { _application = new WebApplication( HttpUnitUtils.newParser().parse( webXml ), webXml.getParentFile().getParentFile(), contextPath ); completeInitialization( contextPath ); }