@Override public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { HttpHeaders headers = httpRequest.getHeaders(); headers.add(HttpHeaders.AUTHORIZATION, encodeCredentialsForBasicAuth(username, password)); return clientHttpRequestExecution.execute(httpRequest, bytes); }
public RestService(String url, String username, String password) { this.url = url; template = new RestTemplate(); List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(); if (username != null) { interceptors.add(new BasicAuthenticationInterceptor(username, password)); } interceptors.add(new LoggingInterceptor()); template.setRequestFactory( new InterceptingClientHttpRequestFactory(template.getRequestFactory(), interceptors)); prismContext = ProxyCreator.getProxy(PrismContext.class, () -> { try { PrismContextFactory factory = new MidPointPrismContextFactory() { @Override protected void registerExtensionSchemas(SchemaRegistryImpl schemaRegistry) throws SchemaException, FileNotFoundException { super.registerExtensionSchemas(schemaRegistry); RestService.this.registerExtensionSchemas(schemaRegistry); } }; return factory.createPrismContext(); } catch (SchemaException | FileNotFoundException ex) { throw new NinjaException("Couldn't load prism context", ex); } }); }