Add Komoot activity import with guided browser-based batch flow #25
2 changed files with 10 additions and 5 deletions
|
|
@ -320,14 +320,17 @@ public class KomootImportService {
|
||||||
|
|
||||||
for (URI candidateUri : candidateUris) {
|
for (URI candidateUri : candidateUris) {
|
||||||
try {
|
try {
|
||||||
ResponseEntity<byte[]> response = restTemplate.exchange(
|
byte[] body = restTemplate.execute(
|
||||||
candidateUri,
|
candidateUri,
|
||||||
HttpMethod.GET,
|
HttpMethod.GET,
|
||||||
httpEntity,
|
request -> request.getHeaders().putAll(httpEntity.getHeaders()),
|
||||||
byte[].class
|
response -> {
|
||||||
|
if (response.getBody() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response.getBody().readAllBytes();
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
byte[] body = response.getBody();
|
|
||||||
if (body == null || body.length == 0) {
|
if (body == null || body.length == 0) {
|
||||||
throw new IllegalStateException("Komoot returned an empty GPX response.");
|
throw new IllegalStateException("Komoot returned an empty GPX response.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,7 @@ class KomootImportServiceTest {
|
||||||
server.expect(once(), requestTo("https://www.komoot.com/api/v007/tours/2880957035.gpx"))
|
server.expect(once(), requestTo("https://www.komoot.com/api/v007/tours/2880957035.gpx"))
|
||||||
.andExpect(method(HttpMethod.GET))
|
.andExpect(method(HttpMethod.GET))
|
||||||
.andExpect(header(HttpHeaders.AUTHORIZATION, authHeader))
|
.andExpect(header(HttpHeaders.AUTHORIZATION, authHeader))
|
||||||
|
.andExpect(header(HttpHeaders.ACCEPT, "application/gpx+xml, application/xml, text/xml"))
|
||||||
.andRespond(withSuccess("""
|
.andRespond(withSuccess("""
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<gpx version="1.1" creator="komoot">
|
<gpx version="1.1" creator="komoot">
|
||||||
|
|
@ -359,6 +360,7 @@ class KomootImportServiceTest {
|
||||||
server.expect(once(), requestTo("https://www.komoot.com/api/v007/tours/2880957036.gpx"))
|
server.expect(once(), requestTo("https://www.komoot.com/api/v007/tours/2880957036.gpx"))
|
||||||
.andExpect(method(HttpMethod.GET))
|
.andExpect(method(HttpMethod.GET))
|
||||||
.andExpect(header(HttpHeaders.AUTHORIZATION, authHeader))
|
.andExpect(header(HttpHeaders.AUTHORIZATION, authHeader))
|
||||||
|
.andExpect(header(HttpHeaders.ACCEPT, "application/gpx+xml, application/xml, text/xml"))
|
||||||
.andRespond(withSuccess("""
|
.andRespond(withSuccess("""
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<gpx version="1.1" creator="komoot">
|
<gpx version="1.1" creator="komoot">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue