Search in sources :

Example 6 with XStreamException

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;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) Document(org.w3c.dom.Document)

Example 7 with XStreamException

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("");
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) ResultsSettings(gdsc.smlm.ij.settings.ResultsSettings) TransformerException(javax.xml.transform.TransformerException) XStreamException(com.thoughtworks.xstream.XStreamException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 8 with XStreamException

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();
            }
        }
    }
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XStreamException(com.thoughtworks.xstream.XStreamException) IOException(java.io.IOException)

Example 9 with XStreamException

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);
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) XStreamException(com.thoughtworks.xstream.XStreamException) Message(org.apache.camel.Message) AbstractDTOBase(org.apache.camel.component.salesforce.api.dto.AbstractDTOBase) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 10 with XStreamException

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;
}
Also used : Response(javax.ws.rs.core.Response) XStreamException(com.thoughtworks.xstream.XStreamException) WebApplicationException(javax.ws.rs.WebApplicationException) ByteArrayInputStream(java.io.ByteArrayInputStream) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollection) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Aggregations

XStreamException (com.thoughtworks.xstream.XStreamException)24 IOException (java.io.IOException)13 XStream (com.thoughtworks.xstream.XStream)12 FileNotFoundException (java.io.FileNotFoundException)9 FileOutputStream (java.io.FileOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)3 InputStream (java.io.InputStream)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 Response (javax.ws.rs.core.Response)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)2 StringReader (java.io.StringReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)2 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)1