/**
 * Copyright 2016 Smoke Turner, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.smoketurner.dropwizard.zipkin.client;

import java.util.Objects;
import javax.annotation.Nonnull;
import javax.ws.rs.client.Client;
import com.github.kristofa.brave.Brave;
import com.github.kristofa.brave.http.DefaultSpanNameProvider;
import com.github.kristofa.brave.http.ServiceNameProvider;
import com.github.kristofa.brave.http.SpanNameProvider;
import com.github.kristofa.brave.http.StringServiceNameProvider;
import com.github.kristofa.brave.jaxrs2.BraveClientRequestFilter;
import com.github.kristofa.brave.jaxrs2.BraveClientResponseFilter;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.setup.Environment;

public class ZipkinClientBuilder {
    private final Environment environment;
    private final Brave brave;

    /**
     * Constructor
     *
     * @param environment
     *            Environment
     */
    public ZipkinClientBuilder(@Nonnull final Environment environment,
            @Nonnull final Brave brave) {
        this.environment = Objects.requireNonNull(environment);
        this.brave = Objects.requireNonNull(brave);
    }

    /**
     * Build a new Jersey Client that is instrumented for Zipkin
     * 
     * @param configuration
     *            Configuration to use for the client
     * @return new Jersey Client
     */
    public Client build(
            @Nonnull final ZipkinClientConfiguration configuration) {
        final Client client = new JerseyClientBuilder(environment)
                .using(configuration).build(configuration.getServiceName());

        final ServiceNameProvider serviceNameProvider = new StringServiceNameProvider(
                configuration.getServiceName());
        final SpanNameProvider spanNameProvider = new DefaultSpanNameProvider();

        // Register the request filter for outgoing client requests
        client.register(new BraveClientRequestFilter(serviceNameProvider,
                spanNameProvider, brave.clientRequestInterceptor()));

        // Register the response filter for incoming client requests
        client.register(new BraveClientResponseFilter(serviceNameProvider,
                spanNameProvider, brave.clientResponseInterceptor()));

        return client;
    }
}

@@ -2125,24 +2125,447 @@
 iceName());%0A
+        return build(configuration, client);%0A    %7D%0A%0A    /**%0A     * Instrument an existing Jersey client%0A     * %0A     * @param configuration%0A     *            Configuration to use for the client%0A     * @param client%0A     *            Jersey client%0A     * @return an instrumented Jersey client%0A     */%0A    public Client build(@Nonnull final ZipkinClientConfiguration configuration,%0A            @Nonnull final Client client) %7B
 %0A        fin

Add a method for instrumenting an existing Jersey client