List of usage examples for javax.xml.stream XMLStreamException getMessage
public String getMessage()
From source file:org.apache.axis2.fastinfoset.FastInfosetPOXMessageFormatter.java
/** * Retrieves the raw bytes from the SOAP envelop. * /*w w w. j a v a 2 s . co m*/ * @see org.apache.axis2.transport.MessageFormatter#getBytes(org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat) */ public byte[] getBytes(MessageContext messageContext, OMOutputFormat format) throws AxisFault { //For POX drop the SOAP envelope and use the message body OMElement element = messageContext.getEnvelope().getBody().getFirstElement(); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); try { //Creates StAX document serializer which actually implements the XMLStreamWriter XMLStreamWriter streamWriter = new StAXDocumentSerializer(outStream); //Since we drop the SOAP envelop we have to manually write the start document and the end document events streamWriter.writeStartDocument(); element.serializeAndConsume(streamWriter); streamWriter.writeEndDocument(); return outStream.toByteArray(); } catch (XMLStreamException xmlse) { logger.error(xmlse.getMessage()); throw new AxisFault(xmlse.getMessage(), xmlse); } }
From source file:org.apache.axis2.fastinfoset.FastInfosetPOXMessageFormatter.java
/** * Write the SOAP envelop to the given OutputStream. * //from w w w. j a v a2 s . com * @see org.apache.axis2.transport.MessageFormatter#writeTo(org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat, java.io.OutputStream, boolean) */ public void writeTo(MessageContext messageContext, OMOutputFormat format, OutputStream outputStream, boolean preserve) throws AxisFault { //For POX drop the SOAP envelope and use the message body OMElement element = messageContext.getEnvelope().getBody().getFirstElement(); try { //Create the StAX document serializer XMLStreamWriter streamWriter = new StAXDocumentSerializer(outputStream); //Since we drop the SOAP envelop we have to manually write the start document and the end document events streamWriter.writeStartDocument(); if (preserve) { element.serialize(streamWriter); } else { element.serializeAndConsume(streamWriter); } streamWriter.writeEndDocument(); } catch (XMLStreamException xmlse) { logger.error(xmlse.getMessage()); throw new AxisFault(xmlse.getMessage(), xmlse); } }
From source file:org.apache.axis2.tcp.TCPEchoRawXMLTest.java
public void testEchoXMLASync() throws Exception { OMElement payload = createPayload(); Options options = new Options(); options.setTo(targetEPR);//w w w .ja va2s . com options.setTransportInProtocol(Constants.TRANSPORT_TCP); options.setAction(Constants.AXIS2_NAMESPACE_URI + "/" + operationName.getLocalPart()); Callback callback = new Callback() { public void onComplete(AsyncResult result) { try { result.getResponseEnvelope().serialize(StAXUtils.createXMLStreamWriter(System.out)); } catch (XMLStreamException e) { onError(e); } finally { finish = true; } } public void onError(Exception e) { log.info(e.getMessage()); finish = true; } }; ServiceClient sender = new ServiceClient(configContext, clientService); sender.setOptions(options); sender.sendReceiveNonBlocking(operationName, payload, callback); int index = 0; while (!finish) { Thread.sleep(1000); index++; if (index > 10) { throw new AxisFault("Server was shutdown as the async response take too long to complete"); } } sender.cleanup(); }
From source file:org.apache.axis2.tcp.TCPTwoChannelEchoRawXMLTest.java
public void testEchoXMLCompleteASync() throws Exception { OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my"); OMElement method = fac.createOMElement("echoOMElement", omNs); OMElement value = fac.createOMElement("myValue", omNs); value.setText("Isaac Asimov, The Foundation Trilogy"); method.addChild(value);/*from ww w .ja v a 2 s . c o m*/ ServiceClient sender; try { Options options = new Options(); options.setTo(targetEPR); options.setTransportInProtocol(Constants.TRANSPORT_TCP); options.setUseSeparateListener(true); options.setAction(operationName.getLocalPart()); Callback callback = new Callback() { public void onComplete(AsyncResult result) { try { result.getResponseEnvelope() .serializeAndConsume(StAXUtils.createXMLStreamWriter(System.out)); } catch (XMLStreamException e) { onError(e); } finally { finish = true; } } public void onError(Exception e) { log.info(e.getMessage()); finish = true; } }; AxisService serviceClient = Utils.createSimpleServiceforClient(serviceName, org.apache.axis2.engine.Echo.class.getName(), operationName); sender = new ServiceClient(configContext, serviceClient); sender.setOptions(options); sender.sendReceiveNonBlocking(operationName, method, callback); int index = 0; while (!finish) { Thread.sleep(1000); index++; if (index > 10) { throw new AxisFault("Server was shutdown as the async response take too long to complete"); } } } finally { if (finish) { } } }
From source file:org.apache.axis2.transport.tcp.TCPEchoRawXMLTest.java
public void testEchoXMLASync() throws Exception { OMElement payload = createPayload(); Options options = new Options(); options.setTo(targetEPR);/* ww w .j a va 2 s. c o m*/ options.setTransportInProtocol(Constants.TRANSPORT_TCP); options.setAction(Constants.AXIS2_NAMESPACE_URI + "/" + operationName.getLocalPart()); AxisCallback callback = new AxisCallback() { public void onComplete(MessageContext msgCtx) { try { msgCtx.getEnvelope().serialize(StAXUtils.createXMLStreamWriter(System.out)); } catch (XMLStreamException e) { onError(e); } finally { finish = true; } } public void onError(Exception e) { log.info(e.getMessage()); finish = true; } public void onComplete() { } public void onFault(MessageContext msgCtx) { onComplete(msgCtx); } public void onMessage(MessageContext msgCtx) { onComplete(msgCtx); } }; ServiceClient sender = new ServiceClient(configContext, clientService); sender.setOptions(options); sender.sendReceiveNonBlocking(operationName, payload, callback); int index = 0; while (!finish) { Thread.sleep(1000); index++; if (index > 10) { throw new AxisFault("Server was shutdown as the async response take too long to complete"); } } sender.cleanup(); }
From source file:org.apache.axis2.transport.tcp.TCPTwoChannelEchoRawXMLTest.java
public void testEchoXMLCompleteASync() throws Exception { OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my"); OMElement method = fac.createOMElement("echoOMElement", omNs); OMElement value = fac.createOMElement("myValue", omNs); value.setText("Isaac Asimov, The Foundation Trilogy"); method.addChild(value);/*from w w w . ja va 2 s . c om*/ ServiceClient sender; try { Options options = new Options(); options.setTo(targetEPR); options.setTransportInProtocol(Constants.TRANSPORT_TCP); options.setUseSeparateListener(true); options.setAction(operationName.getLocalPart()); AxisCallback callback = new AxisCallback() { public void onComplete(MessageContext msgCtx) { try { msgCtx.getEnvelope().serializeAndConsume(StAXUtils.createXMLStreamWriter(System.out)); } catch (XMLStreamException e) { onError(e); } finally { finish = true; } } public void onError(Exception e) { log.info(e.getMessage()); finish = true; } public void onComplete() { } public void onFault(MessageContext msgCtx) { onComplete(msgCtx); } public void onMessage(MessageContext msgCtx) { onComplete(msgCtx); } }; AxisService serviceClient = Utils.createSimpleServiceforClient(serviceName, Echo.class.getName(), operationName); sender = new ServiceClient(configContext, serviceClient); sender.setOptions(options); sender.sendReceiveNonBlocking(operationName, method, callback); int index = 0; while (!finish) { Thread.sleep(1000); index++; if (index > 10) { throw new AxisFault("Server was shutdown as the async response take too long to complete"); } } } finally { if (finish) { } } }
From source file:org.apache.hadoop.util.ConfTest.java
public static List<String> checkConf(InputStream in) { List<NodeInfo> nodes = null; List<String> errors = new ArrayList<String>(); try {//ww w . j a v a 2 s. c o m nodes = parseConf(in); if (nodes == null) { errors.add("bad conf file: top-level element not <configuration>"); } } catch (XMLStreamException e) { errors.add("bad conf file: " + e.getMessage()); } if (!errors.isEmpty()) { return errors; } Map<String, List<Integer>> duplicatedProperties = new HashMap<String, List<Integer>>(); for (NodeInfo node : nodes) { StartElement element = node.getStartElement(); int line = element.getLocation().getLineNumber(); if (!element.getName().equals(new QName("property"))) { errors.add(String.format("Line %d: element not <property>", line)); continue; } List<XMLEvent> events = node.getXMLEventsForQName(new QName("name")); if (events == null) { errors.add(String.format("Line %d: <property> has no <name>", line)); } else { String v = null; for (XMLEvent event : events) { if (event.isAttribute()) { v = ((Attribute) event).getValue(); } else { Characters c = node.getElement(event.asStartElement()); if (c != null) { v = c.getData(); } } if (v == null || v.isEmpty()) { errors.add(String.format("Line %d: <property> has an empty <name>", line)); } } if (v != null && !v.isEmpty()) { List<Integer> lines = duplicatedProperties.get(v); if (lines == null) { lines = new ArrayList<Integer>(); duplicatedProperties.put(v, lines); } lines.add(node.getStartElement().getLocation().getLineNumber()); } } events = node.getXMLEventsForQName(new QName("value")); if (events == null) { errors.add(String.format("Line %d: <property> has no <value>", line)); } for (QName qName : node.getDuplicatedQNames()) { if (!qName.equals(new QName("source"))) { errors.add(String.format("Line %d: <property> has duplicated <%s>s", line, qName)); } } } for (Entry<String, List<Integer>> e : duplicatedProperties.entrySet()) { List<Integer> lines = e.getValue(); if (1 < lines.size()) { errors.add(String.format("Line %s: duplicated <property>s for %s", StringUtils.join(", ", lines), e.getKey())); } } return errors; }
From source file:org.apache.olingo.server.core.deserializer.xml.ODataXmlDeserializer.java
@Override public DeserializerResult property(final InputStream input, final EdmProperty edmProperty) throws DeserializerException { try {//from w ww . j a v a2s. c o m final XMLEventReader reader = getReader(input); final StartElement start = skipBeforeFirstStartElement(reader); Property property = property(reader, start, edmProperty.getType(), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.isCollection()); return DeserializerResultImpl.with().property(property).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.olingo.server.core.deserializer.xml.ODataXmlDeserializer.java
@Override public DeserializerResult entity(final InputStream input, final EdmEntityType edmEntityType) throws DeserializerException { try {// w w w . j a v a 2 s . com final XMLEventReader reader = getReader(input); final StartElement start = skipBeforeFirstStartElement(reader); final Entity entity = entity(reader, start, edmEntityType); if (entity == null) { throw new DeserializerException("No entity found!", DeserializerException.MessageKeys.INVALID_ENTITY); } return DeserializerResultImpl.with().entity(entity).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_ENTITY); } }
From source file:org.apache.olingo.server.core.deserializer.xml.ODataXmlDeserializer.java
@Override public DeserializerResult entityCollection(final InputStream input, final EdmEntityType edmEntityType) throws DeserializerException { try {/*from ww w. j ava2 s .com*/ final XMLEventReader reader = getReader(input); final StartElement start = skipBeforeFirstStartElement(reader); EntityCollection entityCollection = entitySet(reader, start, edmEntityType); if (entityCollection != null) { for (Entity entity : entityCollection.getEntities()) { entity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString()); } } return DeserializerResultImpl.with().entityCollection(entityCollection).build(); } catch (final 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); } }