Search in sources :

Example 1 with Node

use of org.eclipse.jetty.xml.XmlParser.Node in project jetty.project by eclipse.

the class StandardDescriptorProcessor method visitServlet.

public void visitServlet(WebAppContext context, Descriptor descriptor, XmlParser.Node node) {
    String id = node.getAttribute("id");
    // initialize holder
    String name = node.getString("servlet-name", false, true);
    ServletHolder holder = _servletHolderMap.get(name);
    //If servlet of that name does not already exist, create it.
    if (holder == null) {
        holder = context.getServletHandler().newServletHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
        holder.setName(name);
        _servletHolderMap.put(name, holder);
        _servletHolders.add(holder);
    }
    // init params
    Iterator<?> iParamsIter = node.iterator("init-param");
    while (iParamsIter.hasNext()) {
        XmlParser.Node paramNode = (XmlParser.Node) iParamsIter.next();
        String pname = paramNode.getString("param-name", false, true);
        String pvalue = paramNode.getString("param-value", false, true);
        String originName = name + ".servlet.init-param." + pname;
        Descriptor originDescriptor = context.getMetaData().getOriginDescriptor(originName);
        switch(context.getMetaData().getOrigin(originName)) {
            case NotSet:
                {
                    //init-param not already set, so set it
                    holder.setInitParameter(pname, pvalue);
                    context.getMetaData().setOrigin(originName, descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //otherwise just ignore it
                    if (!(descriptor instanceof FragmentDescriptor) && (descriptor != originDescriptor)) {
                        holder.setInitParameter(pname, pvalue);
                        context.getMetaData().setOrigin(originName, descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //previously set by a web-fragment, make sure that the value matches, otherwise its an error
                    if ((descriptor != originDescriptor) && !holder.getInitParameter(pname).equals(pvalue))
                        throw new IllegalStateException("Mismatching init-param " + pname + "=" + pvalue + " in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
    }
    String servlet_class = node.getString("servlet-class", false, true);
    if ("".equals(servlet_class))
        servlet_class = null;
    //Handle the default jsp servlet instance
    if (id != null && id.equals("jsp") && servlet_class != null) {
        try {
            Loader.loadClass(servlet_class);
        } catch (ClassNotFoundException e) {
            LOG.info("NO JSP Support for {}, did not find {}", context.getContextPath(), servlet_class);
            servlet_class = "org.eclipse.jetty.servlet.NoJspServlet";
        }
    }
    //Set the servlet-class
    if (servlet_class != null) {
        ((WebDescriptor) descriptor).addClassName(servlet_class);
        switch(context.getMetaData().getOrigin(name + ".servlet.servlet-class")) {
            case NotSet:
                {
                    //the class of the servlet has not previously been set, so set it
                    holder.setClassName(servlet_class);
                    context.getMetaData().setOrigin(name + ".servlet.servlet-class", descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //the class of the servlet was set by a web xml file, only allow web-override/web-default to change it
                    if (!(descriptor instanceof FragmentDescriptor)) {
                        holder.setClassName(servlet_class);
                        context.getMetaData().setOrigin(name + ".servlet.servlet-class", descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //the class was set by another fragment, ensure this fragment's value is the same
                    if (!servlet_class.equals(holder.getClassName()))
                        throw new IllegalStateException("Conflicting servlet-class " + servlet_class + " in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
    }
    // Handle JSP file
    String jsp_file = node.getString("jsp-file", false, true);
    if (jsp_file != null)
        holder.setForcedPath(jsp_file);
    // handle load-on-startup
    XmlParser.Node startup = node.get("load-on-startup");
    if (startup != null) {
        String s = startup.toString(false, true).toLowerCase(Locale.ENGLISH);
        int order = 0;
        if (s.startsWith("t")) {
            LOG.warn("Deprecated boolean load-on-startup.  Please use integer");
            order = 1;
        } else {
            try {
                if (s != null && s.trim().length() > 0)
                    order = Integer.parseInt(s);
            } catch (Exception e) {
                LOG.warn("Cannot parse load-on-startup " + s + ". Please use integer");
                LOG.ignore(e);
            }
        }
        switch(context.getMetaData().getOrigin(name + ".servlet.load-on-startup")) {
            case NotSet:
                {
                    //not already set, so set it now
                    holder.setInitOrder(order);
                    context.getMetaData().setOrigin(name + ".servlet.load-on-startup", descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //if it was already set by a web xml descriptor and we're parsing another web xml descriptor, then override it
                    if (!(descriptor instanceof FragmentDescriptor)) {
                        holder.setInitOrder(order);
                        context.getMetaData().setOrigin(name + ".servlet.load-on-startup", descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //it was already set by another fragment, if we're parsing a fragment, the values must match
                    if (order != holder.getInitOrder())
                        throw new IllegalStateException("Conflicting load-on-startup value in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
    }
    Iterator<Node> sRefsIter = node.iterator("security-role-ref");
    while (sRefsIter.hasNext()) {
        XmlParser.Node securityRef = (XmlParser.Node) sRefsIter.next();
        String roleName = securityRef.getString("role-name", false, true);
        String roleLink = securityRef.getString("role-link", false, true);
        if (roleName != null && roleName.length() > 0 && roleLink != null && roleLink.length() > 0) {
            if (LOG.isDebugEnabled())
                LOG.debug("link role " + roleName + " to " + roleLink + " for " + this);
            switch(context.getMetaData().getOrigin(name + ".servlet.role-name." + roleName)) {
                case NotSet:
                    {
                        //set it
                        holder.setUserRoleLink(roleName, roleLink);
                        context.getMetaData().setOrigin(name + ".servlet.role-name." + roleName, descriptor);
                        break;
                    }
                case WebXml:
                case WebDefaults:
                case WebOverride:
                    {
                        //only another web xml descriptor (web-default,web-override web.xml) can override an already set value
                        if (!(descriptor instanceof FragmentDescriptor)) {
                            holder.setUserRoleLink(roleName, roleLink);
                            context.getMetaData().setOrigin(name + ".servlet.role-name." + roleName, descriptor);
                        }
                        break;
                    }
                case WebFragment:
                    {
                        if (!holder.getUserRoleLink(roleName).equals(roleLink))
                            throw new IllegalStateException("Conflicting role-link for role-name " + roleName + " for servlet " + name + " in " + descriptor.getResource());
                        break;
                    }
                default:
                    // TODO throw ISE?
                    LOG.warn(new Throwable());
            }
        } else {
            LOG.warn("Ignored invalid security-role-ref element: " + "servlet-name=" + holder.getName() + ", " + securityRef);
        }
    }
    XmlParser.Node run_as = node.get("run-as");
    if (run_as != null) {
        String roleName = run_as.getString("role-name", false, true);
        if (roleName != null) {
            switch(context.getMetaData().getOrigin(name + ".servlet.run-as")) {
                case NotSet:
                    {
                        //run-as not set, so set it
                        holder.setRunAsRole(roleName);
                        context.getMetaData().setOrigin(name + ".servlet.run-as", descriptor);
                        break;
                    }
                case WebXml:
                case WebDefaults:
                case WebOverride:
                    {
                        //run-as was set by a web xml, only allow it to be changed if we're currently parsing another web xml(override/default)
                        if (!(descriptor instanceof FragmentDescriptor)) {
                            holder.setRunAsRole(roleName);
                            context.getMetaData().setOrigin(name + ".servlet.run-as", descriptor);
                        }
                        break;
                    }
                case WebFragment:
                    {
                        //run-as was set by another fragment, this fragment must show the same value
                        if (!holder.getRunAsRole().equals(roleName))
                            throw new IllegalStateException("Conflicting run-as role " + roleName + " for servlet " + name + " in " + descriptor.getResource());
                        break;
                    }
                default:
                    // TODO throw ISE?
                    LOG.warn(new Throwable());
            }
        }
    }
    String async = node.getString("async-supported", false, true);
    if (async != null) {
        boolean val = async.length() == 0 || Boolean.valueOf(async);
        switch(context.getMetaData().getOrigin(name + ".servlet.async-supported")) {
            case NotSet:
                {
                    //set it
                    holder.setAsyncSupported(val);
                    context.getMetaData().setOrigin(name + ".servlet.async-supported", descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //async-supported set by previous web xml descriptor, only allow override if we're parsing another web descriptor(web.xml/web-override.xml/web-default.xml)
                    if (!(descriptor instanceof FragmentDescriptor)) {
                        holder.setAsyncSupported(val);
                        context.getMetaData().setOrigin(name + ".servlet.async-supported", descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //async-supported set by another fragment, this fragment's value must match
                    if (holder.isAsyncSupported() != val)
                        throw new IllegalStateException("Conflicting async-supported=" + async + " for servlet " + name + " in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
    }
    String enabled = node.getString("enabled", false, true);
    if (enabled != null) {
        boolean is_enabled = enabled.length() == 0 || Boolean.valueOf(enabled);
        switch(context.getMetaData().getOrigin(name + ".servlet.enabled")) {
            case NotSet:
                {
                    //hasn't been set yet, so set it
                    holder.setEnabled(is_enabled);
                    context.getMetaData().setOrigin(name + ".servlet.enabled", descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //was set in a web xml descriptor, only allow override from another web xml descriptor
                    if (!(descriptor instanceof FragmentDescriptor)) {
                        holder.setEnabled(is_enabled);
                        context.getMetaData().setOrigin(name + ".servlet.enabled", descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //was set by another fragment, this fragment's value must match
                    if (holder.isEnabled() != is_enabled)
                        throw new IllegalStateException("Conflicting value of servlet enabled for servlet " + name + " in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
    }
    /*
         * If multipart config not set, then set it and record it was by the web.xml or fragment.
         * If it was set by web.xml then if this is a fragment, ignore the settings.
         * If it was set by a fragment, if this is a fragment and the values are different, error!
         */
    XmlParser.Node multipart = node.get("multipart-config");
    if (multipart != null) {
        String location = multipart.getString("location", false, true);
        String maxFile = multipart.getString("max-file-size", false, true);
        String maxRequest = multipart.getString("max-request-size", false, true);
        String threshold = multipart.getString("file-size-threshold", false, true);
        MultipartConfigElement element = new MultipartConfigElement(location, (maxFile == null || "".equals(maxFile) ? -1L : Long.parseLong(maxFile)), (maxRequest == null || "".equals(maxRequest) ? -1L : Long.parseLong(maxRequest)), (threshold == null || "".equals(threshold) ? 0 : Integer.parseInt(threshold)));
        switch(context.getMetaData().getOrigin(name + ".servlet.multipart-config")) {
            case NotSet:
                {
                    //hasn't been set, so set it
                    holder.getRegistration().setMultipartConfig(element);
                    context.getMetaData().setOrigin(name + ".servlet.multipart-config", descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //was set in a web xml, only allow changes if we're parsing another web xml (web.xml/web-default.xml/web-override.xml)
                    if (!(descriptor instanceof FragmentDescriptor)) {
                        holder.getRegistration().setMultipartConfig(element);
                        context.getMetaData().setOrigin(name + ".servlet.multipart-config", descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //another fragment set the value, this fragment's values must match exactly or it is an error
                    MultipartConfigElement cfg = ((ServletHolder.Registration) holder.getRegistration()).getMultipartConfig();
                    if (cfg.getMaxFileSize() != element.getMaxFileSize())
                        throw new IllegalStateException("Conflicting multipart-config max-file-size for servlet " + name + " in " + descriptor.getResource());
                    if (cfg.getMaxRequestSize() != element.getMaxRequestSize())
                        throw new IllegalStateException("Conflicting multipart-config max-request-size for servlet " + name + " in " + descriptor.getResource());
                    if (cfg.getFileSizeThreshold() != element.getFileSizeThreshold())
                        throw new IllegalStateException("Conflicting multipart-config file-size-threshold for servlet " + name + " in " + descriptor.getResource());
                    if ((cfg.getLocation() != null && (element.getLocation() == null || element.getLocation().length() == 0)) || (cfg.getLocation() == null && (element.getLocation() != null || element.getLocation().length() > 0)))
                        throw new IllegalStateException("Conflicting multipart-config location for servlet " + name + " in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
    }
}
Also used : XmlParser(org.eclipse.jetty.xml.XmlParser) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Node(org.eclipse.jetty.xml.XmlParser.Node) Node(org.eclipse.jetty.xml.XmlParser.Node) Source(org.eclipse.jetty.servlet.Source) Constraint(org.eclipse.jetty.util.security.Constraint) ServletException(javax.servlet.ServletException) MultipartConfigElement(javax.servlet.MultipartConfigElement)

Example 2 with Node

use of org.eclipse.jetty.xml.XmlParser.Node in project jetty.project by eclipse.

the class StandardDescriptorProcessor method visitFilter.

public void visitFilter(WebAppContext context, Descriptor descriptor, XmlParser.Node node) {
    String name = node.getString("filter-name", false, true);
    FilterHolder holder = _filterHolderMap.get(name);
    if (holder == null) {
        holder = context.getServletHandler().newFilterHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
        holder.setName(name);
        _filterHolderMap.put(name, holder);
        _filterHolders.add(holder);
    }
    String filter_class = node.getString("filter-class", false, true);
    if (filter_class != null) {
        ((WebDescriptor) descriptor).addClassName(filter_class);
        switch(context.getMetaData().getOrigin(name + ".filter.filter-class")) {
            case NotSet:
                {
                    //no class set yet
                    holder.setClassName(filter_class);
                    context.getMetaData().setOrigin(name + ".filter.filter-class", descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //filter class was set in web.xml, only allow other web xml descriptors (override/default) to change it
                    if (!(descriptor instanceof FragmentDescriptor)) {
                        holder.setClassName(filter_class);
                        context.getMetaData().setOrigin(name + ".filter.filter-class", descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //the filter class was set up by a web fragment, all fragments must be the same
                    if (!holder.getClassName().equals(filter_class))
                        throw new IllegalStateException("Conflicting filter-class for filter " + name + " in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
    }
    Iterator<XmlParser.Node> iter = node.iterator("init-param");
    while (iter.hasNext()) {
        XmlParser.Node paramNode = iter.next();
        String pname = paramNode.getString("param-name", false, true);
        String pvalue = paramNode.getString("param-value", false, true);
        switch(context.getMetaData().getOrigin(name + ".filter.init-param." + pname)) {
            case NotSet:
                {
                    //init-param not already set, so set it
                    holder.setInitParameter(pname, pvalue);
                    context.getMetaData().setOrigin(name + ".filter.init-param." + pname, descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //otherwise just ignore it
                    if (!(descriptor instanceof FragmentDescriptor)) {
                        holder.setInitParameter(pname, pvalue);
                        context.getMetaData().setOrigin(name + ".filter.init-param." + pname, descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //previously set by a web-fragment, make sure that the value matches, otherwise its an error
                    if (!holder.getInitParameter(pname).equals(pvalue))
                        throw new IllegalStateException("Mismatching init-param " + pname + "=" + pvalue + " in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
    }
    String async = node.getString("async-supported", false, true);
    if (async != null)
        holder.setAsyncSupported(async.length() == 0 || Boolean.valueOf(async));
    if (async != null) {
        boolean val = async.length() == 0 || Boolean.valueOf(async);
        switch(context.getMetaData().getOrigin(name + ".filter.async-supported")) {
            case NotSet:
                {
                    //set it
                    holder.setAsyncSupported(val);
                    context.getMetaData().setOrigin(name + ".filter.async-supported", descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //async-supported set by previous web xml descriptor, only allow override if we're parsing another web descriptor(web.xml/web-override.xml/web-default.xml)
                    if (!(descriptor instanceof FragmentDescriptor)) {
                        holder.setAsyncSupported(val);
                        context.getMetaData().setOrigin(name + ".filter.async-supported", descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //async-supported set by another fragment, this fragment's value must match
                    if (holder.isAsyncSupported() != val)
                        throw new IllegalStateException("Conflicting async-supported=" + async + " for filter " + name + " in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
    }
}
Also used : XmlParser(org.eclipse.jetty.xml.XmlParser) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Node(org.eclipse.jetty.xml.XmlParser.Node) Node(org.eclipse.jetty.xml.XmlParser.Node) Source(org.eclipse.jetty.servlet.Source)

Example 3 with Node

use of org.eclipse.jetty.xml.XmlParser.Node in project jetty.project by eclipse.

the class StandardDescriptorProcessor method visitLoginConfig.

public void visitLoginConfig(WebAppContext context, Descriptor descriptor, XmlParser.Node node) throws Exception {
    //ServletSpec 3.0 p74 says elements present 0/1 time if specified in web.xml take
    //precendece over any web-fragment. If not specified in web.xml, then if specified
    //in a web-fragment must be the same across all web-fragments.
    XmlParser.Node method = node.get("auth-method");
    if (method != null) {
        //handle auth-method merge
        switch(context.getMetaData().getOrigin("auth-method")) {
            case NotSet:
                {
                    //not already set, so set it now
                    context.getSecurityHandler().setAuthMethod(method.toString(false, true));
                    context.getMetaData().setOrigin("auth-method", descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //if it was already set by a web xml descriptor and we're parsing another web xml descriptor, then override it
                    if (!(descriptor instanceof FragmentDescriptor)) {
                        context.getSecurityHandler().setAuthMethod(method.toString(false, true));
                        context.getMetaData().setOrigin("auth-method", descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //it was already set by another fragment, if we're parsing a fragment, the values must match
                    if (!context.getSecurityHandler().getAuthMethod().equals(method.toString(false, true)))
                        throw new IllegalStateException("Conflicting auth-method value in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
        //handle realm-name merge
        XmlParser.Node name = node.get("realm-name");
        String nameStr = (name == null ? "default" : name.toString(false, true));
        switch(context.getMetaData().getOrigin("realm-name")) {
            case NotSet:
                {
                    //no descriptor has set the realm-name yet, so set it
                    context.getSecurityHandler().setRealmName(nameStr);
                    context.getMetaData().setOrigin("realm-name", descriptor);
                    break;
                }
            case WebXml:
            case WebDefaults:
            case WebOverride:
                {
                    //set by a web xml file (web.xml/web-default.xm/web-override.xml), only allow it to be changed by another web xml file
                    if (!(descriptor instanceof FragmentDescriptor)) {
                        context.getSecurityHandler().setRealmName(nameStr);
                        context.getMetaData().setOrigin("realm-name", descriptor);
                    }
                    break;
                }
            case WebFragment:
                {
                    //a fragment set it, and we must be parsing another fragment, so the values must match
                    if (!context.getSecurityHandler().getRealmName().equals(nameStr))
                        throw new IllegalStateException("Conflicting realm-name value in " + descriptor.getResource());
                    break;
                }
            default:
                // TODO throw ISE?
                LOG.warn(new Throwable());
        }
        if (Constraint.__FORM_AUTH.equalsIgnoreCase(context.getSecurityHandler().getAuthMethod())) {
            XmlParser.Node formConfig = node.get("form-login-config");
            if (formConfig != null) {
                String loginPageName = null;
                XmlParser.Node loginPage = formConfig.get("form-login-page");
                if (loginPage != null)
                    loginPageName = loginPage.toString(false, true);
                String errorPageName = null;
                XmlParser.Node errorPage = formConfig.get("form-error-page");
                if (errorPage != null)
                    errorPageName = errorPage.toString(false, true);
                //handle form-login-page
                switch(context.getMetaData().getOrigin("form-login-page")) {
                    case NotSet:
                        {
                            //Never been set before, so accept it
                            context.getSecurityHandler().setInitParameter(FormAuthenticator.__FORM_LOGIN_PAGE, loginPageName);
                            context.getMetaData().setOrigin("form-login-page", descriptor);
                            break;
                        }
                    case WebXml:
                    case WebDefaults:
                    case WebOverride:
                        {
                            //a web xml descriptor previously set it, only allow another one to change it (web.xml/web-default.xml/web-override.xml)
                            if (!(descriptor instanceof FragmentDescriptor)) {
                                context.getSecurityHandler().setInitParameter(FormAuthenticator.__FORM_LOGIN_PAGE, loginPageName);
                                context.getMetaData().setOrigin("form-login-page", descriptor);
                            }
                            break;
                        }
                    case WebFragment:
                        {
                            //a web-fragment previously set it. We must be parsing yet another web-fragment, so the values must agree
                            if (!context.getSecurityHandler().getInitParameter(FormAuthenticator.__FORM_LOGIN_PAGE).equals(loginPageName))
                                throw new IllegalStateException("Conflicting form-login-page value in " + descriptor.getResource());
                            break;
                        }
                    default:
                        // TODO throw ISE?
                        LOG.warn(new Throwable());
                }
                //handle form-error-page
                switch(context.getMetaData().getOrigin("form-error-page")) {
                    case NotSet:
                        {
                            //Never been set before, so accept it
                            context.getSecurityHandler().setInitParameter(FormAuthenticator.__FORM_ERROR_PAGE, errorPageName);
                            context.getMetaData().setOrigin("form-error-page", descriptor);
                            break;
                        }
                    case WebXml:
                    case WebDefaults:
                    case WebOverride:
                        {
                            //a web xml descriptor previously set it, only allow another one to change it (web.xml/web-default.xml/web-override.xml)
                            if (!(descriptor instanceof FragmentDescriptor)) {
                                context.getSecurityHandler().setInitParameter(FormAuthenticator.__FORM_ERROR_PAGE, errorPageName);
                                context.getMetaData().setOrigin("form-error-page", descriptor);
                            }
                            break;
                        }
                    case WebFragment:
                        {
                            //a web-fragment previously set it. We must be parsing yet another web-fragment, so the values must agree
                            if (!context.getSecurityHandler().getInitParameter(FormAuthenticator.__FORM_ERROR_PAGE).equals(errorPageName))
                                throw new IllegalStateException("Conflicting form-error-page value in " + descriptor.getResource());
                            break;
                        }
                    default:
                        // TODO throw ISE?
                        LOG.warn(new Throwable());
                }
            } else {
                throw new IllegalStateException("!form-login-config");
            }
        }
    }
}
Also used : XmlParser(org.eclipse.jetty.xml.XmlParser) Node(org.eclipse.jetty.xml.XmlParser.Node)

Example 4 with Node

use of org.eclipse.jetty.xml.XmlParser.Node in project jetty.project by eclipse.

the class StandardDescriptorProcessor method addWelcomeFiles.

public void addWelcomeFiles(WebAppContext context, XmlParser.Node node) {
    Iterator<XmlParser.Node> iter = node.iterator("welcome-file");
    while (iter.hasNext()) {
        XmlParser.Node indexNode = (XmlParser.Node) iter.next();
        String welcome = indexNode.toString(false, true);
        //Servlet Spec 3.0 p. 74 welcome files are additive
        if (welcome != null && welcome.trim().length() > 0)
            context.setWelcomeFiles((String[]) ArrayUtil.addToArray(context.getWelcomeFiles(), welcome, String.class));
    }
}
Also used : XmlParser(org.eclipse.jetty.xml.XmlParser) Node(org.eclipse.jetty.xml.XmlParser.Node) Node(org.eclipse.jetty.xml.XmlParser.Node)

Example 5 with Node

use of org.eclipse.jetty.xml.XmlParser.Node in project jetty.project by eclipse.

the class QuickStartTest method testStandardTestWar.

@Test
public void testStandardTestWar() throws Exception {
    PreconfigureStandardTestWar.main(new String[] {});
    WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-standard-preconfigured/WEB-INF/quickstart-web.xml"));
    descriptor.setValidating(true);
    descriptor.parse();
    Node node = descriptor.getRoot();
    assertThat(node, Matchers.notNullValue());
    System.setProperty("jetty.home", "target");
    //war file or dir to start
    String war = "target/test-standard-preconfigured";
    //optional jetty context xml file to configure the webapp
    Resource contextXml = Resource.newResource("src/test/resources/test.xml");
    Server server = new Server(0);
    QuickStartWebApp webapp = new QuickStartWebApp();
    webapp.setAutoPreconfigure(true);
    webapp.setWar(war);
    webapp.setContextPath("/");
    //apply context xml file
    if (contextXml != null) {
        // System.err.println("Applying "+contextXml);
        XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
        xmlConfiguration.configure(webapp);
    }
    server.setHandler(webapp);
    server.start();
    URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/test/dump/info");
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    assertEquals(200, connection.getResponseCode());
    assertThat(IO.toString((InputStream) connection.getContent()), Matchers.containsString("Dump Servlet"));
    server.stop();
}
Also used : WebDescriptor(org.eclipse.jetty.webapp.WebDescriptor) HttpURLConnection(java.net.HttpURLConnection) Server(org.eclipse.jetty.server.Server) InputStream(java.io.InputStream) Node(org.eclipse.jetty.xml.XmlParser.Node) Resource(org.eclipse.jetty.util.resource.Resource) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Node (org.eclipse.jetty.xml.XmlParser.Node)14 XmlParser (org.eclipse.jetty.xml.XmlParser)9 ArrayList (java.util.ArrayList)4 Source (org.eclipse.jetty.servlet.Source)4 Constraint (org.eclipse.jetty.util.security.Constraint)4 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 Server (org.eclipse.jetty.server.Server)3 Resource (org.eclipse.jetty.util.resource.Resource)3 WebDescriptor (org.eclipse.jetty.webapp.WebDescriptor)3 XmlConfiguration (org.eclipse.jetty.xml.XmlConfiguration)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 ConstraintAware (org.eclipse.jetty.security.ConstraintAware)2 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)2 HashSet (java.util.HashSet)1 DispatcherType (javax.servlet.DispatcherType)1 MultipartConfigElement (javax.servlet.MultipartConfigElement)1 ServletException (javax.servlet.ServletException)1 SessionTrackingMode (javax.servlet.SessionTrackingMode)1