Package org.apache.jetspeed.util.descriptor

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


    }

    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);
            Element targetRoot = targetDoc.getRootElement();
View Full Code Here


 
  protected void startPA(String contextName, FileSystemHelper warStruct,
          ClassLoader paClassLoader, boolean local, 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 = (MutablePortletApplication) registry.getPortletApplication(contextName);

            if (pa != null)
            {
                if ( pa.getApplicationType() != getApplicationType(local) )
                {
                    if ( local )
                    {
                        throw new RegistryException("Cannot start local portlet application "+contextName+": it is not a local application");
                    }
                    else
                    {
                        throw new RegistryException("Cannot start portlet application "+contextName+": it is a local application");
                    }                   
                }
                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, local, 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, local, 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, local, 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

        }
        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(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;
                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);
                  }
                  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);
              }
              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;
           
            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

        FileSystemPAM pam = new FileSystemPAM(webAppsDir, portletRegistry, entityAccess, windowAccess, portletCache, manager);

        try
        {
            DirectoryHelper dirHelper = new DirectoryHelper(new File(webAppsDir + "/" + TEST_PORTLET_APP_NAME));
            paWar1 = new PortletApplicationWar(dirHelper, TEST_PORTLET_APP_NAME, "/"
                    + TEST_PORTLET_APP_NAME);
            pam.undeploy(paWar1);
        }
        catch (Exception e1)
        {

        }

        pam.unregister("jetspeed");

        try
        {
            DirectoryHelper dirHelper = new DirectoryHelper(new File(webAppsDir + "/TestSecurityRoles"));
            paWar3 = new PortletApplicationWar(dirHelper, "TestSecurityRoles", "/TestSecurityRoles" );

            pam.undeploy(paWar3);
        }
        catch (Exception e3)
        {
View Full Code Here

                return;
            }

            boolean isLocal = event.getName().startsWith("jetspeed-");

            PortletApplicationWar deployedWar = null;

            PortletApplicationDefinition pa = registry.getPortletApplicationByIdentifier(paName);
            String webAppContextRoot = null;

            if (pa != null)
            {
                webAppContextRoot = pa.getWebApplicationDefinition().getContextRoot();
            }
            else
            {
                webAppContextRoot = "/" + paName;
            }

            if (isLocal)
            {
                log.info("Preparing to unregister portlet application \"" + paName + "\"");
                pam.unregister(paName);
            }
            else
            {
                log.info("Preparing to undeploy portlet application \"" + paName + "\"");
                DirectoryHelper dir = new DirectoryHelper(new File(webAppDir + "/" + paName));
                deployedWar = new PortletApplicationWar(dir, paName, webAppContextRoot );
                pam.undeploy(deployedWar);
            }

            log.info("Portlet application \"" + paName + "\"" + " was successfuly undeployed.");
        }
View Full Code Here

                int extensionIdx = warFileName.lastIndexOf(".war");
                id = warFileName.substring(0, extensionIdx);
                log.info("Application id not defined in portlet.xml so using war name " + id);
            }

            PortletApplicationWar paWar = new PortletApplicationWar(deploymentObj.getFileObject(), id, "/" + id );

            if (registry.getPortletApplicationByIdentifier(id) != null
                    && !event.getEventType().equals(DeploymentEvent.EVENT_TYPE_REDEPLOY))
            {
                log.info("Portlet application \"" + id + "\""
                        + " already been registered.  Skipping initial deployment.");
                // still need to register the filename to the app name so
                // undeploy works correctly
                appNameToFile.put(deploymentObj.getPath(), id);
                if (isLocal)
                {               
                    portletFactory.addClassLoader(
                        registry.getPortletApplicationByIdentifier(id).getId().toString(),
                        paWar.createClassloader(getClass().getClassLoader()));
                }
                else
                {
                    try
                    {
                        ClassLoader classloader = createPortletClassloader(getClass().getClassLoader(), id);
                        if (classloader != null)
                        {
                            portletFactory.addClassLoader(
                                registry.getPortletApplicationByIdentifier(id).getId().toString(),
                                classloader);
                        }
                    }
                    catch (IOException e1)
                    {
                        log.info("Could not add Portlet Class Loader: " + id);
                    }
                }
                return;
            }

            log.info("Preparing to (re) deploy portlet app \"" + id + "\"");

            if (event.getEventType().equals(DeploymentEvent.EVENT_TYPE_DEPLOY))
            {

                if (isLocal)
                {
                    log.info(fileName + " will be registered as a local portlet applicaiton.");                   
                    pam.register(paWar);
                    MutablePortletApplication mpa = registry.getPortletApplicationByIdentifier(id);
                    if (mpa != null)
                    {
                        portletFactory.addClassLoader(
                            mpa.getId().toString(),
                            paWar.createClassloader(getClass().getClassLoader()));
                    }
                }
                else
                {
                    log.info("Deploying portlet applicaion WAR " + fileName);
View Full Code Here

     */
    private ClassLoader createPortletClassloader(ClassLoader parent, String id) throws IOException
    {
        String portletAppDirectory = pam.getDeploymentPath(id);
        FileSystemHelper target = new DirectoryHelper(new File(portletAppDirectory));
        PortletApplicationWar targetWar = new PortletApplicationWar(target, id, "/" + id);
        return targetWar.createClassloader(parent);
    }
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);
            Element targetRoot = targetDoc.getRootElement();
View Full Code Here

        {
            String portletAppDirectory = webAppsDir + "/" + targetAppName;

            log.info("Portlet application deployment target directory is " + portletAppDirectory);

            PortletApplicationWar targetWar = null;
            if (startState <= nState)
            {
                targetWar = paWar.copyWar(portletAppDirectory);
            }

            nState = UPDATE_WEB_XML;

            if (startState <= nState && targetWar != null)
            {
                targetWar.processWebXML();
            }

            nState = UPDATE_REGISTRY;

            if (startState <= nState)
View Full Code Here

        try
        {
            doUnregister(paWar.getPortletApplicationName(), false);
            String paName = paWar.getPortletApplicationName();
            DirectoryHelper deployedDir = new DirectoryHelper(new File(webAppsDir + "/" + paName));
            PortletApplicationWar existingWar = new PortletApplicationWar(deployedDir, paName, "/" + paName);

            existingWar.removeWar();
            existingWar.close();
            sysDeploy(paWar, DEPLOY_WAR);
        }
        catch (IOException e)
        {
            throw new 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.