Package smilehouse.opensyncro.system

Examples of smilehouse.opensyncro.system.Persister$DatabaseConnectionException


        String lang = req.getParameter(LANGUAGE);

        if(database == null || database.length() == 0) {
            res.sendRedirect("Login?");
        } else {
            Persister pers = null;
            try {
                pers = new Persister(database, true);
                if(pers.loginOk(user, password)) {
                    StandaloneEnvironment.logInUser(req, user, database, lang);
                    res.sendRedirect("Index");
                } else
                    res.sendRedirect("Login?failed=y");
            } catch(Persister.DatabaseConnectionException dbce) {
                Environment.getInstance().log("Error: Attempt to log in to an unknown database '" + database + "'");
                res.sendRedirect("Login?failed=y");
            } catch(Exception e) {
                Environment.getInstance().log(
                    "Exception while trying to log in the database '" + database + "'",
                    e);
                res.sendRedirect("Login?error=y");
            } finally {
                if(pers != null)
                    pers.close();
            }
        }
    }
View Full Code Here


        String database = environment.getDatabaseName(session);

        ParameterManager parameters = new ParameterManager(this, req, environment.getCharsetWWW());

        Persister pers = null;
        PrintWriter out = null;
        try {
            res.setContentType(environment.getContentType());
            out = res.getWriter();
            pers = new Persister(database);
            LabelResource labels = environment.getLabelResource(session);

            Script script = null;
            String scriptString = getScript(labels);
            if(scriptString != null)
                script = new Script()
                    .setLanguage("JavaScript")
                    .setType("text/javascript")
                    .addElement(scriptString);

            String content = handleRequest(req, session, parameters, pers, labels, requestType);

            environment.outputPage(getTabSetId(), getTabId(), content, script != null ? script
                .toString() : null, out, session);
           
        } catch(Throwable e) {
            environment.outputErrorPage(e, out);
        } finally {
            if(pers != null)
                pers.close();
            if(out != null) {
                out.flush();
                out.close();
            }
        }
