List of usage examples for javax.xml.parsers ParserConfigurationException getMessage
public String getMessage()
From source file:be.e_contract.mycarenet.xkms2.KeyBindingAuthenticationSignatureSOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty) { return true; }/* w w w .j av a 2s . com*/ LOG.debug("adding key binding authentication signature"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String requestElementName; if (null != this.prototypeKeyBindingId) { requestElementName = "RegisterRequest"; this.referenceUri = "#" + this.prototypeKeyBindingId; } else if (null != this.revokeKeyBindingId) { requestElementName = "RevokeRequest"; this.referenceUri = "#" + this.revokeKeyBindingId; } else { LOG.error("missing key binding id"); return false; } NodeList requestNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, requestElementName); Element requestElement = (Element) requestNodeList.item(0); if (null == requestElement) { LOG.error("request element not present"); return false; } Document xkmsDocument; try { xkmsDocument = copyDocument(requestElement); } catch (ParserConfigurationException e) { LOG.error("error copying XKMS request: " + e.getMessage(), e); return false; } NodeList keyBindingAuthenticationNodeList = xkmsDocument .getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "KeyBindingAuthentication"); Element keyBindingAuthenticationElement = (Element) keyBindingAuthenticationNodeList.item(0); try { prepareDocument(xkmsDocument); addSignature(keyBindingAuthenticationElement); } catch (Exception e) { LOG.error("error adding authn signature: " + e.getMessage(), e); return false; } Node signatureNode = soapPart.importNode(keyBindingAuthenticationElement.getFirstChild(), true); keyBindingAuthenticationNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "KeyBindingAuthentication"); keyBindingAuthenticationElement = (Element) keyBindingAuthenticationNodeList.item(0); keyBindingAuthenticationElement.appendChild(signatureNode); return true; }
From source file:org.openintents.lib.DeliciousApiHelper.java
public String[] getTags() throws java.io.IOException { String[] result = null;/*from w ww .j ava 2 s .c o m*/ String rpc = mAPI + "tags/get"; Element tag; java.net.URL u = null; try { u = new URL(rpc); } catch (java.net.MalformedURLException mu) { System.out.println("Malformed URL>>" + mu.getMessage()); } Document doc = null; try { javax.net.ssl.HttpsURLConnection connection = (javax.net.ssl.HttpsURLConnection) u.openConnection(); //that's actualy pretty ugly to do, but a neede workaround for m5.rc15 javax.net.ssl.HostnameVerifier v = new org.apache.http.conn.ssl.AllowAllHostnameVerifier(); connection.setHostnameVerifier(v); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(connection.getInputStream()); } catch (java.io.IOException ioe) { System.out.println("Error >>" + ioe.getMessage()); Log.e(_TAG, "Error >>" + ioe.getMessage()); } catch (ParserConfigurationException pce) { System.out.println("ERror >>" + pce.getMessage()); Log.e(_TAG, "ERror >>" + pce.getMessage()); } catch (SAXException se) { System.out.println("ERRROR>>" + se.getMessage()); Log.e(_TAG, "ERRROR>>" + se.getMessage()); } catch (Exception e) { Log.e(_TAG, "Error while excecuting HTTP method. URL is: " + u); System.out.println("Error while excecuting HTTP method. URL is: " + u); e.printStackTrace(); } if (doc == null) { Log.e(_TAG, "document was null, check internet connection?"); throw new java.io.IOException("Error reading stream >>" + rpc + "<<"); } int tagsLen = doc.getElementsByTagName("tag").getLength(); result = new String[tagsLen]; for (int i = 0; i < tagsLen; i++) { tag = (Element) doc.getElementsByTagName("tag").item(i); result[i] = new String(tag.getAttribute("tag").trim()); } //System.out.println( new Scanner( u.openStream() ).useDelimiter( "\\Z" ).next() ); return result; }
From source file:eu.eidas.auth.engine.SAMLEngineUtils.java
/** * * @param xmlObj// www . ja va2 s. com * @return a string containing the xml representation of the entityDescriptor */ public static String serializeObject(XMLObject xmlObj) { StringWriter stringWriter = new StringWriter(); String stringRepresentation = ""; try { DocumentBuilder builder; DocumentBuilderFactory factory = DocumentBuilderFactoryUtil.getSecureDocumentBuilderFactory(); builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Marshaller out = Configuration.getMarshallerFactory().getMarshaller(xmlObj); out.marshall(xmlObj, document); Transformer transformer = TransformerFactory.newInstance().newTransformer(); StreamResult streamResult = new StreamResult(stringWriter); DOMSource source = new DOMSource(document); transformer.transform(source, streamResult); } catch (ParserConfigurationException pce) { LOG.info("ERROR : parser error", pce.getMessage()); LOG.debug("ERROR : parser error", pce); } catch (TransformerConfigurationException tce) { LOG.info("ERROR : transformer configuration error", tce.getMessage()); LOG.debug("ERROR : transformer configuration error", tce); } catch (TransformerException te) { LOG.info("ERROR : transformer error", te.getMessage()); LOG.debug("ERROR : transformer error", te); } catch (MarshallingException me) { LOG.info("ERROR : marshalling error", me.getMessage()); LOG.debug("ERROR : marshalling error", me); } finally { try { stringWriter.close(); stringRepresentation = stringWriter.toString(); } catch (IOException ioe) { LOG.warn("ERROR when closing the marshalling stream {}", ioe); } } return stringRepresentation; }
From source file:org.wikipedia.vlsergey.secretary.utils.AbstractDocumentBuilderPool.java
public DocumentBuilder borrow() throws ParserConfigurationException { try {/*ww w . ja v a 2s.c om*/ return pool.borrowObject(); } catch (ParserConfigurationException exc) { throw exc; } catch (RuntimeException exc) { throw exc; } catch (Exception exc) { log.error(exc.getMessage(), exc); throw new NestableError(exc); } }
From source file:com.aurel.track.admin.customize.category.filter.tree.io.TreeFilterParser.java
private void parse(String xml) { //get a factory SAXParserFactory spf = SAXParserFactory.newInstance(); try {/*from w ww . ja va 2 s .co m*/ //get a new instance of parser SAXParser sp = spf.newSAXParser(); //parse the file and also register this class for call backs InputSource is = new InputSource(new StringReader(xml)); sp.parse(is, this); } catch (SAXException se) { LOGGER.warn("Parsing expression: " + xml + " failed with " + se.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.debug(ExceptionUtils.getStackTrace(se)); } } catch (ParserConfigurationException pce) { LOGGER.warn("Parsing expression: " + xml + " failed with " + pce.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.debug(ExceptionUtils.getStackTrace(pce)); } } catch (IOException ie) { LOGGER.warn("Reading expression: " + xml + " failed with " + ie.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(ie)); } }
From source file:com.oprisnik.semdroid.SemdroidServlet.java
public String getResults(SemdroidReport results, InputStream transformationStyle) { try {//from w w w . j a va2 s . c o m Document doc = XmlUtils.createDocument(); Element rootElement = doc.createElement("AnalysisResults"); doc.appendChild(rootElement); XmlUtils.addResults(results, doc, rootElement); StringWriter writer = new StringWriter(); TransformerFactory transformerFactory = TransformerFactory.newInstance(); StreamSource stylesource = new StreamSource(transformationStyle); Transformer transformer = transformerFactory.newTransformer(stylesource); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(writer); transformer.transform(source, result); return writer.toString(); } catch (ParserConfigurationException pce) { pce.printStackTrace(); log.warning("Exception: " + pce.getMessage()); log.throwing(this.getClass().getName(), "getResults", pce); } catch (TransformerConfigurationException e) { e.printStackTrace(); log.warning("Exception: " + e.getMessage()); log.throwing(this.getClass().getName(), "getResults", e); } catch (TransformerException e) { e.printStackTrace(); log.warning("Exception: " + e.getMessage()); log.throwing(this.getClass().getName(), "getResults", e); } return null; }
From source file:fr.adfab.magebeans.processes.CreateModuleProcess.java
protected void _createConfigXml() { try {/* ww w. j a v a 2 s . c o m*/ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); this.dom = documentBuilder.newDocument(); this.configElement = this.dom.createElement("config"); this.globalElement = this.dom.createElement("global"); // Create config for module version Element moduleElement = this.dom.createElement(this.moduleName); Element versionElement = this.dom.createElement("version"); versionElement.setTextContent("0.1.0"); moduleElement.appendChild(versionElement); this.configElement.appendChild(moduleElement); if (this.hasBlock) { this._createConfigNode("block"); this._createFolders("Block"); } if (this.hasModel) { this._createConfigNode("model"); this._createFolders("Model"); } if (this.hasHelper) { this._createConfigNode("helper"); this._createFolders("Helper"); } if (this.hasSetup) { this._createSetup(); } this.configElement.appendChild(this.globalElement); this.dom.appendChild(this.configElement); } catch (ParserConfigurationException ex) { System.out.println(ex.getMessage()); } }
From source file:org.dspace.submit.lookup.PubmedService.java
public List<Record> search(String query) throws IOException, HttpException { List<Record> results = new ArrayList<>(); if (!ConfigurationManager.getBooleanProperty(SubmissionLookupService.CFG_MODULE, "remoteservice.demo")) { HttpGet method = null;// w ww . j a v a 2s . c om try { HttpClient client = new DefaultHttpClient(); client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); URIBuilder uriBuilder = new URIBuilder("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"); uriBuilder.addParameter("db", "pubmed"); uriBuilder.addParameter("datetype", "edat"); uriBuilder.addParameter("retmax", "10"); uriBuilder.addParameter("term", query); method = new HttpGet(uriBuilder.build()); // Execute the method. HttpResponse response = client.execute(method); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode != HttpStatus.SC_OK) { throw new RuntimeException("WS call failed: " + statusLine); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); Document inDoc = builder.parse(response.getEntity().getContent()); Element xmlRoot = inDoc.getDocumentElement(); Element idList = XMLUtils.getSingleElement(xmlRoot, "IdList"); List<String> pubmedIDs = XMLUtils.getElementValueList(idList, "Id"); results = getByPubmedIDs(pubmedIDs); } catch (ParserConfigurationException e1) { log.error(e1.getMessage(), e1); } catch (SAXException e1) { log.error(e1.getMessage(), e1); } } catch (Exception e1) { log.error(e1.getMessage(), e1); } finally { if (method != null) { method.releaseConnection(); } } } else { InputStream stream = null; try { File file = new File(ConfigurationManager.getProperty("dspace.dir") + "/config/crosswalks/demo/pubmed-search.xml"); stream = new FileInputStream(file); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document inDoc = builder.parse(stream); Element xmlRoot = inDoc.getDocumentElement(); Element idList = XMLUtils.getSingleElement(xmlRoot, "IdList"); List<String> pubmedIDs = XMLUtils.getElementValueList(idList, "Id"); results = getByPubmedIDs(pubmedIDs); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } } } return results; }
From source file:com.telefonica.euro_iaas.paasmanager.installator.rec.services.impl.AbstractBaseService.java
public Document getDocument(String xml) throws ProductInstallatorException { Document doc;/*w w w. j av a 2 s.co m*/ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder; try { docBuilder = docBuilderFactory.newDocumentBuilder(); InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8")); doc = docBuilder.parse(is); } catch (ParserConfigurationException e1) { String msg = "Error parsing vsstring. Desc: " + e1.getMessage(); throw new ProductInstallatorException(msg); } catch (SAXException e) { String msg = "SAXException. Desc: " + e.getMessage(); throw new ProductInstallatorException(msg); } catch (IOException e) { String msg = "IOException. Desc: " + e.getMessage(); throw new ProductInstallatorException(msg); } return doc; }
From source file:demo.SourceHttpMessageConverter.java
private DOMSource readDOMSource(InputStream body) throws IOException { try {/*from ww w . jav a 2 s . c om*/ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", isProcessExternalEntities()); documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd()); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); if (!isProcessExternalEntities()) { documentBuilder.setEntityResolver(NO_OP_ENTITY_RESOLVER); } Document document = documentBuilder.parse(body); return new DOMSource(document); } catch (ParserConfigurationException ex) { throw new HttpMessageNotReadableException("Could not set feature: " + ex.getMessage(), ex); } catch (SAXException ex) { throw new HttpMessageNotReadableException("Could not parse document: " + ex.getMessage(), ex); } }