use of javax.xml.bind.UnmarshalException in project phoenix by apache.
the class XMLResultHandlerTest method testDTDInResults.
@Test
public void testDTDInResults() throws Exception {
URL resultsUrl = XMLConfigParserTest.class.getResource("/malicious_results_with_dtd.xml");
assertNotNull(resultsUrl);
File resultsFile = new File(resultsUrl.getFile());
XMLResultHandler handler = new XMLResultHandler();
try {
handler.readFromResultFile(resultsFile);
fail("Expected to see an exception parsing the results with a DTD");
} catch (UnmarshalException e) {
// If we don't parse the DTD, the variable 'name' won't be defined in the XML
LOG.debug("Caught expected exception", e);
Throwable cause = e.getLinkedException();
assertTrue("Cause was a " + cause.getClass(), cause instanceof XMLStreamException);
}
}
use of javax.xml.bind.UnmarshalException in project opencast by opencast.
the class AclScannerTest method testCorruptedFileUpdate.
@Test
public void testCorruptedFileUpdate() throws Exception {
File file = new File(AclScannerTest.class.getResource("/xacml_errors.xml").toURI());
try {
aclScanner.update(file);
fail("Should not be parsed.");
} catch (XACMLParsingException e) {
assertTrue("The file can not be parsed.", e.getCause() instanceof UnmarshalException);
}
}
use of javax.xml.bind.UnmarshalException in project platformlayer by platformlayer.
the class HttpPlatformLayerClient method listMetrics.
@Override
public MetricInfoCollection listMetrics(PlatformLayerKey key) throws PlatformLayerClientException {
String relativePath = buildRelativePath(key) + "/metrics";
String retval = doRequest(HttpMethod.GET, relativePath, String.class, Format.XML, null, null);
MetricInfoCollection items;
try {
items = JaxbHelper.deserializeXmlObject(retval, MetricInfoCollection.class);
} catch (UnmarshalException e) {
throw new PlatformLayerClientException("Error parsing returned data", e);
}
return items;
}
use of javax.xml.bind.UnmarshalException in project platformlayer by platformlayer.
the class PlatformLayerHttpRequest method doRequest.
public <T> T doRequest(Class<T> retvalClass, Format acceptFormat, Object sendData, Format sendDataFormat) throws PlatformLayerClientException {
try {
populateHttpRequest(acceptFormat, sendDataFormat);
if (debug != null) {
debug.println("Request: " + httpRequest);
}
if (sendData != null) {
if (sendData instanceof String) {
if (debug != null) {
debug.println("Data: " + sendData);
}
String sendDataString = (String) sendData;
httpRequest.setRequestContent(new Utf8StringByteSource(sendDataString));
} else {
switch(sendDataFormat) {
case XML:
if (debug != null) {
debug.println("Data: [XML Content]");
}
JaxbHelper jaxbHelper = JaxbHelper.get(sendData.getClass());
String xml = jaxbHelper.marshal(sendData, false);
httpRequest.setRequestContent(new Utf8StringByteSource(xml));
// jaxbHelper.marshal(sendData, false, getOutputStream());
break;
case JSON:
if (debug != null) {
debug.println("Data: [JSON Content]");
}
JsonHelper jsonHelper = JsonHelper.build(sendData.getClass());
String json = jsonHelper.marshal(sendData, false);
httpRequest.setRequestContent(new Utf8StringByteSource(json));
// jsonHelper.marshal(sendData, false, getOutputStream());
break;
default:
throw new IllegalStateException();
}
}
}
} catch (JAXBException e) {
throw new PlatformLayerClientException("Error while building request", e);
} catch (IOException e) {
throw new PlatformLayerClientException("Error while building request", e);
}
try {
processHttpResponseCode(getResponse());
if (retvalClass == null) {
return null;
} else if (String.class.equals(retvalClass)) {
InputStream is = getInputStream();
String text = null;
if (is != null) {
text = IoUtils.readAll(is);
}
if (debug != null) {
debug.println("Response: " + text);
}
return Casts.as(text, retvalClass);
} else if (StreamingResponse.class.equals(retvalClass)) {
return Casts.as(new StreamingResponse(getResponse()), retvalClass);
} else {
if (debug != null) {
debug.println("Response: XML/JSON content");
}
InputStream is = getInputStream();
return JaxbHelper.deserializeXmlObject(is, retvalClass, true);
}
} catch (ConnectException e) {
throw new PlatformLayerClientException("Error connecting to PlatformLayer service", e);
} catch (UnmarshalException e) {
throw new PlatformLayerClientException("Error while reading PlatformLayer response", e);
} catch (IOException e) {
throw new PlatformLayerClientException("Error communicating with PlatformLayer service", e);
}
}
Aggregations