Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dwdunwetter] should handle properly response messages #14691

Closed
UrsusS opened this issue Mar 27, 2023 · 2 comments · Fixed by #15405
Closed

[dwdunwetter] should handle properly response messages #14691

UrsusS opened this issue Mar 27, 2023 · 2 comments · Fixed by #15405
Assignees
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@UrsusS
Copy link

UrsusS commented Mar 27, 2023

The binding should handle properly the non-XML response messages.
In this case: "This service is not available due to technical problems!" The warning message "Exception occurred while parsing the XML response: Unexpected character 'T' (code 84) in prolog; expected '<' at [row,col {unknown-source}]: [1,1]" is not really helpful.

2023-03-27 07:33:07.918 [DEBUG] [er.internal.dto.DwdWarningDataAccess] - Refreshing Data for cell 809xxxxxx
2023-03-27 07:33:07.995 [TRACE] [er.internal.dto.DwdWarningDataAccess] - Raw request: https://maps.dwd.de/geoserver/dwd/ows?service=WFS&version=2.0.0&request=GetFeature&typeName=dwd:Warnungen_Gemeinden&CQL_FILTER=WARNCELLID+LIKE+%27809xxxxxx%27
2023-03-27 07:33:07.995 [TRACE] [er.internal.dto.DwdWarningDataAccess] - Raw response: This service is not available due to technical problems!
2023-03-27 07:33:07.996 [WARN ] [nwetter.internal.dto.DwdWarningsData] - Exception occurred while parsing the XML response: Unexpected character 'T' (code 84) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
2023-03-27 07:33:07.997 [DEBUG] [nwetter.internal.dto.DwdWarningsData] - Exception trace
com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'T' (code 84) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
	at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:666) ~[?:?]
	at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2148) ~[?:?]
	at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1180) ~[?:?]
	at com.ctc.wstx.evt.WstxEventReader.nextEvent(WstxEventReader.java:283) ~[?:?]
	at org.openhab.binding.dwdunwetter.internal.dto.DwdWarningsData.refresh(DwdWarningsData.java:127) ~[?:?]
	at org.openhab.binding.dwdunwetter.internal.handler.DwdUnwetterHandler.refresh(DwdUnwetterHandler.java:96) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
2023-03-27 07:33:08.001 [DEBUG] [.internal.handler.DwdUnwetterHandler] - Failed to retrieve new data from the server.

This behavior exists since a long time. Currently observed with OH 3.4.1.

@UrsusS UrsusS added the bug An unexpected problem or unintended behavior of an add-on label Mar 27, 2023
@lsiepel
Copy link
Contributor

lsiepel commented Jul 30, 2023

The method responsible for the data access is not very smart. It just calls an url and returns its body:

public String getDataFromEndpoint(String cellId) {
try {
if (cellId == null || cellId.isBlank()) {
logger.warn("No cellId provided");
return "";
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(DWD_URL);
stringBuilder.append("&CQL_FILTER=");
stringBuilder.append(URLEncoder.encode("WARNCELLID LIKE '" + cellId + "'", StandardCharsets.UTF_8));
logger.debug("Refreshing Data for cell {}", cellId);
String rawData = HttpUtil.executeUrl("GET", stringBuilder.toString(), 5000);
logger.trace("Raw request: {}", stringBuilder);
logger.trace("Raw response: {}", rawData);
return rawData;
} catch (IOException e) {
logger.warn("Communication error occurred while getting data: {}", e.getMessage());
logger.debug("Communication error trace", e);
}
return "";
}

I could not find any documentation regarding this API and errors. It could have been nice if we could react to the http response code. But at this moment the only thing i can think of is performing a check to see if the body is (valid) xml and if not, raise an IOException. Maybe @limdul79 as codeowner can give some advise?

@lsiepel lsiepel self-assigned this Jul 30, 2023
lsiepel added a commit to lsiepel/openhab-addons that referenced this issue Aug 6, 2023
Signed-off-by: lsiepel <leosiepel@gmail.com>
@lsiepel
Copy link
Contributor

lsiepel commented Aug 6, 2023

Made a fix. Test jar 4.x is here: https://1drv.ms/u/s!AnMcxmvEeupwjrMmX76PHq61-JUHFQ?e=K0E0TR

Please let me know your test results.

lolodomo pushed a commit that referenced this issue Sep 23, 2023
* Fix #14691
* Add country tag

---------

Signed-off-by: lsiepel <leosiepel@gmail.com>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Pshatsillo pushed a commit to Pshatsillo/openhab-addons that referenced this issue Sep 29, 2023
* Fix openhab#14691
* Add country tag

---------

Signed-off-by: lsiepel <leosiepel@gmail.com>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
pat-git023 pushed a commit to pat-git023/openhab-addons that referenced this issue Oct 13, 2023
* Fix openhab#14691
* Add country tag

---------

Signed-off-by: lsiepel <leosiepel@gmail.com>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
querdenker2k pushed a commit to querdenker2k/openhab-addons that referenced this issue Oct 21, 2023
* Fix openhab#14691
* Add country tag

---------

Signed-off-by: lsiepel <leosiepel@gmail.com>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
querdenker2k pushed a commit to querdenker2k/openhab-addons that referenced this issue Oct 29, 2023
* Fix openhab#14691
* Add country tag

---------

Signed-off-by: lsiepel <leosiepel@gmail.com>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: querdenker2k <querdenker2k@gmx.de>
austvik pushed a commit to austvik/openhab-addons that referenced this issue Mar 27, 2024
* Fix openhab#14691
* Add country tag

---------

Signed-off-by: lsiepel <leosiepel@gmail.com>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants