List of usage examples for javax.xml.stream XMLStreamException getMessage
public String getMessage()
From source file:eu.arthepsy.sonar.plugins.scapegoat.rule.ScapegoatReportSensor.java
private void parseReport(SensorContext context, InputStream stream) { SMInputFactory factory = XmlUtils.createFactory(); try {/*from w ww.j a v a 2s .c om*/ SMHierarchicCursor rootC = factory.rootElementCursor(stream); rootC.advance(); // scapegoat SMInputCursor ruleC = rootC.childElementCursor("warning"); while (ruleC.getNext() != null) { this.parseWarning(context, ruleC); } } catch (XMLStreamException e) { LOG.error(LOG_PREFIX + " xml error parsing report: " + e.getMessage()); } }
From source file:edu.indiana.d2i.sigiri.service.SigiriServiceSkeleton.java
public JobStatusType submitJob(XMLContent jobDescriptionXML, HpcResourceName hpcResource13, String callbackURL, QOSParameter[] qOSParameters14) { if (log.isDebugEnabled()) { log.debug("Submitting new job to queue.."); }//from www. j a va 2s .c o m Date jobSubmisstionTime = new Date(); JobManager jobManager = SigiriServiceComponent.getJobManager(); JobStatusType jobStatus = new JobStatusType(); jobStatus.setStatus(Status_type1.JOB_SUBMISSION_FAILED); try { String jobId = jobManager.addJobToQueue(jobDescriptionXML.getExtraElement().toStringWithConsume(), hpcResource13.getValue(), callbackURL, getQOSParametersAsNameValuePairs(qOSParameters14)); jobStatus.setJobId(jobId); jobStatus.setStatus(Status_type1.JOB_SUBMISSION_ACCEPTED); jobStatus.setDescription(Constants.DESC_JOB_SUBMISSION_SUCCESSFUL); } catch (XMLStreamException e) { log.error("Job submission failed.", e); setErrorStatus(jobStatus, "Job submission failed due XML parsing error." + e.getMessage(), Status_type1.JOB_SUBMISSION_FAILED); } catch (SQLException e) { log.error("Job submission failed.", e); setErrorStatus(jobStatus, "Job submission failed due to dataase error." + e.getMessage(), Status_type1.JOB_SUBMISSION_FAILED); } return jobStatus; }
From source file:com.flexive.shared.media.FxMetadata.java
/** * Get this metadata object as XML document * * @return XML document/*ww w. j a v a2 s . c o m*/ * @throws FxApplicationException on errors */ public String toXML() throws FxApplicationException { StringWriter sw = new StringWriter(2000); try { XMLStreamWriter writer = getXmlOutputFactory().createXMLStreamWriter(sw); writer.writeStartDocument(); writer.writeStartElement("metadata"); writer.writeAttribute("mediatype", getMediaType().name()); writer.writeAttribute("mimetype", getMimeType()); writer.writeAttribute("filename", getFilename()); writeXMLTags(writer); for (FxMetadataItem mdi : getMetadata()) { final String value = mdi.getValue().replaceAll("[\\x00-\\x1F]", ""); //filter out control characters if (StringUtils.isEmpty(value)) continue; writer.writeStartElement("meta"); writer.writeAttribute("key", mdi.getKey()); writer.writeCData(value); writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new FxApplicationException(e, "ex.general.xml", e.getMessage()); } return sw.getBuffer().toString(); }
From source file:com.flexive.chemistry.webdav.TextDocumentResource.java
protected void processXmlProperties(InputStream in) { final XMLInputFactory factory = XMLInputFactory.newInstance(); try {/*from w ww .j av a2s . c o m*/ final XMLStreamReader parser = factory.createXMLStreamReader(in); for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { switch (event) { case XMLStreamConstants.START_ELEMENT: if ("property".equals(parser.getLocalName())) { processProperty(parser); } else if ("name".equals(parser.getLocalName())) { processName(parser); } } } } catch (XMLStreamException e) { throw new RuntimeException("Failed to replace content: " + e.getMessage(), e); } }
From source file:org.fcrepo.serialization.JcrXmlSerializer.java
private void validateJCRXML(final File file) throws InvalidSerializationFormatException, IOException { int depth = 0; try (final FileInputStream fis = new FileInputStream(file)) { final XMLEventReader reader = XMLInputFactory.newFactory().createXMLEventReader(fis); while (reader.hasNext()) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { depth++;//from w w w . j a v a2 s .co m final StartElement startElement = event.asStartElement(); final Attribute nameAttribute = startElement .getAttributeByName(new QName("http://www.jcp.org/jcr/sv/1.0", "name")); if (depth == 1 && nameAttribute != null && "jcr:content".equals(nameAttribute.getValue())) { throw new InvalidSerializationFormatException( "Cannot import JCR/XML starting with content node."); } if (depth == 1 && nameAttribute != null && "jcr:frozenNode".equals(nameAttribute.getValue())) { throw new InvalidSerializationFormatException("Cannot import historic versions."); } final QName name = startElement.getName(); if (!(name.getNamespaceURI().equals("http://www.jcp.org/jcr/sv/1.0") && (name.getLocalPart().equals("node") || name.getLocalPart().equals("property") || name.getLocalPart().equals("value")))) { throw new InvalidSerializationFormatException( "Unrecognized element \"" + name.toString() + "\", in import XML."); } } else { if (event.isEndElement()) { depth--; } } } reader.close(); } catch (XMLStreamException e) { throw new InvalidSerializationFormatException( "Unable to parse XML" + (e.getMessage() != null ? " (" + e.getMessage() + ")." : ".")); } }
From source file:demo.SourceHttpMessageConverter.java
private Source readStAXSource(InputStream body) { try {/*from w w w. j a v a 2 s . co m*/ XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, isSupportDtd()); inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, isProcessExternalEntities()); if (!isProcessExternalEntities()) { inputFactory.setXMLResolver(NO_OP_XML_RESOLVER); } XMLStreamReader streamReader = inputFactory.createXMLStreamReader(body); return new StAXSource(streamReader); } catch (XMLStreamException ex) { throw new HttpMessageNotReadableException("Could not parse document: " + ex.getMessage(), ex); } }
From source file:com.stevpet.sonar.plugins.dotnet.mscover.parser.XmlParserSubject.java
/** * Gets the cursor for the given file//from w w w .j av a 2s. co m * * @param file * @return * @throws FactoryConfigurationError * @throws XMLStreamException */ public SMInputCursor getCursor(File file) { SMInputCursor result = null; try { SMInputFactory inf = new SMInputFactory(XMLInputFactory.newInstance()); SMHierarchicCursor cursor = inf.rootElementCursor(file); result = cursor.advance(); } catch (XMLStreamException e) { String msg = "Could not create cursor " + e.getMessage(); LOG.error(msg); throw new SonarException(msg, e); } return result; }
From source file:com.stevpet.sonar.plugins.dotnet.mscover.parser.XmlParserSubject.java
/** * Gets the cursor for the given file//w ww .j av a 2s .c o m * * @param file * @return * @throws FactoryConfigurationError * @throws XMLStreamException */ public SMInputCursor getCursorFromString(String string) { SMInputCursor result = null; try { SMInputFactory inf = new SMInputFactory(XMLInputFactory.newInstance()); InputStream inputStream = new ByteArrayInputStream(string.getBytes()); SMHierarchicCursor cursor = inf.rootElementCursor(inputStream); result = cursor.advance(); } catch (XMLStreamException e) { String msg = "Could not create cursor " + e.getMessage(); LOG.error(msg); throw new SonarException(msg, e); } return result; }
From source file:org.javelin.sws.ext.bind.SweJaxbMarshaller.java
@Override public void marshal(Object jaxbElement, Result result) throws JAXBException { try {/* w ww .j a v a2 s. c o m*/ XMLEventWriter writer = this.xmlOutputFactory.createXMLEventWriter(result); this.marshal(jaxbElement, writer); writer.flush(); } catch (XMLStreamException e) { throw new JAXBException(e.getMessage(), e); } }
From source file:at.gv.egiz.slbinding.SLUnmarshaller.java
/** * @param source a StreamSource wrapping a Reader (!) for the marshalled Object * @return the unmarshalled Object/*from w w w . j a va 2 s. c om*/ * @throws XMLStreamException * @throws JAXBException */ public Object unmarshal(StreamSource source) throws XMLStreamException, JAXBException { Reader inputReader = source.getReader(); /* Validate XML against XXE, XEE, and SSRF * * This pre-validation step is required because com.sun.xml.stream.sjsxp-1.0.2 XML stream parser library does not * support all XML parser features to prevent these types of attacks */ if (inputReader instanceof InputStreamReader) { try { //create copy of input stream InputStreamReader isReader = (InputStreamReader) inputReader; String encoding = isReader.getEncoding(); byte[] backup = IOUtils.toByteArray(isReader, encoding); //validate input stream DOMUtils.validateXMLAgainstXXEAndSSRFAttacks(new ByteArrayInputStream(backup)); //create new inputStreamReader for reak processing inputReader = new InputStreamReader(new ByteArrayInputStream(backup), encoding); } catch (XMLStreamException e) { log.error("XML data validation FAILED with msg: " + e.getMessage(), e); throw new XMLStreamException("XML data validation FAILED with msg: " + e.getMessage(), e); } catch (IOException e) { log.error("XML data validation FAILED with msg: " + e.getMessage(), e); throw new XMLStreamException("XML data validation FAILED with msg: " + e.getMessage(), e); } } else { log.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); log.error( "Reader is not of type InputStreamReader -> can not make a copy of the InputStream --> extended XML validation is not possible!!! "); log.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * parse XML with original functionality * * This code implements the the original mocca XML processing by using * com.sun.xml.stream.sjsxp-1.0.2 XML stream parser library. Currently, this library is required to get full * security-layer specific XML processing. However, this lib does not fully support XXE, XEE and SSRF * prevention mechanisms (e.g.: XMLInputFactory.SUPPORT_DTD flag is not used) * * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ XMLInputFactory inputFactory = XMLInputFactory.newInstance(); //disallow DTD and external entities inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", false); XMLEventReader eventReader = inputFactory.createXMLEventReader(inputReader); RedirectEventFilter redirectEventFilter = new RedirectEventFilter(); XMLEventReader filteredReader = inputFactory.createFilteredReader(eventReader, redirectEventFilter); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); ReportingValidationEventHandler validationEventHandler = new ReportingValidationEventHandler(); unmarshaller.setEventHandler(validationEventHandler); unmarshaller.setListener(new RedirectUnmarshallerListener(redirectEventFilter)); unmarshaller.setSchema(slSchema); Object object; try { log.trace("Before unmarshal()."); object = unmarshaller.unmarshal(filteredReader); log.trace("After unmarshal()."); } catch (UnmarshalException e) { if (log.isDebugEnabled()) { log.debug("Failed to unmarshal security layer message.", e); } else { log.info("Failed to unmarshal security layer message." + (e.getMessage() != null ? " " + e.getMessage() : "")); } if (validationEventHandler.getErrorEvent() != null) { ValidationEvent errorEvent = validationEventHandler.getErrorEvent(); if (e.getLinkedException() == null) { e.setLinkedException(errorEvent.getLinkedException()); } } throw e; } return object; }