Skip to content

Instantly share code, notes, and snippets.

@dwp-joaomelo
Created August 15, 2017 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwp-joaomelo/80926c3ded0d17e1e94a72245ece2f79 to your computer and use it in GitHub Desktop.
Save dwp-joaomelo/80926c3ded0d17e1e94a72245ece2f79 to your computer and use it in GitHub Desktop.
import org.apache.cxf.BusFactory;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduitFactory;
import org.junit.Test;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
public class HttpConduitTest {
@Test
public void httpConduit() throws Exception {
BusFactory.getThreadDefaultBus().setProperty(AsyncHTTPConduitFactory.USE_POLICY, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
String invalidService = "https://localhost:12341";
ExampleResource exampleResource = JAXRSClientFactory.create(invalidService, ExampleResource.class);
Thread thread = new Thread(() -> {
try {
exampleResource.get("some data");
} catch (Exception e) {
e.printStackTrace();
}
});
thread.start();
Thread.sleep(1000);
BusFactory.getThreadDefaultBus().shutdown(true);
thread.join();
}
@Path("/example")
public interface ExampleResource {
@POST
String get(String data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment