Example usage for javax.xml.stream XMLStreamException getMessage

List of usage examples for javax.xml.stream XMLStreamException getMessage

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.apache.olingo.server.core.deserializer.xml.ODataXmlDeserializer.java

@Override
public DeserializerResult entityReferences(final InputStream stream) throws DeserializerException {
    try {/*w ww. ja va  2 s . c o  m*/
        XMLEventReader reader = getReader(stream);
        ArrayList<URI> references = new ArrayList<URI>();

        while (reader.hasNext()) {
            final XMLEvent event = reader.nextEvent();
            if (event.isStartElement()) {
                StartElement start = event.asStartElement();
                if (entryRefQName.equals(start.getName())) {
                    Attribute context = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
                    URI uri = URI.create(context.getValue());
                    references.add(uri);
                }
            }
        }
        return DeserializerResultImpl.with().entityReferences(references).build();
    } catch (XMLStreamException e) {
        throw new DeserializerException(e.getMessage(), e, DeserializerException.MessageKeys.IO_EXCEPTION);
    }
}

From source file:org.apache.olingo.server.core.deserializer.xml.ODataXmlDeserializer.java

@Override
public DeserializerResult actionParameters(final InputStream stream, final EdmAction edmAction)
        throws DeserializerException {
    Map<String, Parameter> parameters = new LinkedHashMap<String, Parameter>();
    if (edmAction.getParameterNames() == null || edmAction.getParameterNames().isEmpty()
            || edmAction.isBound() && edmAction.getParameterNames().size() == 1) {
        return DeserializerResultImpl.with().actionParameters(parameters).build();
    }/*  w  ww .  ja  v a2 s.  c o  m*/

    try {
        final XMLEventReader reader = getReader(stream);
        while (reader.hasNext()) {
            final XMLEvent event = reader.nextEvent();
            if (event.isStartElement() && parametersQName.equals(event.asStartElement().getName())) {
                consumeParameters(edmAction, reader, event.asStartElement(), parameters);
            }
        }
        // EDM checks.
        for (final String param : edmAction.getParameterNames()) {
            Parameter parameter = parameters.get(param);
            if (parameter == null) {
                final EdmParameter edmParameter = edmAction.getParameter(param);
                if (!edmParameter.isNullable()) {
                    throw new DeserializerException("Non-nullable parameter not present or null: " + param,
                            MessageKeys.INVALID_NULL_PARAMETER, param);
                }
                if (edmParameter.isCollection()) {
                    throw new DeserializerException("Collection must not be null for parameter: " + param,
                            MessageKeys.INVALID_NULL_PARAMETER, param);
                }
                // NULL fill for missing parameters.
                parameter = new Parameter();
                parameter.setName(param);
                parameter.setValue(ValueType.PRIMITIVE, null);
                parameters.put(param, parameter);
            }
        }
        return DeserializerResultImpl.with().actionParameters(parameters).build();
    } catch (XMLStreamException e) {
        throw new DeserializerException(e.getMessage(), e, DeserializerException.MessageKeys.IO_EXCEPTION);
    } catch (final EdmPrimitiveTypeException e) {
        throw new DeserializerException(e.getMessage(), e,
                DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
    }
}

From source file:org.apache.solr.handler.loader.XMLLoader.java

@Override
public void load(SolrQueryRequest req, SolrQueryResponse rsp, ContentStream stream,
        UpdateRequestProcessor processor) throws Exception {
    final String charset = ContentStreamBase.getCharsetFromContentType(stream.getContentType());

    InputStream is = null;// w w w. j  a v a2  s. c  om
    XMLStreamReader parser = null;

    String tr = req.getParams().get(CommonParams.TR, null);
    if (tr != null) {
        final Transformer t = getTransformer(tr, req);
        final DOMResult result = new DOMResult();

        // first step: read XML and build DOM using Transformer (this is no overhead, as XSL always produces
        // an internal result DOM tree, we just access it directly as input for StAX):
        try {
            is = stream.getStream();
            final InputSource isrc = new InputSource(is);
            isrc.setEncoding(charset);
            final XMLReader xmlr = saxFactory.newSAXParser().getXMLReader();
            xmlr.setErrorHandler(xmllog);
            xmlr.setEntityResolver(EmptyEntityResolver.SAX_INSTANCE);
            final SAXSource source = new SAXSource(xmlr, isrc);
            t.transform(source, result);
        } catch (TransformerException te) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, te.getMessage(), te);
        } finally {
            IOUtils.closeQuietly(is);
        }
        // second step: feed the intermediate DOM tree into StAX parser:
        try {
            parser = inputFactory.createXMLStreamReader(new DOMSource(result.getNode()));
            this.processUpdate(req, processor, parser);
        } catch (XMLStreamException e) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e.getMessage(), e);
        } finally {
            if (parser != null)
                parser.close();
        }
    }
    // Normal XML Loader
    else {
        try {
            is = stream.getStream();
            if (log.isTraceEnabled()) {
                final byte[] body = IOUtils.toByteArray(is);
                // TODO: The charset may be wrong, as the real charset is later
                // determined by the XML parser, the content-type is only used as a hint!
                log.trace("body",
                        new String(body, (charset == null) ? ContentStreamBase.DEFAULT_CHARSET : charset));
                IOUtils.closeQuietly(is);
                is = new ByteArrayInputStream(body);
            }
            parser = (charset == null) ? inputFactory.createXMLStreamReader(is)
                    : inputFactory.createXMLStreamReader(is, charset);
            this.processUpdate(req, processor, parser);
        } catch (XMLStreamException e) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e.getMessage(), e);
        } finally {
            if (parser != null)
                parser.close();
            IOUtils.closeQuietly(is);
        }
    }
}

