You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@opennlp.apache.org by "mawiesne (via GitHub)" <gi...@apache.org> on 2023/04/11 06:57:18 UTC

[GitHub] [opennlp-sandbox] mawiesne commented on a diff in pull request #97: Modernize sandbox components towards a more recent version of Jersey 2.x

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


##########
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:
   Don't know - code was there before - I just moved it around or formatted it.



-- 
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: dev-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org