Skip to content

Commit eecd680

Browse files
committed
Add a seperate client for doing search without http auth header
1 parent dae8d5d commit eecd680

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

app/channel/channelfinder/src/main/java/org/phoebus/channelfinder/ChannelFinderClientImpl.java

+22-18
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@
6565
*
6666
*/
6767
public class ChannelFinderClientImpl implements ChannelFinderClient {
68-
private final WebResource service;
68+
private final WebResource cfAuthenticatedResource;
69+
private final WebResource cfResource;
70+
6971
private final ExecutorService executor;
7072

7173
private static final String resourceChannels = "resources/channels";
@@ -268,12 +270,14 @@ public boolean verify(String hostname, SSLSession session) {
268270
ChannelFinderClientImpl(URI uri, ClientConfig config, HTTPBasicAuthFilter httpBasicAuthFilter,
269271
ExecutorService executor) {
270272
Client client = Client.create(config);
273+
cfResource = client.resource(uri.toString());
271274
if (httpBasicAuthFilter != null) {
272275
client.addFilter(httpBasicAuthFilter);
273276
}
277+
// TODO add a preference to add logging
274278
// client.addFilter(new RawLoggingFilter(Logger.getLogger(RawLoggingFilter.class.getName())));
275279
client.setFollowRedirects(true);
276-
service = client.resource(uri.toString());
280+
cfAuthenticatedResource = client.resource(uri.toString());
277281
this.executor = executor;
278282
}
279283

@@ -292,7 +296,7 @@ public Collection<String> call() throws Exception {
292296
List<XmlProperty> xmlproperties = new ArrayList<XmlProperty>();
293297
try {
294298
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),
296300
new TypeReference<List<XmlProperty>>() {
297301
});
298302
} catch (JsonParseException e) {
@@ -320,7 +324,7 @@ public List<Property> call() throws Exception {
320324
List<XmlProperty> xmlproperties = new ArrayList<>();
321325
try {
322326
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),
324328
new TypeReference<List<XmlProperty>>() {
325329
});
326330
} catch (Exception e) {
@@ -347,7 +351,7 @@ public Collection<String> call() {
347351
List<XmlTag> xmltags = new ArrayList<XmlTag>();
348352
try {
349353
xmltags = mapper.readValue(
350-
service.path(resourceTags)
354+
cfResource.path(resourceTags)
351355
.accept(MediaType.APPLICATION_JSON)
352356
.get(String.class), new TypeReference<List<XmlTag>>() { });
353357
} catch ( JsonParseException | JsonMappingException e) {
@@ -414,7 +418,7 @@ public Channel call() throws UniformInterfaceException
414418
{
415419
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
416420
try {
417-
return new Channel(mapper.readValue(service.path(resourceChannels).path(channelName)
421+
return new Channel(mapper.readValue(cfResource.path(resourceChannels).path(channelName)
418422
.get(ClientResponse.class).getEntityInputStream(), XmlChannel.class));
419423
} catch (JsonParseException | JsonMappingException e) {
420424
log.log(Level.WARNING, "Failed to process the list of channels", e);
@@ -451,7 +455,7 @@ public SetChannel(XmlChannel xmlChannel) {
451455
public void run() {
452456
ObjectMapper mapper = new ObjectMapper();
453457
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)
455459
.put(mapper.writeValueAsString(this.pxmlChannel));
456460
} catch (JsonProcessingException e) {
457461
log.log(Level.WARNING, "Failed to process the list of channel ", e);
@@ -486,7 +490,7 @@ public void run() {
486490
mapper.writeValue(out, this.pxmlchannels);
487491
final byte[] data = ((ByteArrayOutputStream) out).toByteArray();
488492
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);
490494
} catch (JsonParseException | JsonMappingException e) {
491495
log.log(Level.WARNING, "Failed to process the list of channels ", e);
492496
} catch ( IOException e) {
@@ -574,7 +578,7 @@ public SetTag(XmlTag xmlTag) {
574578
public void run() {
575579
ObjectMapper mapper = new ObjectMapper();
576580
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)
578582
.accept(MediaType.APPLICATION_JSON).put(mapper.writeValueAsString(this.pxmlTag));
579583
} catch (JsonProcessingException e) {
580584
log.log(Level.WARNING, "Failed to process the list of tags ", e);
@@ -671,7 +675,7 @@ private class SetProperty implements Runnable {
671675
@Override
672676
public void run() {
673677
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)
675679
.accept(MediaType.APPLICATION_JSON).put(mapper.writeValueAsString(this.pxmlProperty));
676680
} catch (JsonProcessingException e) {
677681
log.log(Level.WARNING, "Failed to process the list of properties ", e);
@@ -701,7 +705,7 @@ private class UpdateChannel implements Runnable {
701705
@Override
702706
public void run() {
703707
try {
704-
service.path(resourceChannels)
708+
cfAuthenticatedResource.path(resourceChannels)
705709
.path(this.channel.getName())
706710
.type(MediaType.APPLICATION_JSON)
707711
.post(mapper.writeValueAsString(this.channel));
@@ -770,7 +774,7 @@ private class UpdateTag implements Runnable {
770774
@Override
771775
public void run() {
772776
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)
774778
.post(mapper.writeValueAsString(this.pxmlTag));
775779
} catch (UniformInterfaceException e) {
776780
throw new ChannelFinderException(e);
@@ -814,7 +818,7 @@ private class UpdateChannelProperty implements Runnable {
814818
@Override
815819
public void run() {
816820
try {
817-
service.path(resourceProperties)
821+
cfAuthenticatedResource.path(resourceProperties)
818822
.path(this.pxmlProperty.getName())
819823
.type(MediaType.APPLICATION_JSON)
820824
.put(mapper.writeValueAsString(this.pxmlProperty));
@@ -885,7 +889,7 @@ private class UpdateProperty implements Runnable {
885889
@Override
886890
public void run() {
887891
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)
889893
.accept(MediaType.APPLICATION_JSON).post(mapper.writeValueAsString(this.pxmlProperty));
890894
} catch (UniformInterfaceException e) {
891895
throw new ChannelFinderException(e);
@@ -1035,7 +1039,7 @@ public Collection<Channel> call() throws Exception {
10351039
List<XmlChannel> xmlchannels = new ArrayList<XmlChannel>();
10361040
long start = System.currentTimeMillis();
10371041
try {
1038-
xmlchannels = mapper.readValue(service.path(resourceChannels).queryParams(this.map)
1042+
xmlchannels = mapper.readValue(cfResource.path(resourceChannels).queryParams(this.map)
10391043
.accept(MediaType.APPLICATION_JSON).get(String.class), new TypeReference<List<XmlChannel>>() {
10401044
});
10411045
} catch (Exception e) {
@@ -1142,7 +1146,7 @@ private class DeleteElement implements Runnable
11421146

11431147
@Override
11441148
public void run() {
1145-
service.path(elementType).path(elementName).delete();
1149+
cfAuthenticatedResource.path(elementType).path(elementName).delete();
11461150
}
11471151

11481152
}
@@ -1237,7 +1241,7 @@ private class DeleteElementfromChannel implements Runnable
12371241
@Override
12381242
public void run()
12391243
{
1240-
service.path(this.elementType).path(this.elementName).path(this.channelName)
1244+
cfAuthenticatedResource.path(this.elementType).path(this.elementName).path(this.channelName)
12411245
.accept(MediaType.APPLICATION_JSON).delete();
12421246
}
12431247

@@ -1300,7 +1304,7 @@ public Collection<Channel> getAllChannels()
13001304
List<XmlChannel> xmlchannels = new ArrayList<XmlChannel>();
13011305
try {
13021306
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),
13041308
new TypeReference<List<XmlChannel>>() {
13051309
});
13061310
} catch (JsonParseException | JsonMappingException e) {

0 commit comments

Comments
 (0)