2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.wemo.internal.http;
15 import java.io.ByteArrayInputStream;
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.nio.charset.StandardCharsets;
19 import java.util.Properties;
21 import org.openhab.binding.wemo.internal.WemoBindingConstants;
22 import org.openhab.core.io.net.http.HttpUtil;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * The {@link WemoHttpCall} is responsible for calling a WeMo device to send commands or retrieve status updates.
29 * @author Hans-Jörg Merk - Initial contribution
32 public class WemoHttpCall {
34 private final Logger logger = LoggerFactory.getLogger(WemoHttpCall.class);
36 public String executeCall(String wemoURL, String soapHeader, String content) {
38 Properties wemoHeaders = new Properties();
39 wemoHeaders.setProperty("CONTENT-TYPE", WemoBindingConstants.HTTP_CALL_CONTENT_HEADER);
40 wemoHeaders.put("SOAPACTION", soapHeader);
42 InputStream wemoContent = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
44 String wemoCallResponse = HttpUtil.executeUrl("POST", wemoURL, wemoHeaders, wemoContent, null, 2000);
45 return wemoCallResponse;
46 } catch (IOException e) {
47 // throw new IllegalStateException("Could not call WeMo", e);
48 logger.debug("Could not make HTTP call to WeMo");