use of javax.xml.stream.XMLStreamException in project sonarqube by SonarSource.
the class DuplicationsParser method parse.
public List<Block> parse(ComponentDto component, @Nullable String duplicationsData, DbSession session) {
Map<String, ComponentDto> componentsByKey = newHashMap();
List<Block> blocks = newArrayList();
if (duplicationsData != null) {
try {
SMInputFactory inputFactory = initStax();
SMHierarchicCursor root = inputFactory.rootElementCursor(new StringReader(duplicationsData));
// <duplications>
root.advance();
SMInputCursor cursor = root.childElementCursor("g");
while (cursor.getNext() != null) {
List<Duplication> duplications = newArrayList();
SMInputCursor bCursor = cursor.childElementCursor("b");
while (bCursor.getNext() != null) {
String from = bCursor.getAttrValue("s");
String size = bCursor.getAttrValue("l");
String componentKey = bCursor.getAttrValue("r");
if (from != null && size != null && componentKey != null) {
duplications.add(createDuplication(componentsByKey, from, size, componentKey, session));
}
}
Collections.sort(duplications, new DuplicationComparator(component.uuid(), component.projectUuid()));
blocks.add(new Block(duplications));
}
Collections.sort(blocks, new BlockComparator());
} catch (XMLStreamException e) {
throw new IllegalStateException("XML is not valid", e);
}
}
return blocks;
}
use of javax.xml.stream.XMLStreamException in project modrun by nanosai.
the class ModuleDependencyReader method readDependencies.
public static List<Dependency> readDependencies(Reader pomReader) {
List<Dependency> dependencies = new ArrayList<>();
XMLInputFactory factory = XMLInputFactory.newInstance();
try {
XMLStreamReader streamReader = factory.createXMLStreamReader(pomReader);
while (streamReader.hasNext()) {
streamReader.next();
if (streamReader.getEventType() == XMLStreamReader.START_ELEMENT) {
String elementName = streamReader.getLocalName();
if (elementName.equals("dependency")) {
Dependency dependency = parseDependency(streamReader);
dependencies.add(dependency);
}
}
}
} catch (XMLStreamException e) {
e.printStackTrace();
}
return dependencies;
}
use of javax.xml.stream.XMLStreamException in project openhab1-addons by openhab.
the class DenonConnector method getDocument.
private <T> T getDocument(String uri, Class<T> response) {
try {
String result = doHttpRequest("GET", uri, null);
logger.trace("result of getDocument for uri '{}':\r\n{}", uri, result);
if (StringUtils.isNotBlank(result)) {
JAXBContext jc = JAXBContext.newInstance(response);
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(IOUtils.toInputStream(result));
xsr = new PropertyRenamerDelegate(xsr);
@SuppressWarnings("unchecked") T obj = (T) jc.createUnmarshaller().unmarshal(xsr);
return obj;
}
} catch (UnmarshalException e) {
logger.debug("Failed to unmarshal xml document: {}", e.getMessage());
} catch (JAXBException e) {
logger.debug("Unexpected error occurred during unmarshalling of document: {}", e.getMessage());
} catch (XMLStreamException e) {
logger.debug("Communication error: {}", e.getMessage());
}
return null;
}
use of javax.xml.stream.XMLStreamException in project midpoint by Evolveum.
the class XmlParser method parse.
public void parse(InputStream is, XmlObjectHandler handler) {
XMLStreamReader stream;
try {
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
stream = xmlInputFactory.createXMLStreamReader(is);
int serial = 1;
Map<String, String> nsMap = new HashMap<String, String>();
int eventType = stream.nextTag();
if (eventType == XMLStreamConstants.START_ELEMENT) {
if (!stream.getName().equals(ToolsUtils.C_OBJECTS)) {
parseObject(stream, handler, serial, nsMap);
return;
}
for (int i = 0; i < stream.getNamespaceCount(); i++) {
nsMap.put(stream.getNamespacePrefix(i), stream.getNamespaceURI(i));
}
} else {
throw new XMLStreamException("StAX problem, shouldn't happen.");
}
while (stream.hasNext()) {
eventType = stream.next();
if (eventType == XMLStreamConstants.START_ELEMENT) {
if (!parseObject(stream, handler, serial, nsMap)) {
break;
}
serial++;
}
}
} catch (XMLStreamException ex) {
//todo error handling
ex.printStackTrace();
}
}
use of javax.xml.stream.XMLStreamException in project tdi-studio-se by Talend.
the class MSCRMClient method createCRMSecurityHeaderBlock.
private static SOAPHeaderBlock createCRMSecurityHeaderBlock(SecurityData securityData) throws XMLStreamException {
RequestDateTimeData dateTimeData = WsdlTokenManager.getRequestDateTime();
String currentDateTime = dateTimeData.getCreatedDateTime();
String expireDateTime = dateTimeData.getExpiresDateTime();
String securityHeaderTemplate = "<EncryptedData " + " xmlns=\"http://www.w3.org/2001/04/xmlenc#\"" + " Id=\"Assertion0\" " + " Type=\"http://www.w3.org/2001/04/xmlenc#Element\">" + " <EncryptionMethod " + " Algorithm=\"http://www.w3.org/2001/04/xmlenc#tripledes-cbc\"/>" + " <ds:KeyInfo " + " xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">" + " <EncryptedKey>" + " <EncryptionMethod " + " Algorithm=\"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p\"/>" + " <ds:KeyInfo Id=\"keyinfo\">" + " <wsse:SecurityTokenReference " + " xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">" + " <wsse:KeyIdentifier " + " EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\" " + " ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier\">%s</wsse:KeyIdentifier>" + " </wsse:SecurityTokenReference>" + " </ds:KeyInfo>" + " <CipherData>" + " <CipherValue>%s</CipherValue>" + " </CipherData>" + " </EncryptedKey>" + " </ds:KeyInfo>" + " <CipherData>" + " <CipherValue>%s</CipherValue>" + " </CipherData>" + "</EncryptedData>";
String securityHeader = String.format(securityHeaderTemplate, securityData.getKeyIdentifier(), securityData.getSecurityToken0(), securityData.getSecurityToken1());
try {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace securityNS = factory.createOMNamespace("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "o");
OMNamespace utitlityNS = factory.createOMNamespace("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "u");
OMElement timeStamp = factory.createOMElement("Timestamp", utitlityNS);
timeStamp.addAttribute("Id", "_0", utitlityNS);
OMElement created = factory.createOMElement("Created", utitlityNS);
OMText createdTime = factory.createOMText(currentDateTime + "Z");
created.addChild(createdTime);
OMElement expires = factory.createOMElement("Expires", utitlityNS);
OMText expiresTime = factory.createOMText(expireDateTime + "Z");
expires.addChild(expiresTime);
timeStamp.addChild(created);
timeStamp.addChild(expires);
SOAPHeaderBlock wsseHeader = OMAbstractFactory.getSOAP12Factory().createSOAPHeaderBlock("Security", securityNS);
wsseHeader.setMustUnderstand(true);
wsseHeader.addChild(timeStamp);
wsseHeader.addChild(AXIOMUtil.stringToOM(factory, securityHeader));
return wsseHeader;
} catch (XMLStreamException e) {
logger.error(e.getMessage());
throw e;
}
}
Aggregations