public void close() throws IOException {
myInputStream.close();
}
public String getMessage() throws LLPException, IOException {
AbstractHl7OverHttpDecoder decoder;
if (myProtocol.getRole() == ServerRoleEnum.CLIENT) {
decoder = new Hl7OverHttpResponseDecoder();
} else {
Hl7OverHttpRequestDecoder requestDecoder = new Hl7OverHttpRequestDecoder();
requestDecoder.setAuthorizationCallback(myProtocol.getAuthorizationServerCallback());
decoder = requestDecoder;
decoder.setSigner(myProtocol.getSigner());
}
try {
decoder.readHeadersAndContentsFromInputStreamAndDecode(myInputStream);
} catch (DecodeException e) {
if (myProtocol.getRole() == ServerRoleEnum.CLIENT) {
throw new LLPException("Failed to process response", e);
} else {
ourLog.info("Failed to read contents", e);
HTTPUtils.write400BadRequest(myWriter.getOutputStream(), e.getMessage());
myInputStream.close();
myWriter.getOutputStream().close();
throw new LLPException("Failed to read message", e);
}
} catch (NoMessageReceivedException e) {
return null;
} catch (SignatureVerificationException e) {
throw new LLPException("Failed to verify message signature", e);
}
if (myProtocol.getRole() == ServerRoleEnum.SERVER) {
Charset charset = decoder.getCharset();
myWriter.setCharsetForNextMessage(charset);
IAuthorizationServerCallback authorizationCallback = myProtocol.getAuthorizationServerCallback();
if (authorizationCallback != null) {
boolean auth = authorizationCallback.authorize(decoder.getPath(), decoder.getUsername(), decoder.getPassword());
if (!auth) {
HTTPUtils.write401Unauthorized(myWriter.getOutputStream());
throw new LLPException("Authorization at URI[" + decoder.getPath() + "] failed for user[" + decoder.getUsername() + "]");
}
}
}
return decoder.getMessage();
}