use of org.xml.sax.InputSource in project liquibase by liquibase.
the class LiquibaseSchemaResolverTest method shouldReturnNullWhenNoResourceAsStreamFound.
@Test
public void shouldReturnNullWhenNoResourceAsStreamFound() {
when(resourceAccessorXsdStreamResolver.getResourceAsStream(XSD_FILE)).thenReturn(null);
InputSource inputSource = liquibaseSchemaResolver.resolve(liquibaseParser);
assertThat(inputSource).isNull();
}
use of org.xml.sax.InputSource in project liquibase by liquibase.
the class LiquibaseSchemaResolverTest method shouldReturnNullWhenExceptionOccurs.
@Test
public void shouldReturnNullWhenExceptionOccurs() {
when(resourceAccessorXsdStreamResolver.getResourceAsStream(XSD_FILE)).thenThrow(new RuntimeException());
InputSource inputSource = liquibaseSchemaResolver.resolve(liquibaseParser);
assertThat(inputSource).isNull();
}
use of org.xml.sax.InputSource in project android-async-http by loopj.
the class SaxAsyncHttpResponseHandler method getResponseData.
/**
* Deconstructs response into given content handler
*
* @param entity returned HttpEntity
* @return deconstructed response
* @throws java.io.IOException if there is problem assembling SAX response from stream
* @see cz.msebera.android.httpclient.HttpEntity
*/
@Override
protected byte[] getResponseData(HttpEntity entity) throws IOException {
if (entity != null) {
InputStream instream = entity.getContent();
InputStreamReader inputStreamReader = null;
if (instream != null) {
try {
SAXParserFactory sfactory = SAXParserFactory.newInstance();
SAXParser sparser = sfactory.newSAXParser();
XMLReader rssReader = sparser.getXMLReader();
rssReader.setContentHandler(handler);
inputStreamReader = new InputStreamReader(instream, getCharset());
rssReader.parse(new InputSource(inputStreamReader));
} catch (SAXException e) {
AsyncHttpClient.log.e(LOG_TAG, "getResponseData exception", e);
} catch (ParserConfigurationException e) {
AsyncHttpClient.log.e(LOG_TAG, "getResponseData exception", e);
} finally {
AsyncHttpClient.silentCloseInputStream(instream);
if (inputStreamReader != null) {
try {
inputStreamReader.close();
} catch (IOException e) {
/*ignore*/
}
}
}
}
}
return null;
}
use of org.xml.sax.InputSource in project camel by apache.
the class XAdESSignatureProperties method createChildFromXmlFragmentOrText.
protected Element createChildFromXmlFragmentOrText(Document doc, Input input, String localElementName, String errorMessage, String elementOrText) throws IOException, ParserConfigurationException, XmlSignatureException {
String ending = localElementName + ">";
Element child;
if (elementOrText.startsWith("<") && elementOrText.endsWith(ending)) {
try {
// assume xml
InputSource source = new InputSource(new StringReader(elementOrText));
source.setEncoding("UTF-8");
Document parsedDoc = XmlSignatureHelper.newDocumentBuilder(Boolean.TRUE).parse(source);
replacePrefixes(parsedDoc, input);
child = (Element) doc.adoptNode(parsedDoc.getDocumentElement());
// check for correct namespace
String ns = findNamespace(input.getMessage());
if (!ns.equals(child.getNamespaceURI())) {
throw new XmlSignatureException(String.format("The XAdES confguration is invalid. The root element '%s' of the provided XML fragment '%s' has the invalid namespace '%s'. The correct namespace is '%s'.", child.getLocalName(), elementOrText, child.getNamespaceURI(), ns));
}
} catch (SAXException e) {
throw new XmlSignatureException(String.format(errorMessage, elementOrText, localElementName, namespace), e);
}
} else {
child = createElement(localElementName, doc, input);
child.setTextContent(elementOrText);
}
return child;
}
use of org.xml.sax.InputSource in project camel by apache.
the class XmlRpcDataFormat method unmarshalResponse.
protected Object unmarshalResponse(Exchange exchange, InputStream stream) throws Exception {
InputSource isource = new InputSource(stream);
XMLReader xr = newXMLReader();
XmlRpcResponseParser xp;
try {
xp = new XmlRpcResponseParser(xmlRpcStreamRequestConfig, typeFactory);
xr.setContentHandler(xp);
xr.parse(isource);
} catch (SAXException e) {
throw new XmlRpcClientException("Failed to parse server's response: " + e.getMessage(), e);
} catch (IOException e) {
throw new XmlRpcClientException("Failed to read server's response: " + e.getMessage(), e);
}
if (xp.isSuccess()) {
return xp.getResult();
}
Throwable t = xp.getErrorCause();
if (t == null) {
throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage());
}
if (t instanceof XmlRpcException) {
throw (XmlRpcException) t;
}
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage(), t);
}
Aggregations