У меня проблемы с кодировщиком URL-адресов, он работает локально и на сцене, но не работает вживую.
Я использую фильтры для получения названий брендов, но в некоторых из этих названий есть пробелы. Когда я отправляю запрос в реальном времени, он возвращает ошибку 500.
java.net.URISyntaxException: недопустимый символ в запросе по индексу 236: http://gateway-service/deal-solution -service/api/deals?categories=false&phonesAndSim=false<eAndSim=false&tabletsAndLaptops=false&connectivity=false&priceMin=0&priceMax=50000&duration36=false&duration24=false&brand=Huawei Spa
он должен был позаботиться об этом "Huawei" Спа»
мой сервисImpl
Код: Выделить всё
@Override
public Collection getDistinctBrands(Filter1 productFilter) {
List distinctBrands = new ArrayList();
if (productFilter != null && productFilter.getBrand() != null && !productFilter.getBrand().isEmpty()) {
String encodedBrand = URLEncoder.encode(productFilter.getBrand(), StandardCharsets.UTF_8);
distinctBrands.addAll(Arrays.asList(encodedBrand.split("[^a-zA-Z0-9\\-_']+")));
} else {
distinctBrands = dealRepository.findDistinctBrands();
}
return distinctBrands;
}
Код: Выделить всё
@Override
public ResponseEntity getDistinctBrands(Filter1 filter) {
Collection distinctBrands = dealService.getDistinctBrands(filter);
if (!distinctBrands.isEmpty()) {
List decodedBrands = new ArrayList();
for (String brand : distinctBrands) {
decodedBrands.add(URLDecoder.decode(brand, StandardCharsets.UTF_8));
}
return ResponseEntity.ok(decodedBrands);
} else {
return ResponseEntity.notFound().build();
}
}
if my brand name contain spaces I want to encode my URL to fill in the spaces.
Источник: https://stackoverflow.com/questions/781 ... ted-issues