11package net .trajano .ms .sample ;
22
3+ import java .util .concurrent .ExecutionException ;
4+ import java .util .concurrent .Future ;
5+
36import javax .annotation .security .PermitAll ;
47import javax .ws .rs .GET ;
58import javax .ws .rs .Path ;
69import javax .ws .rs .Produces ;
10+ import javax .ws .rs .client .Client ;
11+ import javax .ws .rs .container .AsyncResponse ;
12+ import javax .ws .rs .container .Suspended ;
713import javax .ws .rs .core .Context ;
814import javax .ws .rs .core .MediaType ;
15+ import javax .ws .rs .core .Response ;
916
1017import org .springframework .beans .factory .annotation .Autowired ;
1118
1219import io .swagger .annotations .Api ;
20+ import io .swagger .annotations .ApiOperation ;
1321import io .vertx .ext .web .RoutingContext ;
1422
1523@ Api
@@ -18,12 +26,35 @@ public class Hello {
1826
1927 private int count ;
2028
29+ @ Context
30+ private Client jaxrsClient ;
31+
2132 @ Autowired
2233 SomeRequestScope req ;
2334
2435 @ Autowired
2536 ISomeAppScope scope ;
2637
38+ @ ApiOperation (value = "displays openid config of google async" ,
39+ hidden = true )
40+ @ GET
41+ @ Produces (MediaType .APPLICATION_JSON )
42+ @ Path ("/async" )
43+ @ PermitAll
44+ public void async (@ Suspended final AsyncResponse asyncResponse ) throws InterruptedException ,
45+ ExecutionException {
46+
47+ final Future <Response > futureResponseFromClient = jaxrsClient .target ("https://accounts.google.com/.well-known/openid-configuration" ).request ().header (javax .ws .rs .core .HttpHeaders .USER_AGENT , "curl/7.55.1" ).async ().get ();
48+
49+ final Response responseFromClient = futureResponseFromClient .get ();
50+ try {
51+ final String object = responseFromClient .readEntity (String .class );
52+ asyncResponse .resume (object );
53+ } finally {
54+ responseFromClient .close ();
55+ }
56+ }
57+
2758 @ GET
2859 @ Path ("/cough" )
2960 public String cough () {
0 commit comments