List of usage examples for javax.xml.parsers ParserConfigurationException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
public static Document startXMLDocument(String _firstTag) { DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = null; Document doc = null;/* www .j ava 2 s .co m*/ try { docBuilder = dbfac.newDocumentBuilder(); doc = docBuilder.newDocument(); Element xmlRoot = doc.createElement(_firstTag); doc.appendChild(xmlRoot); } catch (ParserConfigurationException e) { System.out.println("C:" + e.getClass() + "\nM:" + e.getMessage()); return null; } return doc; }
From source file:com.waitwha.nessus.server.Server.java
/** * Constructor/* ww w . j a v a 2 s .c o m*/ * * @param url End-point URL of the Nessus Server. (i.e. https://localhost:8834) */ public Server(final String url) { this.url = url; /* * Configure XML parsing. */ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { this.builder = factory.newDocumentBuilder(); log.finest(String.format("Successfully configured XML parsing using builder: %s", this.builder.getClass().getName())); } catch (ParserConfigurationException e) { log.warning(String.format("Could not configure XML parsing: %s", e.getMessage())); } /* * Setup SSL for HttpClient configurations. Here we will configure SSL/TLS to * accept all hosts (no verification on certificates). This is because Nessus by * default used a self-generate CA and certificate for the servers. So, a simple * self-signed-strategy will not work as we are not dealing with strictly * self-signed certs, but ones generated and signed by a self-generated CA. * * TODO Perhaps the serial number of the CA is always the same so in the future we * could use a strategy to only accept certs by this one serial. * * See http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientConfiguration.java. * * TODO We need to work on the code here to be more up-to-date. SSLSocketFactory is deprecated, but * finding up-to-date docs on how to use SSLContext with a custom TrustStrategy and not using a KeyStore is * not currently available. */ //SSLContext sslContext = SSLContexts.createSystemDefault(); Registry<ConnectionSocketFactory> socketFactoryRegistry = null; try { socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new SSLSocketFactory(new MyTrustStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)) .build(); log.finest(String.format("Configured SSL/TLS connections for %s.", url)); } catch (Exception e) { log.warning( String.format("Could not configure SSL/TLS: %s %s", e.getClass().getName(), e.getMessage())); } SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).build(); this.connectionManager = new BasicHttpClientConnectionManager(socketFactoryRegistry); this.connectionManager.setSocketConfig(socketConfig); log.finest(String.format("Configured socket connections for %s.", url)); this.cookieStore = new BasicCookieStore() { private static final long serialVersionUID = 1L; /** * @see org.apache.http.impl.client.BasicCookieStore#addCookie(org.apache.http.cookie.Cookie) */ @Override public synchronized void addCookie(Cookie cookie) { log.finest(String.format("[%s] Cookie added: %s=%s", url, cookie.getName(), cookie.getValue())); super.addCookie(cookie); } }; log.finest(String.format("Configured default/basic cookie storage for connections to %s", url)); }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Get all scripts to be run to create logging db tables with procs and * constraints Execute each scripts/*from www . ja v a 2 s. co m*/ */ private void ProcessConfigFile() { try { InputStream in = getClass() .getResourceAsStream("shnakkydoodle/measuring/provider/resources/config.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder; dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(in); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("resourcepath"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; String resourcePath = eElement.getTextContent(); // Read in script and execute if (ReadExecuteScript(resourcePath)) { System.out.println("Successfully created: " + resourcePath); } else { System.err.println("Failed on creating: " + resourcePath); } } } } catch (ParserConfigurationException e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); } catch (SAXException e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); } }