Example usage for javax.xml.transform Result toString

List of usage examples for javax.xml.transform Result toString

Introduction

In this page you can find the example usage for javax.xml.transform Result toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.openmrs.module.casereport.HealthInfoExchangeListener.java

/**
 * @see ApplicationListener#onApplicationEvent(ApplicationEvent)
 *///from  w  w  w  . java 2s . c o  m
@Override
public void onApplicationEvent(CaseReportSubmittedEvent event) {

    try {
        CaseReport caseReport = (CaseReport) event.getSource();
        CaseReportForm form = new ObjectMapper().readValue(caseReport.getReportForm(), CaseReportForm.class);
        form.setReportUuid(caseReport.getUuid());
        form.setReportDate(caseReport.getDateCreated());
        ProvideAndRegisterDocumentSetRequestType docRequest = new ProvideAndRegisterDocGenerator(form)
                .generate();
        JAXBElement rootElement = objectFactory.createProvideAndRegisterDocumentSetRequest(docRequest);

        if (log.isDebugEnabled()) {
            log.debug("Saving Case report document to the file system.....");
        }

        File docFile = DocumentUtil.getSubmittedCaseReportFile(caseReport);
        Result out = new StringResult();
        webServiceTemplate.getMarshaller().marshal(rootElement, out);
        FileUtils.writeStringToFile(docFile, out.toString(), DocumentConstants.ENCODING);

        if (log.isDebugEnabled()) {
            log.debug("Case report document successfully saved to the file system");
        }

        if (log.isDebugEnabled()) {
            log.debug("Sending Case report document.....");
        }

        String url = Context.getAdministrationService().getGlobalProperty(DocumentConstants.GP_OPENHIM_URL);
        Object response = webServiceTemplate.marshalSendAndReceive(url, rootElement, messageCallback);
        String lf = SystemUtils.LINE_SEPARATOR;
        RegistryResponseType regResp = ((JAXBElement<RegistryResponseType>) response).getValue();
        if (!XDSConstants.XDS_B_STATUS_SUCCESS.equals(regResp.getStatus())) {
            StringBuffer sb = new StringBuffer();
            if (regResp.getRegistryErrorList() != null
                    && regResp.getRegistryErrorList().getRegistryError() != null) {
                for (RegistryError re : regResp.getRegistryErrorList().getRegistryError()) {
                    sb.append("Severity: "
                            + (StringUtils.isNotBlank(re.getSeverity())
                                    ? re.getSeverity().substring(re.getSeverity().lastIndexOf(":") + 1)
                                    : "?")
                            + ", Code: " + (StringUtils.isNotBlank(re.getErrorCode()) ? re.getErrorCode() : "?")
                            + ", Message: "
                            + (StringUtils.isNotBlank(re.getCodeContext()) ? re.getCodeContext() : "?") + lf);
                }
            }

            throw new APIException(sb.toString());
        }

        if (log.isDebugEnabled()) {
            log.debug("Case report document successfully sent");
        }
    } catch (Exception e) {

        log.warn("An error occurred while submitting a case report document to the HIE");

        APIException rethrow;
        if (e instanceof APIException) {
            rethrow = (APIException) e;
        } else {
            rethrow = new APIException(e);
        }

        throw rethrow;
    }
}

From source file:de.extra.client.plugins.outputplugin.ws.WsOutputPlugin.java

private ExtraOutputPluginRuntimeException extractSoapFaultClientException(
        final SoapFaultClientException soapFaultClientException) {
    try {/*from w w w  .j  a v  a  2  s.c o m*/
        final StringBuilder message = new StringBuilder();
        final Result resultFault = new StringResult();
        TransformerFactory.newInstance().newTransformer()
                .transform(soapFaultClientException.getSoapFault().getSource(), resultFault);
        final String resultFaultAsString = resultFault.toString();
        message.append(resultFaultAsString);
        // operation_logger.error("SoapFault Detail:\n {}",
        // resultFaultAsString);
        return new ExtraOutputPluginRuntimeException(ExceptionCode.EXTRA_TRANSFER_EXCEPTION,
                message.toString());
    } catch (final Exception e) {
        operation_logger.error("Schwerwiegender Fehler beim Extrahieren des SOAP-Fehlers!", e.getMessage());
        throw new ExtraCoreRuntimeException(ExceptionCode.UNEXPECTED_INTERNAL_EXCEPTION,
                "Schwerwiegender Fehler beim Extrahieren des SOAP-Fehlers!" + e.getMessage());
    }
}