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.commonjava.rwx.impl.stax.StaxParser.java

public StaxParser(final InputStream in) throws XmlRpcException {
    factory = XMLInputFactory.newInstance();
    try {//from ww w.j  a  v a  2  s  . c o m
        reader = factory.createXMLStreamReader(in);
    } catch (final XMLStreamException e) {
        throw new XmlRpcException("Failed to initialize stream reader: " + e.getMessage(), e);
    }
}

From source file:org.commonjava.rwx.impl.stax.StaxParser.java

public StaxParser(final Reader in) throws XmlRpcException {
    factory = XMLInputFactory.newInstance();
    try {//  w  w w . ja  va2s  .c o m
        reader = factory.createXMLStreamReader(in);
    } catch (final XMLStreamException e) {
        throw new XmlRpcException("Failed to initialize stream reader: " + e.getMessage(), e);
    }
}

From source file:org.commonjava.rwx.impl.stax.StaxParser.java

public StaxParser(final String in) throws XmlRpcException {
    factory = XMLInputFactory.newInstance();
    try {// ww  w  .  j  a va  2  s  .com
        reader = factory.createXMLStreamReader(new StringReader(in));
    } catch (final XMLStreamException e) {
        throw new XmlRpcException("Failed to initialize stream reader: " + e.getMessage(), e);
    }
}

From source file:org.commonjava.rwx.impl.stax.StaxParser.java

public void parse(final XmlRpcListener l) throws XmlRpcException {
    XmlRpcListener listener = l;/*from   ww w.j  a v  a 2 s .  com*/
    Logger logger = LoggerFactory.getLogger(getClass());
    TrackingXmlRpcListener tracker = null;
    //        EventStreamParserImpl estream = null;
    //        if ( logger.isTraceEnabled() )
    //        {
    tracker = new TrackingXmlRpcListener(l);
    listener = tracker;
    //            estream = new EventStreamParserImpl( tracker );
    //            listener = estream;
    //        }

    try {
        while (reader.hasNext()) {
            final int tag = reader.next();
            if (tag == XMLStreamReader.START_ELEMENT) {
                final String tagName = reader.getName().getLocalPart();
                if (XmlRpcConstants.REQUEST.equals(tagName)) {
                    RequestHelper.parse(reader, listener);
                } else if (XmlRpcConstants.RESPONSE.equals(tagName)) {
                    ResponseHelper.parse(reader, listener);
                }
            }
        }
    } catch (final XMLStreamException e) {
        throw new XmlRpcException("Failed to parse input: " + e.getMessage(), e);
    } catch (final RuntimeException e) {

    }
    //        finally
    //        {
    //            if ( logger.isTraceEnabled() )
    //            {
    //                try
    //                {
    //                    logger.trace( "Message parse call trace:\n\n  {}\n\nEvent tree:\n\n  {}\n\n",
    //                                  StringUtils.join( tracker.getCalls(), "\n  " ), estream.renderEventTree() );
    //                }
    //                catch ( Throwable t )
    //                {
    //                }
    //            }
    //        }
}

From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java

/**
 * Writes a corpus graph to the xml stream
 * /*from www  .  j ava2 s . c o  m*/
 * @param graph
 *            the corpus graph to be written
 * @param embedded
 *            determines whether this corpus graph is part of a saltProject
 * @param xml
 *            xml stream to write corpus graph to, if the passed one is
 *            null, a new one will be created
 */
