private static GatewayFilter createFilter( InputStream stream, ServletContext servletContext ) throws ServletException { try { GatewayFilter filter = null; if( stream != null ) { try { GatewayDescriptor descriptor = GatewayDescriptorFactory.load("xml", new InputStreamReader(stream, StandardCharsets.UTF_8)); filter = GatewayFactory.create( descriptor ); } finally { stream.close(); } } GatewayConfig gatewayConfig = (GatewayConfig) servletContext.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE); if (gatewayConfig.isMetricsEnabled()) { GatewayServices gatewayServices = (GatewayServices) servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE); MetricsService metricsService = gatewayServices.getService(GatewayServices.METRICS_SERVICE); if (metricsService != null) { GatewayFilter instrumentedFilter = metricsService.getInstrumented(filter); if (instrumentedFilter != null) { filter = instrumentedFilter; } } } return filter; } catch( IOException e ) { throw new ServletException( e ); } catch( URISyntaxException e ) { throw new ServletException( e ); } }
private static GatewayFilter createFilter( InputStream stream, ServletContext servletContext ) throws ServletException { try { GatewayFilter filter = null; if( stream != null ) { try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)){ GatewayDescriptor descriptor = GatewayDescriptorFactory.load("xml", reader); filter = GatewayFactory.create( descriptor ); } finally { stream.close(); } } GatewayConfig gatewayConfig = (GatewayConfig) servletContext.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE); if (gatewayConfig.isMetricsEnabled()) { GatewayServices gatewayServices = (GatewayServices) servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE); MetricsService metricsService = gatewayServices.getService(GatewayServices.METRICS_SERVICE); if (metricsService != null) { GatewayFilter instrumentedFilter = metricsService.getInstrumented(filter); if (instrumentedFilter != null) { filter = instrumentedFilter; } } } return filter; } catch( IOException | URISyntaxException e ) { throw new ServletException( e ); } }