]> git.basschouten.com Git - openhab-addons.git/blob
459906e57f95ffc30c03ca47068a96165c55aec3
[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               """
33             <?xml version="1.0" encoding="UTF-8"?>
34             <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
35              <soapenv:Body>
36              </soapenv:Body>
37             </soapenv:Envelope>\
38             """;
39     // @formatter:on
40
41     private String url;
42     private int timeout;
43
44     public IhcBaseService(IhcConnectionPool ihcConnectionPool, int timeout, String host, String service) {
45         super(ihcConnectionPool);
46         this.timeout = timeout;
47         this.url = createUrl(host, service);
48     }
49
50     private String createUrl(String host, String service) {
51         return "https://" + host + "/ws/" + service;
52     }
53
54     protected String sendSoapQuery(String soapAction, String query) throws IhcExecption {
55         return sendSoapQuery(soapAction, query, timeout);
56     }
57
58     protected String sendSoapQuery(String soapAction, String query, int timeout) throws IhcExecption {
59         Map<String, String> reqProperties = null;
60         if (soapAction != null) {
61             reqProperties = new HashMap<>();
62             reqProperties.put("SOAPAction", soapAction);
63         }
64         return sendQuery(url, reqProperties, query, timeout);
65     }
66
67     protected int getTimeout() {
68         return timeout;
69     }
70 }