Search in sources :

Example 1 with DefaultXMLParser

use of ca.uhn.hl7v2.parser.DefaultXMLParser in project carbon-mediation by wso2.

the class HL7StoreAdminService method sendMessage.

public boolean sendMessage(String msg, String storeName, String proxyName) {
    OMElement message = null;
    Message hl7Message = null;
    String hl7MessageStr = null;
    String xmlMessage = null;
    String messageControlerID = null;
    boolean validationPassed = true;
    msg = msg.replaceAll("\n", "\r\n");
    try {
        PipeParser parser = new PipeParser();
        if (!isTrueProxyParameter(storeName, proxyName, HL7Constants.HL7_VALIDATE_MESSAGE)) {
            parser.setValidationContext(new NoValidation());
        }
        hl7Message = new PipeParser().parse(msg);
        hl7MessageStr = hl7Message.encode();
        xmlMessage = new DefaultXMLParser().encode(hl7Message);
        message = HL7Utils.generateHL7MessageElement(xmlMessage);
    } catch (HL7Exception e) {
        if (isTrueProxyParameter(storeName, proxyName, HL7Constants.HL7_BUILD_RAW_MESSAGE)) {
            validationPassed = false;
            xmlMessage = "<rawMessage>" + StringEscapeUtils.escapeXml(hl7MessageStr) + "</rawMessage>";
            try {
                message = HL7Utils.generateHL7MessageElement(xmlMessage);
            } catch (XMLStreamException e2) {
                handleError("Could not build XML from message. " + e.getMessage());
                return false;
            }
        } else {
            handleError("Could not build XML from message. " + e.getMessage());
            return false;
        }
    } catch (XMLStreamException e) {
        handleError("Could not build XML from message. " + e.getMessage());
        return false;
    }
    try {
        Terser terser = new Terser(hl7Message);
        messageControlerID = terser.get("/MSH-10");
        if (messageControlerID == null || messageControlerID.length() == 0) {
            handleError("MSH segment missing required field: Control ID (MSH-10)");
            return false;
        }
    } catch (HL7Exception e) {
        handleError("MSH segment missing required field: Control ID (MSH-10)");
        return false;
    }
    JPAStore store = (JPAStore) getMessageStoreImpl(storeName);
    SynapseEnvironment synapseEnvironment = store.getSynapseEnvironment();
    if (proxyName == null || proxyName.equals("")) {
        handleError("Proxy service name not specified");
    }
    // Prepare axis2 message context
    org.apache.axis2.context.MessageContext axis2MsgCtx = new org.apache.axis2.context.MessageContext();
    HL7TransportOutInfo outinfo = new HL7TransportOutInfo();
    outinfo.setMessageControllerID(messageControlerID);
    axis2MsgCtx.setProperty(Constants.OUT_TRANSPORT_INFO, outinfo);
    ConfigurationContext configurationContext = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext();
    axis2MsgCtx.setConfigurationContext(configurationContext);
    axis2MsgCtx.setIncomingTransportName(Constants.TRANSPORT_LOCAL);
    axis2MsgCtx.setServerSide(true);
    axis2MsgCtx.setProperty(HL7Constants.HL7_MESSAGE_OBJECT, hl7Message);
    axis2MsgCtx.setProperty(HL7Constants.HL7_VALIDATION_PASSED, validationPassed);
    axis2MsgCtx.setProperty(HL7Constants.HL7_PASS_THROUGH_INVALID_MESSAGES, isTrueProxyParameter(storeName, proxyName, HL7Constants.HL7_PASS_THROUGH_INVALID_MESSAGES));
    // there's no transport out when message is injected to proxy via HL7 Store UI
    TransportOutDescription dummyTransportOut = new TransportOutDescription("Dummy Transport Out");
    dummyTransportOut.setSender(new DummyTransportSender());
    axis2MsgCtx.setTransportOut(dummyTransportOut);
    try {
        AxisService axisService = configurationContext.getAxisConfiguration().getService(proxyName);
        if (axisService == null) {
            handleError("Proxy Service: " + proxyName + " not found");
        }
        axis2MsgCtx.setAxisService(axisService);
    } catch (AxisFault axisFault) {
        handleError("Error occurred while attempting to find the Proxy Service");
        return false;
    }
    SOAPEnvelope envelope = new SOAP11Factory().createSOAPEnvelope();
    try {
        PayloadHelper.setXMLPayload(envelope, message.cloneOMElement());
        axis2MsgCtx.setEnvelope(envelope);
    } catch (AxisFault axisFault) {
        handleError("Error in setting the message payload : " + message);
        return false;
    }
    try {
        if (log.isDebugEnabled()) {
            log.debug("injecting message to proxy service : " + proxyName);
        }
        AxisEngine.receive(axis2MsgCtx);
    } catch (AxisFault axisFault) {
        handleError("Error occurred while invoking proxy service : " + proxyName);
        return false;
    }
    return true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) PersistentHL7Message(org.wso2.carbon.business.messaging.hl7.store.entity.PersistentHL7Message) Message(ca.uhn.hl7v2.model.Message) TransferableHL7Message(org.wso2.carbon.business.messaging.hl7.store.entity.TransferableHL7Message) DefaultXMLParser(ca.uhn.hl7v2.parser.DefaultXMLParser) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) AxisService(org.apache.axis2.description.AxisService) HL7TransportOutInfo(org.wso2.carbon.business.messaging.hl7.transport.HL7TransportOutInfo) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) JPAStore(org.wso2.carbon.business.messaging.hl7.store.jpa.JPAStore) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SerializableMessageContext(org.wso2.carbon.business.messaging.hl7.store.util.SerializableMessageContext) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) PipeParser(ca.uhn.hl7v2.parser.PipeParser) Terser(ca.uhn.hl7v2.util.Terser) XMLStreamException(javax.xml.stream.XMLStreamException) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) HL7Exception(ca.uhn.hl7v2.HL7Exception) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation)

