]> git.basschouten.com Git - openhab-addons.git/blob
4547528f5a7e18614a6cf10464479eee6b52f74b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.ihc.internal.ws.services;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.openhab.binding.ihc.internal.ws.exeptions.IhcExecption;
19 import org.openhab.binding.ihc.internal.ws.http.IhcConnectionPool;
20 import org.openhab.binding.ihc.internal.ws.http.IhcHttpsClient;
21
22 /**
23  * Base class for all IHC / ELKO services.
24  *
25  *
26  * @author Pauli Anttila - Initial contribution
27  */
28 public abstract class IhcBaseService extends IhcHttpsClient {
29
30     // @formatter:off
31     protected static final String EMPTY_QUERY =
32               "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
33             + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
34             + " <soapenv:Body>\n"
35             + " </soapenv:Body>\n"
36             + "</soapenv:Envelope>";
37     // @formatter:on
38
39     private String url;
40     private int timeout;
41
42     public IhcBaseService(IhcConnectionPool ihcConnectionPool, int timeout, String host, String service) {
43         super(ihcConnectionPool);
44         this.timeout = timeout;
45         this.url = createUrl(host, service);
46     }
47
48     private String createUrl(String host, String service) {
49         return "https://" + host + "/ws/" + service;
50     }
51
52     protected String sendSoapQuery(String soapAction, String query) throws IhcExecption {
53         return sendSoapQuery(soapAction, query, timeout);
54     }
55
56     protected String sendSoapQuery(String soapAction, String query, int timeout) throws IhcExecption {
57         Map<String, String> reqProperties = null;
58         if (soapAction != null) {
59             reqProperties = new HashMap<>();
60             reqProperties.put("SOAPAction", soapAction);
61         }
62         return sendQuery(url, reqProperties, query, timeout);
63     }
64
65     protected int getTimeout() {
66         return timeout;
67     }
68 }