Can I return a JSON when exception happened in ESB actions on JBoss SOA-Platform 5.2?

StackOverflow https://stackoverflow.com/questions/10474404

  •  06-06-2021
  •  | 
  •  

Question

I'm using JBoss SOA-P 5.2, which should be equivalent to JBoss ESB 4.10. And our ESB service uses a Http Gateway, which listens request from a web site.

The happy-path is all good: we can return a JSON response to web site application according to the HttpRequest. The problem comes from the exceptional path, where java code throws some exception from the action pipeline. Is there a way that we can catch exception generated in the action pipeline and customized the returned message to web application?

Thanks a lot!

Was it helpful?

Solution

It's suggested by RedHat that we can use RestEasy to accept HTTP requests and invoice ESB service through ServiceInvoker.

OTHER TIPS

The message can be setted in the fault exception message. (ActionProcessingFaultException)

Ex:

    public Message process(Message message) throws ActionProcessingException {
    try {
        Object obj = payloadProxy.getPayload(message);
        String value = "";
        if(obj instanceof String) {
            value = (String) obj;
        } else if(obj instanceof byte[]) {
            value = new String((byte[])obj);
        }
        RouteRequest req = gson.fromJson(value, RouteRequest.class);
        if(req == null) {
            logger.warn("Invalid JSON Request to Solve Service. "+value);
            throw new ActionProcessingException("Invalid JSON Request to Solve Service.");
        }
        payloadProxy.setPayload(message, req);
    } catch (MessageDeliverException e) {
        logger.error("Error handling with payload", e);
        throw new ActionProcessingException("Error handling with payload", e);
    } catch (Exception e) {
        String htmlHelp = "<html><body><h1>Bad Format</h1></body></html>";
        message.getBody().add(htmlHelp);
        throw new ActionProcessingFaultException(message, "Error converting Json Object.");
    }

    return message;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top