Search in sources :

Example 36 with XMLStreamException

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;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SMInputFactory(org.codehaus.staxmate.SMInputFactory) SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader)

Example 37 with XMLStreamException

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;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) ArrayList(java.util.ArrayList) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 38 with XMLStreamException

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;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) UnmarshalException(javax.xml.bind.UnmarshalException) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 39 with XMLStreamException

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();
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) HashMap(java.util.HashMap) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 40 with XMLStreamException

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;
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) RequestDateTimeData(org.talend.ms.crm.sdk.RequestDateTimeData) XMLStreamException(javax.xml.stream.XMLStreamException) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock)

Aggregations

XMLStreamException (javax.xml.stream.XMLStreamException)442 XMLStreamReader (javax.xml.stream.XMLStreamReader)137 IOException (java.io.IOException)126 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)75 XMLInputFactory (javax.xml.stream.XMLInputFactory)69 InputStream (java.io.InputStream)66 Document (org.w3c.dom.Document)36 JAXBException (javax.xml.bind.JAXBException)35 Fault (org.apache.cxf.interceptor.Fault)34 Element (org.w3c.dom.Element)32 StringReader (java.io.StringReader)30 XMLEvent (javax.xml.stream.events.XMLEvent)28 DOMSource (javax.xml.transform.dom.DOMSource)27 ByteArrayInputStream (java.io.ByteArrayInputStream)25 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)23 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)23 Node (org.w3c.dom.Node)22 StringWriter (java.io.StringWriter)21 XMLEventReader (javax.xml.stream.XMLEventReader)20