Search in sources :

Example 1 with ExecutionContext

use of org.milyn.container.ExecutionContext in project coprhd-controller by CoprHD.

the class SmooksUtil method getParsedXMLJavaResult.

/**
 * This initializes the Smooks & parse the given inputStream and returns the javaResult.
 *
 * @param inputStream : Response in inputStream received from server.
 * @param configFile : Smooks configuration file.
 * @return
 */
public static JavaResult getParsedXMLJavaResult(InputStream inputStream, String configFile) {
    Smooks smooks = null;
    JavaResult javaResult = null;
    try {
        smooks = new Smooks(configFile);
        log.debug("initialized smooks");
        ExecutionContext executionContext = smooks.createExecutionContext();
        // The result of this transform is a set of Java objects...
        javaResult = new JavaResult();
        // Filter the input message to extract, using the execution context...
        smooks.filterSource(executionContext, new StreamSource(inputStream), javaResult);
        log.debug("Parsing completed");
    } catch (Exception e) {
        log.error("Unable to parse the response received from server.", e);
        throw HDSException.exceptions.unableToParseResponse();
    } finally {
        if (null != smooks) {
            smooks.close();
        }
    }
    return javaResult;
}
Also used : ExecutionContext(org.milyn.container.ExecutionContext) Smooks(org.milyn.Smooks) StreamSource(javax.xml.transform.stream.StreamSource) JavaResult(org.milyn.payload.JavaResult) HDSException(com.emc.storageos.hds.HDSException)

Aggregations

HDSException (com.emc.storageos.hds.HDSException)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Smooks (org.milyn.Smooks)1 ExecutionContext (org.milyn.container.ExecutionContext)1 JavaResult (org.milyn.payload.JavaResult)1