From source file:org.apache.solr.handler.XMLLoader.java

@Override
public void load(SolrQueryRequest req, SolrQueryResponse rsp, ContentStream stream) throws Exception {
    errHeader = "XMLLoader: " + stream.getSourceInfo();
    InputStream is = null;/*w w  w. j  a v  a2 s . c  o m*/
    XMLStreamReader parser = null;
    try {
        is = stream.getStream();
        final String charset = ContentStreamBase.getCharsetFromContentType(stream.getContentType());
        if (XmlUpdateRequestHandler.log.isTraceEnabled()) {
            final byte[] body = IOUtils.toByteArray(is);
            // TODO: The charset may be wrong, as the real charset is later
            // determined by the XML parser, the content-type is only used as a hint!
            XmlUpdateRequestHandler.log.trace("body",
                    new String(body, (charset == null) ? ContentStreamBase.DEFAULT_CHARSET : charset));
            IOUtils.closeQuietly(is);
            is = new ByteArrayInputStream(body);
        }
        parser = (charset == null) ? inputFactory.createXMLStreamReader(is)
                : inputFactory.createXMLStreamReader(is, charset);
        this.processUpdate(req, processor, parser);
    } catch (XMLStreamException e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e.getMessage(), e);
    } finally {
        if (parser != null)
            parser.close();
        IOUtils.closeQuietly(is);
    }
}

From source file:org.apache.solr.handler.XsltXMLLoader.java

@Override
public void load(SolrQueryRequest req, SolrQueryResponse rsp, ContentStream stream) throws Exception {
    final DOMResult result = new DOMResult();
    final Transformer t = getTransformer(req);
    InputStream is = null;/* w w w.  j  a v  a 2  s.  co m*/
    XMLStreamReader parser = null;
    // first step: read XML and build DOM using Transformer (this is no overhead, as XSL always produces
    // an internal result DOM tree, we just access it directly as input for StAX):
    try {
        is = stream.getStream();
        final String charset = ContentStreamBase.getCharsetFromContentType(stream.getContentType());
        final InputSource isrc = new InputSource(is);
        isrc.setEncoding(charset);
        final SAXSource source = new SAXSource(isrc);
        t.transform(source, result);
    } catch (TransformerException te) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, te.getMessage(), te);
    } finally {
        IOUtils.closeQuietly(is);
    }
    // second step feed the intermediate DOM tree into StAX parser:
    try {
        parser = inputFactory.createXMLStreamReader(new DOMSource(result.getNode()));
        this.processUpdate(processor, parser);
    } catch (XMLStreamException e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e.getMessage(), e);
    } finally {
        if (parser != null)
            parser.close();
    }
}

From source file:org.apache.synapse.config.xml.SynapseConfigurationBuilder.java

