Closed jfrense closed 2 years ago
Honestly I have no clue, how the dependency injection works with objects that are dynamically generated.
Obviously your custom As2MessageHandler
is instantiated using reflection by as2-lib. I think the best thing you can do, is to explicitly pass in the ApplicationContext
via setter.
If you look at the example application, class ServletConfig
you may iterate all objects of AS2_SESSION.getMessageProcessor ().getAllModules ()
and check with instanceof
for your handler. Then call a setApplicationContext
method you need to implement. hth
Thanks for the insight! I was able to add the As2handler programmatically in the servlet config so it can be spring managed and thus easily access the spring application context.
@Autowired
private As2MessageHandler as2MessageHandler;
private void initAS2Modules() {
// Adding AS2 Handler Programmatically so it can be spring managed.
try {
AS2_SESSION.getMessageProcessor().addModule(as2MessageHandler);
AS2_SESSION.getMessageProcessor().startActiveModules();
} catch (final AS2Exception ex)
{
throw new InitializationException (ex);
}
}
@Bean
public ServletRegistrationBean <MyAS2ReceiveServlet> servletRegistrationBeanAS2 ()
{
initAS2Modules();
_initScope ();
return new ServletRegistrationBean <> (new MyAS2ReceiveServlet (), "/as2");
}
@Bean
public ServletRegistrationBean <MyAS2MDNReceiveServlet> servletRegistrationBeanMDN ()
{
_initScope ();
return new ServletRegistrationBean <> (new MyAS2MDNReceiveServlet (), "/as2mdn");
}
This way seems to be even smarter :) Thanks for sharing!
I was wondering if its possible to load the custom handler module as a spring managed component on startup so that we have access to the application context in the custom handler?
I have the following config.xml with my custom handler (As2MessageHandler) defined:
And in my As2Handler class I would like to access the application context so I can access drop the message onto a spring integration channel for further downstream processing: As2MessageHandler class:
^^ When running the spring boot application I currently get context not defined which makes me thing that the As2 Session is not referencing the spring managed implementation of this class. Can you provide any insight on how to achieve this?