Ejemplo n.º 1
0
        protected override void handleThrowable(HttpServletResponse response, Throwable e)

        {
            log.log(Level.WARNING, e.ToString(), e);

            OutputStream os   = response.getOutputStream();
            WriteStream  @out = Vfs.openWrite(os);

            @out.println(e);
            @out.close();
        }
Ejemplo n.º 2
0
        static string GetExceptionString(Throwable ex, string appName)
        {
            string result  = "";
            string newLine = System.Environment.NewLine;

            string exception = ex.ToString();
            var    nowDate   = string.Format("{0:dd-MMMM-yyyy}", DateTime.Now);
            var    nowTime   = string.Format("{0:HH-mm-ss}", DateTime.Now);
            string device    = "";

            //device += "VERSION.BaseOs: "           + Build.VERSION.BaseOs         + newLine;
            device += "VERSION.Codename: " + Build.VERSION.Codename + newLine;
            device += "VERSION.Incremental: " + Build.VERSION.Incremental + newLine;
            //device += "VERSION.PreviewSdkInt: "  + Build.VERSION.PreviewSdkInt  + newLine;
            device += "VERSION.Release: " + Build.VERSION.Release + newLine;
            device += "VERSION.Sdk: " + Build.VERSION.Sdk + newLine;
            device += "VERSION.SdkInt: " + Build.VERSION.SdkInt + newLine;
            //device += "VERSION.SecurityPatch: "  + Build.VERSION.SecurityPatch  + newLine;
            device += "Board: " + Build.Board + newLine;
            device += "Bootloader: " + Build.Bootloader + newLine;
            device += "Brand: " + Build.Brand + newLine;
            device += "CpuAbi: " + Build.CpuAbi + newLine;
            device += "CpuAbi2: " + Build.CpuAbi2 + newLine;
            device += "Device: " + Build.Device + newLine;
            device += "Display: " + Build.Display + newLine;
            device += "Fingerprint: " + Build.Fingerprint + newLine;
            device += "Hardware: " + Build.Hardware + newLine;
            device += "Host: " + Build.Host + newLine;
            device += "Id: " + Build.Id + newLine;
            device += "Manufacturer: " + Build.Manufacturer + newLine;
            device += "Model: " + Build.Model + newLine;
            device += "Product: " + Build.Product + newLine;
            device += "Radio: " + Build.Radio + newLine;
            device += "RadioVersion: " + Build.RadioVersion + newLine;
            device += "Serial: " + Build.Serial + newLine;
            device += "Tags: " + Build.Tags + newLine;
            device += "Time: " + Build.Time + newLine;
            device += "Type: " + Build.Type + newLine;
            device += "Unknown: " + Build.Unknown + newLine;
            device += "User: "******"app: " + appName + newLine +
                     "date: " + nowDate + newLine +
                     "time: " + nowTime + newLine +
                     newLine +
                     "exception: " + newLine +
                     exception + newLine +
                     "device: " + newLine + device +
                     newLine +
                     new DeviceInfoAndroid() + newLine;

            return(result);
        }
