/**
* {@inheritDoc}
*/
public void writeMessage(String theRawMessage) throws LLPException, IOException {
AbstractHl7OverHttpEncoder e;
if (myProtocol.getRole() == ServerRoleEnum.CLIENT) {
e = new Hl7OverHttpRequestEncoder();
if (myProtocol.getAuthorizationClientCallback() != null) {
e.setUsername(myProtocol.getAuthorizationClientCallback().provideUsername(myProtocol.getUriPath()));
e.setPassword(myProtocol.getAuthorizationClientCallback().providePassword(myProtocol.getUriPath()));
}
} else {
e = new Hl7OverHttpResponseEncoder();
}
if (myProtocol.getRole() == ServerRoleEnum.CLIENT) {
e.setSigner(myProtocol.getSigner());
}
e.setMessage(theRawMessage);
if (myCharsetForNextMessage != null) {
e.setCharset(myCharsetForNextMessage);
myCharsetForNextMessage = null;
} else if (getPreferredCharset() != null) {
e.setCharset(getPreferredCharset());
}
e.setPath(myProtocol.getUriPath());
DataOutputStream dos = new DataOutputStream(myOutputStream);
try {
e.encodeToOutputStream(dos);
} catch (EncodeException e1) {
throw new LLPException("Failed to encode message", e1);
}
dos.flush();