public void setConfiguration(InputStream is) {

    OMElement root = null;/*  w w  w  . ja v a 2s  .c o  m*/
    try {
        root = new StAXOMBuilder(is).getDocumentElement();
    } catch (XMLStreamException e) {
        String msg = "Error parsing Synapse configuration : " + e.getMessage();
        log.error(msg);
        throw new SynapseException(msg);
    }
    root.build();

    // digest defined Sequences
    OMContainer definitions = root.getFirstChildWithName(Constants.DEFINITIONS_ELT);
    if (definitions != null) {
        Iterator iter = definitions.getChildrenWithName(Constants.SEQUENCE_ELT);
        while (iter.hasNext()) {
            OMElement elt = (OMElement) iter.next();
            defineSequence(elt);
        }
    }

    // digest defined Endpoints
    OMContainer endpoints = root.getFirstChildWithName(Constants.ENDPOINT_ELT);
    if (endpoints != null) {
        Iterator iter = endpoints.getChildrenWithName(Constants.ENDPOINT_ELT);
        while (iter.hasNext()) {
            OMElement elt = (OMElement) iter.next();
            //defineEndpoint(synCfg, elt); //TODO process Endpoints
        }
    }

    // digest defined Global properties
    OMContainer properties = root.getFirstChildWithName(Constants.PROPERTY_ELT);
    if (properties != null) {
        Iterator iter = properties.getChildrenWithName(Constants.PROPERTY_ELT);
        while (iter.hasNext()) {
            OMElement elt = (OMElement) iter.next();
            defineProperty(elt);
        }
    }

    OMElement elem = root.getFirstChildWithName(Constants.RULES_ELT);
    if (elem == null) {
        String msg = "A valid Synapse configuration MUST specify the main mediator using the <rules> element";
        log.error(msg);
        throw new SynapseException(msg);
    } else {
        SynapseMediator sm = (SynapseMediator) MediatorFactoryFinder.getInstance().getMediator(elem);
        if (sm.getList().isEmpty()) {
            String msg = "Invalid configuration, the main mediator specified by the <rules> element is empty";
            log.error(msg);
            throw new SynapseException(msg);
        } else {
            config.setMainMediator(sm);
        }
    }

    if (is != null) {
        try {
            is.close();
        } catch (IOException e) {
        }
    }
}

From source file:org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.java

