Created
August 15, 2017 23:03
-
-
Save dwp-joaomelo/80926c3ded0d17e1e94a72245ece2f79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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