// Path: api/src/main/java/io/tracee/Tracee.java
// public final class Tracee {
// 
// 	private Tracee() {
// 
// 	}
// 
// 	/**
// 	 * Returns the TraceeBackend. There must be exactly one Tracee implementation on the classpath.
// 	 * <p/>
// 	 * A call to this method may initially block to lookup the implementation with a {@link java.util.ServiceLoader}.
// 	 * The call to this method from multiple threads with different class loader contexts may initially be slow
// 	 * because cache writes can overwrite each other in concurrent situations and some class loader contexts may have
// 	 * to be looked up multiple times. This allows the lookup mechanism to completely avoid synchronization.
// 	 * <p/>
// 	 * TODO: If you run a nested class loader environment (like a servlet container) and have the Tracee Api in a top
// 	 * level class loader and a Tracee Implementation in a child class loader, the child class loader may not be unloaded
// 	 * until a low memory situation occurs (since the SoftReference keeps the TraceeBackendProvider in memory).
// 	 * It could be a solution to change the SoftReference to WeakReference but let a TraceeBackend keep a strong
// 	 * reference to its TraceeBackendProvider.
// 	 */
// 	public static TraceeBackend getBackend() {
// 		return getBackend(new BackendProviderResolver());
// 	}
// 
// 	protected static TraceeBackend getBackend(final BackendProviderResolver resolver) {
// 		final Set<TraceeBackendProvider> backendProviders;
// 		try {
// 			backendProviders = resolver.getBackendProviders();
// 		} catch (RuntimeException e) {
// 			throw new TraceeException("Unable to load available backend providers", e);
// 		}
// 		if (backendProviders.isEmpty()) {
// 			final Set<TraceeBackendProvider> defaultProvider = resolver.getDefaultTraceeBackendProvider();
// 			if (defaultProvider.isEmpty()) {
// 				throw new TraceeException("Unable to find a TracEE backend provider. Make sure that you have " +
// 					"tracee-core (for slf4j) or any other backend implementation on the classpath.");
// 			}
// 			return defaultProvider.iterator().next().provideBackend();
// 		}
// 		if (backendProviders.size() > 1) {
// 			final List<Class<?>> providerClasses = new ArrayList<>(backendProviders.size());
// 			for (TraceeBackendProvider backendProvider : backendProviders) {
// 				providerClasses.add(backendProvider.getClass());
// 			}
// 			final String providerClassNames = Arrays.toString(providerClasses.toArray());
// 			throw new TraceeException("Multiple TracEE backend providers found. Don't know which one of the following to use: "
// 				+ providerClassNames);
// 		}
// 		return backendProviders.iterator().next().provideBackend();
// 	}
// }
// 
// Path: api/src/main/java/io/tracee/TraceeConstants.java
// public final class TraceeConstants {
// 
// 	// TPIC = TracEE propagated invocation context
// 	public static final String TPIC_HEADER = "TPIC";
// 
// 	public static final String SOAP_HEADER_NAMESPACE = "http://tracee.io/tpic/1.0";
// 
// 	public static final QName SOAP_HEADER_QNAME = new QName(SOAP_HEADER_NAMESPACE, TPIC_HEADER);
// 
// 	public static final String SESSION_ID_KEY = "TPIC.sessionId";
// 	public static final String INVOCATION_ID_KEY = "TPIC.invocationId";
// 
// 	private TraceeConstants() {
// 	}
// }


import io.tracee.Tracee;
import io.tracee.TraceeConstants;
import io.tracee.binding.springws.itest.testservice.JaxwsTestserviceEndpoint;
import io.tracee.testhelper.PortUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ws.client.core.WebServiceTemplate;
import javax.annotation.PostConstruct;
import javax.xml.ws.Endpoint;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.not;
package io.tracee.binding.springws.itest;




@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:jaxWsServer.xml")
public class SpringWsClientToJaxWsServerIT {

	public static final String ENDPOINT_URL = "http://127.0.0.1:" + PortUtil.randomTestPort() + "/jaxws/TestserviceEndpoint";
	private Endpoint endpoint;

	@Autowired
	private TraceeSpringWsClient wsClient;

	@Autowired
	private WebServiceTemplate webServiceTemplate;

	@Before
	public void before() {
		endpoint = Endpoint.publish(ENDPOINT_URL, new JaxwsTestserviceEndpoint());
	}

	@After
	public void after() {
		endpoint.stop();
	}

	@PostConstruct
	public void prepareTestClient() {
		webServiceTemplate.setDefaultUri(ENDPOINT_URL);
	}