protected StandardContext parseContextFile(File file) throws MojoExecutionException {
    try {/*from ww w  . j a  va  2  s .com*/
        StandardContext standardContext = new StandardContext();
        XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(new FileInputStream(file));

        int tag = reader.next();

        while (true) {
            if (tag == XMLStreamConstants.START_ELEMENT
                    && StringUtils.equals("Context", reader.getLocalName())) {
                String path = reader.getAttributeValue(null, "path");
                if (StringUtils.isNotBlank(path)) {
                    standardContext.setPath(path);
                }

                String docBase = reader.getAttributeValue(null, "docBase");
                if (StringUtils.isNotBlank(docBase)) {
                    standardContext.setDocBase(docBase);
                }
            }
            if (!reader.hasNext()) {
                break;
            }
            tag = reader.next();
        }

        return standardContext;
    } catch (XMLStreamException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:org.atomserver.core.validators.SimpleXMLContentValidator.java

private void validateWellFormed(Reader reader) throws BadContentException {
    try {/*from   w  w  w . j  a  v a2s  .  com*/
        // we will simply walk the doc and see if it throws an Exception
        XMLInputFactory xif = new WstxInputFactory();
        XMLStreamReader xmlreader = xif.createXMLStreamReader(reader);

        while (xmlreader.hasNext()) {
            // Errors won't occur unless we actually access the data...
            touchEvent(xmlreader);
        }
        xmlreader.close();
    } catch (XMLStreamException ee) {
        String msg = "Not well-formed XML :: XMLStreamException:: " + ee.getMessage();
        log.error(msg);
        throw new BadContentException(msg);
    }
}

From source file:org.auraframework.impl.factory.SVGParser.java

@Override
public SVGDef getDefinition(DefDescriptor<SVGDef> descriptor, TextSource<SVGDef> source)
        throws SVGParserException, QuickFixException {
    if (descriptor.getDefType() == DefType.SVG) {
        XMLStreamReader reader = null;
        String contents = source.getContents();
        //If the file is too big throw before we parse the whole thing.
        SVGDef ret = new SVGDefHandler<>(descriptor, source).createDefinition();
        try (StringReader stringReader = new StringReader(contents)) {
            reader = xmlInputFactory.createXMLStreamReader(stringReader);
            if (reader != null) {
                LOOP: while (reader.hasNext()) {
                    int type = reader.next();
                    switch (type) {
                    case XMLStreamConstants.END_DOCUMENT:
                        break LOOP;
                    //This is plain text inside the file
                    case XMLStreamConstants.CHARACTERS:
                        if (DISSALOWED_LIST.matcher(reader.getText()).matches()) {
                            throw new InvalidDefinitionException(
                                    String.format("Text contains disallowed symbols: %s", reader.getText()),
                                    XMLParser.getLocation(reader, source));
                        }//from  w  w w.  j  a v a 2 s .  com
                        break;
                    case XMLStreamConstants.START_ELEMENT:
                        String name = reader.getName().toString().toLowerCase();
                        if (!SVG_TAG_WHITELIST.contains(name)) {
                            throw new InvalidDefinitionException(
                                    String.format("Invalid SVG tag specified: %s", name),
                                    XMLParser.getLocation(reader, source));
                        }
                        for (int i = 0; i < reader.getAttributeCount(); i++) {
                            QName qAttr = reader.getAttributeName(i);
                            String attr = qAttr.getLocalPart();
                            if (SVG_ATTR_BLACKLIST.contains(attr)) {
                                throw new InvalidDefinitionException(
                                        String.format("Invalid SVG attribute specified: %s", attr),
                                        XMLParser.getLocation(reader, source));
                            }
                        }
                        break;
                    case XMLStreamConstants.END_ELEMENT:
                    case XMLStreamConstants.COMMENT:
                    case XMLStreamConstants.DTD:
                    case XMLStreamConstants.SPACE:
                        continue;
                    default:
                        throw new InvalidDefinitionException(String.format("Found unexpected element in xml."),
                                XMLParser.getLocation(reader, source));
                    }
                }
            }
        } catch (XMLStreamException e) {
            throw new SVGParserException(StringEscapeUtils.escapeHtml4(e.getMessage()));
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (XMLStreamException e) {
                    //Well I tried to play nicely
                }
            }
        }
        return ret;
    }
    return null;
}

From source file:org.auraframework.impl.svg.parser.SVGParser.java

@Override
public SVGDef parse(DefDescriptor<SVGDef> descriptor, Source<SVGDef> source)
        throws SVGParserException, QuickFixException {
    if (descriptor.getDefType() == DefType.SVG) {
        XMLStreamReader reader = null;
        String contents = source.getContents();
        //If the file is too big throw before we parse the whole thing.
        SVGDef ret = new SVGDefHandler<>(descriptor, source).createDefinition();
        try (StringReader stringReader = new StringReader(contents)) {
            reader = xmlInputFactory.createXMLStreamReader(stringReader);
            if (reader != null) {
                LOOP: while (reader.hasNext()) {
                    int type = reader.next();
                    switch (type) {
                    case XMLStreamConstants.END_DOCUMENT:
                        break LOOP;
                    //This is plain text inside the file
                    case XMLStreamConstants.CHARACTERS:
                        if (DISSALOWED_LIST.matcher(reader.getText()).matches()) {
                            throw new InvalidDefinitionException(
                                    String.format("Text contains disallowed symbols: %s", reader.getText()),
                                    XMLParser.getLocation(reader, source));
                        }//from  w w  w  .  j a  v  a  2s  .c  o  m
                        break;
                    case XMLStreamConstants.START_ELEMENT:
                        String name = reader.getName().toString().toLowerCase();
                        if (!SVG_TAG_WHITELIST.contains(name)) {
                            throw new InvalidDefinitionException(
                                    String.format("Invalid SVG tag specified: %s", name),
                                    XMLParser.getLocation(reader, source));
                        }
                        for (int i = 0; i < reader.getAttributeCount(); i++) {
                            QName qAttr = reader.getAttributeName(i);
                            String attr = qAttr.getLocalPart();
                            if (SVG_ATTR_BLACKLIST.contains(attr)) {
                                throw new InvalidDefinitionException(
                                        String.format("Invalid SVG attribute specified: %s", attr),
                                        XMLParser.getLocation(reader, source));
                            }
                        }
                        break;
                    case XMLStreamConstants.END_ELEMENT:
                    case XMLStreamConstants.COMMENT:
                    case XMLStreamConstants.DTD:
                    case XMLStreamConstants.SPACE:
                        continue;
                    default:
                        throw new InvalidDefinitionException(String.format("Found unexpected element in xml."),
                                XMLParser.getLocation(reader, source));
                    }
                }
            }
        } catch (XMLStreamException e) {
            throw new SVGParserException(StringEscapeUtils.escapeHtml4(e.getMessage()));
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (XMLStreamException e) {
                    //Well I tried to play nicely
                }
            }
        }
        return ret;
    }
    return null;
}