Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Spring MessageContext

How to get Spring MessageContext from Java class?

Should I use some @Resource or @Autowire to inject context var to class or, for instance, to use some global context SpringContext or some other in order to get MessageContext.

What is approach?

like image 433
sergionni Avatar asked Sep 03 '25 13:09

sergionni


2 Answers

If I understand correctly You're using Spring Webflow with JSF and need to access Webflow MessageContext from within a JSF ActionListener?

If so You can always use the RequestContextHolder (watch out to use the one from Webflow, as Spring MVC has it's own!), but it uses ThreadLocal so it's not too elegant:

MessageContext messageContext = 
    RequestContextHolder.getRequestContext().getMessageContext();

You cannot use standard DI, as the MessageContext is created per each request by the FlowExecutor on every flow start or resume, using MessageSource.

like image 157
Roadrunner Avatar answered Sep 05 '25 02:09

Roadrunner


I'd start by reading what the standard method of doing this is and try that:

@Resource WebServiceContext wsContext;

@WebMethod public String echoHello(String msg) {
    MessageContext context = wsContext.getMessageContext();

    ...
}

That's how to do it on the server side. On the client side, the request and response contexts are just simple maps that you retrieve from the service stub (which will implement BindingProvider even if you don't explicitly ask for it); they don't need the scope management that MessageContext adds.

like image 26
Donal Fellows Avatar answered Sep 05 '25 02:09

Donal Fellows