use of org.teleal.cling.model.message.UpnpResponse in project openhab1-addons by openhab.
the class StreamClientImpl method createResponseHandler.
protected ResponseHandler<StreamResponseMessage> createResponseHandler() {
return new ResponseHandler<StreamResponseMessage>() {
@Override
public StreamResponseMessage handleResponse(final HttpResponse httpResponse) throws IOException {
StatusLine statusLine = httpResponse.getStatusLine();
log.fine("Received HTTP response: " + statusLine);
// Status
UpnpResponse responseOperation = new UpnpResponse(statusLine.getStatusCode(), statusLine.getReasonPhrase());
// Message
StreamResponseMessage responseMessage = new StreamResponseMessage(responseOperation);
// Headers
responseMessage.setHeaders(new UpnpHeaders(HeaderUtil.get(httpResponse)));
// Body
HttpEntity entity = httpResponse.getEntity();
if (entity == null || entity.getContentLength() == 0) {
return responseMessage;
}
if (responseMessage.isContentTypeMissingOrText()) {
log.fine("HTTP response message contains text entity");
responseMessage.setBody(UpnpMessage.BodyType.STRING, EntityUtils.toString(entity));
} else {
log.fine("HTTP response message contains binary entity");
responseMessage.setBody(UpnpMessage.BodyType.BYTES, EntityUtils.toByteArray(entity));
}
return responseMessage;
}
};
}
Aggregations