Search in sources :

Example 1 with StreamResponseMessage

use of org.teleal.cling.model.message.StreamResponseMessage 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;
        }
    };
}
Also used : StatusLine(org.apache.http.StatusLine) ResponseHandler(org.apache.http.client.ResponseHandler) UpnpResponse(org.teleal.cling.model.message.UpnpResponse) HttpEntity(org.apache.http.HttpEntity) UpnpHeaders(org.teleal.cling.model.message.UpnpHeaders) StreamResponseMessage(org.teleal.cling.model.message.StreamResponseMessage) HttpResponse(org.apache.http.HttpResponse)

Aggregations

HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1 ResponseHandler (org.apache.http.client.ResponseHandler)1 StreamResponseMessage (org.teleal.cling.model.message.StreamResponseMessage)1 UpnpHeaders (org.teleal.cling.model.message.UpnpHeaders)1 UpnpResponse (org.teleal.cling.model.message.UpnpResponse)1