Source:
<code>public Response interceptDescribeFeatureType(MutableHttpServletRequest request, Response response) { LOG.debug("Intercepting WFS DescribeFeatureType response"); ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { if (response.getHeaders().get("content-type").get(0).toLowerCase(Locale.ROOT).contains("json")) { ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonObject = objectMapper.readTree(response.getBody()); String ns = jsonObject.get("targetPrefix").asText(); ArrayNode featureTypes = (ArrayNode) jsonObject.get("featureTypes"); List<Layer> allowedLayers = layerService.findAll(); for (int i = 0; i < featureTypes.size(); i++) { String typeName = ns + ":" + featureTypes.get(i).get("typeName").asText(); boolean match = false; for (Layer allowedLayer : allowedLayers) { if (allowedLayer.getSource() instanceof TileWmsLayerDataSource) { String names = ((TileWmsLayerDataSource) allowedLayer.getSource()).getLayerNames(); if (names.equalsIgnoreCase(typeName)) { match = true; } } } if (!match) { featureTypes.remove(i); } } final byte[] bytes = objectMapper.writeValueAsBytes(jsonObject); response.setBody(bytes); return response; } DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(response.getBody())); removeFeatureTypes(doc); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(new DOMSource(doc), new StreamResult(bout)); response.setBody(bout.toByteArray()); <START> } catch (NullPointerException | ParserConfigurationException | SAXException | IOException | XPathExpressionException | TransformerException e) { <END> LOG.warn("Problem when intercepting WFS GetCapabilities: {}", e.getMessage()); LOG.trace("Stack trace:", e); return null; } return response; }</code><technical_language>heart_eyes:</technical_language>

Target:
public Response interceptDescribeFeatureType(MutableHttpServletRequest request, Response response) { LOG.debug("Intercepting WFS DescribeFeatureType response"); ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { if (response.getHeaders().get("content-type").get(0).toLowerCase(Locale.ROOT).contains("json")) { ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonObject = objectMapper.readTree(response.getBody()); String ns = jsonObject.get("targetPrefix").asText(); ArrayNode featureTypes = (ArrayNode) jsonObject.get("featureTypes"); List<Layer> allowedLayers = layerService.findAll(); int size = featureTypes.size(); for (int i = 0; i < size; i++) { String typeName = ns + ":" + featureTypes.get(i).get("typeName").asText(); boolean match = false; for (Layer allowedLayer : allowedLayers) { if (allowedLayer.getSource() instanceof TileWmsLayerDataSource) { String names = ((TileWmsLayerDataSource) allowedLayer.getSource()).getLayerNames(); if (names.equalsIgnoreCase(typeName)) { match = true; break; } } } if (!match) { featureTypes.remove(i); } } final byte[] bytes = objectMapper.writeValueAsBytes(jsonObject); response.setBody(bytes); return response; } DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(response.getBody())); removeFeatureTypes(doc); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(new DOMSource(doc), new StreamResult(bout)); response.setBody(bout.toByteArray()); } catch (NullPointerException | ParserConfigurationException | SAXException | IOException | XPathExpressionException | TransformerException e) { LOG.warn("Problem when intercepting WFS GetCapabilities: {}", e.getMessage()); LOG.trace("Stack trace:", e); return null; } return response; }