Created
June 18, 2017 17:04
-
-
Save igorzg/fb859cdc7c8525ddebd7cc12258117f9 to your computer and use it in GitHub Desktop.
Jaxrs async marshaling feature reqeust
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
@Path("/{partner}/sync") | |
@Produces(MediaType.APPLICATION_JSON) | |
public class SyncResource { | |
@PathParam("partner") String partner; | |
@Inject SyncService syncService; | |
/** | |
* IMPLEMENTATION PROPOSAL | |
*/ | |
@GET | |
@Path("{model}") | |
public CompletableFuture<SyncStatus> asyncReqeust(@PathParam("model") String model) { | |
return syncService.sync(model, partner) | |
.exceptionally((Throwable e) -> | |
Response.status(500).entity(SyncStatus.error(partner, "Sync successfully finished", e)).build() | |
); | |
} | |
/** | |
* CURRENT IMPLEMENTATION | |
* Sync one collection | |
* | |
* @param model model name | |
* @param asyncResponse AsyncResponse | |
*/ | |
@GET | |
@Path("{model}") | |
public void syncOne(@PathParam("model") String model, @Suspended AsyncResponse asyncResponse) { | |
registerTimeoutHandler(asyncResponse); | |
syncService.sync(model, partner) | |
.thenApply(data -> asyncResponse.resume(data)) | |
.exceptionally((Throwable e) -> { | |
return asyncResponse.resume( | |
Response.status(500).entity(SyncStatus.error(partner, "Sync successfully finished", e)).build() | |
); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or it would be in case of global exception handler: