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;
}
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);
}
}
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;
}
Aggregations