Example 2 with DefaultXMLParser

use of ca.uhn.hl7v2.parser.DefaultXMLParser in project carbon-mediation by wso2.

the class HL7MessageBuilder method serializeHL7toXML.

private String serializeHL7toXML(Message message) throws AxisFault {
    Parser xmlParser = new DefaultXMLParser();
    xmlParser.setValidationContext(new NoValidation());
    try {
        return xmlParser.encode(message);
    } catch (HL7Exception e) {
        throw new AxisFault("Error on converting to HL7 XML: " + e.getMessage(), e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) DefaultXMLParser(ca.uhn.hl7v2.parser.DefaultXMLParser) HL7Exception(ca.uhn.hl7v2.HL7Exception) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation) Parser(ca.uhn.hl7v2.parser.Parser) DefaultXMLParser(ca.uhn.hl7v2.parser.DefaultXMLParser)

Example 3 with DefaultXMLParser

use of ca.uhn.hl7v2.parser.DefaultXMLParser in project carbon-mediation by wso2.

the class HL7MessageProcessor method createEnvelope.

private SOAPEnvelope createEnvelope(MessageContext msgCtx, Message message) throws HL7Exception, XMLStreamException {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope envelope = fac.getDefaultEnvelope();
    Parser xmlParser = new DefaultXMLParser();
    String xmlDoc = "";
    try {
        xmlDoc = xmlParser.encode(message);
        msgCtx.setProperty(HL7Constants.HL7_VALIDATION_PASSED, new Boolean(true));
    } catch (HL7Exception e) {
        msgCtx.setProperty(HL7Constants.HL7_VALIDATION_PASSED, new Boolean(false));
        if (this.endpoint.getProcessingContext().isBuildRawMessages()) {
            xmlDoc = "<rawMessage>" + StringEscapeUtils.escapeXml(message.encode()) + "</rawMessage>";
        } else {
            log.error("Could not encode HL7 message into XML: " + e.getMessage() + " " + "Set " + HL7Constants.HL7_BUILD_RAW_MESSAGE + " to build invalid HL7 messages containing raw HL7 message.");
        }
    }
    OMElement messageEl = HL7Utils.generateHL7MessageElement(xmlDoc);
    envelope.getBody().addChild(messageEl);
    return envelope;
}
Also used : DefaultXMLParser(ca.uhn.hl7v2.parser.DefaultXMLParser) HL7Exception(ca.uhn.hl7v2.HL7Exception) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) Parser(ca.uhn.hl7v2.parser.Parser) DefaultXMLParser(ca.uhn.hl7v2.parser.DefaultXMLParser)

Aggregations

HL7Exception (ca.uhn.hl7v2.HL7Exception)3 DefaultXMLParser (ca.uhn.hl7v2.parser.DefaultXMLParser)3 Parser (ca.uhn.hl7v2.parser.Parser)2 NoValidation (ca.uhn.hl7v2.validation.impl.NoValidation)2 OMElement (org.apache.axiom.om.OMElement)2 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)2 AxisFault (org.apache.axis2.AxisFault)2 Message (ca.uhn.hl7v2.model.Message)1 PipeParser (ca.uhn.hl7v2.parser.PipeParser)1 Terser (ca.uhn.hl7v2.util.Terser)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 SOAPFactory (org.apache.axiom.soap.SOAPFactory)1 SOAP11Factory (org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory)1 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)1 AxisService (org.apache.axis2.description.AxisService)1 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)1 MessageContext (org.apache.synapse.MessageContext)1 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)1