List of usage examples for javax.xml.stream XMLStreamException getLocalizedMessage
public String getLocalizedMessage()
From source file:co.turnus.trace.io.XmlTraceStreamWriter.java
public void writeAttribute(String name, Object value) { try {// w w w. j a v a2 s .c om writer.writeStartElement(ATTRIBUTE); writer.writeAttribute(ATTRIBUTE_NAME, name); writeObject(value); writer.writeEndElement(); } catch (XMLStreamException e) { throw new TurnusRuntimeException("Trace Writer Error: " + e.getLocalizedMessage(), e.getCause()); } }
From source file:co.turnus.trace.io.XmlTraceStreamWriter.java
private void writeStartDocument() { try {/* w w w . ja va 2s .co m*/ String date = new SimpleDateFormat("yyyy.MM.dd, HH:mm:ss").format(new Date()); writer.writeStartDocument(); writer.writeComment("Trace exported the " + date); writer.writeStartElement(TRACE); } catch (XMLStreamException e) { throw new TurnusRuntimeException("Trace Writer Error: " + e.getLocalizedMessage(), e.getCause()); } }
From source file:co.turnus.trace.io.XmlTraceStreamWriter.java
public void write(Step step) { try {//from w w w . j a v a 2s .c om boolean noAttributes = hasEmptyAttributes(step); if (noAttributes) { writer.writeEmptyElement(STEP); } else { writer.writeStartElement(STEP); } writer.writeAttribute(STEP_FIRING, Long.toString(step.getID())); writer.writeAttribute(STEP_ACTOR, step.getActor()); writer.writeAttribute(STEP_ACTION, step.getAction()); writer.writeAttribute(STEP_ACTOR_CLASS, step.getActorClass()); if (!noAttributes) { writeAttributes(step); writer.writeEndElement(); } } catch (XMLStreamException e) { throw new TurnusRuntimeException("Trace Writer Error: " + e.getLocalizedMessage(), e.getCause()); } }
From source file:co.turnus.trace.io.XmlTraceStreamWriter.java
@SuppressWarnings("rawtypes") private void writeObject(Object v) { try {// w w w .j a va2 s . c o m if (v instanceof Boolean) { writer.writeEmptyElement(TYPE_BOOLEAN); writer.writeAttribute(VALUE, Boolean.toString((Boolean) v)); } else if (v instanceof Byte || v instanceof Short || v instanceof Integer) { writer.writeEmptyElement(TYPE_INTEGER); writer.writeAttribute(VALUE, Integer.toString((Integer) v)); } else if (v instanceof Long) { writer.writeEmptyElement(TYPE_INTEGER); writer.writeAttribute(VALUE, Long.toString((Long) v)); } else if (v instanceof Float) { writer.writeEmptyElement(TYPE_REAL); writer.writeAttribute(VALUE, Float.toString((Float) v)); } else if (v instanceof Double) { writer.writeEmptyElement(TYPE_REAL); writer.writeAttribute(VALUE, Double.toString((Double) v)); } else if (v instanceof String) { writer.writeEmptyElement(TYPE_STRING); writer.writeAttribute(VALUE, (String) v); } else if (v instanceof List) { writer.writeStartElement(TYPE_LIST); for (Object o : (List) v) { writeObject(o); } writer.writeEndElement(); } else if (v instanceof Set) { writer.writeStartElement(TYPE_SET); for (Object o : (Set) v) { writeObject(o); } writer.writeEndElement(); } else if (v instanceof Map) { writer.writeStartElement(TYPE_MAP); for (Object k : ((Map) v).keySet()) { writer.writeStartElement(ENTRY); writeObject(k); writeObject(((Map) v).get(k)); writer.writeEndElement(); } writer.writeEndElement(); } } catch (XMLStreamException e) { throw new TurnusRuntimeException("Trace Writer Error: " + e.getLocalizedMessage(), e.getCause()); } }
From source file:co.turnus.trace.io.XmlTraceStreamWriter.java
public void write(Dependency dep) { try {/*from w w w. j a v a 2 s .c om*/ boolean noAttributes = hasEmptyAttributes(dep); if (noAttributes) { writer.writeEmptyElement(DEPENDENCY); } else { writer.writeStartElement(DEPENDENCY); } writer.writeAttribute(DEPENDENCY_SOURCE, Long.toString(dep.getSource().getID())); writer.writeAttribute(DEPENDENCY_TARGET, Long.toString(dep.getTarget().getID())); Kind kind = dep.getKind(); writer.writeAttribute(DEPENDENCY_KIND, dep.getKind().literal()); switch (kind) { case FSM: { break; } case TOKENS: { writer.writeAttribute(SOURCE_PORT, dep.getSourcePort()); writer.writeAttribute(TARGET_PORT, dep.getTargetPort()); writer.writeAttribute(COUNT, Integer.toString(dep.getCount())); break; } case STATEVAR: { writer.writeAttribute(VARIABLE, dep.getVariable()); writer.writeAttribute(DIRECTION, dep.getDirection().literal()); break; } case PORT: { writer.writeAttribute(PORT, dep.getPort()); writer.writeAttribute(DIRECTION, dep.getDirection().literal()); break; } case GUARD: { writer.writeAttribute(GUARD, dep.getGuard()); writer.writeAttribute(DIRECTION, dep.getDirection().literal()); break; } default: throw new TurnusRuntimeException("Unsupported Dependence kind " + dep); } if (!noAttributes) { writeAttributes(dep); writer.writeEndElement(); } } catch (XMLStreamException e) { throw new TurnusRuntimeException("Trace Writer Error: " + e.getLocalizedMessage(), e.getCause()); } }
From source file:com.rockhoppertech.music.midi.js.xml.ModeFactoryXMLHelper.java
/** * Read modes.xml and create {@code Scale instances} from those definitions. *//*from w w w . jav a 2 s . co m*/ public static void init() { List<Integer> intervals = null; Scale currentMode = null; String tagContent = null; XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = null; try { reader = factory.createXMLStreamReader(ClassLoader.getSystemResourceAsStream("modes.xml")); } catch (XMLStreamException e) { e.printStackTrace(); return; } try { while (reader.hasNext()) { int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: String el = reader.getLocalName(); logger.debug("start element '{}'", el); if ("mode".equals(el)) { currentMode = new Scale(); intervals = new ArrayList<>(); } if ("modes".equals(el)) { modeList = new ArrayList<>(); } break; case XMLStreamConstants.CHARACTERS: tagContent = reader.getText().trim(); logger.debug("tagcontent '{}'", tagContent); break; case XMLStreamConstants.END_ELEMENT: switch (reader.getLocalName()) { case "mode": // wow. both guava and commmons to get an int[] array Integer[] array = FluentIterable.from(intervals).toArray(Integer.class); // same as Integer[] array = intervals.toArray(new // Integer[intervals.size()]); int[] a = ArrayUtils.toPrimitive(array); currentMode.setIntervals(a); modeList.add(currentMode); ScaleFactory.registerScale(currentMode); break; case "interval": logger.debug("interval '{}'", tagContent); logger.debug("intervals '{}'", intervals); intervals.add(Integer.parseInt(tagContent)); break; case "name": currentMode.setName(tagContent); break; } break; case XMLStreamConstants.START_DOCUMENT: modeList = new ArrayList<>(); intervals = new ArrayList<>(); break; } } } catch (XMLStreamException e) { logger.error(e.getLocalizedMessage(), e); e.printStackTrace(); } logger.debug("mode list \n{}", modeList); }
From source file:org.apache.synapse.commons.json.JsonFormatter.java
public void writeTo(MessageContext messageContext, OMOutputFormat omOutputFormat, OutputStream outputStream, boolean preserve) throws AxisFault { OMElement element = messageContext.getEnvelope().getBody().getFirstElement(); if (element == null) { if (preserve) { messageContext.setProperty(JsonUtil.PRESERVE_JSON_STREAM, true); }//from ww w.j av a2s .c om JsonUtil.writeAsJson(messageContext, outputStream); if (logger.isDebugEnabled()) { logger.debug("#writeTo. Wrote JSON stream to output stream. MessageID: " + messageContext.getMessageID()); } return; } if (element instanceof OMSourcedElementImpl) { try { OMDataSource dataSource = ((OMSourcedElementImpl) element).getDataSource(); if (dataSource instanceof JsonDataSource) { dataSource.serialize(outputStream, null); if (logger.isDebugEnabled()) { logger.debug("#writeTo. Wrote JSON DataSource to output stream. MessageID: " + messageContext.getMessageID()); } return; } } catch (XMLStreamException e) { logger.error("#writeTo. Could not write JSON message. MessageID: " + messageContext.getMessageID() + ". Error>>> " + e.getLocalizedMessage()); throw new AxisFault("Could not Write JSON message.", e); } } JsonUtil.writeAsJson(element, outputStream); if (logger.isDebugEnabled()) { logger.debug("#writeTo. Converted XML payload to JSON output stream. MessageID: " + messageContext.getMessageID()); } }
From source file:org.apache.synapse.commons.json.JsonUtil.java
/** * Converts a JSON input stream to its XML representation. * * @param jsonStream JSON input stream/*from www .ja va2 s .c o m*/ * @param pIs Whether or not to add XML processing instructions to the output XML.<br/> * This property is useful when converting JSON payloads with array objects. * @return OMElement that is the XML representation of the input JSON data. */ public static OMElement toXml(InputStream jsonStream, boolean pIs) throws AxisFault { if (jsonStream == null) { logger.error("#toXml. Could not convert JSON Stream to XML. JSON input stream is null."); return null; } try { XMLStreamReader streamReader = getReader(jsonStream, pIs); return new StAXOMBuilder(streamReader).getDocumentElement(); } catch (XMLStreamException e) {//invalid JSON? logger.error("#toXml. Could not convert JSON Stream to XML. Cannot handle JSON input. Error>>> " + e.getLocalizedMessage()); throw new AxisFault("Could not convert JSON Stream to XML. Cannot handle JSON input.", e); } }
From source file:org.apache.synapse.commons.json.JsonUtil.java
/** * Converts an XML element to its JSON representation and writes it to an output stream.<br/> * Note that this method removes all existing namespace declarations and namespace prefixes of the provided XML element<br/> * * @param element XML element of which JSON representation is expected. * @param outputStream Output Stream to write the JSON representation.<br/> * At the end of a successful conversion, its flush method will be called. * @throws AxisFault//from www .j a va 2 s . c om */ public static void writeAsJson(OMElement element, OutputStream outputStream) throws AxisFault { XMLEventReader xmlEventReader = null; XMLEventWriter jsonWriter = null; if (element == null) { logger.error("#writeAsJson. OMElement is null. Cannot convert to JSON."); throw new AxisFault("OMElement is null. Cannot convert to JSON."); } if (outputStream == null) { return; } transformElement(element, true); try { org.apache.commons.io.output.ByteArrayOutputStream xmlStream = new org.apache.commons.io.output.ByteArrayOutputStream(); element.serialize(xmlStream); xmlStream.flush(); xmlEventReader = xmlInputFactory.createXMLEventReader(new XmlReaderDelegate( xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(xmlStream.toByteArray())), processNCNames)); jsonWriter = jsonOutputFactory.createXMLEventWriter(outputStream); jsonWriter.add(xmlEventReader); outputStream.flush(); } catch (XMLStreamException e) { logger.error("#writeAsJson. Could not convert OMElement to JSON. Invalid XML payload. Error>>> " + e.getLocalizedMessage()); throw new AxisFault("Could not convert OMElement to JSON. Invalid XML payload.", e); } catch (IOException e) { logger.error("#writeAsJson. Could not convert OMElement to JSON. Error>>> " + e.getLocalizedMessage()); throw new AxisFault("Could not convert OMElement to JSON.", e); } finally { if (xmlEventReader != null) { try { xmlEventReader.close(); } catch (XMLStreamException ex) { //ignore } } if (jsonWriter != null) { try { jsonWriter.close(); } catch (XMLStreamException ex) { //ignore } } } }
From source file:org.apache.synapse.message.store.impl.commons.MessageConverter.java
private static SOAPEnvelope getSoapEnvelope(String soapEnvelpe) { try {/*from w ww . j av a2 s. com*/ //This is a temporary fix for ESBJAVA-1157 for Andes based(QPID) Client libraries //Thread.currentThread().setContextClassLoader(SynapseEnvironment.class.getClassLoader()); XMLStreamReader xmlReader = StAXUtils .createXMLStreamReader(new ByteArrayInputStream(getUTF8Bytes(soapEnvelpe))); StAXBuilder builder = new StAXSOAPModelBuilder(xmlReader); SOAPEnvelope soapEnvelope = (SOAPEnvelope) builder.getDocumentElement(); soapEnvelope.build(); String soapNamespace = soapEnvelope.getNamespace().getNamespaceURI(); if (soapEnvelope.getHeader() == null) { SOAPFactory soapFactory; if (soapNamespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { soapFactory = OMAbstractFactory.getSOAP12Factory(); } else { soapFactory = OMAbstractFactory.getSOAP11Factory(); } soapFactory.createSOAPHeader(soapEnvelope); } return soapEnvelope; } catch (XMLStreamException e) { logger.error("Cannot create SOAP Envelop. Error:" + e.getLocalizedMessage(), e); return null; } }