mawiesne commented on code in PR #97:
URL: https://github.com/apache/opennlp-sandbox/pull/97#discussion_r1162377711


##########
corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/CSQueueCollectionReader.java:
##########
@@ -79,62 +81,57 @@ public void initialize() throws 
ResourceInitializationException {
     corpusName = (String) getConfigParameterValue(CORPUS_NAME);
     
     String queueName = (String) getConfigParameterValue(QUEUE_NAME);
-    
     String searchQuery = (String) getConfigParameterValue(SEARCH_QUERY);
     
-    Client client = Client.create();
-    
+    Client c = ClientBuilder.newClient();
+
     // Create a queue if the search query is specified
     if (searchQuery != null) {
-      WebResource r = client.resource(serverAddress + "/queues/");
+      WebTarget r = c.target(serverAddress + "/queues/");
 
-      ClientResponse response = r.path("_createTaskQueue")
+      try (Response response = r.path("_createTaskQueue")
           .queryParam("corpusId", corpusName)
           .queryParam("queueId", queueName)
           .queryParam("q", searchQuery)
-          .accept(MediaType.TEXT_XML)
-          // TODO: How to fix this? Shouldn't accept do it?
-          .header("Content-Type", MediaType.TEXT_XML)
-          .post(ClientResponse.class);
-      
-      if (response.getStatus() != 204) {
-         throw new ResourceInitializationException(
-                         new Exception("Failed to create queue: " + 
response.getStatus()));
-      }
-      
-      if (logger.isLoggable(Level.INFO)) {
-        logger.log(Level.INFO, "Successfully created queue: " + queueName + " 
for corpus: " + corpusName);
+          .request(MediaType.TEXT_XML)
+          // as this is an query-param driven POST request,
+          // we just set an empty string to the body.
+          .post(Entity.entity("", MediaType.TEXT_PLAIN_TYPE))) {
+
+        if (response.getStatus() != 204) {
+          throw new ResourceInitializationException(
+                  new Exception("Failed to create queue: " + 
response.getStatus()));

Review Comment:
   Will have a look and make it prettier, I guess.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to