- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncRestTask.java
More file actions
Latest commit
33 lines (29 loc) · 1 KB
/
Copy pathAsyncRestTask.java
File metadata and controls
33 lines (29 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
publicclassAsyncRestTaskimplementsAsyncStreamTask, InitableTask, ClosableTask {
privateClientclient;
privateWebTargettarget;
@Override
publicvoidinit(Configconfig, TaskContexttaskContext) throwsException {
client = ClientBuilder.newClient();
target = client.target("http://example.com/resource/").path("hello");
}
@Override
publicvoidprocessAsync(IncomingMessageEnvelopeenvelope, MessageCollectorcollector,
TaskCoordinatorcoordinator, finalTaskCallbackcallback) {
target.request().async().get(newInvocationCallback<Response>() {
@Override
publicvoidcompleted(Responseresponse) {
System.out.println("Response status code " + response.getStatus() + " received.");
callback.complete();
}
@Override
publicvoidfailed(Throwablethrowable) {
System.out.println("Invocation failed.");
callback.failure(throwable);
}
});
}
@Override
publicvoidclose() throwsException {
client.close();
}
}