List of usage examples for javax.xml.parsers ParserConfigurationException getMessage
public String getMessage()
From source file:es.upm.fi.dia.oeg.sitemap4rdf.Generator.java
/** * Generates the sitemap.xml file/*from ww w . ja v a2 s . c om*/ * @param result an existing ResultSet if we did cross the limit of URLs per sitemap.xml file * @param index of the current generation of the sitemap file, useful when we are creating sitemap_index.xml files */ protected void generateSiteMap(ResultSet result, int index) { try { DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element root = doc.createElement(urlSetTag); root.setAttribute(XMLNS, namespace); if (!semanticSectionGenerated) { root.setAttribute(XMLNS + ":" + PREFIX_SEMANTIC_SITEMAP, NS_SEMANTIC_SITEMAP); } doc.appendChild(root); generateSemanticSection(doc, root); ResultSet rs = generateFromEndPoint(doc, root, result); doc.setXmlStandalone(true); String outputFileName = (index == 0) ? (outputFile + extensionOutputFile) : (outputFile + index + extensionOutputFile); //String outputFileNameDirIncluded = outputFileName; //if (outputDir!=null && !outputDir.isEmpty()) //outputFileNameDirIncluded = outputDir+outputFileName; if (files == null) files = new HashMap<String, Document>(); files.put(outputFileName, doc); if (rs != null) generateSiteMap(rs, ++index); } catch (ParserConfigurationException e) { logger.debug("ParserConfigurationException ", e); System.err.println(e.getMessage()); System.exit(3); } }
From source file:eu.eidas.auth.engine.AbstractSAMLEngine.java
/** * Method that transform the received SAML object into a byte array * representation./*from w ww . j a v a 2 s . co m*/ * * @param samlToken the SAML token. * @return the byte[] of the SAML token. * @throws SAMLEngineException the SAML engine exception */ private byte[] marshall(final XMLObject samlToken) throws SAMLEngineException { try { final MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); final Marshaller marshaller = marshallerFactory.getMarshaller(samlToken); // See http://stackoverflow.com/questions/9828254/is-documentbuilderfactory-thread-safe-in-java-5 DocumentBuilder documentBuilder = DOCUMENT_BUILDER_POOL.poll(); if (documentBuilder == null) { DocumentBuilderFactory documentBuilderFactory = DOCUMENT_BUILDER_FACTORY_POOL.poll(); if (documentBuilderFactory == null) { documentBuilderFactory = newDocumentBuilderFactory(); } documentBuilder = documentBuilderFactory.newDocumentBuilder(); DOCUMENT_BUILDER_FACTORY_POOL.offer(documentBuilderFactory); } final Document doc = documentBuilder.newDocument(); marshaller.marshall(samlToken, doc); // Obtain a byte array representation of the marshalled SAML object final DOMSource domSource = new DOMSource(doc); final StringWriter writer = new StringWriter(); final StreamResult result = new StreamResult(writer); // See http://stackoverflow.com/questions/9828254/is-documentbuilderfactory-thread-safe-in-java-5 Transformer transformer = TRANSFORMER_POOL.poll(); if (transformer == null) { TransformerFactory transformerFactory = TRANSFORMER_FACTORY_POOL.poll(); if (transformerFactory == null) { transformerFactory = TransformerFactory.newInstance(); } transformer = transformerFactory.newTransformer(); TRANSFORMER_FACTORY_POOL.offer(transformerFactory); } transformer.transform(domSource, result); LOG.debug("SAML request \n" + writer.toString()); return writer.toString().getBytes(CHARACTER_ENCODING); } catch (ParserConfigurationException e) { LOG.error("ParserConfigurationException.", e.getMessage()); throw new SAMLEngineException(e); } catch (MarshallingException e) { LOG.info("ERROR : MarshallingException.", e.getMessage()); throw new SAMLEngineException(e); } catch (TransformerConfigurationException e) { LOG.info("ERROR : TransformerConfigurationException.", e.getMessage()); throw new SAMLEngineException(e); } catch (TransformerException e) { LOG.info("ERROR : TransformerException.", e.getMessage()); throw new SAMLEngineException(e); } catch (UnsupportedEncodingException e) { LOG.error("ERROR : UnsupportedEncodingException: " + CHARACTER_ENCODING, e.getMessage()); throw new SAMLEngineException(e); } }
From source file:net.sbbi.upnp.messages.ActionMessage.java
/** * Executes the message and retuns the UPNP device response, according to the UPNP specs, * this method could take up to 30 secs to process ( time allowed for a device to respond to a request ) * @return a response object containing the UPNP parsed response * @throws IOException if some IOException occurs during message send and reception process * @throws UPNPResponseException if an UPNP error message is returned from the server * or if some parsing exception occurs ( detailErrorCode = 899, detailErrorDescription = SAXException message ) *//*from w w w . j av a2 s .c om*/ public ActionResponse service() throws IOException, UPNPResponseException { ActionResponse rtrVal = null; UPNPResponseException upnpEx = null; IOException ioEx = null; StringBuffer body = new StringBuffer(256); body.append("<?xml version=\"1.0\"?>\r\n"); body.append("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""); body.append(" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"); body.append("<s:Body>"); body.append("<u:").append(serviceAction.getName()).append(" xmlns:u=\"").append(service.getServiceType()) .append("\">"); if (serviceAction.getInputActionArguments() != null) { // this action requires params so we just set them... for (Iterator itr = inputParameters.iterator(); itr.hasNext();) { InputParamContainer container = (InputParamContainer) itr.next(); body.append("<").append(container.name).append(">").append(container.value); body.append("</").append(container.name).append(">"); } } body.append("</u:").append(serviceAction.getName()).append(">"); body.append("</s:Body>"); body.append("</s:Envelope>"); if (log.isDebugEnabled()) log.debug("POST prepared for URL " + service.getControlURL()); URL url = new URL(service.getControlURL().toString()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestMethod("POST"); HttpURLConnection.setFollowRedirects(false); //conn.setConnectTimeout( 30000 ); conn.setRequestProperty("HOST", url.getHost() + ":" + url.getPort()); conn.setRequestProperty("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); conn.setRequestProperty("CONTENT-LENGTH", Integer.toString(body.length())); conn.setRequestProperty("SOAPACTION", "\"" + service.getServiceType() + "#" + serviceAction.getName() + "\""); OutputStream out = conn.getOutputStream(); out.write(body.toString().getBytes()); out.flush(); out.close(); conn.connect(); InputStream input = null; if (log.isDebugEnabled()) log.debug("executing query :\n" + body); try { input = conn.getInputStream(); } catch (IOException ex) { // java can throw an exception if he error code is 500 or 404 or something else than 200 // but the device sends 500 error message with content that is required // this content is accessible with the getErrorStream input = conn.getErrorStream(); } if (input != null) { int response = conn.getResponseCode(); String responseBody = getResponseBody(input); if (log.isDebugEnabled()) log.debug("received response :\n" + responseBody); SAXParserFactory saxParFact = SAXParserFactory.newInstance(); saxParFact.setValidating(false); saxParFact.setNamespaceAware(true); ActionMessageResponseParser msgParser = new ActionMessageResponseParser(serviceAction); StringReader stringReader = new StringReader(responseBody); InputSource src = new InputSource(stringReader); try { SAXParser parser = saxParFact.newSAXParser(); parser.parse(src, msgParser); } catch (ParserConfigurationException confEx) { // should never happen // we throw a runtimeException to notify the env problem throw new RuntimeException( "ParserConfigurationException during SAX parser creation, please check your env settings:" + confEx.getMessage()); } catch (SAXException saxEx) { // kind of tricky but better than nothing.. upnpEx = new UPNPResponseException(899, saxEx.getMessage()); } finally { try { input.close(); } catch (IOException ex) { // ignore } } if (upnpEx == null) { if (response == HttpURLConnection.HTTP_OK) { rtrVal = msgParser.getActionResponse(); } else if (response == HttpURLConnection.HTTP_INTERNAL_ERROR) { upnpEx = msgParser.getUPNPResponseException(); } else { ioEx = new IOException("Unexpected server HTTP response:" + response); } } } try { out.close(); } catch (IOException ex) { // ignore } conn.disconnect(); if (upnpEx != null) { throw upnpEx; } if (rtrVal == null && ioEx == null) { ioEx = new IOException("Unable to receive a response from the UPNP device"); } if (ioEx != null) { throw ioEx; } return rtrVal; }
From source file:com.sshtools.common.configuration.SshToolsConnectionProfile.java
/** * * * @param in// w w w . j a v a 2 s . c o m * * @throws InvalidProfileFileException */ public void open(InputStream in) throws InvalidProfileFileException { try { SAXParserFactory saxFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxFactory.newSAXParser(); XMLHandler handler = new XMLHandler(); saxParser.parse(in, handler); handler = null; // in.close(); } catch (IOException ioe) { throw new InvalidProfileFileException("IO error. " + ioe.getMessage()); } catch (SAXException sax) { throw new InvalidProfileFileException("SAX Error: " + sax.getMessage()); } catch (ParserConfigurationException pce) { throw new InvalidProfileFileException("SAX Parser Error: " + pce.getMessage()); } finally { } }
From source file:com.mercatis.lighthouse3.commons.commons.XmlMuncher.java
/** * The constructor, which sets up the XML muncher against an XML document * * @param xml the XML document to munch. * @throws DOMException an exception is thrown in case of an error during XML parsing *///from w ww . j ava2s. c om public XmlMuncher(String xml) throws DOMException { SAXParser saxParser = null; try { saxParser = (SAXParser) pool.borrowObject(); saxParser.parse(new InputSource(new StringReader(xml)), new DefaultHandler() { private LinkedList<String> currentPathStack = new LinkedList<String>(); private StringBuilder currentValue; @Override public void characters(char[] ch, int start, int length) throws SAXException { if (this.currentValue != null) this.currentValue.append(ch, start, length); } @Override public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { this.currentValue = new StringBuilder(); String newPath = null; if (this.currentPathStack.isEmpty()) { newPath = "/" + localName; rootElementName = localName; documentPaths.add(new LinkedHashMap<String, String>()); } else { newPath = this.currentPathStack.getFirst() + "/" + localName; } this.currentPathStack.add(0, newPath); addDocumentPath(documentPaths, newPath, null); } @Override public void endElement(String uri, String localName, String name) throws SAXException { String currentPath = this.currentPathStack.removeFirst(); if (currentValue != null && !"".equals(this.currentValue.toString())) addDocumentPath(documentPaths, currentPath, this.currentValue.toString()); this.currentValue = null; } }); } catch (ParserConfigurationException e) { throw new DOMException((short) 0, "SAX-Parser configuration exception caught while munching XML document: " + e.getMessage()); } catch (SAXException e) { throw new DOMException((short) 0, "SAX parsing exception caught while munching XML document: " + e.getMessage()); } catch (IOException e) { throw new DOMException((short) 0, "IO exception caught while munching XML document: " + e.getMessage()); } catch (Exception e) { throw new DOMException((short) 0, "exception caught while munching XML document: " + e.getMessage()); } finally { try { pool.returnObject(saxParser); } catch (Exception e) { throw new DOMException((short) 0, "exception caught while munching XML document: " + e.getMessage()); } } }
From source file:eu.eidas.auth.engine.core.stork.StorkExtensionProcessor.java
private static void parseSignedDoc(List<XMLObject> attributeValues, String value) { Document document;// w ww .j av a 2 s . c o m // Parse the signedDoc value into an XML DOM Document try { document = DocumentBuilderFactoryUtil.parse(value); } catch (SAXException e1) { LOG.info("ERROR : SAX Error while parsing signModule attribute", e1.getMessage()); LOG.debug("ERROR : SAX Error while parsing signModule attribute", e1); throw new EIDASSAMLEngineRuntimeException(e1); } catch (ParserConfigurationException e2) { LOG.info("ERROR : Parser Configuration Error while parsing signModule attribute", e2.getMessage()); LOG.debug("ERROR : Parser Configuration Error while parsing signModule attribute", e2); throw new EIDASSAMLEngineRuntimeException(e2); } catch (IOException e4) { LOG.info("ERROR : IO Error while parsing signModule attribute", e4.getMessage()); LOG.debug("ERROR : IO Error while parsing signModule attribute", e4); throw new EIDASSAMLEngineRuntimeException(e4); } // Create the XML statement(this will be overwritten with the previous DOM structure) final XSAny xmlValue = (XSAny) BuilderFactoryUtil.buildXmlObject(XML_VALUE_TYPE, XSAny.TYPE_NAME); //Set the signedDoc XML content to this element xmlValue.setDOM(document.getDocumentElement()); // Create the attribute statement final XSAny attrValue = (XSAny) BuilderFactoryUtil.buildXmlObject(STORK_REQUESTED_ATTRIBUTE_VALUE_TYPE, XSAny.TYPE_NAME); //Add previous signedDocXML to the AttributeValue Element attrValue.getUnknownXMLObjects().add(xmlValue); attributeValues.add(attrValue); }
From source file:de.escidoc.core.common.business.indexing.IndexingHandler.java
/** * Protected constructor to prevent instantiation outside of the Spring-context. */// www .j a v a2 s .c o m protected IndexingHandler() throws SystemException { final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); try { this.docBuilder = docBuilderFactory.newDocumentBuilder(); } catch (final ParserConfigurationException e) { throw new SystemException(e.getMessage(), e); } this.notifyIndexerEnabled = EscidocConfiguration.getInstance() .getAsBoolean(EscidocConfiguration.ESCIDOC_CORE_NOTIFY_INDEXER_ENABLED); }
From source file:org.gege.caldavsyncadapter.caldav.CaldavFacade.java
private void parseXML(HttpResponse response, ContentHandler contentHandler) throws IOException, CaldavProtocolException { InputStream is = response.getEntity().getContent(); /*BufferedReader bReader = new BufferedReader(new InputStreamReader(is, "UTF-8")); String Content = "";//from w ww . j av a 2 s . c om String Line = bReader.readLine(); while (Line != null) { Content += Line; Line = bReader.readLine(); }*/ SAXParserFactory factory = SAXParserFactory.newInstance(); try { SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(contentHandler); reader.parse(new InputSource(is)); } catch (ParserConfigurationException e) { throw new AssertionError("ParserConfigurationException " + e.getMessage()); } catch (IllegalStateException e) { throw new CaldavProtocolException(e.getMessage()); } catch (SAXException e) { throw new CaldavProtocolException(e.getMessage()); } }
From source file:de.betterform.xml.xforms.XFormsProcessorImpl.java
/** * reads serialized host document from ObjectInputStream and parses the resulting String * to a DOM Document. After that the host document is passed to the processor. init() is NOT yet * called on the processor to allow an using application to do its own configuration work (like * setting of baseURI and passing of context params). * * todo: rethink the question of the baseURI - is this still necessary when deaserializing? Presumably yes to further allow dynamic resolution. * @param objectInput/*from w w w . j a va 2 s . com*/ * @throws IOException * @throws ClassNotFoundException */ public void readExternal(ObjectInput objectInput) throws IOException, ClassNotFoundException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("deserializing XForms host document"); } String read = objectInput.readUTF(); Document host = null; try { host = DOMUtil.parseString(read, true, false); String baseURI = host.getDocumentElement().getAttribute("bf:baseURI"); setContextParam("betterform.baseURI", baseURI); setBaseURI(baseURI); setXForms(host.getDocumentElement()); } catch (ParserConfigurationException e) { throw new IOException("Parser misconfigured: " + e.getMessage()); } catch (SAXException e) { throw new IOException("Parsing failed: " + e.getMessage()); } catch (XFormsException e) { throw new IOException("An XForms error occurred when passing the host document: " + e.getMessage()); } }
From source file:com.wisemapping.rest.MindmapController.java
private byte[] binary2hexadecimal(HttpServletRequest request, final String mySvg) throws IOException, UnsupportedEncodingException { final ServletContext servletContext = request.getSession().getServletContext(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try {// w w w. jav a 2 s . c o m final ExporterFactory factory = new ExporterFactory(servletContext); ExportFormat exportFormat = ExportFormat.fromContentType("image/png"); final ExportProperties exportProperties = ExportProperties.create(exportFormat); final ExportProperties.ImageProperties imageProperties = (ExportProperties.ImageProperties) exportProperties; imageProperties.setSize(ExportProperties.ImageProperties.Size.MEDIUM); factory.export(exportProperties, null, outputStream, mySvg); //FileUtils.writeByteArrayToFile(new File("c:/Users/A549232/Desktop/img.jpg"), outputStream.toByteArray()); } catch (ParserConfigurationException e) { new WiseMappingException(e.getMessage()); } catch (ExportException e) { new WiseMappingException(e.getMessage()); } catch (TranscoderException e) { new WiseMappingException(e.getMessage()); } return Hex.encodeHexString(outputStream.toByteArray()).getBytes(); }