public void writeCorpusGraph(XMLStreamWriter xml, SCorpusGraph graph, boolean embedded) {
    try {
        if (!embedded) {
            xml.writeStartDocument("1.0");
            if (isPrettyPrint) {
                xml.writeCharacters("\n");
                xml.writeStartElement(NS_SALTCOMMON, TAG_SCORPUSGRAPH, NS_VALUE_SALTCOMMON);
                xml.writeNamespace(NS_SCORPUSSTRUCTURE, NS_VALUE_SCORPUSSTRUCTURE);
                xml.writeNamespace(NS_XMI, NS_VALUE_XMI);
                xml.writeNamespace(NS_XSI, NS_VALUE_XSI);
                xml.writeNamespace(NS_SALTCORE, NS_VALUE_SALTCORE);
                xml.writeNamespace(NS_SALTCOMMON, NS_VALUE_SALTCOMMON);
                xml.writeAttribute(NS_VALUE_XMI, ATT_XMI_VERSION, "2.0");
            }
        } else {
            xml.writeStartElement(TAG_SCORPUSGRAPH);
        }

        // write all labels
        if (graph.getLabels() != null) {
            Iterator<Label> labelIt = graph.getLabels().iterator();
            while (labelIt.hasNext()) {
                if (isPrettyPrint) {
                    xml.writeCharacters("\n");
                    xml.writeCharacters("\t");
                }
                writeLabel(xml, labelIt.next());
            }
        }
        // stores the position of a single node in the list of nodes to
        // refer them in a relation
        Map<SNode, Integer> nodePositions = new HashMap<>();

        // write all nodes
        if (graph.getNodes() != null) {
            Iterator<SNode> nodeIt = graph.getNodes().iterator();
            Integer position = 0;
            while (nodeIt.hasNext()) {
                SNode node = nodeIt.next();
                writeNode(xml, node, null);
                nodePositions.put(node, position);
                position++;
            }
        }

        // write all relations
        if (graph.getRelations() != null) {
            Iterator<SRelation<SNode, SNode>> relIt = graph.getRelations().iterator();
            while (relIt.hasNext()) {
                SRelation<SNode, SNode> rel = relIt.next();
                writeRelation(xml, rel, nodePositions, null);
            }
        }
        if (isPrettyPrint) {
            xml.writeCharacters("\n");
            xml.writeCharacters("\t");
        }
        xml.writeEndElement();
    } catch (XMLStreamException e) {
        throw new SaltResourceException(
                "Cannot store salt project to file '" + getLocationStr() + "'. " + e.getMessage(), e);
    } finally {
        if (!embedded) {
            if (xml != null) {
                try {
                    xml.flush();
                    xml.close();
                } catch (XMLStreamException e) {
                    throw new SaltResourceException("Cannot store salt project to file '" + getLocationStr()
                            + "', because the opened stream is not closable. ", e);
                }
            }
        }
    }
}

From source file:org.deegree.metadata.MetadataRecordFactory.java

/**
 * Creates a {@link MetadataRecord} instance out a {@link XMLStreamReader}. The reader must point to the
 * START_ELEMENT of the record. After reading the record the stream points to the END_ELEMENT of the record.
 * //w w  w  . j ava 2  s . c  om
 * @param xmlStream
 *            xmlStream must point to the START_ELEMENT of the record, must not be <code>null</code>
 * @return a {@link MetadataRecord} instance, never <code>null</code>
 */
public static MetadataRecord create(XMLStreamReader xmlStream) {
    if (!xmlStream.isStartElement()) {
        throw new XMLParsingException(xmlStream, "XMLStreamReader does not point to a START_ELEMENT.");
    }
    String ns = xmlStream.getNamespaceURI();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLStreamWriter writer = null;
    XMLStreamReader recordAsXmlStream;
    InputStream in = null;
    try {
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out);

        writer.writeStartDocument();
        XMLAdapter.writeElement(writer, xmlStream);
        writer.writeEndDocument();

        writer.close();
        in = new ByteArrayInputStream(out.toByteArray());
        recordAsXmlStream = XMLInputFactory.newInstance().createXMLStreamReader(in);
    } catch (XMLStreamException e) {
        throw new XMLParsingException(xmlStream, e.getMessage());
    } catch (FactoryConfigurationError e) {
        throw new XMLParsingException(xmlStream, e.getMessage());
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
    if (ISO_RECORD_NS.equals(ns)) {
        return new ISORecord(recordAsXmlStream);
    }
    if (RIM_NS.equals(ns)) {
        throw new UnsupportedOperationException(
                "Creating ebRIM records from XMLStreamReader is not implemented yet.");
    }
    if (DC_RECORD_NS.equals(ns)) {
        throw new UnsupportedOperationException(
                "Creating DC records from XMLStreamReader is not implemented yet.");
    }
    throw new IllegalArgumentException("Unknown / unsuppported metadata namespace '" + ns + "'.");

}

