Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Catch All Bugs with BugTrap!

, 31 Jan 2009 Ms-PL
A tool that can catch unhandled errors and exceptions, and deliver error reports to remote support servers.
bugtrap_demoapplication.zip
BugTrap Demo Application
BugTrap.dll
BugTrapTest.exe
dbghelp.dll
BugTrap_Documentation.zip
BugTrap.pdf
BugTrap_Setup.zip
BugTrapSetup.exe
bugtrap_sourcecode.zip
BugTrap_SourceCode
doc
BugTrap.doc
BugTrap.pdf
Drawing.vsd
Server
BugTrapServer
BugTrapServer.csproj.user
BugTrapServer.nrproj
Properties
Resources
Bug.ico
Services
Web References
BugTrapWebServer
BugTrapWebServer.nrproj
Source
App_Code
Global.asax
ConfigTemplates
JBugTrapServer
BugTrapServer
JBugTrapServer.pg
JBugTrapServer.prj
manifest.mf
Setup
Bug.ico
BugTrap Support Web Site.url
BugTrapSetup.iss
DoNothing.exe
DoNothing.rar
MSXML4
msxml4.dll
msxml4.inf
msxml4a.dll
msxml4r.dll
Win32
BugTrap
BugTrap.aqt
BugTrap.cfg
BugTrap.def
BugTrap.vcproj.MONSTER.Max.user
BugTrap.vcproj.VIRGO.Max.user
CompleteBugTrap.cfg
res
Bug.ico
Checkmark.bmp
ImageToolbar.bmp
SortArrows.bmp
Upload.avi
CrashExplorer
CrashExplorer.cfg
CrashExplorer.vcproj.MONSTER.Max.user
CrashExplorer.vcproj.VIRGO.Max.user
res
Bug.ico
Test.rar
Examples
BugTrapConsoleTest
BugTrapConsoleTest.vcproj.MONSTER.Max.user
BugTrapConsoleTest.vcproj.VIRGO.Max.user
BugTrapNetTest
app.exe.manifest
BugTrapNetTest.csproj.user
Properties
Settings.settings
BugTrapTest
BugTrapTest.vcproj.MONSTER.Max.user
BugTrapTest.vcproj.VIRGO.Max.user
res
BugTrapTest.ico
BugTrapTestDoc.ico
Toolbar.bmp
/*
 * This is a part of the BugTrap package.
 * Copyright (c) 2005-2007 IntelleSoft.
 * All rights reserved.
 *
 * Description: Server parameters block.
 * Author: Maksim Pyatkovskiy.
 *
 * This source code is only intended as a supplement to the
 * BugTrap package reference and related electronic documentation
 * provided with the product. See these sources for detailed
 * information regarding the BugTrap package.
 */

package BugTrapServer;

import java.io.*;
import java.util.*;
import org.w3c.dom.*;
import org.w3c.dom.traversal.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.xpath.*;

/** Server parameters block. */
class ApplicationSettings {
	/** Parent path for error logs. */
	public String reportPath = null;
	/**
	 * Host address of SMTP server used for sending
	 * notification e-mails.
	 */
	public String smtpHost = null;
	/**
	 * Port number of SMTP server used for sending
	 * notification e-mails.
	 */
	public short smtpPort = -1;
	/** User name of SMTP account. */
	public String smtpUser = null;
	/** Password of SMTP account. */
	public String smtpPassword = null;
	/**
	 * Sender e-mail address used in notification
	 * e-mail message.
	 */
	public String senderAddress = null;
	/**
	 * List of applications handled by the server.
	 * Pass empty list to omit filtering.
	 */
	public TreeSet<AppEntry> applicationList = null;
	/** List of report file extensions accepted by the server. */
	public TreeSet<String> reportFileExtensions = null;
	/** Maximum reports number stored by the system. */
	public int reportsLimit = -1;
	/** Maximum acceptable size of network stream. */
	public int maxReportSize = -1;
	/** Server port number. */
	public short portNumber = 9999;
	/** Unique numbers of last bug reports. */
	public TreeMap<String, AppDirInfo> lastReportNumbers = new TreeMap<String, AppDirInfo>(IgnoreCaseComparator.getInstance());

	/**
	 * Load parameters block.
	 */
	public void load() throws Exception {
		this.loadSettings();
		this.loadDirectories();
	}

	/**
	 * Loads application settings from XML configuration file.
	 */
	private void loadSettings() throws Exception {
		File configFile = getConfigFile();
		InputSource input = new InputSource(configFile.toURI().toURL().toString());
		XPath xpath = XPathFactory.newInstance().newXPath();
		this.loadAppSettings(input, xpath);
		this.loadAppList(input, xpath);
	}

