2222import static org .junit .Assert .assertNotNull ;
2323import static org .junit .Assert .assertTrue ;
2424
25+ import javax .ws .rs .client .Client ;
26+ import javax .ws .rs .client .ClientBuilder ;
27+
2528import java .io .IOException ;
26- import java .lang .reflect .UndeclaredThrowableException ;
2729import java .net .HttpURLConnection ;
2830import java .net .URI ;
29- import java .net .URL ;
3031import java .util .List ;
3132
33+ import javax .ws .rs .core .GenericType ;
3234import javax .ws .rs .core .MediaType ;
35+ import javax .ws .rs .core .Response ;
3336
37+ import org .apache .hadoop .classification .VisibleForTesting ;
3438import org .apache .hadoop .conf .Configuration ;
3539import org .apache .hadoop .hbase .HBaseTestingUtility ;
3640import org .apache .hadoop .yarn .api .records .timelineservice .FlowActivityEntity ;
3741import org .apache .hadoop .yarn .conf .YarnConfiguration ;
3842import org .apache .hadoop .yarn .server .timelineservice .storage .DataGeneratorForTest ;
39- import org .apache .hadoop .yarn .webapp .YarnJacksonJaxbJsonProvider ;
43+ import org .glassfish .jersey .client .ClientConfig ;
44+ import org .glassfish .jersey .client .HttpUrlConnectorProvider ;
4045import org .junit .Assert ;
4146
42- import com .sun .jersey .api .client .Client ;
43- import com .sun .jersey .api .client .ClientResponse ;
44- import com .sun .jersey .api .client .ClientResponse .Status ;
45- import com .sun .jersey .api .client .GenericType ;
46- import com .sun .jersey .api .client .config .ClientConfig ;
47- import com .sun .jersey .api .client .config .DefaultClientConfig ;
48- import com .sun .jersey .client .urlconnection .HttpURLConnectionFactory ;
49- import com .sun .jersey .client .urlconnection .URLConnectionClientHandler ;
50-
5147/**
5248 * Test Base for TimelineReaderServer HBase tests.
5349 */
@@ -109,19 +105,17 @@ protected void addFilters(Configuration conf) {
109105 }
110106
111107 protected Client createClient () {
112- ClientConfig cfg = new DefaultClientConfig ();
113- cfg .getClasses ().add (YarnJacksonJaxbJsonProvider .class );
114- return new Client (
115- new URLConnectionClientHandler (new DummyURLConnectionFactory ()), cfg );
108+ final ClientConfig cc = new ClientConfig ();
109+ cc .connectorProvider (getHttpURLConnectionFactory ());
110+ return ClientBuilder .newClient (cc );
116111 }
117112
118- protected ClientResponse getResponse (Client client , URI uri )
113+ protected Response getResponse (Client client , URI uri )
119114 throws Exception {
120- ClientResponse resp =
121- client .resource (uri ).accept (MediaType .APPLICATION_JSON )
122- .type (MediaType .APPLICATION_JSON ).get (ClientResponse .class );
115+ Response resp =
116+ client .target (uri ).request (MediaType .APPLICATION_JSON ).get ();
123117 if (resp == null || resp .getStatusInfo ()
124- .getStatusCode () != ClientResponse . Status . OK . getStatusCode () ) {
118+ .getStatusCode () != HttpURLConnection . HTTP_OK ) {
125119 String msg = "" ;
126120 if (resp != null ) {
127121 msg = String .valueOf (resp .getStatusInfo ().getStatusCode ());
@@ -132,39 +126,38 @@ protected ClientResponse getResponse(Client client, URI uri)
132126 return resp ;
133127 }
134128
135- protected void verifyHttpResponse (Client client , URI uri , Status status ) {
136- ClientResponse resp =
137- client .resource (uri ).accept (MediaType .APPLICATION_JSON )
138- .type (MediaType .APPLICATION_JSON ).get (ClientResponse .class );
129+ protected void verifyHttpResponse (Client client , URI uri , Response .Status status ) {
130+ Response resp = client .target (uri ).request (MediaType .APPLICATION_JSON ).get ();
139131 assertNotNull (resp );
140132 assertTrue ("Response from server should have been " + status ,
141- resp .getStatusInfo ().getStatusCode () == status . getStatusCode () );
142- System .out .println ("Response is: " + resp .getEntity (String .class ));
133+ resp .getStatusInfo ().getStatusCode () == HttpURLConnection . HTTP_OK );
134+ System .out .println ("Response is: " + resp .readEntity (String .class ));
143135 }
144136
145137 protected List <FlowActivityEntity > verifyFlowEntites (Client client , URI uri ,
146138 int noOfEntities ) throws Exception {
147- ClientResponse resp = getResponse (client , uri );
139+ Response resp = getResponse (client , uri );
148140 List <FlowActivityEntity > entities =
149- resp .getEntity (new GenericType <List <FlowActivityEntity >>() {
141+ resp .readEntity (new GenericType <List <FlowActivityEntity >>() {
150142 });
151143 assertNotNull (entities );
152144 assertEquals (noOfEntities , entities .size ());
153145 return entities ;
154146 }
155147
156- protected static class DummyURLConnectionFactory
157- implements HttpURLConnectionFactory {
158-
159- @ Override
160- public HttpURLConnection getHttpURLConnection (final URL url )
161- throws IOException {
162- try {
163- return (HttpURLConnection ) url .openConnection ();
164- } catch (UndeclaredThrowableException e ) {
165- throw new IOException (e .getCause ());
166- }
167- }
148+ @ VisibleForTesting
149+ protected HttpUrlConnectorProvider getHttpURLConnectionFactory () {
150+ return new HttpUrlConnectorProvider ().connectionFactory (
151+ url -> {
152+ HttpURLConnection conn ;
153+ try {
154+ HttpURLConnection .setFollowRedirects (false );
155+ conn = (HttpURLConnection ) url .openConnection ();
156+ } catch (Exception e ) {
157+ throw new IOException (e );
158+ }
159+ return conn ;
160+ });
168161 }
169162
170163 protected static HBaseTestingUtility getHBaseTestingUtility () {
0 commit comments