Пример #1
0
  @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();
  }
Пример #2
0
  public void setDefaults(Resource webDefaults) throws Exception {
    _webDefaultsRoot = new DefaultsDescriptor(webDefaults);
    _webDefaultsRoot.parse();
    if (_webDefaultsRoot.isOrdered()) {
      if (_ordering == null) _ordering = new Ordering.AbsoluteOrdering(this);

      List<String> order = _webDefaultsRoot.getOrdering();
      for (String s : order) {
        if (s.equalsIgnoreCase("others")) ((Ordering.AbsoluteOrdering) _ordering).addOthers();
        else ((Ordering.AbsoluteOrdering) _ordering).add(s);
      }
    }
  }
Пример #3
0
  public boolean isDistributable() {
    boolean distributable =
        ((_webDefaultsRoot != null && _webDefaultsRoot.isDistributable())
            || (_webXmlRoot != null && _webXmlRoot.isDistributable()));

    for (WebDescriptor d : _webOverrideRoots) distributable &= d.isDistributable();

    List<Resource> orderedResources = getOrderedWebInfJars();
    for (Resource r : orderedResources) {
      FragmentDescriptor d = _webFragmentResourceMap.get(r);
      if (d != null) distributable = distributable && d.isDistributable();
    }
    return distributable;
  }
Пример #4
0
  public void setWebXml(Resource webXml) throws Exception {
    _webXmlRoot = new WebDescriptor(webXml);
    _webXmlRoot.parse();
    _metaDataComplete = _webXmlRoot.getMetaDataComplete() == MetaDataComplete.True;

    if (_webXmlRoot.isOrdered()) {
      if (_ordering == null) _ordering = new Ordering.AbsoluteOrdering(this);

      List<String> order = _webXmlRoot.getOrdering();
      for (String s : order) {
        if (s.equalsIgnoreCase("others")) ((Ordering.AbsoluteOrdering) _ordering).addOthers();
        else ((Ordering.AbsoluteOrdering) _ordering).add(s);
      }
    }
  }
 public boolean isMetaDataComplete(WebDescriptor d) {
   return (d != null && d.getMetaDataComplete() == MetaDataComplete.True);
 }
Пример #6
0
  /** Resolve all servlet/filter/listener metadata from all sources: descriptors and annotations. */
  public void resolve(WebAppContext context) throws Exception {
    LOG.debug("metadata resolve {}", context);

    // Ensure origins is fresh
    _origins.clear();

    // Set the ordered lib attribute
    if (_ordering != null) {
      List<String> orderedLibs = new ArrayList<String>();
      for (Resource webInfJar : _orderedWebInfJars) {
        // get just the name of the jar file
        String fullname = webInfJar.getName();
        int i = fullname.indexOf(".jar");
        int j = fullname.lastIndexOf("/", i);
        orderedLibs.add(fullname.substring(j + 1, i + 4));
      }
      context.setAttribute(ServletContext.ORDERED_LIBS, orderedLibs);
    }

    // set the webxml version
    if (_webXmlRoot != null) {
      context.getServletContext().setEffectiveMajorVersion(_webXmlRoot.getMajorVersion());
      context.getServletContext().setEffectiveMinorVersion(_webXmlRoot.getMinorVersion());
    }

    for (DescriptorProcessor p : _descriptorProcessors) {
      p.process(context, getWebDefault());
      p.process(context, getWebXml());
      for (WebDescriptor wd : getOverrideWebs()) {
        LOG.debug("process {} {}", context, wd);
        p.process(context, wd);
      }
    }

    // get an apply the annotations that are not associated with a fragment (and hence for
    // which no ordering applies
    List<DiscoveredAnnotation> nonFragAnnotations = _annotations.get(NON_FRAG_RESOURCE);
    if (nonFragAnnotations != null) {
      for (DiscoveredAnnotation a : nonFragAnnotations) {
        LOG.debug("apply {}", a);
        a.apply();
      }
    }

    // apply the annotations that are associated with a fragment, according to the
    // established ordering
    List<Resource> resources = getOrderedWebInfJars();
    for (Resource r : resources) {
      FragmentDescriptor fd = _webFragmentResourceMap.get(r);
      if (fd != null) {
        for (DescriptorProcessor p : _descriptorProcessors) {
          LOG.debug("process {} {}", context, fd);
          p.process(context, fd);
        }
      }

      List<DiscoveredAnnotation> fragAnnotations = _annotations.get(r);
      if (fragAnnotations != null) {
        for (DiscoveredAnnotation a : fragAnnotations) {
          LOG.debug("apply {}", a);
          a.apply();
        }
      }
    }
  }