import org.openhab.binding.roku.internal.dto.TvChannel;
import org.openhab.binding.roku.internal.dto.TvChannels;
import org.openhab.binding.roku.internal.dto.TvChannels.Channel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Methods for accessing the HTTP interface of the Roku
*/
@NonNullByDefault
public class RokuCommunicator {
- private final Logger logger = LoggerFactory.getLogger(RokuCommunicator.class);
private final HttpClient httpClient;
private final String urlKeyPress;
try {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_DEVICE_INFO;
if (ctx != null) {
+ final String response = getCommand(urlQryDevice);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
- XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY
- .createXMLStreamReader(new StringReader(getCommand(urlQryDevice)));
+ XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
DeviceInfo device = (DeviceInfo) unmarshaller.unmarshal(xsr);
if (device != null) {
return device;
try {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_ACTIVE_APP;
if (ctx != null) {
+ final String response = getCommand(urlQryActiveApp);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
- XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY
- .createXMLStreamReader(new StringReader(getCommand(urlQryActiveApp)));
+ XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
ActiveApp activeApp = (ActiveApp) unmarshaller.unmarshal(xsr);
if (activeApp != null) {
return activeApp;
try {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_APPS;
if (ctx != null) {
+ final String response = getCommand(urlQryApps);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
- XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY
- .createXMLStreamReader(new StringReader(getCommand(urlQryApps)));
+ XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
Apps appList = (Apps) unmarshaller.unmarshal(xsr);
if (appList != null) {
return appList.getApp();
try {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_PLAYER;
if (ctx != null) {
+ final String response = getCommand(urlQryPlayer);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
- XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY
- .createXMLStreamReader(new StringReader(getCommand(urlQryPlayer)));
+ XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
Player playerInfo = (Player) unmarshaller.unmarshal(xsr);
if (playerInfo != null) {
return playerInfo;
try {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_TVCHANNEL;
if (ctx != null) {
+ final String response = getCommand(urlQryActiveTvChannel);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
- XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY
- .createXMLStreamReader(new StringReader(getCommand(urlQryActiveTvChannel)));
+ XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
TvChannel tvChannelInfo = (TvChannel) unmarshaller.unmarshal(xsr);
if (tvChannelInfo != null) {
return tvChannelInfo;
try {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_TVCHANNELS;
if (ctx != null) {
+ final String response = getCommand(urlQryTvChannels);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
- XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY
- .createXMLStreamReader(new StringReader(getCommand(urlQryTvChannels)));
+ XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
TvChannels tvChannels = (TvChannels) unmarshaller.unmarshal(xsr);
if (tvChannels != null) {
return tvChannels.getChannel();
*
* @param url The url to send with the command embedded in the URI
* @return The response content of the http request
+ * @throws RokuHttpException
*/
- private String getCommand(String url) {
+ private String getCommand(String url) throws RokuHttpException {
try {
return httpClient.GET(url).getContentAsString();
- } catch (InterruptedException | TimeoutException | ExecutionException e) {
- logger.debug("Error executing player GET command, URL: {}, {} ", url, e.getMessage());
- return "";
+ } catch (TimeoutException | ExecutionException e) {
+ throw new RokuHttpException("Error executing GET command for URL: " + url, e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RokuHttpException("InterruptedException executing GET command for URL: " + url, e);
}
}
private void postCommand(String url) throws RokuHttpException {
try {
httpClient.POST(url).method(HttpMethod.POST).send();
- } catch (InterruptedException | TimeoutException | ExecutionException e) {
- throw new RokuHttpException("Error executing player POST command, URL: " + url + e.getMessage());
+ } catch (TimeoutException | ExecutionException e) {
+ throw new RokuHttpException("Error executing POST command, URL: " + url, e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RokuHttpException("InterruptedException executing POST command for URL: " + url, e);
}
}
}