From source file:org.deegree.services.csw.CSWController.java

@Override
public void doSOAP(SOAPEnvelope soapDoc, HttpServletRequest request, HttpResponseBuffer response,
        List<FileItem> multiParts, SOAPFactory factory) throws OMException, ServletException {
    SOAPVersion version = soapDoc.getVersion();
    try {//from w  ww.  j  a  va  2s . c om
        if (version instanceof SOAP11Version) {
            response.setContentType("application/soap+xml");
            XMLStreamWriter xmlWriter = response.getXMLWriter();
            String soapEnvNS = "http://schemas.xmlsoap.org/soap/envelope/";
            String xsiNS = "http://www.w3.org/2001/XMLSchema-instance";
            xmlWriter.writeStartElement("soap", "Envelope", soapEnvNS);
            xmlWriter.writeNamespace("soap", soapEnvNS);
            xmlWriter.writeNamespace("xsi", xsiNS);
            xmlWriter.writeAttribute(xsiNS, "schemaLocation",
                    "http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/");
            xmlWriter.writeStartElement(soapEnvNS, "Body");
        } else {
            beginSOAPResponse(response);
        }
        doXML(soapDoc.getBody().getFirstElement(), response);
    } catch (XMLStreamException e) {
        LOG.debug(e.getMessage(), e);
        sendSoapException(soapDoc, factory, response, new OWSException(e.getMessage(), e, NO_APPLICABLE_CODE),
                request, version);
    } catch (OWSException e) {
        LOG.debug(e.getMessage(), e);
        sendSoapException(soapDoc, factory, response, e, request, version);
    } catch (IOException e) {
        LOG.debug(e.getMessage(), e);
        sendSoapException(soapDoc, factory, response, new OWSException(e.getMessage(), e, NO_APPLICABLE_CODE),
                request, version);
    } catch (MissingParameterException e) {
        LOG.debug(e.getMessage(), e);
        sendSoapException(soapDoc, factory, response,
                new OWSException(e.getMessage(), e, MISSING_PARAMETER_VALUE), request, version);
    } catch (InvalidParameterValueException e) {
        LOG.debug(e.getMessage(), e);
        sendSoapException(soapDoc, factory, response,
                new OWSException(e.getMessage(), e, INVALID_PARAMETER_VALUE), request, version);
    } catch (FailedAuthentication e) {
        LOG.debug(e.getMessage(), e);
        sendSoapException(soapDoc, factory, response, new OWSException(e.getMessage(), e, NO_APPLICABLE_CODE),
                request, version);
    } catch (Throwable t) {
        String msg = "An unexpected error occured: " + t.getMessage();
        LOG.debug(msg, t);
        sendSoapException(soapDoc, factory, response, new OWSException(msg, t, NO_APPLICABLE_CODE), request,
                version);
    }
}

From source file:org.deegree.services.wps.input.EmbeddedComplexInput.java

@Override
public InputStream getValueAsBinaryStream() {

    XMLStreamReader xmlStream = null;
    String textValue = null;/* ww w  .  j  a va  2  s .  c o  m*/
    try {
        try {
            xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(store.getInputStream());
        } catch (Throwable t) {
            throw new RuntimeException(t.getMessage());
        }
        XMLStreamUtils.skipStartDocument(xmlStream);
        textValue = xmlStream.getElementText();
    } catch (XMLStreamException e) {
        LOG.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage());
    } finally {
        if (xmlStream != null) {
            try {
                xmlStream.close();
            } catch (XMLStreamException e) {
                // nothing to do
            }
        }
    }

    ByteArrayInputStream is = null;

    if ("base64".equals(getEncoding())) {
        LOG.debug("Performing base64 decoding of embedded ComplexInput: " + textValue);
        is = new ByteArrayInputStream(Base64.decodeBase64(textValue));
    } else {
        LOG.warn("Unsupported encoding '" + getEncoding() + "'.");
        is = new ByteArrayInputStream(textValue.getBytes());
    }

    return is;
}

From source file:org.deegree.services.wps.provider.jrxml.contentprovider.map.MapContentProvider.java

@Override
public Pair<InputStream, Boolean> prepareJrxmlAndReadInputParameters(InputStream jrxml,
        Map<String, Object> params, ProcessletInputs in, List<CodeType> processedIds,
        Map<String, String> parameters) throws ProcessletException {
    for (ProcessletInput input : in.getParameters()) {
        if (!processedIds.contains(input.getIdentifier()) && input instanceof ComplexInput) {
            ComplexInput complexIn = (ComplexInput) input;
            if (SCHEMA.equals(complexIn.getSchema()) && MIME_TYPE.equals(complexIn.getMimeType())) {

                String mapId = complexIn.getIdentifier().getCode();
                LOG.debug("Found input parameter " + mapId + " representing a map!");

                try {
                    // JAXBContext jc = JAXBContext.newInstance( "org.deegree.services.wps.provider.jrxml.jaxb.map"
                    // );
                    JAXBContext jc = JAXBContext
                            .newInstance(org.deegree.services.wps.provider.jrxml.jaxb.map.Map.class);
                    Unmarshaller unmarshaller = jc.createUnmarshaller();
                    org.deegree.services.wps.provider.jrxml.jaxb.map.Map map = (org.deegree.services.wps.provider.jrxml.jaxb.map.Map) unmarshaller
                            .unmarshal(complexIn.getValueAsXMLStream());

                    XMLAdapter jrxmlAdapter = new XMLAdapter(jrxml);
                    OMElement root = jrxmlAdapter.getRootElement();

                    List<OrderedDatasource<?>> datasources = anaylizeRequestOrder(
                            map.getDatasources().getWMSDatasourceOrWFSDatasource());

                    // MAP
                    int resolution = map.getResolution().intValue();
                    String mapKey = getParameterFromIdentifier(mapId, SUFFIXES.MAP_SUFFIX);
                    if (parameters.containsKey(mapKey)) {
                        OMElement mapImgRep = jrxmlAdapter.getElement(root,
                                new XPath(".//jasper:image[jasper:imageExpression/text()='$P{" + mapKey
                                        + "}']/jasper:reportElement", nsContext));
                        if (mapImgRep == null) {
                            LOG.info(/* ww w . j  av a  2 s .c  o m*/
                                    "Could not find image tag in the jrxml for map parameter '" + mapKey + "'");
                            break;
                        }
                        int originalWidth = jrxmlAdapter.getRequiredNodeAsInteger(mapImgRep,
                                new XPath("@width", nsContext));
                        int originalHeight = jrxmlAdapter.getRequiredNodeAsInteger(mapImgRep,
                                new XPath("@height", nsContext));

                        int width = adjustSpan(originalWidth, resolution);
                        int height = adjustSpan(originalHeight, resolution);

                        Envelope bbox = calculateBBox(map.getDetail(), mapId, width, height, resolution);

                        params.put(mapKey, prepareMap(datasources, parameters.get(mapKey), originalWidth,
                                originalHeight, width, height, bbox, resolution));
                        // SCALE
                        double scale = RenderHelper.calcScaleWMS130(width, height, bbox,
                                bbox.getCoordinateSystem(), MapUtils.DEFAULT_PIXEL_SIZE);
                        String scaleKey = getParameterFromIdentifier(mapId, SUFFIXES.SCALE_SUFFIX);
                        if (parameters.containsKey(scaleKey)) {
                            params.put(scaleKey, convert(scale, parameters.get(scaleKey)));
                        }

                        // SCALEBAR
                        String scalebarKey = getParameterFromIdentifier(mapId, SUFFIXES.SCALEBAR_SUFFIX);
                        if (parameters.containsKey(scalebarKey)) {
                            prepareScaleBar(params, scalebarKey, jrxmlAdapter, datasources,
                                    parameters.get(scalebarKey), bbox, width);
                        }
                    }

                    // LAYERLIST
                    prepareLayerlist(getParameterFromIdentifier(mapId, SUFFIXES.LAYERLIST_SUFFIX), jrxmlAdapter,
                            map, datasources);

                    // LEGEND
                    String legendKey = getParameterFromIdentifier(mapId, SUFFIXES.LEGEND_SUFFIX);
                    if (parameters.containsKey(legendKey)) {
                        params.put(legendKey, prepareLegend(legendKey, jrxmlAdapter, datasources,
                                parameters.get(legendKey), resolution));
                    }

                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    try {
                        if (LOG.isTraceEnabled()) {
                            LOG.trace("Adjusted jrxml: " + jrxmlAdapter.getRootElement());
                        }
                        jrxmlAdapter.getRootElement().serialize(bos);
                        jrxml = new ByteArrayInputStream(bos.toByteArray());
                    } catch (XMLStreamException e) {
                        throw new RuntimeException(e);
                    } finally {
                        IOUtils.closeQuietly(bos);
                    }

                } catch (JAXBException e) {
                    String msg = "Could not parse map configuration from parameter '"
                            + complexIn.getIdentifier() + "': " + e.getMessage();
                    LOG.debug(msg, e);
                    throw new ProcessletException(msg);
                } catch (IOException e) {
                    String msg = "Could not read map configuration from parameter '" + complexIn.getIdentifier()
                            + "': " + e.getMessage();
                    LOG.debug(msg, e);
                    throw new ProcessletException(msg);
                } catch (XMLStreamException e) {
                    String msg = "Could not read map configuration as xml from parameter '"
                            + complexIn.getIdentifier() + "': " + e.getMessage();
                    LOG.debug(msg, e);
                    throw new ProcessletException(msg);
                }
                processedIds.add(input.getIdentifier());
            }
        }
    }
    return new Pair<InputStream, Boolean>(jrxml, false);
}

From source file:org.deegree.services.wps.WPService.java

private void doDescribeProcess(DescribeProcessRequest request, HttpResponseBuffer response)
        throws OWSException {

    LOG.trace("doDescribeProcess invoked, request: " + request);

    // check that all requested processes exist (and resolve special value 'ALL')
    List<WPSProcess> processes = new ArrayList<WPSProcess>();
    for (CodeType identifier : request.getIdentifiers()) {
        LOG.debug("Looking up process '" + identifier + "'");
        if (ALL_PROCESSES_IDENTIFIER.equals(identifier)) {
            processes.addAll(processManager.getProcesses().values());
            break;
        }//from w w  w  .jav  a2 s.c  o  m
        WPSProcess process = processManager.getProcess(identifier);
        if (process != null) {
            processes.add(process);
        } else {
            throw new OWSException("InvalidParameterValue: Identifier\nNo process with id " + identifier
                    + " is registered in the WPS.", OWSException.INVALID_PARAMETER_VALUE);
        }
    }

    try {
        response.setContentType("text/xml; charset=UTF-8");
        XMLStreamWriter xmlWriter = response.getXMLWriter();

        Map<ProcessDefinition, String> processDefToWSDLUrl = new HashMap<ProcessDefinition, String>();
        for (WPSProcess process : processes) {
            ProcessDefinition processDef = process.getDescription();
            CodeType processId = new CodeType(processDef.getIdentifier().getValue(),
                    processDef.getIdentifier().getCodeSpace());
            // TODO WSDL
            // if ( processIdToWSDL.containsKey( processId ) ) {
            // String wsdlURL = OGCFrontController.getHttpGetURL()
            // + "service=WPS&version=1.0.0&request=GetWPSWSDL&identifier=" + processId.getCode();
            // processDefToWSDLUrl.put( processDef, wsdlURL );
            // }
        }

        DescribeProcessResponseXMLAdapter.export100(xmlWriter, processes, processDefToWSDLUrl);
        xmlWriter.flush();
    } catch (XMLStreamException e) {
        e.printStackTrace();
        LOG.error("Internal error: " + e.getMessage());
        throw new OWSException("Error occured while creating response for DescribeProcess operation",
                NO_APPLICABLE_CODE);
    } catch (IOException e) {
        throw new OWSException("Error occured while creating response for DescribeProcess operation",
                NO_APPLICABLE_CODE);
    } catch (Exception e) {
        e.printStackTrace();
        LOG.error("Internal error: " + e.getMessage());
    }

    LOG.trace("doDescribeProcess finished");
}