View Full Code Here

       
      if(messages == null){
            messages = new HashSet();
        }
     
      persister=new Persister(info.getDatabaseName());
     
      try{
      if(!saved){
          persister.save(this);
          saved=true;
View Full Code Here

        //Go through each database listed in the properties file and, depending on the settings, start or remove
        //found pipe execution request.
        HashMap db=Environment.getInstance().getDatabaseInfo();
        Iterator it=db.keySet().iterator();
        while(it.hasNext()){
          Persister pers;
          String database=(String)it.next();
          try{
            pers=new Persister(database);
          }
          catch(DatabaseConnectionException dce){
            Environment.getInstance().log(dce.getMessage());
            continue;
          }
          String mode=(String)db.get(database);
          //Database listed, but no resumemode specified
         
          if(mode==null){
            Environment.getInstance().log("Mode not specified for database "+database);
          }
          //Delete all execution request from this database
          else if(mode.equalsIgnoreCase(CLEAR_MODE)){
            pers.deleteAllPipeExecutionRequests(null);
          }
          //Execute found execution requests
          else if(mode.equalsIgnoreCase(EXECUTE_MODE)){
            Iterator pipeIt=pers.loadAllPipes().iterator();
           
            //Iterate through all the pipes found in the database
            while (pipeIt.hasNext()) {
              Persister perPipePersister = new Persister(database);
          Pipe p = perPipePersister.findPipeByName(((Pipe) pipeIt.next()).getName());
          String dbase = perPipePersister.getDatabaseName();
          PipeWrapper pw = new PipeWrapper(p, dbase, dbase + p.getName());
          PipeExecutionThread pet = new PipeExecutionThread(pipesAndThreads,
              p.getId(),perPipePersister);
          //PipeExecutionQueue peq = new PipeExecutionQueue(perPipePersister,
            //  p.getId());
View Full Code Here

      
        // HashMap persisters contains a persister for each active pipe that is started via HttpStart.
       if(persisters == null)
      persisters = new HashMap();
       
        Persister pers=(Persister)persisters.get(database + pipeName);
        if(pers==null||pers.isClosed()){
          try {
        pers = new Persister(database);
        //unique pipe identification by database name and pipename
        persisters.put(database + pipeName, pers);
      } catch (DatabaseConnectionException e) {
        return("ERROR: Invalid database name");
      }
        }
       
    int queueLength = 0;
    try {
      PipeWrapper pipe = null;

      Map pipesAndThreads = null;

      // Get pipesAndThreads object from webapp context.
      // This is where running pipes and threads are listed
      pipesAndThreads = (Map) this.getServletContext().getAttribute(PIPES_AND_THREADS);
      boolean newThread = false;

      if (pipesAndThreads == null) {
        // No pipesAndThreads object exists -> no pipes have been started via HttpStart
        // nor has SyncroStartup started any.
        // Create synchronized map, as it may be modified simultaneously by several threads
        pipesAndThreads = Collections.synchronizedMap(new HashMap());
        this.getServletContext().setAttribute(PIPES_AND_THREADS,
            pipesAndThreads);
      }
     
      Iterator pipesIt=pipesAndThreads.keySet().iterator();
      boolean newPipe=true;
      // Iterate through active pipes to see if the pipe the incoming request refers to
      // is already executing

      while(pipesIt.hasNext()){
        PipeWrapper p = (PipeWrapper)pipesIt.next();
        String db=((PipeExecutionThread)pipesAndThreads.get(p)).getDatabaseName();
        //Since two databases could have pipes with the same name it is necessary to
        //check that in addition to pipe name database name also matches.
        if(p.getPipe().getName().equals(pipeName) && db.equals(database)){
          //Pipe was found. No need to create a new pipe
          newPipe=false;
          pipe=p;
        }
      }
      if(newPipe)
        pipe = new PipeWrapper(pers.findPipeByName(pipeName), database, database + pipeName);
     
      if(pipe == null || pipe.getPipe().getStartPassword() == null
          || !pipe.getPipe().getStartPassword().equals(startPassword)) {
        return "ERROR: Incorrect pipe name or start password";
      }
View Full Code Here

            setExecutionEndInfo( new Date(), System.currentTimeMillis()-start, statusCode);
            addLogEntry(logEntry, statusCode);
           
            // Add "--" log message entry when there are no other entries.
            // Needed to display log entries that don't have log message entries.
            Persister persister = new Persister(database);
            if (persister.getLogMessageEntries(logEntry.getId(), MessageLogger.LOG_DYNAMIC).size() == 0){
              logEntry.setIndex(1);
              logEntry.logMessage("--", MessageLogger.ERROR);
            }

        }
View Full Code Here

        // ever-increasing amount of server resources.

        //this.log.add(logEntry);
        String status = getStatusString(statusCode);
       
        Persister persister = new Persister(database);

        try {
            persister.update(logEntry);

            List messages;
           
            boolean mailAddressNotSet =((getMailHost() == null || getRecipientAddress() == null) ||
                    (getMailHost().length() == 0 || getRecipientAddress().length() == 0));
           
            // Notification via email only if host and email address are present
            if(!mailAddressNotSet&&!(getTransferLogNotificationLevel()==MessageLogger.MAIL_NONE)) {
               

                String date = dateFormat.format(new Date());
                String subject = this.getName() + " " + status + " " + date + " (" + database + ")";
                String message = "";

                // Get number of log messages at or below transferLogNotificationLevel. 
               
                int entries=persister.getLogMessageEntries(logEntry.getId(), getTransferLogNotificationLevel()).size();
               
                //Generate mail message
                if(entries > 0) {
                  
                  messages = persister.getLogMessageEntries(
                             logEntry.getId(),
                             getLoggingVerbosityLevel());
                    for(Iterator m = messages.iterator(); m.hasNext();) {
                        LogMessageEntry messageEntry = (LogMessageEntry) m.next();
                        message += (messageEntry.getMessage()) + "\n";
                    }
                } else {
                    message += MAIL_MESSAGE_NO_ENTRIES;
                }
               
                // Send notification email except when the message is
        // MAIL_MESSAGE_NO_ENTRIES or the pipe has aborted and
                // isAbortMailEnabled()==true
        if (!message.equals(MAIL_MESSAGE_NO_ENTRIES)
            || (statusCode==LogEntry.STATUS_ABORTED && isAbortMailEnabled())) {
          try {

            Properties props = new Properties();
            props.put("mail.host", getMailHost());

            Session mailConnection = Session.getInstance(props,
                null);
            Message msg = new MimeMessage(mailConnection);
            Address sender = new InternetAddress(MAIL_SENDER + "@"
                + getMailHost(), MAIL_SENDER);
            Address[] receivers = receiverAddresses(getRecipientAddress());

            // Set mail content and subject
            msg.setContent(message, "text/plain");
            msg.setFrom(sender);
            msg.setRecipients(Message.RecipientType.TO, receivers);
            msg.setSubject(subject);

            // Send the mail
            Transport.send(msg);

          } catch (MessagingException e) {
            String error = "An error occurred when sending mail report from "
                + MAIL_SENDER
                + "@"
                + getMailHost()
                + " to "
                + getRecipientAddress()
                + ":\n"
                + e.getMessage();
            Environment.getInstance().log(error);
            logEntry.logMessage(error, this, MessageLogger.ERROR);
            persister.update(logEntry);
          } catch (RuntimeException ex) {
            Environment.getInstance().log(
                "A RuntimeException has occurred: "
                    + ex.getMessage()
                    + ex.getStackTrace().toString());
          }
        }
      }
            // Remove unnecessary (debug level) messages from the LogEntry if Transfer log
            // verbosity level is set to DYNAMIC and the current LogEntry's status is either
            // OK or ABORTED
            if(getLoggingVerbosityLevel() == MessageLogger.LOG_DYNAMIC
                    && (statusCode == LogEntry.STATUS_OK || statusCode == LogEntry.STATUS_ABORTED) ) {
                messages = persister.getLogMessageEntries(logEntry.getId(), MessageLogger.DEBUG);
                if(messages.size() > 0) {
                    for(Iterator m = messages.iterator(); m.hasNext();) {
                        LogMessageEntry messageEntry = (LogMessageEntry) m.next();
                        if(messageEntry.getMessageType() == MessageLogger.DEBUG) {
                            persister.delete(messageEntry);
                           
                        }
                    }
                }
            }
        } catch(Exception e) {
            Environment.getInstance().log(e.getMessage());
        } finally {
            persister.close();
        }
    }
View Full Code Here

TOP

Related Classes of smilehouse.opensyncro.system.Persister$DatabaseConnectionException

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.