use of org.opennms.netmgt.jasper.measurement.EmptyJRDataSource in project opennms by OpenNMS.
the class LocalMeasurementDataSourceWrapper method createDataSource.
@Override
public JRRewindableDataSource createDataSource(String query) throws JRException {
Objects.requireNonNull(query);
QueryRequest queryRequest = unmarshal(query);
Objects.requireNonNull(queryRequest);
// Enforce relaxed mode
queryRequest.setRelaxed(true);
try {
QueryResponse response = fetchService.query(queryRequest);
return new MeasurementDataSource(response);
} catch (ResourceNotFoundException rnfe) {
LOG.warn("A attribute or resource was not found", rnfe);
return new EmptyJRDataSource();
} catch (Exception e) {
LOG.error("An error occurred while fetching the measurement results", e);
throw new JRException(e);
}
}
use of org.opennms.netmgt.jasper.measurement.EmptyJRDataSource in project opennms by OpenNMS.
the class RemoteMeasurementDataSourceWrapper method createDataSource.
@Override
public JRRewindableDataSource createDataSource(String query) throws JRException {
try {
QueryRequest queryRequest = unmarshal(query);
// enforce relaxed mode
queryRequest.setRelaxed(true);
query = marshal(queryRequest);
Result result = connector.execute(useSsl, url, username, password, query);
// therefore do not allow redirection at all.
if (result.wasRedirection()) {
throw new IOException("Request was redirected. This is not supported.");
}
// if there is no data
if (404 == result.getResponseCode()) {
LOG.warn("Got a 404 (Not Found) response. This might be due to a wrong url or the resource does not exist. Requested URL was: '{}'", url);
return new EmptyJRDataSource();
}
// OK
if (result.wasSuccessful() && result.getInputStream() != null) {
return new MeasurementDataSource(result.getInputStream());
}
// Error
ByteArrayOutputStream errorMessageStream = new ByteArrayOutputStream();
if (result.getErrorStream() != null) {
ByteStreams.copy(result.getErrorStream(), errorMessageStream);
}
throw new JRException("Invalid request. Response was : " + result.getResponseCode() + " (" + result.getResponseMessage() + ")\n" + errorMessageStream.toString());
} catch (IOException ioException) {
throw new JRException(ioException);
}
}
Aggregations