/** * Returns a String representing the encoding of the given message, if the encoding is * recognized. For example if the given message appears to be encoded using HL7 2.x XML rules * then "XML" would be returned. If the encoding is not recognized then null is returned. That * this method returns a specific encoding does not guarantee that the message is correctly * encoded (e.g. well formed XML) - just that it is not encoded using any other encoding than * the one returned. Returns null if the encoding is not recognized. */ public String getEncoding(String message) { String encoding = primaryParser.getEncoding(message); return (encoding == null ? secondaryParser.getEncoding(message) : encoding); }
/** * Returns a String representing the encoding of the given message, if the encoding is * recognized. For example if the given message appears to be encoded using HL7 2.x XML rules * then "XML" would be returned. If the encoding is not recognized then null is returned. That * this method returns a specific encoding does not guarantee that the message is correctly * encoded (e.g. well formed XML) - just that it is not encoded using any other encoding than * the one returned. Returns null if the encoding is not recognized. */ public String getEncoding(String message) { String encoding = primaryParser.getEncoding(message); return (encoding == null ? secondaryParser.getEncoding(message) : encoding); }
private String handleProcessMessageException(String incomingMessageString, Map<String, Object> theMetadata, Message incomingMessageObject, Exception e) throws HL7Exception { String outgoingMessageString; Segment inHeader = incomingMessageObject != null ? (Segment) incomingMessageObject.get("MSH") : null; outgoingMessageString = logAndMakeErrorMessage(e, inHeader, myParser, myParser.getEncoding(incomingMessageString)); if (outgoingMessageString != null && myExceptionHandler != null) { outgoingMessageString = myExceptionHandler.processException(incomingMessageString, theMetadata, outgoingMessageString, e); } return outgoingMessageString; }
private String handleProcessMessageException(String incomingMessageString, Map<String, Object> theMetadata, Message incomingMessageObject, Exception e) throws HL7Exception { String outgoingMessageString; Segment inHeader = incomingMessageObject != null ? (Segment) incomingMessageObject.get("MSH") : null; outgoingMessageString = logAndMakeErrorMessage(e, inHeader, myParser, myParser.getEncoding(incomingMessageString)); if (outgoingMessageString != null && myExceptionHandler != null) { outgoingMessageString = myExceptionHandler.processException(incomingMessageString, theMetadata, outgoingMessageString, e); } return outgoingMessageString; }
log.debug("Exception parsing incoming message", e); try { outgoingMessageString = logAndMakeErrorMessage(e, myParser.getCriticalResponseData(incomingMessageString), myParser, myParser.getEncoding(incomingMessageString)); } catch (HL7Exception e2) { log.error("Exception occurred while logging parse failure", e2); outgoingMessageString = myParser.encode(response, myParser.getEncoding(incomingMessageString));
log.debug("Exception parsing incoming message", e); try { outgoingMessageString = logAndMakeErrorMessage(e, myParser.getCriticalResponseData(incomingMessageString), myParser, myParser.getEncoding(incomingMessageString)); } catch (HL7Exception e2) { log.error("Exception occurred while logging parse failure", e2); outgoingMessageString = myParser.encode(response, myParser.getEncoding(incomingMessageString));
/** * Parse a message using a specific model package instead of the default, using * {@link ModelClassFactory#getMessageClassInASpecificPackage(String, String, boolean, String)} * . * * <b>WARNING: This method is only implemented in some parser implementations</b>. Currently it * will only work with the PipeParser parser implementation. Use with caution. * * @param message message string * @param packageName name of the package of the models * @return parsed message * @throws HL7Exception if an error occurred while parsing */ public Message parseForSpecificPackage(String message, String packageName) throws HL7Exception { String encoding = getEncoding(message); if (!supportsEncoding(encoding)) { throw new EncodingNotSupportedException("Can't parse message beginning " + message.substring(0, Math.min(message.length(), 50))); } String version = getVersion(message); assertVersionExists(version); assertMessageValidates(message, encoding, version); Message result = doParseForSpecificPackage(message, version, packageName); assertMessageValidates(result); result.setParser(this); return result; }
/** * Parse a message using a specific model package instead of the default, using * {@link ModelClassFactory#getMessageClassInASpecificPackage(String, String, boolean, String)} * . * * <b>WARNING: This method is only implemented in some parser implementations</b>. Currently it * will only work with the PipeParser parser implementation. Use with caution. * * @param message message string * @param packageName name of the package of the models * @return parsed message * @throws HL7Exception if an error occurred while parsing */ public Message parseForSpecificPackage(String message, String packageName) throws HL7Exception { String encoding = getEncoding(message); if (!supportsEncoding(encoding)) { throw new EncodingNotSupportedException("Can't parse message beginning " + message.substring(0, Math.min(message.length(), 50))); } String version = getVersion(message); assertVersionExists(version); assertMessageValidates(message, encoding, version); Message result = doParseForSpecificPackage(message, version, packageName); assertMessageValidates(result); result.setParser(this); return result; }
String encoding = getEncoding(message); if (!supportsEncoding(encoding)) { String startOfMessage = null;
String encoding = getEncoding(message); if (!supportsEncoding(encoding)) { String startOfMessage = null;
private static Transportable makeAcceptAck(Transportable theMessage, String theAckCode, ErrorCode theErrorCode, String theDescription) throws HL7Exception { Segment header = ourParser.getCriticalResponseData(theMessage.getMessage()); Message dummy = header.getMessage(); // MSH header refers to dummy, but not the other way round! DeepCopy.copy(header, (Segment)dummy.get("MSH")); try { HL7Exception hl7e = new HL7Exception(theDescription, theErrorCode); AcknowledgmentCode code = theAckCode == null ? AcknowledgmentCode.CR : AcknowledgmentCode.valueOf(theAckCode); Message out = dummy.generateACK(code, hl7e); String originalEncoding = ourParser.getEncoding(theMessage.getMessage()); String ackText = ourParser.encode(out, originalEncoding); return new TransportableImpl(ackText); } catch (IOException e) { throw new HL7Exception(e); } }
private static Transportable makeAcceptAck(Transportable theMessage, String theAckCode, ErrorCode theErrorCode, String theDescription) throws HL7Exception { Segment header = ourParser.getCriticalResponseData(theMessage.getMessage()); Message dummy = header.getMessage(); // MSH header refers to dummy, but not the other way round! DeepCopy.copy(header, (Segment)dummy.get("MSH")); try { HL7Exception hl7e = new HL7Exception(theDescription, theErrorCode); AcknowledgmentCode code = theAckCode == null ? AcknowledgmentCode.CR : AcknowledgmentCode.valueOf(theAckCode); Message out = dummy.generateACK(code, hl7e); String originalEncoding = ourParser.getEncoding(theMessage.getMessage()); String ackText = ourParser.encode(out, originalEncoding); return new TransportableImpl(ackText); } catch (IOException e) { throw new HL7Exception(e); } }