Package org.apache.jetspeed.util.descriptor

Examples of org.apache.jetspeed.util.descriptor.PortletApplicationWar


  protected void startPA(String contextName, FileSystemHelper warStruct,
    ClassLoader paClassLoader, boolean local)
    throws RegistryException
  {
    PortletApplicationWar paWar = null;

    try
    {
      try
      {
        paWar = new PortletApplicationWar(warStruct, contextName, "/" + contextName);

        if (paClassLoader == null)
        {
          paClassLoader = paWar.createClassloader(getClass().getClassLoader());
        }
      }
      catch (IOException e)
      {
        String msg = "Failed to create PA WAR for " + contextName;
        log.error(msg, e);
        throw new RegistryException(msg, e);
      }

      MutablePortletApplication pa = (MutablePortletApplication) registry
        .getPortletApplication(contextName);

      if ((pa != null) && (paWar.getPortletApplicationChecksum() == pa.getChecksum()))
      {
                portletFactory.unregisterPortletApplication(pa);
      }
      else
      {
        pa = registerPortletApplication(paWar, pa, local);
      }
            portletFactory.registerPortletApplication(pa, paClassLoader);
    }
    finally
    {
      if (paWar != null)
      {
        try
        {
          paWar.close();
        }
        catch (IOException e)
        {
          log.error("Failed to close PA WAR for " + contextName, e);
        }
View Full Code Here


        }
        if (log.isDebugEnabled())
        {
            log.debug("Is portlet application " + contextName + " monitored? -> " + monitored);
        }
        PortletApplicationWar paWar = null;
        try
        {
            if (log.isDebugEnabled())
            {
                log.debug("Try to start portlet application " + contextName + ".");
            }
            // create PA  from war (file) structure
            // paWar = new PortletApplicationWar(warStruct, contextName, "/" + contextName, checksum);
            paWar = new PortletApplicationWar(warStruct, contextName, contextPath, checksum, this.descriptorService);
            try
            {
                if (paClassLoader == null)
                {
                    paClassLoader = paWar.createClassloader(this.getClass().getClassLoader());
                }               
                // create checksum from PA descriptors
                checksum = paWar.getPortletApplicationChecksum();               
               
                if (log.isDebugEnabled())
                {
                    log.debug("New checksum for portlet application " + contextName + " is " + checksum);
                }
View Full Code Here

    }

    public void testInfusingWebXML() throws Exception
    {
        File warFile = new File("./test/testdata/deploy/webapp");
        PortletApplicationWar paWar = new PortletApplicationWar(new DirectoryHelper(warFile), "unit-test", "/" );

        SAXBuilder builder = new SAXBuilder(false);

        // Use the local dtd instead of remote dtd. This
        // allows to deploy the application offline
        builder.setEntityResolver(new EntityResolver()
        {
            public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
                throws SAXException, java.io.IOException
            {

                if (systemId.equals("http://java.sun.com/dtd/web-app_2_3.dtd"))
                {
                    return new InputSource(PortletApplicationWar.class.getResourceAsStream("web-app_2_3.dtd"));
                }
                else
                    return null;
            }
        });

        FileReader srcReader = new FileReader("./test/testdata/deploy/webapp/WEB-INF/web.xml");
        FileReader targetReader = null;
        Document  doc = builder.build(srcReader);

        Element root = doc.getRootElement();

        try
        {
            Object jetspeedServlet = XPath.selectSingleNode(root, PortletApplicationWar.JETSPEED_SERVLET_XPATH);
            Object jetspeedServletMapping = XPath.selectSingleNode(root, PortletApplicationWar.JETSPEED_SERVLET_MAPPING_XPATH);

            assertNull(jetspeedServlet);
            assertNull(jetspeedServletMapping);

            PortletApplicationWar targetWar = paWar.copyWar("./target/webapp");
            targetWar.processWebXML();

            targetReader = new FileReader("./target/webapp/WEB-INF/web.xml");

            Document targetDoc = builder.build(targetReader);
View Full Code Here

   
    public void testSecurityRoles() throws Exception
    {
        System.out.println("Testing securityRoles");
        File warFile = new File("./test/testdata/deploy/webapp");
        PortletApplicationWar paWar = new PortletApplicationWar(new DirectoryHelper(warFile), "unit-test", "/" );

        MutablePortletApplication app = paWar.createPortletApp();
        assertNotNull("App is null", app);

        MutableWebApplication webApp = paWar.createWebApp();
        assertNotNull("WebApp is null", webApp);

        app.setWebApplicationDefinition(webApp);

        PortletDefinition portlet = app.getPortletDefinitionByName("TestPortlet");
        assertNotNull("TestPortlet is null", portlet);
        checkWebSecurityRoles(webApp);
        checkPortletSecurityRoleRefs(portlet);
        boolean validateFailed = false;
        try
        {
            paWar.validate();
        }
        catch (PortletApplicationException e)
        {
            validateFailed = true;
        }
        assertTrue("Invalid PortletDescriptor validation result", validateFailed);
        SecurityRoleImpl role = new SecurityRoleImpl();
        role.setRoleName("users.manager");
        webApp.addSecurityRole(role);
        try
        {
            paWar.validate();
            validateFailed = false;
        }
        catch (PortletApplicationException e)
        {
        }
        assertEquals("Invalid PortletDescriptor validation result", false, validateFailed);

        // persist the app
        try
        {
           
            portletRegistry.registerPortletApplication(app);
           
        }
        catch (Exception e)
        {
            String msg = "Unable to register portlet application, " + app.getName()
                    + ", through the portlet registry: " + e.toString();
           
            throw new Exception(msg, e);
        }
        // clear cache
       

        // read back in
        app = portletRegistry.getPortletApplication("unit-test");
        validateFailed = true;
        try
        {
            paWar.validate();
            validateFailed = false;
        }
        catch (PortletApplicationException e)
        {
        }
View Full Code Here

 
  protected void startPA(String contextName, FileSystemHelper warStruct,
          ClassLoader paClassLoader, int paType, long checksum)
  throws RegistryException
  {
        PortletApplicationWar paWar = null;
    try
    {
            boolean register = true;
            boolean monitored = checksum != 0;
            paWar = new PortletApplicationWar(warStruct, contextName, "/" + contextName, checksum);
            try
            {
                if (paClassLoader == null)
                {
                    paClassLoader = paWar.createClassloader(getClass().getClassLoader());
                }               
                checksum = paWar.getPortletApplicationChecksum();               
            }
            catch (IOException e)
            {
                String msg = "Invalid PA WAR for " + contextName;
                log.error(msg, e);
                if ( paClassLoader == null )
                {
                    // nothing to be done about it anymore: this pa is beyond repair :(
                    throw new RegistryException(e);
                }
                register = false;
            }

      MutablePortletApplication pa = registry.getPortletApplication(contextName);

            if (pa != null)
            {
                if ( pa.getApplicationType() != paType )
                {
                    throw new RegistryException("Cannot start portlet application "+contextName+": as Application Types don't match: " + pa.getApplicationType() + " != " + paType);
                }
                DescriptorChangeMonitor changeMonitor = this.monitor;
                if (!monitored && changeMonitor != null)
                {
                    changeMonitor.remove(contextName);
                }
                portletFactory.unregisterPortletApplication(pa);                       
            }
//            if (register && (pa == null || checksum != pa.getChecksum()))
            if (register)
            {
              if (pa == null)
              {
                // new
                  try
                  {
                      pa = registerPortletApplication(paWar, pa, paType, paClassLoader);
                  }
                  catch (Exception e)
                  {
                      // don't register the pa
                      register = false;
                  }
              }
              else
              {
                int status = nodeManager.checkNode(new Long(pa.getId().toString()), pa.getName());
              boolean reregister = false;
              boolean deploy = false;
              switch (status)
              {
                case  NodeManager.NODE_NEW:
                {
                    //only reason is that the file got somehow corrupted
                    // so we really do not know what is going on here...
                    // the best chance at this point is to reregister (which might be the absolute wrong choice)
                    log.warn("The portlet application " + pa.getName() + " is registered in the database but not locally .... we will reregister");
                    reregister = true;
                  if (checksum != pa.getChecksum())
                  {
                        log.warn("The provided portlet application " + pa.getName() + " is a different version than in the database (db-checksum=" + pa.getChecksum() + ", local-checksum=: " + checksum + ") .... we will redeploy (also to the database)");
                  deploy = true;
                  }
                  break;
                }
                case  NodeManager.NODE_SAVED:
                {
                  if (checksum != pa.getChecksum())
                        { 
                        log.warn("The provided portlet application " + pa.getName() + " is a different version than in the local node info and the database (db-checksum=" + pa.getChecksum() + ", local-checksum=: " + checksum + ") .... we will reregister AND redeploy (also to the database)");
                    //database and local node info are in synch, so we assume that this is a brand new
                    // war .... let's deploy
                    reregister = true;
                    deploy = true;
                        }
                  break;
                }
                case  NodeManager.NODE_OUTDATED:
                {
                    //database version is older (determined by id) than the database
                  //let's deploy and reregister
                  if (checksum != pa.getChecksum())
                        log.error("The portlet application " + pa.getName() + " provided for the upgrade IS WRONG. The database checksum= " + pa.getChecksum() + ", but the local=" + checksum + "....THIS NEEDS TO BE CORRECTED");
                   reregister = true;
                  break;
                }
              }
              if (deploy)
                      pa = registerPortletApplication(paWar, pa, paType, paClassLoader);
              else
                if (reregister)
                {
                  // add to search engine result
                  this.updateSearchEngine(true, pa);
                  this.updateSearchEngine(false, pa);
                 
                  // and add to the current node info
                  try
                  {
                    nodeManager.addNode(new Long(pa.getId().toString()), pa.getName());
                  } catch (Exception e)
                  {
                    log.error("Adding node for portlet application " + pa.getName() + " caused exception" , e);
                  }
                }
               
             
              }
            }
            if (register)
            {
                portletFactory.registerPortletApplication(pa, paClassLoader);
            }
           
            DescriptorChangeMonitor changeMonitor = this.monitor;
            if (!monitored && changeMonitor != null)
            {
                changeMonitor.monitor(contextName,paClassLoader, paType, warStruct.getRootDirectory(), checksum);
            }
    }
    finally
    {
      if (paWar != null)
      {
        try
        {
          paWar.close();
        }
        catch (IOException e)
        {
          log.error("Failed to close PA WAR for " + contextName, e);
        }
View Full Code Here

    // override to implement versioning logic
    protected void attemptStartPA(String contextName, String contextPath, FileSystemHelper warStruct,
            ClassLoader paClassLoader, int paType, long checksum, boolean silent)
    throws RegistryException
    {
        PortletApplicationWar paWar = null;
        try
        {
            paWar = new PortletApplicationWar(warStruct, contextName, contextPath, checksum);
            try
            {
                if (paClassLoader == null)
                {
                    paClassLoader = paWar.createClassloader(getClass().getClassLoader());
                }
            }
            catch (IOException e)
            {
                String msg = "Invalid PA WAR for " + contextName;
                if (!silent || log.isDebugEnabled())
                {
                    log.error(msg, e);
                }
                if ( paClassLoader == null )
                {
                    // nothing to be done about it anymore: this pa is beyond repair :(
                    throw new RegistryException(e);
                }
                //register = false;
            }
           
            MutablePortletApplication regPA = registry.getPortletApplication(contextName);
            MutablePortletApplication newPA = paWar.createPortletApp(false);
            if (regPA == null)
            {
                System.out.println("**** New portlet app found - registration required..." + contextName);
                regPA = registerPortletApplication(paWar, null, paType, paClassLoader, silent);
            }
View Full Code Here

   
    public void testSecurityRoles() throws Exception
    {
        System.out.println("Testing securityRoles");
        File warFile = new File("./test/testdata/deploy/webapp");
        PortletApplicationWar paWar = new PortletApplicationWar(new DirectoryHelper(warFile), "unit-test", "/" );

        MutablePortletApplication app = paWar.createPortletApp(false);
        assertNotNull("App is null", app);

        MutableWebApplication webApp = paWar.createWebApp();
        assertNotNull("WebApp is null", webApp);

        app.setWebApplicationDefinition(webApp);

        PortletDefinition portlet = app.getPortletDefinitionByName("TestPortlet");
        assertNotNull("TestPortlet is null", portlet);
        checkWebSecurityRoles(webApp);
        checkPortletSecurityRoleRefs(portlet);
        boolean validateFailed = false;
        try
        {
            paWar.validate();
        }
        catch (PortletApplicationException e)
        {
            validateFailed = true;
        }
        assertTrue("Invalid PortletDescriptor validation result", validateFailed);
        SecurityRoleImpl role = new SecurityRoleImpl();
        role.setRoleName("users.manager");
        webApp.addSecurityRole(role);
        try
        {
            paWar.validate();
            validateFailed = false;
        }
        catch (PortletApplicationException e)
        {
        }
        assertEquals("Invalid PortletDescriptor validation result", false, validateFailed);

        // persist the app
        try
        {
           
            portletRegistry.registerPortletApplication(app);
           
        }
        catch (Exception e)
        {
            String msg = "Unable to register portlet application, " + app.getName()
                    + ", through the portlet registry: " + e.toString();
           
            throw new Exception(msg, e);
        }
        // clear cache
       

        // read back in
        app = portletRegistry.getPortletApplication("unit-test");
        validateFailed = true;
        try
        {
            paWar.validate();
            validateFailed = false;
        }
        catch (PortletApplicationException e)
        {
        }
View Full Code Here

    }

    public void testInfusingWebXML() throws Exception
    {
        File warFile = new File("./test/testdata/deploy/webapp");
        PortletApplicationWar paWar = new PortletApplicationWar(new DirectoryHelper(warFile), "unit-test", "/" );

        SAXBuilder builder = new SAXBuilder(false);

        // Use the local dtd instead of remote dtd. This
        // allows to deploy the application offline
        builder.setEntityResolver(new EntityResolver()
        {
            public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
                throws SAXException, java.io.IOException
            {

                if (systemId.equals("http://java.sun.com/dtd/web-app_2_3.dtd"))
                {
                    return new InputSource(PortletApplicationWar.class.getResourceAsStream("web-app_2_3.dtd"));
                }
                else
                    return null;
            }
        });

        FileReader srcReader = new FileReader("./test/testdata/deploy/webapp/WEB-INF/web.xml");
        FileReader targetReader = null;
        Document  doc = builder.build(srcReader);

        Element root = doc.getRootElement();

        try
        {
            Object jetspeedServlet = XPath.selectSingleNode(root, PortletApplicationWar.JETSPEED_SERVLET_XPATH);
            Object jetspeedServletMapping = XPath.selectSingleNode(root, PortletApplicationWar.JETSPEED_SERVLET_MAPPING_XPATH);

            assertNull(jetspeedServlet);
            assertNull(jetspeedServletMapping);

            PortletApplicationWar targetWar = paWar.copyWar("./target/webapp");
            targetWar.processWebXML();

            targetReader = new FileReader("./target/webapp/WEB-INF/web.xml");

            Document targetDoc = builder.build(targetReader);
View Full Code Here

        }
        if (log.isDebugEnabled())
        {
            log.debug("Is portlet application " + contextName + " monitored? -> " + monitored);
        }
        PortletApplicationWar paWar = null;
    try
    {
            if (log.isDebugEnabled())
            {
                log.debug("Try to start portlet application " + contextName + ".");
            }
            // create PA  from war (file) structure
            // paWar = new PortletApplicationWar(warStruct, contextName, "/" + contextName, checksum);
            paWar = new PortletApplicationWar(warStruct, contextName, contextPath, checksum);
            try
            {
                if (paClassLoader == null)
                {
                    paClassLoader = paWar.createClassloader(this.getClass().getClassLoader());
                }               
                // create checksum from PA descriptors
                checksum = paWar.getPortletApplicationChecksum();               
               
                if (log.isDebugEnabled())
                {
                    log.debug("New checksum for portlet application " + contextName + " is " + checksum);
                }
            }
            catch (IOException e)
            {
                String msg = "Invalid PA WAR for " + contextName;
                if (!silent || log.isDebugEnabled())
                {
                    log.error(msg, e);
                }
                if ( paClassLoader == null )
                {
                    // nothing to be done about it anymore: this pa is beyond repair :(
                    throw new RegistryException(e);
                }
                register = false;
            }

      // try to get the PA from database by context name
      MutablePortletApplication pa = registry.getPortletApplication(contextName);

            if (pa != null)
            {
                if (log.isDebugEnabled())
                {
                    log.debug("Portlet Application " + contextName + " found in registry.");
              }
                if ( pa.getApplicationType() != paType )
                {
                    throw new RegistryException("Cannot start portlet application "+contextName+": as Application Types don't match: " + pa.getApplicationType() + " != " + paType);
                }
                if (!monitored && changeMonitor != null)
                {
                    changeMonitor.remove(contextName);
                }
                if (log.isDebugEnabled())
                {
                    log.debug("unregistering portlet application " + contextName + "...");
                }
                portletFactory.unregisterPortletApplication(pa);                       
            }
//            if (register && (pa == null || checksum != pa.getChecksum()))
            if (register)
            {
              if (pa == null)
              {
                // new
                  try
                  {
                      if (log.isDebugEnabled())
                        {
                          log.debug("Register new portlet application " + contextName + ".");
                        }
                      pa = registerPortletApplication(paWar, pa, paType, paClassLoader, silent);
                  }
                  catch (Exception e)
                  {
                      String msg = "Error register new portlet application " + contextName + ".";
                   
                      if (log.isDebugEnabled())
                    {
                        log.debug(msg);
                    }
                      throw new RegistryException(msg);
                     
                  }
              }
              else
              {
                    if (log.isDebugEnabled())
                    {
                        log.debug("Re-register existing portlet application " + contextName + ".");
                    }
                int status = nodeManager.checkNode(new Long(pa.getId().toString()), pa.getName());
              boolean reregister = false;
              boolean deploy = false;
              switch (status)
              {
                case  NodeManager.NODE_NEW:
                {
                            if (log.isDebugEnabled())
                            {
                                log.debug("Node for Portlet application " + contextName + " is NEW.");
                            }
                    //only reason is that the file got somehow corrupted
                    // so we really do not know what is going on here...
                    // the best chance at this point is to reregister (which might be the absolute wrong choice)
                    log.warn("The portlet application " + pa.getName() + " is registered in the database but not locally .... we will reregister");
                    reregister = true;
                  if (checksum != pa.getChecksum())
                  {
                      log.warn("The provided portlet application " + pa.getName() + " is a different version than in the database (db-checksum=" + pa.getChecksum() + ", local-checksum=: " + checksum + ") .... we will redeploy (also to the database)");
                  deploy = true;
                  }
                  break;
                }
                case  NodeManager.NODE_SAVED:
                {
                            if (log.isDebugEnabled())
                            {
                                log.debug("Node for Portlet application " + contextName + " is SAVED.");
                            }
                  if (checksum != pa.getChecksum())
                        { 
                      log.warn("The provided portlet application " + pa.getName() + " is a different version than in the local node info and the database (db-checksum=" + pa.getChecksum() + ", local-checksum=: " + checksum + ") .... we will reregister AND redeploy (also to the database)");
                    //database and local node info are in synch, so we assume that this is a brand new
                    // war .... let's deploy
                    reregister = true;
                    deploy = true;
                        }
                  break;
                }
                case  NodeManager.NODE_OUTDATED:
                {
                            // new version in database, maybe changed by a different cluster node
                    if (log.isDebugEnabled())
                    {
                        log.debug("Node for Portlet application " + contextName + " is OUTDATED (local PA.id < DB PA.id).");
                    }
                    //database version is older (determined by id) than the database
                  //let's deploy and reregister
                    if (checksum != pa.getChecksum())
                    {
                      log.error("The portlet application " + pa.getName() + " provided for the upgrade IS WRONG. The database checksum= " + pa.getChecksum() + ", but the local=" + checksum + "....THIS NEEDS TO BE CORRECTED");
                      // if the checksums do not match make sure the database is updated with the new PA from file system
                      // I've observed "unavailable PA" in clustered env for the cluster node that reported OUTDATED state
                      deploy = true;
                  }
                    reregister = true;
                    break;
                }
              }
              if (deploy)
              {
                  if (log.isDebugEnabled())
                  {
                      log.debug("Register (deploy=true) Portlet application " + contextName + " in database.");
                        }
                      pa = registerPortletApplication(paWar, pa, paType, paClassLoader, silent);
              }
              else
                if (reregister)
                {
                            if (log.isDebugEnabled())
                            {
                                log.debug("Re-Register (reregister=true) Portlet application " + contextName + ".");
                            }
                  // add to search engine result
                  this.updateSearchEngine(true, pa);
                  this.updateSearchEngine(false, pa);
                 
                  // and add to the current node info
                  try
                  {
                    nodeManager.addNode(new Long(pa.getId().toString()), pa.getName());
                  } catch (Exception e)
                  {
                      log.error("Adding node for portlet application " + pa.getName() + " caused exception" , e);
                  }
                }
               
             
              }
            }
            if (register)
            {
                if (log.isDebugEnabled())
                {
                    log.debug("Register Portlet application " + contextName + " in portlet factory.");
                }
                portletFactory.registerPortletApplication(pa, paClassLoader);
            }
           
            if (!monitored && changeMonitor != null)
            {
                if (log.isDebugEnabled())
                {
                    log.debug("Add change monitor for application " + contextName + " with checksum " + checksum + ".");
                }
                changeMonitor.monitor(contextName, contextPath, paClassLoader, paType, warStruct.getRootDirectory(), checksum);
            }
    }
        catch (Exception e)
        {
            String msg = "Error starting portlet application " + contextName;
           
            if (!silent || log.isDebugEnabled())
            {
                log.error(msg, e);
            }
            // monitor PA for changes
            // do not add monitor if a monitor already exists
            if (!monitored && changeMonitor != null)
            {
                // this code should be hit only during startup process
                if (log.isDebugEnabled())
                {
                    log.debug("Add change monitor for application " + contextName + " and set unsuccessful starts to 1.");
                }
                changeMonitor.monitor(contextName, contextPath, paClassLoader, paType, warStruct.getRootDirectory(), checksum);
                changeMonitor.get(contextName).setUnsuccessfulStarts(1);
            }
            throw new RegistryException(msg);
        }
    finally
    {
      if (paWar != null)
      {
        try
        {
          paWar.close();
        }
        catch (IOException e)
        {
            log.error("Failed to close PA WAR for " + contextName, e);
        }
View Full Code Here

   
    public void testSecurityRoles() throws Exception
    {
        System.out.println("Testing securityRoles");
        File warFile = new File("./test/testdata/deploy/webapp");
        PortletApplicationWar paWar = new PortletApplicationWar(new DirectoryHelper(warFile), "unit-test", "/" );

        MutablePortletApplication app = paWar.createPortletApp();
        assertNotNull("App is null", app);

        MutableWebApplication webApp = paWar.createWebApp();
        assertNotNull("WebApp is null", webApp);

        app.setWebApplicationDefinition(webApp);

        PortletDefinition portlet = app.getPortletDefinitionByName("TestPortlet");
        assertNotNull("TestPortlet is null", portlet);
        checkWebSecurityRoles(webApp);
        checkPortletSecurityRoleRefs(portlet);
        boolean validateFailed = false;
        try
        {
            paWar.validate();
        }
        catch (PortletApplicationException e)
        {
            validateFailed = true;
        }
        assertTrue("Invalid PortletDescriptor validation result", validateFailed);
        SecurityRoleImpl role = new SecurityRoleImpl();
        role.setRoleName("users.manager");
        webApp.addSecurityRole(role);
        try
        {
            paWar.validate();
            validateFailed = false;
        }
        catch (PortletApplicationException e)
        {
        }
        assertEquals("Invalid PortletDescriptor validation result", false, validateFailed);

        // persist the app
        try
        {
           
            portletRegistry.registerPortletApplication(app);
           
        }
        catch (Exception e)
        {
            String msg = "Unable to register portlet application, " + app.getName()
                    + ", through the portlet registry: " + e.toString();
           
            throw new Exception(msg, e);
        }
        // clear cache
       

        // read back in
        app = portletRegistry.getPortletApplication("unit-test");
        validateFailed = true;
        try
        {
            paWar.validate();
            validateFailed = false;
        }
        catch (PortletApplicationException e)
        {
        }
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.util.descriptor.PortletApplicationWar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.