	/**
	 * Load parameters from "applicationSettings" section.
	 * @param input - input stream.
	 * @param xpath - XPath object.
	 */
	private void loadAppSettings(InputSource input, XPath xpath) throws Exception {
		Node appSettings = (Node)xpath.evaluate("/configuration/applicationSettings", input, XPathConstants.NODE);
		String settingValue;
		settingValue = xpath.evaluate("./serverPort/text()", appSettings);
		if (settingValue != null && settingValue.length() > 0) {
			this.portNumber = Short.parseShort(settingValue);
		}
		settingValue = xpath.evaluate("./reportPath/text()", appSettings);
		if (settingValue != null && settingValue.length() > 0) {
			this.reportPath = settingValue;
		}
		settingValue = xpath.evaluate("./reportsLimit/text()", appSettings);
		if (settingValue != null && settingValue.length() > 0) {
			this.reportsLimit = Integer.parseInt(settingValue);
		}
		settingValue = xpath.evaluate("./maxReportSize/text()", appSettings);
		if (settingValue != null && settingValue.length() > 0) {
			this.maxReportSize = Integer.parseInt(settingValue);
		}
		settingValue = xpath.evaluate("./smtpHost/text()", appSettings);
		if (settingValue != null && settingValue.length() > 0) {
			this.smtpHost = settingValue;
		}
		settingValue = xpath.evaluate("./smtpPort/text()", appSettings);
		if (settingValue != null && settingValue.length() > 0) {
			this.smtpPort = Short.parseShort(settingValue);
		}
		settingValue = xpath.evaluate("./smtpUser/text()", appSettings);
		if (settingValue != null && settingValue.length() > 0) {
			this.smtpUser = settingValue;
		}
		settingValue = xpath.evaluate("./smtpPassword/text()", appSettings);
		if (settingValue != null && settingValue.length() > 0) {
			this.smtpPassword = settingValue;
		}
		settingValue = xpath.evaluate("./senderAddress/text()", appSettings);
		if (settingValue != null && settingValue.length() > 0) {
			this.senderAddress = settingValue;
		}
		settingValue = xpath.evaluate("./reportFileExtensions/text()", appSettings);
		if (settingValue != null && settingValue.length() > 0) {
			this.reportFileExtensions = new TreeSet<String>(IgnoreCaseComparator.getInstance());
			String[] extensions = settingValue.split(",|;");
			for (int i = 0; i < extensions.length; ++i) {
				this.reportFileExtensions.add(extensions[i]);
			}
		}
	}

	/**
	 * Load parameters from "applicationList" block.
	 * @param input - input stream.
	 * @param xpath - XPath object.
	 */
	private void loadAppList(InputSource input, XPath xpath) throws Exception {
		NodeList appItems = (NodeList)xpath.evaluate("/configuration/applicationSettings/applicationList/application", input, XPathConstants.NODESET);
		int numItems = appItems.getLength();
		this.applicationList = new TreeSet<AppEntry>();
		for (int itemNum = 0; itemNum < numItems; ++itemNum) {
			Element applicationElement = (Element)appItems.item(itemNum);
			AppEntry appEntry = new AppEntry();
			appEntry.name = applicationElement.getTextContent();
			Attr attrVersion = applicationElement.getAttributeNode("version");
			if (attrVersion != null) {
			    appEntry.version = attrVersion.getValue();
			}
			this.applicationList.add(appEntry);
		}
	}

	/**
	 * Load directories contents from disk.
	 */
	private void loadDirectories() {
		File reportPath = new File(this.reportPath);
		reportPath.mkdirs();
		File[] directories = reportPath.listFiles();
		for (int dirIndex = 0; dirIndex < directories.length; dirIndex++) {
			if (! directories[dirIndex].isDirectory()) {
				continue;
			}
			File directory = directories[dirIndex];
			String appTitle = directory.getName();
            AppDirInfo appDirInfo = new AppDirInfo();
			File[] files = directory.listFiles();
			for (int fileIndex = 0; fileIndex < files.length; fileIndex++) {
				File file = files[fileIndex];
				if (! file.isFile())
					continue;
				String fileName = file.getName();
				if (! fileName.startsWith(RequestHandler.reportNamePattern))
					continue;
				int dotPos = fileName.indexOf('.');
				if (dotPos < 0)
					continue;
				int reportNumber = Integer.parseInt(fileName.substring(RequestHandler.reportNamePattern.length(), dotPos));
				if (appDirInfo.maxReportNumber < reportNumber)
					appDirInfo.maxReportNumber = reportNumber;
				++appDirInfo.numReports;
			}
			this.lastReportNumbers.put(appTitle, appDirInfo);
		}
	}

	/**
	 * Get configuration file.
	 * @return configuration file object.
	 */
	private static File getConfigFile() {
		String appPath = System.getProperty("user.dir");
		File configFile = new File(appPath, "BugTrapServer.config");
		return configFile;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Maksim Pyatkovskiy

United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 31 Jan 2009
Article Copyright 2006 by Maksim Pyatkovskiy
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid