@@ -0,0 +1,2417 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.%0Apackage com.yahoo.vespa.jaxrs.client;%0A%0Aimport ai.vespa.util.http.VespaClientBuilderFactory;%0Aimport com.yahoo.vespa.applicationmodel.HostName;%0Aimport org.glassfish.jersey.client.ClientProperties;%0Aimport org.glassfish.jersey.client.HttpUrlConnectorProvider;%0Aimport org.glassfish.jersey.client.proxy.WebResourceFactory;%0A%0Aimport javax.ws.rs.client.Client;%0Aimport javax.ws.rs.client.ClientRequestFilter;%0Aimport javax.ws.rs.client.WebTarget;%0Aimport javax.ws.rs.core.HttpHeaders;%0Aimport javax.ws.rs.core.UriBuilder;%0Aimport java.util.List;%0A%0A/**%0A * Factory for creating Jersey based Vespa clients from a JAX-RS resource interface.%0A *%0A * @author bjorncs%0A */%0Apublic class VespaJerseyJaxRsClientFactory implements JaxRsClientFactory, AutoCloseable %7B%0A%0A    private final VespaClientBuilderFactory clientBuilder = new VespaClientBuilderFactory();%0A    // Client is a heavy-weight object with a finalizer so we create only one and re-use it%0A    private final Client client;%0A%0A    public VespaJerseyJaxRsClientFactory(String userAgent) %7B%0A        this.client = clientBuilder.newBuilder()%0A                .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true) // Allow empty PUT%0A                .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // Allow e.g. PATCH method.%0A                .property(ClientProperties.FOLLOW_REDIRECTS, true)%0A                .register((ClientRequestFilter) context -%3E context.getHeaders().put(HttpHeaders.USER_AGENT, List.of(userAgent)))%0A                .build();%0A    %7D%0A%0A    @Override%0A    public %3CT%3E T createClient(Params%3CT%3E params) %7B%0A        WebTarget target = client.target(params.uri());%0A        target.property(ClientProperties.CONNECT_TIMEOUT, (int) params.connectTimeout().toMillis());%0A        target.property(ClientProperties.READ_TIMEOUT, (int) params.readTimeout().toMillis());%0A        return WebResourceFactory.newResource(params.apiClass(), target);%0A    %7D%0A%0A    @Override%0A    public %3CT%3E T createClient(Class%3CT%3E apiClass, HostName hostName, int port, String pathPrefix, String scheme) %7B%0A        UriBuilder uriBuilder = UriBuilder.fromPath(pathPrefix).host(hostName.s()).port(port).scheme(scheme);%0A        return createClient(new Params%3C%3E(apiClass, uriBuilder.build()));%0A    %7D%0A%0A    @Override%0A    public void close() %7B%0A        clientBuilder.close();%0A    %7D%0A%7D%0A

Add VespaJerseyJaxRsClientFactory that is based on VespaClientBuilderFactory