Ejemplo n.º 3
0
        /**
         * Save an error for subsequent calls to
         * {@link #errorCode} and {@link #errorInfo},
         * and depending on the value of {@link #setErrmode}
         * show nothing, show a warning, or throw an exception.
         */
        public void error(Env env, Throwable exception)
        {
            log.log(Level.FINE, exception.ToString(), exception);

            string errorCode;
            string errorMessage;
            int    driverError;

            if (exception instanceof SQLException)
            {
                SQLException sqlException = (SQLException)exception;
                errorCode    = sqlException.getSQLState();
                errorMessage = sqlException.getMessage();
                driverError  = sqlException.getErrorCode();
            }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructs a {@code BootstrapMethodError} with the specified
 /// cause.
 /// </summary>
 /// <param name="cause"> the cause, may be {@code null}. </param>
 public BootstrapMethodError(Throwable cause) : base(cause == null ? null : cause.ToString())
 {
     // cf. Throwable(Throwable cause) constructor.
     InitCause(cause);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Format the given message to XML.
        /// <para>
        /// This method can be overridden in a subclass.
        /// It is recommended to use the <seealso cref="Formatter#formatMessage"/>
        /// convenience method to localize and format the message field.
        ///
        /// </para>
        /// </summary>
        /// <param name="record"> the log record to be formatted. </param>
        /// <returns> a formatted log record </returns>
        public override String Format(LogRecord record)
        {
            StringBuilder sb = new StringBuilder(500);

            sb.Append("<record>\n");

            sb.Append("  <date>");
            AppendISO8601(sb, record.Millis);
            sb.Append("</date>\n");

            sb.Append("  <millis>");
            sb.Append(record.Millis);
            sb.Append("</millis>\n");

            sb.Append("  <sequence>");
            sb.Append(record.SequenceNumber);
            sb.Append("</sequence>\n");

            String name = record.LoggerName;

            if (name != null)
            {
                sb.Append("  <logger>");
                Escape(sb, name);
                sb.Append("</logger>\n");
            }

            sb.Append("  <level>");
            Escape(sb, record.Level.ToString());
            sb.Append("</level>\n");

            if (record.SourceClassName != null)
            {
                sb.Append("  <class>");
                Escape(sb, record.SourceClassName);
                sb.Append("</class>\n");
            }

            if (record.SourceMethodName != null)
            {
                sb.Append("  <method>");
                Escape(sb, record.SourceMethodName);
                sb.Append("</method>\n");
            }

            sb.Append("  <thread>");
            sb.Append(record.ThreadID);
            sb.Append("</thread>\n");

            if (record.Message != null)
            {
                // Format the message string and its accompanying parameters.
                String message = formatMessage(record);
                sb.Append("  <message>");
                Escape(sb, message);
                sb.Append("</message>");
                sb.Append("\n");
            }

            // If the message is being localized, output the key, resource
            // bundle name, and params.
            ResourceBundle bundle = record.ResourceBundle;

            try
            {
                if (bundle != null && bundle.GetString(record.Message) != null)
                {
                    sb.Append("  <key>");
                    Escape(sb, record.Message);
                    sb.Append("</key>\n");
                    sb.Append("  <catalog>");
                    Escape(sb, record.ResourceBundleName);
                    sb.Append("</catalog>\n");
                }
            }
            catch (Exception)
            {
                // The message is not in the catalog.  Drop through.
            }

            Object[] parameters = record.Parameters;
            //  Check to see if the parameter was not a messagetext format
            //  or was not null or empty
            if (parameters != null && parameters.Length != 0 && record.Message.IndexOf("{") == -1)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    sb.Append("  <param>");
                    try
                    {
                        Escape(sb, parameters[i].ToString());
                    }
                    catch (Exception)
                    {
                        sb.Append("???");
                    }
                    sb.Append("</param>\n");
                }
            }

            if (record.Thrown != null)
            {
                // Report on the state of the throwable.
                Throwable th = record.Thrown;
                sb.Append("  <exception>\n");
                sb.Append("    <message>");
                Escape(sb, th.ToString());
                sb.Append("</message>\n");
                StackTraceElement[] trace = th.StackTrace;
                for (int i = 0; i < trace.Length; i++)
                {
                    StackTraceElement frame = trace[i];
                    sb.Append("    <frame>\n");
                    sb.Append("      <class>");
                    Escape(sb, frame.ClassName);
                    sb.Append("</class>\n");
                    sb.Append("      <method>");
                    Escape(sb, frame.MethodName);
                    sb.Append("</method>\n");
                    // Check for a line number.
                    if (frame.LineNumber >= 0)
                    {
                        sb.Append("      <line>");
                        sb.Append(frame.LineNumber);
                        sb.Append("</line>\n");
                    }
                    sb.Append("    </frame>\n");
                }
                sb.Append("  </exception>\n");
            }

            sb.Append("</record>\n");
            return(sb.ToString());
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructs a <code>SQLClientInfoException</code> object initialized with
 /// a given <code>cause</code> and <code>failedProperties</code>.
 ///
 /// The <code>reason</code>  is initialized to <code>null</code> if
 /// <code>cause==null</code> or to <code>cause.toString()</code> if
 /// <code>cause!=null</code> and the vendor code is initialized to 0.
 ///
 /// <para>
 ///
 /// </para>
 /// </summary>
 /// <param name="failedProperties">          A Map containing the property values that could not
 ///                                  be set.  The keys in the Map
 ///                                  contain the names of the client info
 ///                                  properties that could not be set and
 ///                                  the values contain one of the reason codes
 ///                                  defined in <code>ClientInfoStatus</code> </param>
 /// <param name="cause">                                     the (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
 ///     the cause is non-existent or unknown.
 /// <para>
 /// @since 1.6 </param>
 public SQLClientInfoException(IDictionary <String, ClientInfoStatus> failedProperties, Throwable cause) : base(cause != null?cause.ToString():null)
 {
     InitCause(cause);
     this.FailedProperties_Renamed = failedProperties;
 }
Ejemplo n.º 7
0
        /**
         * Send mail using JavaMail.
         */
        public static bool mail(Env env,
                                string to,
                                string subject,
                                StringValue message,
                                @Optional string additionalHeaders,
                                @Optional string additionalParameters)
        {
            Transport smtp = null;

            try {
                HashMap <String, String> headers = splitHeaders(additionalHeaders);

                if (to == null || to.equals(""))
                {
                    to = headers.get("to");
                }

                Properties props = new Properties();

                StringValue host = env.getIni("SMTP");
                if (host != null && !host.ToString().equals(""))
                {
                    props.put("mail.smtp.host", host.ToString());
                }
                else if (System.getProperty("mail.smtp.host") != null)
                {
                    props.put("mail.smtp.host", System.getProperty("mail.smtp.host"));
                }

                StringValue port = env.getIni("smtp_port");
                if (port != null && !port.ToString().equals(""))
                {
                    props.put("mail.smtp.port", port.ToString());
                }
                else if (System.getProperty("mail.smtp.port") != null)
                {
                    props.put("mail.smtp.port", System.getProperty("mail.smtp.port"));
                }

                if (System.getProperty("mail.smtp.class") != null)
                {
                    props.put("mail.smtp.class", System.getProperty("mail.smtp.class"));
                }

                StringValue user = null;

                if (headers.get("from") != null)
                {
                    user = env.createString(headers.get("from"));
                }

                if (user == null)
                {
                    user = env.getIni("sendmail_from");
                }

                if (user != null && !user.ToString().equals(""))
                {
                    string userString = user.ToString();

                    props.put("mail.from", userString);
                }
                else if (System.getProperty("mail.from") != null)
                {
                    props.put("mail.from", System.getProperty("mail.from"));
                }
                else
                {
                    try {
                        InetAddress addr = InetAddress.getLocalHost();

                        string email = (System.getProperty("user.name")
                                        + "@" + addr.getHostName());


                        int index = email.indexOf('@');

                        // for certain windows smtp servers
                        if (email.indexOf('.', index) < 0)
                        {
                            email += ".com";
                        }

                        props.put("mail.from", email);
                    } catch (Exception e) {
                        log.log(Level.FINER, e.ToString(), e);
                    }
                }

                string username = env.getIniString("smtp_username");
                string password = env.getIniString("smtp_password");

                if (password != null && !"".equals(password))
                {
                    props.put("mail.smtp.auth", "true");
                }

                Session mailSession = Session.getInstance(props, null);
                smtp = mailSession.getTransport("smtp");

                QuercusMimeMessage msg = new QuercusMimeMessage(mailSession);

                if (subject == null)
                {
                    subject = "";
                }

                msg.setSubject(subject);
                msg.setContent(message.ToString(), "text/plain");

                ArrayList <Address> addrList = new ArrayList <Address>();

                if (to != null && to.length() > 0)
                {
                    addRecipients(msg, Message.RecipientType.TO, to, addrList);
                }

                if (headers != null)
                {
                    addHeaders(msg, headers, addrList);
                }

                Address [] from = msg.getFrom();
                if (from == null || from.length == 0)
                {
                    log.fine(L.l(
                                 "mail 'From' not set, setting to Java System property 'user.name'"));
                    msg.setFrom();
                }

                msg.saveChanges();

                from = msg.getFrom();
                log.fine(L.l("sending mail, From: {0}, To: {1}", from[0], addrList));

                if (password != null && !"".equals(password))
                {
                    smtp.connect(username, password);
                }
                else
                {
                    smtp.connect();
                }

                Address[] addr;

                addr = new Address[addrList.size()];
                addrList.toArray(addr);

                smtp.sendMessage(msg, addr);

                log.fine("quercus-mail: sent mail to " + to);

                return(true);
            } catch (AuthenticationFailedException e) {
                log.warning(L.l("Quercus[] mail could not send mail to '{0}' because authentication failed\n{1}",
                                to,
                                e.getMessage()));

                log.log(Level.FINE, e.ToString(), e);

                env.warning(e.ToString());

                return(false);
            } catch (MessagingException e) {
                Throwable cause = e;

                log.warning(L.l("Quercus[] mail could not send mail to '{0}'\n{1}",
                                to,
                                cause.getMessage()));

                log.log(Level.FINE, cause.ToString(), cause);

                env.warning(cause.getMessage());

                return(false);
            } catch (Exception e) {
                Throwable cause = e;

                log.warning(L.l("Quercus[] mail could not send mail to '{0}'\n{1}",
                                to,
                                e));

                log.log(Level.FINE, cause.ToString(), cause);

                env.warning(cause.ToString());

                return(false);
            } finally {
                try {
                    if (smtp != null)
                    {
                        smtp.close();
                    }
                } catch (Exception e) {
                    log.log(Level.FINER, e.ToString(), e);
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructs an InvalidPropertiesFormatException with the specified
 /// cause.
 /// </summary>
 /// <param name="cause"> the cause (which is saved for later retrieval by the
 ///         <seealso cref="Throwable#getCause()"/> method). </param>
 public InvalidPropertiesFormatException(Throwable cause) : base(cause == null ? null : cause.ToString())
 {
     this.InitCause(cause);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a {@code CertPathValidatorException} that wraps the
 /// specified throwable. This allows any exception to be converted into a
 /// {@code CertPathValidatorException}, while retaining information
 /// about the wrapped exception, which may be useful for debugging. The
 /// detail message is set to ({@code cause==null ? null : cause.toString()})
 /// (which typically contains the class and detail message of
 /// cause).
 /// </summary>
 /// <param name="cause"> the cause (which is saved for later retrieval by the
 /// <seealso cref="#getCause getCause()"/> method). (A {@code null} value is
 /// permitted, and indicates that the cause is nonexistent or unknown.) </param>
 public CertPathValidatorException(Throwable cause) : this((cause == null ? null : cause.ToString()), cause)
 {
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Constructs a <code>BatchUpdateException</code> object initialized with a
 /// given <code>cause</code> and <code>updateCounts</code>.
 /// The <code>SQLState</code> is initialized
 /// to <code>null</code> and the vendor code is initialized to 0.
 /// The <code>reason</code>  is initialized to <code>null</code> if
 /// <code>cause==null</code> or to <code>cause.toString()</code> if
 /// <code>cause!=null</code>.
 /// <para>
 /// <strong>Note:</strong> There is no validation of {@code updateCounts} for
 /// overflow and because of this it is recommended that you use the constructor
 /// {@code BatchUpdateException(String reason, String SQLState,
 /// int vendorCode, long []updateCounts,Throwable cause) }.
 /// </para> </summary>
 /// <param name="updateCounts"> an array of <code>int</code>, with each element
 /// indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
 /// <code>Statement.EXECUTE_FAILED</code> for each SQL command in
 /// the batch for JDBC drivers that continue processing
 /// after a command failure; an update count or
 /// <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
 /// prior to the failure for JDBC drivers that stop processing after a command
 /// failure </param>
 /// <param name="cause"> the underlying reason for this <code>SQLException</code>
 /// (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
 /// the cause is non-existent or unknown.
 /// @since 1.6 </param>
 /// <seealso cref= #BatchUpdateException(java.lang.String, java.lang.String, int, long[],
 /// java.lang.Throwable) </seealso>
 public BatchUpdateException(int[] updateCounts, Throwable cause) : this((cause == null ? null : cause.ToString()), null, 0, updateCounts, cause)
 {
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructs a <code>BatchUpdateException</code> object initialized with
 ///  a given <code>cause</code>.
 /// The <code>SQLState</code> and <code>updateCounts</code>
 /// are initialized
 /// to <code>null</code> and the vendor code is initialized to 0.
 /// The <code>reason</code>  is initialized to <code>null</code> if
 /// <code>cause==null</code> or to <code>cause.toString()</code> if
 ///  <code>cause!=null</code>. </summary>
 /// <param name="cause"> the underlying reason for this <code>SQLException</code>
 /// (which is saved for later retrieval by the <code>getCause()</code> method);
 /// may be null indicating the cause is non-existent or unknown.
 /// @since 1.6 </param>
 /// <seealso cref= #BatchUpdateException(java.lang.String, java.lang.String, int, long[],
 /// java.lang.Throwable) </seealso>
 public BatchUpdateException(Throwable cause) : this((cause == null ? null : cause.ToString()), null, 0, (int[])null, cause)
 {
 }
Ejemplo n.º 12
0
 public Throwable(Throwable cause) : base(cause == null ? null : cause.ToString(), cause)
 {
     this.cause = cause;
 }