22
22
import static org .junit .Assert .assertNotNull ;
23
23
import static org .junit .Assert .assertTrue ;
24
24
25
+ import javax .ws .rs .client .Client ;
26
+ import javax .ws .rs .client .ClientBuilder ;
27
+
25
28
import java .io .IOException ;
26
- import java .lang .reflect .UndeclaredThrowableException ;
27
29
import java .net .HttpURLConnection ;
28
30
import java .net .URI ;
29
- import java .net .URL ;
30
31
import java .util .List ;
31
32
33
+ import javax .ws .rs .core .GenericType ;
32
34
import javax .ws .rs .core .MediaType ;
35
+ import javax .ws .rs .core .Response ;
33
36
37
+ import org .apache .hadoop .classification .VisibleForTesting ;
34
38
import org .apache .hadoop .conf .Configuration ;
35
39
import org .apache .hadoop .hbase .HBaseTestingUtility ;
36
40
import org .apache .hadoop .yarn .api .records .timelineservice .FlowActivityEntity ;
37
41
import org .apache .hadoop .yarn .conf .YarnConfiguration ;
38
42
import 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 ;
40
45
import org .junit .Assert ;
41
46
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
-
51
47
/**
52
48
* Test Base for TimelineReaderServer HBase tests.
53
49
*/
@@ -109,19 +105,17 @@ protected void addFilters(Configuration conf) {
109
105
}
110
106
111
107
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 );
116
111
}
117
112
118
- protected ClientResponse getResponse (Client client , URI uri )
113
+ protected Response getResponse (Client client , URI uri )
119
114
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 ();
123
117
if (resp == null || resp .getStatusInfo ()
124
- .getStatusCode () != ClientResponse . Status . OK . getStatusCode () ) {
118
+ .getStatusCode () != HttpURLConnection . HTTP_OK ) {
125
119
String msg = "" ;
126
120
if (resp != null ) {
127
121
msg = String .valueOf (resp .getStatusInfo ().getStatusCode ());
@@ -132,39 +126,38 @@ protected ClientResponse getResponse(Client client, URI uri)
132
126
return resp ;
133
127
}
134
128
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 ();
139
131
assertNotNull (resp );
140
132
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 ));
143
135
}
144
136
145
137
protected List <FlowActivityEntity > verifyFlowEntites (Client client , URI uri ,
146
138
int noOfEntities ) throws Exception {
147
- ClientResponse resp = getResponse (client , uri );
139
+ Response resp = getResponse (client , uri );
148
140
List <FlowActivityEntity > entities =
149
- resp .getEntity (new GenericType <List <FlowActivityEntity >>() {
141
+ resp .readEntity (new GenericType <List <FlowActivityEntity >>() {
150
142
});
151
143
assertNotNull (entities );
152
144
assertEquals (noOfEntities , entities .size ());
153
145
return entities ;
154
146
}
155
147
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
+ });
168
161
}
169
162
170
163
protected static HBaseTestingUtility getHBaseTestingUtility () {
0 commit comments