use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.
the class BatchPeakFit method getDefaultSettingsXmlDocument.
private Document getDefaultSettingsXmlDocument() {
// Create an XML document of the default settings
Document doc = null;
try {
String configXml = xs.toXML(new FitEngineConfiguration(new FitConfiguration()));
doc = loadDocument(configXml);
} catch (XStreamException ex) {
ex.printStackTrace();
}
return doc;
}
use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.
the class BatchPeakFit method processImage.
private void processImage(BatchSettings settings, ImagePlus imp, ArrayList<String> xmlSettings) {
String imageFilename = imp.getOriginalFileInfo().directory + imp.getOriginalFileInfo().fileName;
String basename = getBaseName(imp.getOriginalFileInfo().fileName);
String format = settings.resultsDirectory + File.separatorChar + basename + ".%05d";
String statusSuffix = String.format(" / %d: %s", xmlSettings.size(), imp.getOriginalFileInfo().fileName);
for (int i = 0; i < xmlSettings.size(); i++) {
IJ.showStatus((i + 1) + statusSuffix);
// Create the configuration
FitEngineConfiguration fitConfig = null;
try {
fitConfig = (FitEngineConfiguration) xs.fromXML(xmlSettings.get(i));
} catch (XStreamException e) {
// Ignore
}
if (fitConfig == null)
continue;
// No need to skip settings that do not make sense as we will catch exceptions.
// This relies on the fit engine throw exceptions for invalid settings.
// Ensure the state is restored after XStream object reconstruction
fitConfig.getFitConfiguration().initialiseState();
String prefix = String.format(format, i);
// Save the settings
String settingsFilename = saveRunSettings(prefix, imageFilename, fitConfig);
// Run the fit engine
if (settings.runPeakFit) {
ResultsSettings resultsSettings = createResultsSettings(fitConfig, prefix);
try {
PeakFit peakFit = new PeakFit(fitConfig, resultsSettings, settings.getCalibration());
peakFit.setSilent(true);
peakFit.run(imp, false);
IJ.log(String.format("%s : %s : Size %d : Time = %s", imageFilename, settingsFilename, peakFit.getSize(), Utils.timeToString(peakFit.getTime())));
} catch (Exception e) {
// Ignore this as we assume this is from incorrect fit configuration
}
}
}
IJ.showStatus("");
}
use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.
the class PCPALMAnalysis method saveResult.
private void saveResult(XStream xs, CorrelationResult result) {
String outputFilename = String.format("%s/%s.%d.xml", resultsDirectory, (result.spatialDomain) ? "Spatial" : "Frequency", result.id);
FileOutputStream fs = null;
try {
fs = new FileOutputStream(outputFilename);
xs.toXML(result, fs);
} catch (XStreamException ex) {
//ex.printStackTrace();
IJ.log("Failed to save correlation result to file: " + outputFilename);
} catch (Exception e) {
IJ.log("Failed to save correlation result to file: " + outputFilename);
} finally {
if (fs != null) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of com.thoughtworks.xstream.XStreamException in project camel by apache.
the class XmlRestProcessor method getRequestStream.
protected InputStream getRequestStream(Exchange exchange) throws SalesforceException {
try {
// get request stream from In message
Message in = exchange.getIn();
InputStream request = in.getBody(InputStream.class);
if (request == null) {
AbstractDTOBase dto = in.getBody(AbstractDTOBase.class);
if (dto != null) {
// marshall the DTO
request = getRequestStream(dto);
} else {
// if all else fails, get body as String
final String body = in.getBody(String.class);
if (null == body) {
String msg = "Unsupported request message body " + (in.getBody() == null ? null : in.getBody().getClass());
throw new SalesforceException(msg, null);
} else {
request = new ByteArrayInputStream(body.getBytes(StringUtil.__UTF8));
}
}
}
return request;
} catch (XStreamException e) {
String msg = "Error marshaling request: " + e.getMessage();
throw new SalesforceException(msg, e);
} catch (UnsupportedEncodingException e) {
String msg = "Error marshaling request: " + e.getMessage();
throw new SalesforceException(msg, e);
}
}
use of com.thoughtworks.xstream.XStreamException in project ddf by codice.
the class FeatureCollectionMessageBodyReaderWfs10 method readFrom.
@Override
public WfsFeatureCollection readFrom(Class<WfsFeatureCollection> clazz, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream inStream) throws IOException, WebApplicationException {
// Save original input stream for any exception message that might need to be
// created
String originalInputStream = IOUtils.toString(inStream, StandardCharsets.UTF_8.name());
// Re-create the input stream (since it has already been read for potential
// exception message creation)
inStream = new ByteArrayInputStream(originalInputStream.getBytes(StandardCharsets.UTF_8.name()));
WfsFeatureCollection featureCollection = null;
try {
featureCollection = (WfsFeatureCollection) xstream.fromXML(inStream);
} catch (XStreamException e) {
// If a ServiceExceptionReport is sent from the remote WFS site it will be sent with an
// JAX-RS "OK" status, hence the ErrorResponse exception mapper will not fire.
// Instead the ServiceExceptionReport will come here and be treated like a GetFeature
// response, resulting in an XStreamException since ExceptionReport cannot be
// unmarshalled. So this catch clause is responsible for catching that XStream
// exception and creating a JAX-RS response containing the original stream
// (with the ExceptionReport) and rethrowing it as a WebApplicationException,
// which CXF will wrap as a ClientException that the WfsSource catches, converts
// to a WfsException, and logs.
LOGGER.debug("Exception unmarshalling", e);
ByteArrayInputStream bis = new ByteArrayInputStream(originalInputStream.getBytes(StandardCharsets.UTF_8));
ResponseBuilder responseBuilder = Response.ok(bis);
responseBuilder.type("text/xml");
Response response = responseBuilder.build();
throw new WebApplicationException(e, response);
} finally {
IOUtils.closeQuietly(inStream);
}
return featureCollection;
}
Aggregations