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.dwdunwetter.internal.data;
15 import java.io.IOException;
16 import java.net.URLEncoder;
17 import java.nio.charset.StandardCharsets;
19 import org.apache.commons.lang.StringUtils;
20 import org.openhab.core.io.net.http.HttpUtil;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Provides the access to the API Endpoint
27 * @author Martin Koehler - Initial contribution
29 public class DwdWarningDataAccess {
31 private final Logger logger = LoggerFactory.getLogger(DwdWarningDataAccess.class);
34 private static final String DWD_URL = "https://maps.dwd.de/geoserver/dwd/ows?service=WFS&version=2.0.0&request=GetFeature&typeName=dwd:Warnungen_Gemeinden";
37 * Returns the raw Data from the Endpoint.
38 * In case of errors or empty cellId value, returns an {@link StringUtils#EMPTY Empty String}.
40 * @param cellId The warnCell-Id for which the warnings should be returned
41 * @return The raw data received or an empty string.
43 public String getDataFromEndpoint(String cellId) {
45 if (StringUtils.isBlank(cellId)) {
46 logger.warn("No cellId provided");
47 return StringUtils.EMPTY;
50 StringBuilder stringBuilder = new StringBuilder();
51 stringBuilder.append(DWD_URL);
52 stringBuilder.append("&CQL_FILTER=");
54 .append(URLEncoder.encode("WARNCELLID LIKE '" + cellId + "'", StandardCharsets.UTF_8.toString()));
55 logger.debug("Refreshing Data for cell {}", cellId);
56 String rawData = HttpUtil.executeUrl("GET", stringBuilder.toString(), 5000);
57 logger.trace("Raw request: {}", stringBuilder);
58 logger.trace("Raw response: {}", rawData);
61 } catch (IOException e) {
62 logger.warn("Communication error occurred while getting data: {}", e.getMessage());
63 logger.debug("Communication error trace", e);
66 return StringUtils.EMPTY;