use of javax.xml.transform.stax.StAXSource in project spring-framework by spring-projects.
the class SourceHttpMessageConverterTests method readStAXSourceExternal.
@Test
public void readStAXSourceExternal() throws Exception {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(bodyExternal.getBytes(StandardCharsets.UTF_8));
inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML);
converter.setSupportDtd(true);
StAXSource result = (StAXSource) converter.read(StAXSource.class, inputMessage);
XMLStreamReader streamReader = result.getXMLStreamReader();
assertThat(streamReader.hasNext()).isTrue();
streamReader.next();
streamReader.next();
String s = streamReader.getLocalName();
assertThat(s).isEqualTo("root");
try {
s = streamReader.getElementText();
assertThat(s).isNotEqualTo("Foo Bar");
} catch (XMLStreamException ex) {
// Some parsers raise a parse exception
}
streamReader.close();
}
use of javax.xml.transform.stax.StAXSource in project spring-framework by spring-projects.
the class AbstractUnmarshallerTests method unmarshalJaxp14StaxSourceXmlEventReader.
@Test
public void unmarshalJaxp14StaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
StAXSource source = new StAXSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
use of javax.xml.transform.stax.StAXSource in project spring-framework by spring-projects.
the class SourceHttpMessageConverter method readStAXSource.
private Source readStAXSource(InputStream body, HttpInputMessage inputMessage) {
try {
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, inputMessage);
}
}
use of javax.xml.transform.stax.StAXSource in project Activiti by Activiti.
the class BpmnXMLConverter method validateModel.
public void validateModel(XMLStreamReader xmlStreamReader) throws Exception {
Schema schema = createSchema();
Validator validator = schema.newValidator();
validator.validate(new StAXSource(xmlStreamReader));
}
use of javax.xml.transform.stax.StAXSource in project uPortal by Jasig.
the class ImportExportController method importEntity.
@RequestMapping(value = "/import", method = RequestMethod.POST)
public void importEntity(@RequestParam("file") MultipartFile entityFile, HttpServletRequest request, HttpServletResponse response) throws IOException, XMLStreamException {
// Get a StAX reader for the source to determine info about the data to import
final BufferedXMLEventReader bufferedXmlEventReader = createSourceXmlEventReader(entityFile);
final PortalDataKey portalDataKey = getPortalDataKey(bufferedXmlEventReader);
String target = determineTarget(portalDataKey);
final IPerson person = personManager.getPerson(request);
final EntityIdentifier ei = person.getEntityIdentifier();
final IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
if (!ap.hasPermission("UP_SYSTEM", "IMPORT_ENTITY", target)) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
portalDataHandlerService.importData(new StAXSource(bufferedXmlEventReader));
response.setStatus(HttpServletResponse.SC_OK);
}
Aggregations