	@Test
	public void callRemoteMethodWithoutInvocationId() throws Exception {
		Tracee.getBackend().remove(TraceeConstants.INVOCATION_ID_KEY);
		final String remoteInvocationId = wsClient.getCurrentTraceeContext();
// Path: api/src/main/java/io/tracee/Tracee.java
// public final class Tracee {
// 
// 	private Tracee() {
// 
// 	}
// 
// 	/**
// 	 * Returns the TraceeBackend. There must be exactly one Tracee implementation on the classpath.
// 	 * <p/>
// 	 * A call to this method may initially block to lookup the implementation with a {@link java.util.ServiceLoader}.
// 	 * The call to this method from multiple threads with different class loader contexts may initially be slow
// 	 * because cache writes can overwrite each other in concurrent situations and some class loader contexts may have
// 	 * to be looked up multiple times. This allows the lookup mechanism to completely avoid synchronization.
// 	 * <p/>
// 	 * TODO: If you run a nested class loader environment (like a servlet container) and have the Tracee Api in a top
// 	 * level class loader and a Tracee Implementation in a child class loader, the child class loader may not be unloaded
// 	 * until a low memory situation occurs (since the SoftReference keeps the TraceeBackendProvider in memory).
// 	 * It could be a solution to change the SoftReference to WeakReference but let a TraceeBackend keep a strong
// 	 * reference to its TraceeBackendProvider.
// 	 */
// 	public static TraceeBackend getBackend() {
// 		return getBackend(new BackendProviderResolver());
// 	}
// 
// 	protected static TraceeBackend getBackend(final BackendProviderResolver resolver) {
// 		final Set<TraceeBackendProvider> backendProviders;
// 		try {
// 			backendProviders = resolver.getBackendProviders();
// 		} catch (RuntimeException e) {
// 			throw new TraceeException("Unable to load available backend providers", e);
// 		}
// 		if (backendProviders.isEmpty()) {
// 			final Set<TraceeBackendProvider> defaultProvider = resolver.getDefaultTraceeBackendProvider();
// 			if (defaultProvider.isEmpty()) {
// 				throw new TraceeException("Unable to find a TracEE backend provider. Make sure that you have " +
// 					"tracee-core (for slf4j) or any other backend implementation on the classpath.");
// 			}
// 			return defaultProvider.iterator().next().provideBackend();
// 		}
// 		if (backendProviders.size() > 1) {
// 			final List<Class<?>> providerClasses = new ArrayList<>(backendProviders.size());
// 			for (TraceeBackendProvider backendProvider : backendProviders) {
// 				providerClasses.add(backendProvider.getClass());
// 			}
// 			final String providerClassNames = Arrays.toString(providerClasses.toArray());
// 			throw new TraceeException("Multiple TracEE backend providers found. Don't know which one of the following to use: "
// 				+ providerClassNames);
// 		}
// 		return backendProviders.iterator().next().provideBackend();
// 	}
// }
// 
// Path: api/src/main/java/io/tracee/TraceeConstants.java
// public final class TraceeConstants {
// 
// 	// TPIC = TracEE propagated invocation context
// 	public static final String TPIC_HEADER = "TPIC";
// 
// 	public static final String SOAP_HEADER_NAMESPACE = "http://tracee.io/tpic/1.0";
// 
// 	public static final QName SOAP_HEADER_QNAME = new QName(SOAP_HEADER_NAMESPACE, TPIC_HEADER);
// 
// 	public static final String SESSION_ID_KEY = "TPIC.sessionId";
// 	public static final String INVOCATION_ID_KEY = "TPIC.invocationId";
// 
// 	private TraceeConstants() {
// 	}
// }


// Path: binding/springws/src/test/java/io/tracee/binding/springws/itest/SpringWsClientToJaxWsServerIT.java
import io.tracee.Tracee;
import io.tracee.TraceeConstants;
import io.tracee.binding.springws.itest.testservice.JaxwsTestserviceEndpoint;
import io.tracee.testhelper.PortUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ws.client.core.WebServiceTemplate;
import javax.annotation.PostConstruct;
import javax.xml.ws.Endpoint;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.not;

package io.tracee.binding.springws.itest;




@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:jaxWsServer.xml")
public class SpringWsClientToJaxWsServerIT {

	public static final String ENDPOINT_URL = "http://127.0.0.1:" + PortUtil.randomTestPort() + "/jaxws/TestserviceEndpoint";
	private Endpoint endpoint;

	@Autowired
	private TraceeSpringWsClient wsClient;

	@Autowired
	private WebServiceTemplate webServiceTemplate;

	@Before
	public void before() {
		endpoint = Endpoint.publish(ENDPOINT_URL, new JaxwsTestserviceEndpoint());
	}

	@After
	public void after() {
		endpoint.stop();
	}

	@PostConstruct
	public void prepareTestClient() {
		webServiceTemplate.setDefaultUri(ENDPOINT_URL);
	}

	@Test
	public void callRemoteMethodWithoutInvocationId() throws Exception {
		Tracee.getBackend().remove(TraceeConstants.INVOCATION_ID_KEY);
		final String remoteInvocationId = wsClient.getCurrentTraceeContext();
		assertThat(remoteInvocationId, not(isEmptyOrNullString()));