-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from weblyzard/feature/annotation-service
add: generic class allowing to connect to any AnnotationService
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/java/main/com/weblyzard/api/client/GenericAnnotatorClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.weblyzard.api.client; | ||
|
||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import com.weblyzard.api.model.document.Document; | ||
import com.weblyzard.api.service.AnnotationService; | ||
|
||
/** | ||
* Provide access to Web services implementing the AnnotationService interface. | ||
* | ||
* @see AnnotationService | ||
* | ||
* @author Philipp Kuntschik | ||
* @author Albert Weichselbraun | ||
*/ | ||
public class GenericAnnotatorClient extends BasicClient implements AnnotationService { | ||
|
||
|
||
private static final String ANNOTATE_DOCUMENT_SERVICE_URL = "/rest/annotate_document"; | ||
|
||
public GenericAnnotatorClient(WebserviceClientConfig c) { | ||
super(c, "/annotator"); | ||
} | ||
|
||
@Override | ||
public Document annotateDocument(Document data) { | ||
|
||
try (Response response = super.getTarget(ANNOTATE_DOCUMENT_SERVICE_URL) | ||
.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(data))) { | ||
|
||
super.checkResponseStatus(response); | ||
Document result = response.readEntity(Document.class); | ||
return result; | ||
} | ||
} | ||
} |