List of usage examples for javax.xml.stream XMLStreamException XMLStreamException
public XMLStreamException(Throwable th)
From source file:org.wso2.carbon.registry.jira2.issues.test2.Carbon0102TestCase.java
/** * Remove the changes from the registry xml. * @throws IOException/* w w w . j a v a2 s . c o m*/ * @throws XMLStreamException */ public void renewRegistryXML() throws IOException, XMLStreamException { FileOutputStream fileOutputStream = null; XMLStreamWriter writer = null; File srcFile = new File(registryXmlPath); try { OMElement registryXML = getRegistryXmlOmElement(); Iterator iterator = registryXML.getChildrenWithName(new QName("tasks")); OMElement ele = (OMElement) iterator.next(); Iterator childIterator = ele.getChildrenWithName(new QName("task")); childIterator.remove(); registryXML.build(); fileOutputStream = new FileOutputStream(srcFile); writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream); registryXML.serialize(writer); } catch (FileNotFoundException e) { throw new FileNotFoundException("Registry.xml file not found" + e); } catch (XMLStreamException e) { throw new XMLStreamException("XML stream exception" + e); } finally { if (writer != null) { writer.close(); } if (fileOutputStream != null) { fileOutputStream.close(); } } }
From source file:org.wso2.esb.integration.common.utils.clients.axis2client.AxisServiceClientUtils.java
public static void sendRequest(String eprUrl, String operation, String payload, int numberOfInstances, List<String> expectedStrings, boolean twoWay) throws Exception { waitForServiceDeployment(eprUrl);//from w w w . j a va 2s. c om assertFalse(!AxisServiceClientUtils.isServiceAvailable(eprUrl)); for (int i = 0; i < numberOfInstances; i++) { try { EndpointReference epr = new EndpointReference(eprUrl + "/" + operation); if (twoWay) { OMElement result = AxisServiceClientUtils.sendRequest(payload, epr); if (expectedStrings != null) { for (String expectedString : expectedStrings) { assertFalse(!result.toString().contains(expectedString)); } } } else { AxisServiceClientUtils.sendRequestOneWay(payload, epr); } } catch (XMLStreamException e) { log.error(e); throw new XMLStreamException("cannot read xml stream " + e); } catch (AxisFault axisFault) { log.error(axisFault.getMessage()); throw new AxisFault("cannot read xml stream " + axisFault.getMessage()); } } }
From source file:org.wso2.esb.integration.common.utils.clients.axis2client.AxisServiceClientUtils.java
public static void sendRequest(String eprUrl, String operation, String payload, int numberOfInstances, String expectedException, boolean twoWay) throws XMLStreamException, AxisFault { assertFalse(!AxisServiceClientUtils.isServiceAvailable(eprUrl)); for (int i = 0; i < numberOfInstances; i++) { try {/*from www .j av a2s . c o m*/ EndpointReference epr = new EndpointReference(operation); if (twoWay) { OMElement result = AxisServiceClientUtils.sendRequest(payload, epr); fail("Exception expected!!! : " + result.toString()); } else { AxisServiceClientUtils.sendRequestOneWay(payload, epr); } } catch (XMLStreamException e) { if (!e.getClass().getSimpleName().equals(expectedException)) { throw new XMLStreamException(e); } } catch (AxisFault axisFault) { if (!axisFault.getClass().getSimpleName().equals(expectedException)) { throw new AxisFault(axisFault.getMessage()); } } if (expectedException != null) { fail("Exception expected. But not found!!"); } } }
From source file:tds.itemscoringengine.ItemScoreResponse.java
private void writeXmlInternal(Object out) throws XMLStreamException { try {/*from w ww . j a v a 2 s. c o m*/ Marshaller jaxbMarshaller = JAXBContext.newInstance(ItemScoreResponse.class).createMarshaller(); // Shiva: We do not want to escape CDATA. JaxB does not internally // support // it. // Here is an alternate way to achieve the same thing: // http://odedpeer.blogspot.com/2010/07/jaxb-sun-and-how-to-marshal-cdata.html // However this is a sun internal class and we probably should not // be // using. TODO. There may be "access restriction" issues: // http://stackoverflow.com/questions/860187/access-restriction-on-class-due-to-restriction-on-required-library-rt-jar // http://stackoverflow.com/questions/16653519/jaxb-marshal-setproperty-com-sun-xml-bind-characterescapehandler jaxbMarshaller.setProperty("com.sun.xml.bind.characterEscapeHandler", new CharacterEscapeHandler() { @Override public void escape(char[] ac, int i, int j, boolean flag, Writer writer) throws IOException { if (ac != null && i < ac.length && (i + j) <= ac.length) { StringBuilder incomingStringBuilder = new StringBuilder(); for (int counter1 = i; counter1 < i + j; ++counter1) { incomingStringBuilder.append(ac[counter1]); } String incomingString = incomingStringBuilder.toString(); final String BEGIN_CDATA = "<![CDATA["; final String END_CDATA = "]]>"; StringBuilder outgoingString = new StringBuilder(); // there may be multiple CDATA sections. first lets find the index // of "<![CDATA[". // Shiva: Assumptions 1) the CDATA section is whole i.e. we will not // see something like "abc <!CDATA[ x y z". instead we will see // "abc <!CDATA[ x y z ]]> m n o p" // 2) CDATA may be anywhere. 3) there may be multiple CDATA segments // but each will be whole. int currentIndex = 0; while (currentIndex < incomingString.length()) { int indexOfBeginCdata = incomingString.indexOf(BEGIN_CDATA, currentIndex); if (indexOfBeginCdata >= 0) { if (indexOfBeginCdata != currentIndex) { // we will copy everything upto the begining of CDATA and // escape it. String substr = incomingString.substring(currentIndex, indexOfBeginCdata); outgoingString.append(StringEscapeUtils.escapeXml(substr)); } // lets move the current index to at least after the match. currentIndex = indexOfBeginCdata + BEGIN_CDATA.length(); // do we have a end cdata int indexOfEndCData = incomingString.indexOf(END_CDATA, currentIndex); // because of our assumptions above we are not going to check if // this is < 0. outgoingString.append(incomingString.subSequence(indexOfBeginCdata, indexOfEndCData + END_CDATA.length())); // move currentIndex again. currentIndex = indexOfEndCData + END_CDATA.length(); } else { // no more CDATA sections left. outgoingString.append(StringEscapeUtils.escapeXml( incomingString.substring(currentIndex, incomingString.length()))); break; } } writer.write(outgoingString.toString()); // do not escape } else { // TODO Shiva: if they are not within the range then I do not know // what to do. i will just let it go. writer.write(ac, i, j); } } }); if (out instanceof OutputStream) jaxbMarshaller.marshal(this, (OutputStream) out); else if (out instanceof XMLStreamWriter) jaxbMarshaller.marshal(this, (XMLStreamWriter) out); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); _logger.error("Exception writing ItemScoreResponse", e); throw new XMLStreamException(e); } }