I have a web service that accepts xml events from another system, processes them using a specific workflow, and sends a list of potential errors back as an HTTP response.
The event processing workflow consists of several handlers (say: a preprocessor, a Persian, and a validator) implemented using the Guava EventBus . Handlers send events to each other. Something like that:
public class RequestHandler {
@RequestMapping
public Errors handleRequest(String xmlData) {
eventBus.post(new XmlReceivedEvent(xmlData));
...
return errors;
}
}
public class Preprocessor {
@Subscribe
public void onXmlReceived(XmlReceivedEvent event) {
...
eventBus.post(new PreprocessingCompleteEvent(preprocessingResult));
}
}
public class Persister {
@Subscribe
public void onPreprocessingComplete(PreprocessingCompleteEvent event) {
...
eventBus.post(new PersistenceCompleteEvent(persistenceResult));
}
}
public class Validator {
@Subscribe
public void onPersistenceComplete(PersistenceCompleteEvent event) {
...
eventBus.post(new ValidationCompleteEvent(errors));
}
}
The problem is this: how to return the processing result from the Validator handler back to the starting point (RequestHandler) so that the user can get an HTTP response
I am considering two options:
, Validator, .
RequestHandler ValidationCompleteEvent Validator .
public class RequestHandler {
private Errors errors;
@RequestMapping
public Errors handleRequest(String xmlData) {
XmlReceivedEvent event = new XmlReceivedEvent(xmlData);
eventBus.post(event);
...
return this.errors;
}
@Subscribe
public void onValidationComplete(ValidationCompleteEvent event) {
this.errors = event.getErrors();
}
}
, , RequestHandler Spring (singleton), - .
.