65
65
*
66
66
*/
67
67
public class ChannelFinderClientImpl implements ChannelFinderClient {
68
- private final WebResource service ;
68
+ private final WebResource cfAuthenticatedResource ;
69
+ private final WebResource cfResource ;
70
+
69
71
private final ExecutorService executor ;
70
72
71
73
private static final String resourceChannels = "resources/channels" ;
@@ -268,12 +270,14 @@ public boolean verify(String hostname, SSLSession session) {
268
270
ChannelFinderClientImpl (URI uri , ClientConfig config , HTTPBasicAuthFilter httpBasicAuthFilter ,
269
271
ExecutorService executor ) {
270
272
Client client = Client .create (config );
273
+ cfResource = client .resource (uri .toString ());
271
274
if (httpBasicAuthFilter != null ) {
272
275
client .addFilter (httpBasicAuthFilter );
273
276
}
277
+ // TODO add a preference to add logging
274
278
// client.addFilter(new RawLoggingFilter(Logger.getLogger(RawLoggingFilter.class.getName())));
275
279
client .setFollowRedirects (true );
276
- service = client .resource (uri .toString ());
280
+ cfAuthenticatedResource = client .resource (uri .toString ());
277
281
this .executor = executor ;
278
282
}
279
283
@@ -292,7 +296,7 @@ public Collection<String> call() throws Exception {
292
296
List <XmlProperty > xmlproperties = new ArrayList <XmlProperty >();
293
297
try {
294
298
xmlproperties = mapper .readValue (
295
- service .path (resourceProperties ).accept (MediaType .APPLICATION_JSON ).get (String .class ),
299
+ cfResource .path (resourceProperties ).accept (MediaType .APPLICATION_JSON ).get (String .class ),
296
300
new TypeReference <List <XmlProperty >>() {
297
301
});
298
302
} catch (JsonParseException e ) {
@@ -320,7 +324,7 @@ public List<Property> call() throws Exception {
320
324
List <XmlProperty > xmlproperties = new ArrayList <>();
321
325
try {
322
326
xmlproperties = mapper .readValue (
323
- service .path (resourceProperties ).accept (MediaType .APPLICATION_JSON ).get (String .class ),
327
+ cfResource .path (resourceProperties ).accept (MediaType .APPLICATION_JSON ).get (String .class ),
324
328
new TypeReference <List <XmlProperty >>() {
325
329
});
326
330
} catch (Exception e ) {
@@ -347,7 +351,7 @@ public Collection<String> call() {
347
351
List <XmlTag > xmltags = new ArrayList <XmlTag >();
348
352
try {
349
353
xmltags = mapper .readValue (
350
- service .path (resourceTags )
354
+ cfResource .path (resourceTags )
351
355
.accept (MediaType .APPLICATION_JSON )
352
356
.get (String .class ), new TypeReference <List <XmlTag >>() { });
353
357
} catch ( JsonParseException | JsonMappingException e ) {
@@ -414,7 +418,7 @@ public Channel call() throws UniformInterfaceException
414
418
{
415
419
mapper .configure (DeserializationFeature .ACCEPT_SINGLE_VALUE_AS_ARRAY , true );
416
420
try {
417
- return new Channel (mapper .readValue (service .path (resourceChannels ).path (channelName )
421
+ return new Channel (mapper .readValue (cfResource .path (resourceChannels ).path (channelName )
418
422
.get (ClientResponse .class ).getEntityInputStream (), XmlChannel .class ));
419
423
} catch (JsonParseException | JsonMappingException e ) {
420
424
log .log (Level .WARNING , "Failed to process the list of channels" , e );
@@ -451,7 +455,7 @@ public SetChannel(XmlChannel xmlChannel) {
451
455
public void run () {
452
456
ObjectMapper mapper = new ObjectMapper ();
453
457
try {
454
- service .path (resourceChannels ).path (this .pxmlChannel .getName ()).type (MediaType .APPLICATION_JSON )
458
+ cfAuthenticatedResource .path (resourceChannels ).path (this .pxmlChannel .getName ()).type (MediaType .APPLICATION_JSON )
455
459
.put (mapper .writeValueAsString (this .pxmlChannel ));
456
460
} catch (JsonProcessingException e ) {
457
461
log .log (Level .WARNING , "Failed to process the list of channel " , e );
@@ -486,7 +490,7 @@ public void run() {
486
490
mapper .writeValue (out , this .pxmlchannels );
487
491
final byte [] data = ((ByteArrayOutputStream ) out ).toByteArray ();
488
492
String test = new String (data );
489
- service .path (resourceChannels ).type (MediaType .APPLICATION_JSON ).put (test );
493
+ cfAuthenticatedResource .path (resourceChannels ).type (MediaType .APPLICATION_JSON ).put (test );
490
494
} catch (JsonParseException | JsonMappingException e ) {
491
495
log .log (Level .WARNING , "Failed to process the list of channels " , e );
492
496
} catch ( IOException e ) {
@@ -574,7 +578,7 @@ public SetTag(XmlTag xmlTag) {
574
578
public void run () {
575
579
ObjectMapper mapper = new ObjectMapper ();
576
580
try {
577
- service .path (resourceTags ).path (this .pxmlTag .getName ()).type (MediaType .APPLICATION_JSON )
581
+ cfAuthenticatedResource .path (resourceTags ).path (this .pxmlTag .getName ()).type (MediaType .APPLICATION_JSON )
578
582
.accept (MediaType .APPLICATION_JSON ).put (mapper .writeValueAsString (this .pxmlTag ));
579
583
} catch (JsonProcessingException e ) {
580
584
log .log (Level .WARNING , "Failed to process the list of tags " , e );
@@ -671,7 +675,7 @@ private class SetProperty implements Runnable {
671
675
@ Override
672
676
public void run () {
673
677
try {
674
- service .path (resourceProperties ).path (this .pxmlProperty .getName ()).type (MediaType .APPLICATION_JSON )
678
+ cfAuthenticatedResource .path (resourceProperties ).path (this .pxmlProperty .getName ()).type (MediaType .APPLICATION_JSON )
675
679
.accept (MediaType .APPLICATION_JSON ).put (mapper .writeValueAsString (this .pxmlProperty ));
676
680
} catch (JsonProcessingException e ) {
677
681
log .log (Level .WARNING , "Failed to process the list of properties " , e );
@@ -701,7 +705,7 @@ private class UpdateChannel implements Runnable {
701
705
@ Override
702
706
public void run () {
703
707
try {
704
- service .path (resourceChannels )
708
+ cfAuthenticatedResource .path (resourceChannels )
705
709
.path (this .channel .getName ())
706
710
.type (MediaType .APPLICATION_JSON )
707
711
.post (mapper .writeValueAsString (this .channel ));
@@ -770,7 +774,7 @@ private class UpdateTag implements Runnable {
770
774
@ Override
771
775
public void run () {
772
776
try {
773
- service .path (resourceTags ).path (this .pxmlTag .getName ()).type (MediaType .APPLICATION_JSON )
777
+ cfAuthenticatedResource .path (resourceTags ).path (this .pxmlTag .getName ()).type (MediaType .APPLICATION_JSON )
774
778
.post (mapper .writeValueAsString (this .pxmlTag ));
775
779
} catch (UniformInterfaceException e ) {
776
780
throw new ChannelFinderException (e );
@@ -814,7 +818,7 @@ private class UpdateChannelProperty implements Runnable {
814
818
@ Override
815
819
public void run () {
816
820
try {
817
- service .path (resourceProperties )
821
+ cfAuthenticatedResource .path (resourceProperties )
818
822
.path (this .pxmlProperty .getName ())
819
823
.type (MediaType .APPLICATION_JSON )
820
824
.put (mapper .writeValueAsString (this .pxmlProperty ));
@@ -885,7 +889,7 @@ private class UpdateProperty implements Runnable {
885
889
@ Override
886
890
public void run () {
887
891
try {
888
- service .path (resourceProperties ).path (this .pxmlProperty .getName ()).type (MediaType .APPLICATION_JSON )
892
+ cfAuthenticatedResource .path (resourceProperties ).path (this .pxmlProperty .getName ()).type (MediaType .APPLICATION_JSON )
889
893
.accept (MediaType .APPLICATION_JSON ).post (mapper .writeValueAsString (this .pxmlProperty ));
890
894
} catch (UniformInterfaceException e ) {
891
895
throw new ChannelFinderException (e );
@@ -1035,7 +1039,7 @@ public Collection<Channel> call() throws Exception {
1035
1039
List <XmlChannel > xmlchannels = new ArrayList <XmlChannel >();
1036
1040
long start = System .currentTimeMillis ();
1037
1041
try {
1038
- xmlchannels = mapper .readValue (service .path (resourceChannels ).queryParams (this .map )
1042
+ xmlchannels = mapper .readValue (cfResource .path (resourceChannels ).queryParams (this .map )
1039
1043
.accept (MediaType .APPLICATION_JSON ).get (String .class ), new TypeReference <List <XmlChannel >>() {
1040
1044
});
1041
1045
} catch (Exception e ) {
@@ -1142,7 +1146,7 @@ private class DeleteElement implements Runnable
1142
1146
1143
1147
@ Override
1144
1148
public void run () {
1145
- service .path (elementType ).path (elementName ).delete ();
1149
+ cfAuthenticatedResource .path (elementType ).path (elementName ).delete ();
1146
1150
}
1147
1151
1148
1152
}
@@ -1237,7 +1241,7 @@ private class DeleteElementfromChannel implements Runnable
1237
1241
@ Override
1238
1242
public void run ()
1239
1243
{
1240
- service .path (this .elementType ).path (this .elementName ).path (this .channelName )
1244
+ cfAuthenticatedResource .path (this .elementType ).path (this .elementName ).path (this .channelName )
1241
1245
.accept (MediaType .APPLICATION_JSON ).delete ();
1242
1246
}
1243
1247
@@ -1300,7 +1304,7 @@ public Collection<Channel> getAllChannels()
1300
1304
List <XmlChannel > xmlchannels = new ArrayList <XmlChannel >();
1301
1305
try {
1302
1306
xmlchannels = mapper .readValue (
1303
- service .path (resourceChannels ).accept (MediaType .APPLICATION_JSON ).get (String .class ),
1307
+ cfAuthenticatedResource .path (resourceChannels ).accept (MediaType .APPLICATION_JSON ).get (String .class ),
1304
1308
new TypeReference <List <XmlChannel >>() {
1305
1309
});
1306
1310
} catch (JsonParseException | JsonMappingException e ) {
0 commit comments