Я использую фильтры для получения названий брендов, но некоторые из них в названиях брендов есть пробелы. Когда я отправляю запрос в реальном времени, он возвращает ошибку 500.
java.net.URISyntaxException: недопустимый символ в запросе по индексу 236:
http://gateway-service/deal-solution-se ... and=Huawei
Спа
Он должен был позаботиться об этом «Huawei Spa»
мой сервис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();
}
}
Если название моего бренда содержит пробелы, я хочу закодировать свой URL-адрес, чтобы заполнить пробелы.
Подробнее здесь: https://stackoverflow.com/questions/781 ... ted-issues