DWR3.0 rc3 - Spring MVC 4.0.5 java based configuration

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

DWR3.0 rc3 - Spring MVC 4.0.5 java based configuration

amit.sharma
Hello everyone,
I am trying to integerate DWR with one of our projects. We are not using XML based configurations here and so have to do every configuration in Java Configuration classes.

for java based configurations I am using following lines of code in MVCConfiguration.

    @Bean
    public DwrController dwrController(){
        Map<String,String> configParam = new HashMap<String, String>();
        configParam.put("activeReverseAjaxEnabled","true");

        DwrController dwrController = new DwrController();
        dwrController.setDebug(true);
        dwrController.setConfigParams(configParam);
/*
        AnnotationsConfigurator annotationsConfigurator = new AnnotationsConfigurator();
        annotationsConfigurator.configure();
        dwrController.setConfigurators(configurators);
*/
        List<Configurator> configurators = new ArrayList<Configurator>();
        configurators.add(annotationsConfigurator);
        return dwrController;
    }
    @Bean
    public BeanNameUrlHandlerMapping beanNameUrlHandlerMapping(){
        BeanNameUrlHandlerMapping beanNameUrlHandlerMapping = new BeanNameUrlHandlerMapping();
        return beanNameUrlHandlerMapping;
    }
    @Bean
    public DwrHandlerMapping dwrHandlerMapping(){
        Map<String,String> urlMap = new HashMap<String, String>();
        urlMap.put("/dwr/**/*","dwrController");

        DwrHandlerMapping dwrHandlerMapping = new DwrHandlerMapping();
        dwrHandlerMapping.setAlwaysUseFullPath(true);
        dwrHandlerMapping.setUrlMap(urlMap);
        return dwrHandlerMapping;
    }
WebApplicationInitializer extending class i have added mapping for dwr requests.

        ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/dwr/*");
        dispatcher.addMapping("/");

But on deployment it shows error stating "The required 'configurators' property should be set".
Can you please suggest if the configuration requires any modifications also how to set the configurators.

Thanks ,
Amit

Reply | Threaded
Open this post in threaded view
|

Re: DWR3.0 rc3 - Spring MVC 4.0.5 java based configuration

david@butterdev.com
Amit,
Unfortunately we do not currently support Java based config.  I looked at our code and I am not sure how much work it would be to implement.  Can you create a feature request in Jira?  https://directwebremoting.atlassian.net/secure/Dashboard.jspa

"We are not using XML based configurations here and so have to do every configuration in Java Configuration classes."

This is not mandated by Spring, you can mix and match (use XML and Java Configuration).  For now I would suggest you use XML config for the DWR stuff.

-David



On 01/07/2015 02:02 AM, Amit Sharma wrote:
Hello everyone,
I am trying to integerate DWR with one of our projects. We are not using XML based configurations here and so have to do every configuration in Java Configuration classes.

for java based configurations I am using following lines of code in MVCConfiguration.

    @Bean
    public DwrController dwrController(){
        Map<String,String> configParam = new HashMap<String, String>();
        configParam.put("activeReverseAjaxEnabled","true");

        DwrController dwrController = new DwrController();
        dwrController.setDebug(true);
        dwrController.setConfigParams(configParam);
/*
        AnnotationsConfigurator annotationsConfigurator = new AnnotationsConfigurator();
        annotationsConfigurator.configure();
        dwrController.setConfigurators(configurators);
*/
        List<Configurator> configurators = new ArrayList<Configurator>();
        configurators.add(annotationsConfigurator);
        return dwrController;
    }
    @Bean
    public BeanNameUrlHandlerMapping beanNameUrlHandlerMapping(){
        BeanNameUrlHandlerMapping beanNameUrlHandlerMapping = new BeanNameUrlHandlerMapping();
        return beanNameUrlHandlerMapping;
    }
    @Bean
    public DwrHandlerMapping dwrHandlerMapping(){
        Map<String,String> urlMap = new HashMap<String, String>();
        urlMap.put("/dwr/**/*","dwrController");

        DwrHandlerMapping dwrHandlerMapping = new DwrHandlerMapping();
        dwrHandlerMapping.setAlwaysUseFullPath(true);
        dwrHandlerMapping.setUrlMap(urlMap);
        return dwrHandlerMapping;
    }
WebApplicationInitializer extending class i have added mapping for dwr requests.

        ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/dwr/*");
        dispatcher.addMapping("/");

But on deployment it shows error stating "The required 'configurators' property should be set".
Can you please suggest if the configuration requires any modifications also how to set the configurators.

Thanks ,
Amit


Reply | Threaded
Open this post in threaded view
|

Re: DWR3.0 rc3 - Spring MVC 4.0.5 java based configuration

david@butterdev.com
Amit,
I don't think this will be too hard.  If you want there are a few things
you can try out.  If you pull down the DWR source you will see in
ConfigurationParser the following code where we register a
SpringConfigurator bean with Spring:

public static BeanDefinition
registerConfigurationIfNecessary(BeanDefinitionRegistry registry)
{
     if
(!registry.containsBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID))
     {
        BeanDefinitionBuilder builder =
BeanDefinitionBuilder.rootBeanDefinition(SpringConfigurator.class);
        builder.addPropertyValue("creators", new ManagedMap());
        builder.addPropertyValue("converters", new ManagedMap());
        builder.addPropertyValue("filters", new ManagedList());
        registry.registerBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID,
builder.getBeanDefinition());
     }
     return registry.getBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID);
}

If you can modify your Java Config class to register the
SpringConfigurator bean before you init DWRController it MAY solve your
issue.  This would be a quick hack.  If it works report back and we will
work on a more permanent solution.  Currently most of our Spring stuff
assumes xml/annotation config.


On 2015-01-07 05:44, David Marginian wrote:

> Amit,
>  Unfortunately we do not currently support Java based config.  I
> looked at our code and I am not sure how much work it would be to
> implement.  Can you create a feature request in Jira? 
> https://directwebremoting.atlassian.net/secure/Dashboard.jspa [1]
>
>  "We are not using XML based configurations here and so have to do
> every configuration in Java Configuration classes."
>
>  This is not mandated by Spring, you can mix and match (use XML and
> Java Configuration).  For now I would suggest you use XML config for
> the DWR stuff.
>
>  -David
>
>  On 01/07/2015 02:02 AM, Amit Sharma wrote:
>
>> Hello everyone,
>> I am trying to integerate DWR with one of our projects. We are not
>> using XML based configurations here and so have to do every
>> configuration in Java Configuration classes.
>>
>> for java based configurations I am using following lines of code in
>> MVCConfiguration.
>>
>>     @Bean
>>     public DwrController dwrController(){
>>         Map<String,String> configParam = new HashMap<String,
>> String>();
>>         configParam.put("activeReverseAjaxEnabled","true");
>>
>>         DwrController dwrController = new DwrController();
>>         dwrController.setDebug(true);
>>         dwrController.setConfigParams(configParam);
>> /*
>>         AnnotationsConfigurator annotationsConfigurator =
>> new AnnotationsConfigurator();
>>         annotationsConfigurator.configure();
>>         dwrController.setConfigurators(configurators);
>> */
>>         List<Configurator> configurators = new
>> ArrayList<Configurator>();
>>         configurators.add(annotationsConfigurator);
>>         return dwrController;
>>     }
>>     @Bean
>>     public BeanNameUrlHandlerMapping
>> beanNameUrlHandlerMapping(){
>>         BeanNameUrlHandlerMapping beanNameUrlHandlerMapping
>> = new BeanNameUrlHandlerMapping();
>>         return beanNameUrlHandlerMapping;
>>     }
>>     @Bean
>>     public DwrHandlerMapping dwrHandlerMapping(){
>>         Map<String,String> urlMap = new HashMap<String,
>> String>();
>>         urlMap.put("/dwr/**/*","dwrController");
>>
>>         DwrHandlerMapping dwrHandlerMapping = new
>> DwrHandlerMapping();
>>         dwrHandlerMapping.setAlwaysUseFullPath(true);
>>         dwrHandlerMapping.setUrlMap(urlMap);
>>         return dwrHandlerMapping;
>>     }
>> WebApplicationInitializer extending class i have added mapping for
>> dwr requests.
>>
>>         ServletRegistration.Dynamic dispatcher =
>> container.addServlet("dispatcher", new
>> DispatcherServlet(dispatcherContext));
>>         dispatcher.setLoadOnStartup(1);
>>         dispatcher.addMapping("/dwr/*");
>>         dispatcher.addMapping("/");
>>
>> But on deployment it shows error stating "The required
>> 'configurators' property should be set".
>> Can you please suggest if the configuration requires any
>> modifications also how to set the configurators.
>>
>> Thanks ,
>> Amit
>
>
>
> Links:
> ------
> [1] https://directwebremoting.atlassian.net/secure/Dashboard.jspa
Reply | Threaded
Open this post in threaded view
|

Re: DWR3.0 rc3 - Spring MVC 4.0.5 java based configuration

amit.sharma
In reply to this post by amit.sharma
Thanks for your response. I will definitely give it a try.
Until now, I can make a request to. dwr/engine.js and dwr/util.js but my DWR service class's js is not getting generating.
I am  assuming the reason, DWR is not able to scan my remote classes. Can you tell me how can I add DWR component scan path in my configuration class. On 07-Jan-2015 7:14 PM, [hidden email] wrote:

>
> Amit,
> I don't think this will be too hard.  If you want there are a few things
> you can try out.  If you pull down the DWR source you will see in
> ConfigurationParser the following code where we register a
> SpringConfigurator bean with Spring:
>
> public static BeanDefinition
> registerConfigurationIfNecessary(BeanDefinitionRegistry registry)
> {
>      if
> (!registry.containsBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID))
>      {
>         BeanDefinitionBuilder builder =
> BeanDefinitionBuilder.rootBeanDefinition(SpringConfigurator.class);
>         builder.addPropertyValue("creators", new ManagedMap());
>         builder.addPropertyValue("converters", new ManagedMap());
>         builder.addPropertyValue("filters", new ManagedList());
>         registry.registerBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID,
> builder.getBeanDefinition());
>      }
>      return registry.getBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID);
> }
>
> If you can modify your Java Config class to register the
> SpringConfigurator bean before you init DWRController it MAY solve your
> issue.  This would be a quick hack.  If it works report back and we will
> work on a more permanent solution.  Currently most of our Spring stuff
> assumes xml/annotation config.
>
>
> On 2015-01-07 05:44, David Marginian wrote:
> > Amit,
> >  Unfortunately we do not currently support Java based config.  I
> > looked at our code and I am not sure how much work it would be to
> > implement.  Can you create a feature request in Jira? 
> > https://directwebremoting.atlassian.net/secure/Dashboard.jspa [1]
> >
> >  "We are not using XML based configurations here and so have to do
> > every configuration in Java Configuration classes."
> >
> >  This is not mandated by Spring, you can mix and match (use XML and
> > Java Configuration).  For now I would suggest you use XML config for
> > the DWR stuff.
> >
> >  -David
> >
> >  On 01/07/2015 02:02 AM, Amit Sharma wrote:
> >
> >> Hello everyone,
> >> I am trying to integerate DWR with one of our projects. We are not
> >> using XML based configurations here and so have to do every
> >> configuration in Java Configuration classes.
> >>
> >> for java based configurations I am using following lines of code in
> >> MVCConfiguration.
> >>
> >>     @Bean
> >>     public DwrController dwrController(){
> >>         Map<String,String> configParam = new HashMap<String,
> >> String>();
> >>         configParam.put("activeReverseAjaxEnabled","true");
> >>
> >>         DwrController dwrController = new DwrController();
> >>         dwrController.setDebug(true);
> >>         dwrController.setConfigParams(configParam);
> >> /*
> >>         AnnotationsConfigurator annotationsConfigurator =
> >> new AnnotationsConfigurator();
> >>         annotationsConfigurator.configure();
> >>         dwrController.setConfigurators(configurators);
> >> */
> >>         List<Configurator> configurators = new
> >> ArrayList<Configurator>();
> >>         configurators.add(annotationsConfigurator);
> >>         return dwrController;
> >>     }
> >>     @Bean
> >>     public BeanNameUrlHandlerMapping
> >> beanNameUrlHandlerMapping(){
> >>         BeanNameUrlHandlerMapping beanNameUrlHandlerMapping
> >> = new BeanNameUrlHandlerMapping();
> >>         return beanNameUrlHandlerMapping;
> >>     }
> >>     @Bean
> >>     public DwrHandlerMapping dwrHandlerMapping(){
> >>         Map<String,String> urlMap = new HashMap<String,
> >> String>();
> >>         urlMap.put("/dwr/**/*","dwrController");
> >>
> >>         DwrHandlerMapping dwrHandlerMapping = new
> >> DwrHandlerMapping();
> >>         dwrHandlerMapping.setAlwaysUseFullPath(true);
> >>         dwrHandlerMapping.setUrlMap(urlMap);
> >>         return dwrHandlerMapping;
> >>     }
> >> WebApplicationInitializer extending class i have added mapping for
> >> dwr requests.
> >>
> >>         ServletRegistration.Dynamic dispatcher =
> >> container.addServlet("dispatcher", new
> >> DispatcherServlet(dispatcherContext));
> >>         dispatcher.setLoadOnStartup(1);
> >>         dispatcher.addMapping("/dwr/*");
> >>         dispatcher.addMapping("/");
> >>
> >> But on deployment it shows error stating "The required
> >> 'configurators' property should be set".
> >> Can you please suggest if the configuration requires any
> >> modifications also how to set the configurators.
> >>
> >> Thanks ,
> >> Amit
> >
> >
> >
> > Links:
> > ------
> > [1] https://directwebremoting.atlassian.net/secure/Dashboard.jspa 
Reply | Threaded
Open this post in threaded view
|

Re: DWR3.0 rc3 - Spring MVC 4.0.5 java based configuration

david@butterdev.com
Let me clarify my previous response.  The error you are getting - "The
required 'configurators' property should be set" is coming from
DwrController.  DWR's Spring integration is not being set-up properly
because we currently only support xml/annotation configurations.  Since
you are using Java Config the SpringConfigurator (which registers
converters, creators, etc.) and likely other essential pieces have not
been created. You have a few options:

1) Configure Spring/DWR via xml, not Java Config.  Spring allows you to
use both.
2) Look at the DWR source (serverside/spring) and determine the
essential pieces you need to create in your config classes.  It
shouldn't be too difficult to figure this out.  The current codes works
via xml and xml/annotation configurations (xml is parsed, beans are
registered with Spring).  You just need to figure out the essential
pieces and add them to your config class.
3) Wait for us to do number 2 for you -  I have created a new feature
request in Jira - https://directwebremoting.atlassian.net/browse/DWR-628

-David


On 2015-01-07 11:12, Amit Sharma wrote:

> Thanks for your response. I will definitely give it a try.
> Until now, I can make a request to. dwr/engine.js and dwr/util.js but
> my DWR service class's js is not getting generating.
> I am  assuming the reason, DWR is not able to scan my remote classes.
> Can you tell me how can I add DWR component scan path in my
> configuration class. On 07-Jan-2015 7:14 PM, [hidden email]
> wrote:
>>
>> Amit,
>> I don't think this will be too hard.  If you want there are a few
>> things
>> you can try out.  If you pull down the DWR source you will see in
>> ConfigurationParser the following code where we register a
>> SpringConfigurator bean with Spring:
>>
>> public static BeanDefinition
>> registerConfigurationIfNecessary(BeanDefinitionRegistry registry)
>> {
>>      if
>> (!registry.containsBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID))
>>      {
>>         BeanDefinitionBuilder builder =
>> BeanDefinitionBuilder.rootBeanDefinition(SpringConfigurator.class);
>>         builder.addPropertyValue("creators", new ManagedMap());
>>         builder.addPropertyValue("converters", new ManagedMap());
>>         builder.addPropertyValue("filters", new ManagedList());
>>        
>> registry.registerBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID,
>> builder.getBeanDefinition());
>>      }
>>      return
>> registry.getBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID);
>> }
>>
>> If you can modify your Java Config class to register the
>> SpringConfigurator bean before you init DWRController it MAY solve
>> your
>> issue.  This would be a quick hack.  If it works report back and we
>> will
>> work on a more permanent solution.  Currently most of our Spring stuff
>> assumes xml/annotation config.
>>
>>
>> On 2015-01-07 05:44, David Marginian wrote:
>> > Amit,
>> >  Unfortunately we do not currently support Java based config.  I
>> > looked at our code and I am not sure how much work it would be to
>> > implement.  Can you create a feature request in Jira? 
>> > https://directwebremoting.atlassian.net/secure/Dashboard.jspa [1]
>> >
>> >  "We are not using XML based configurations here and so have to do
>> > every configuration in Java Configuration classes."
>> >
>> >  This is not mandated by Spring, you can mix and match (use XML and
>> > Java Configuration).  For now I would suggest you use XML config for
>> > the DWR stuff.
>> >
>> >  -David
>> >
>> >  On 01/07/2015 02:02 AM, Amit Sharma wrote:
>> >
>> >> Hello everyone,
>> >> I am trying to integerate DWR with one of our projects. We are not
>> >> using XML based configurations here and so have to do every
>> >> configuration in Java Configuration classes.
>> >>
>> >> for java based configurations I am using following lines of code in
>> >> MVCConfiguration.
>> >>
>> >>     @Bean
>> >>     public DwrController dwrController(){
>> >>         Map<String,String> configParam = new HashMap<String,
>> >> String>();
>> >>         configParam.put("activeReverseAjaxEnabled","true");
>> >>
>> >>         DwrController dwrController = new DwrController();
>> >>         dwrController.setDebug(true);
>> >>         dwrController.setConfigParams(configParam);
>> >> /*
>> >>         AnnotationsConfigurator annotationsConfigurator =
>> >> new AnnotationsConfigurator();
>> >>         annotationsConfigurator.configure();
>> >>         dwrController.setConfigurators(configurators);
>> >> */
>> >>         List<Configurator> configurators = new
>> >> ArrayList<Configurator>();
>> >>         configurators.add(annotationsConfigurator);
>> >>         return dwrController;
>> >>     }
>> >>     @Bean
>> >>     public BeanNameUrlHandlerMapping
>> >> beanNameUrlHandlerMapping(){
>> >>         BeanNameUrlHandlerMapping beanNameUrlHandlerMapping
>> >> = new BeanNameUrlHandlerMapping();
>> >>         return beanNameUrlHandlerMapping;
>> >>     }
>> >>     @Bean
>> >>     public DwrHandlerMapping dwrHandlerMapping(){
>> >>         Map<String,String> urlMap = new HashMap<String,
>> >> String>();
>> >>         urlMap.put("/dwr/**/*","dwrController");
>> >>
>> >>         DwrHandlerMapping dwrHandlerMapping = new
>> >> DwrHandlerMapping();
>> >>         dwrHandlerMapping.setAlwaysUseFullPath(true);
>> >>         dwrHandlerMapping.setUrlMap(urlMap);
>> >>         return dwrHandlerMapping;
>> >>     }
>> >> WebApplicationInitializer extending class i have added mapping for
>> >> dwr requests.
>> >>
>> >>         ServletRegistration.Dynamic dispatcher =
>> >> container.addServlet("dispatcher", new
>> >> DispatcherServlet(dispatcherContext));
>> >>         dispatcher.setLoadOnStartup(1);
>> >>         dispatcher.addMapping("/dwr/*");
>> >>         dispatcher.addMapping("/");
>> >>
>> >> But on deployment it shows error stating "The required
>> >> 'configurators' property should be set".
>> >> Can you please suggest if the configuration requires any
>> >> modifications also how to set the configurators.
>> >>
>> >> Thanks ,
>> >> Amit
>> >
>> >
>> >
>> > Links:
>> > ------
>> > [1] https://directwebremoting.atlassian.net/secure/Dashboard.jspa
Reply | Threaded
Open this post in threaded view
|

Re: DWR3.0 rc3 - Spring MVC 4.0.5 java based configuration

david@butterdev.com
In reply to this post by amit.sharma
Try something like:

DwrController dwrController = new DwrController();
Configurator dwrSpringConfigurator = new SpringConfigurator();
List<Configurator> configurators = new ArrayList<Configurator>();
configurators.add(dwrSpringConfigurator);
dwrController.setConfigurators(configurators);

Doing this SHOULD get you past the initial error.  Now you need to get
the DWR annotated remote proxies, etc. into your Spring Container.  Your
current code isn't going to work (that will scan for Spring
annotations).  You need to use our stuff:

ClassPathBeanDefinitionScanner scanner = new
DwrClassPathBeanDefinitionScanner(yourAppContextHere);
// Set some properties on the scanner, see DWR's AnnotationScannerParser
for a few hints.
scanner.scan(""); // You likely want to pass in a base package here so
you don't scan the entire classpath

This is all untested but should help point you in the right direction.  
Please write back and let us know how it goes.



On 2015-01-07 11:12, Amit Sharma wrote:

> Thanks for your response. I will definitely give it a try.
> Until now, I can make a request to. dwr/engine.js and dwr/util.js but
> my DWR service class's js is not getting generating.
> I am  assuming the reason, DWR is not able to scan my remote classes.
> Can you tell me how can I add DWR component scan path in my
> configuration class. On 07-Jan-2015 7:14 PM, [hidden email]
> wrote:
>>
>> Amit,
>> I don't think this will be too hard.  If you want there are a few
>> things
>> you can try out.  If you pull down the DWR source you will see in
>> ConfigurationParser the following code where we register a
>> SpringConfigurator bean with Spring:
>>
>> public static BeanDefinition
>> registerConfigurationIfNecessary(BeanDefinitionRegistry registry)
>> {
>>      if
>> (!registry.containsBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID))
>>      {
>>         BeanDefinitionBuilder builder =
>> BeanDefinitionBuilder.rootBeanDefinition(SpringConfigurator.class);
>>         builder.addPropertyValue("creators", new ManagedMap());
>>         builder.addPropertyValue("converters", new ManagedMap());
>>         builder.addPropertyValue("filters", new ManagedList());
>>        
>> registry.registerBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID,
>> builder.getBeanDefinition());
>>      }
>>      return
>> registry.getBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID);
>> }
>>
>> If you can modify your Java Config class to register the
>> SpringConfigurator bean before you init DWRController it MAY solve
>> your
>> issue.  This would be a quick hack.  If it works report back and we
>> will
>> work on a more permanent solution.  Currently most of our Spring stuff
>> assumes xml/annotation config.
>>
>>
>> On 2015-01-07 05:44, David Marginian wrote:
>> > Amit,
>> >  Unfortunately we do not currently support Java based config.  I
>> > looked at our code and I am not sure how much work it would be to
>> > implement.  Can you create a feature request in Jira? 
>> > https://directwebremoting.atlassian.net/secure/Dashboard.jspa [1]
>> >
>> >  "We are not using XML based configurations here and so have to do
>> > every configuration in Java Configuration classes."
>> >
>> >  This is not mandated by Spring, you can mix and match (use XML and
>> > Java Configuration).  For now I would suggest you use XML config for
>> > the DWR stuff.
>> >
>> >  -David
>> >
>> >  On 01/07/2015 02:02 AM, Amit Sharma wrote:
>> >
>> >> Hello everyone,
>> >> I am trying to integerate DWR with one of our projects. We are not
>> >> using XML based configurations here and so have to do every
>> >> configuration in Java Configuration classes.
>> >>
>> >> for java based configurations I am using following lines of code in
>> >> MVCConfiguration.
>> >>
>> >>     @Bean
>> >>     public DwrController dwrController(){
>> >>         Map<String,String> configParam = new HashMap<String,
>> >> String>();
>> >>         configParam.put("activeReverseAjaxEnabled","true");
>> >>
>> >>         DwrController dwrController = new DwrController();
>> >>         dwrController.setDebug(true);
>> >>         dwrController.setConfigParams(configParam);
>> >> /*
>> >>         AnnotationsConfigurator annotationsConfigurator =
>> >> new AnnotationsConfigurator();
>> >>         annotationsConfigurator.configure();
>> >>         dwrController.setConfigurators(configurators);
>> >> */
>> >>         List<Configurator> configurators = new
>> >> ArrayList<Configurator>();
>> >>         configurators.add(annotationsConfigurator);
>> >>         return dwrController;
>> >>     }
>> >>     @Bean
>> >>     public BeanNameUrlHandlerMapping
>> >> beanNameUrlHandlerMapping(){
>> >>         BeanNameUrlHandlerMapping beanNameUrlHandlerMapping
>> >> = new BeanNameUrlHandlerMapping();
>> >>         return beanNameUrlHandlerMapping;
>> >>     }
>> >>     @Bean
>> >>     public DwrHandlerMapping dwrHandlerMapping(){
>> >>         Map<String,String> urlMap = new HashMap<String,
>> >> String>();
>> >>         urlMap.put("/dwr/**/*","dwrController");
>> >>
>> >>         DwrHandlerMapping dwrHandlerMapping = new
>> >> DwrHandlerMapping();
>> >>         dwrHandlerMapping.setAlwaysUseFullPath(true);
>> >>         dwrHandlerMapping.setUrlMap(urlMap);
>> >>         return dwrHandlerMapping;
>> >>     }
>> >> WebApplicationInitializer extending class i have added mapping for
>> >> dwr requests.
>> >>
>> >>         ServletRegistration.Dynamic dispatcher =
>> >> container.addServlet("dispatcher", new
>> >> DispatcherServlet(dispatcherContext));
>> >>         dispatcher.setLoadOnStartup(1);
>> >>         dispatcher.addMapping("/dwr/*");
>> >>         dispatcher.addMapping("/");
>> >>
>> >> But on deployment it shows error stating "The required
>> >> 'configurators' property should be set".
>> >> Can you please suggest if the configuration requires any
>> >> modifications also how to set the configurators.
>> >>
>> >> Thanks ,
>> >> Amit
>> >
>> >
>> >
>> > Links:
>> > ------
>> > [1] https://directwebremoting.atlassian.net/secure/Dashboard.jspa
Reply | Threaded
Open this post in threaded view
|

Re: DWR3.0 rc3 - Spring MVC 4.0.5 java based configuration

amit.sharma
Hi David,
Tried the way you suggested but while accesssing m,y dwr service class as /dwr/testService.js it throws an exception stating Class not found : testService.

Seems like scanning is not perfomed at all.
I am a bit confused. I was looking at the class AnnotationsConfigurator & DwrClassPathBeanDefinitionScanner, seems like these are the classes responsible for component scanning. But

* Method registerBeanDefinition() in DwrClassPathBeanDefinitionScanner is never called as it is responsible for registering the respective Proxy,Converter classes
* Method configure() 's parameter context doesnt have my dwr service bean.

my currunt config method is :
<b>
@Bean
    public DwrController dwrController(ApplicationContext applicationContext){

        BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry)applicationContext.getAutowireCapableBeanFactory();
        Map<String,String> configParam = new HashMap<String, String>();
        configParam.put("activeReverseAjaxEnabled","true");

        ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(beanDefinitionRegistry);
        scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
        scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
        scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
        scanner.scan("in.til");

        DwrController dwrController = new DwrController();
        dwrController.setDebug(true);
        dwrController.setConfigParams(configParam);

        SpringConfigurator springConfigurator = new SpringConfigurator();
        List<Configurator> configurators = new ArrayList<Configurator>();
//        AnnotationsConfigurator annotationsConfigurator = new AnnotationsConfigurator();
//        configurators.add(annotationsConfigurator);
        configurators.add(springConfigurator);
        dwrController.setConfigurators(configurators);


        return dwrController;
    }
@Bean
    public DwrHandlerMapping dwrHandlerMapping(DwrController dwrController){
        Map<String,DwrController> urlMap = new HashMap<String, DwrController>();
        urlMap.put("/dwr/**/*",dwrController);

        DwrHandlerMapping dwrHandlerMapping = new DwrHandlerMapping();
        dwrHandlerMapping.setAlwaysUseFullPath(true);
        dwrHandlerMapping.setUrlMap(urlMap);
        return dwrHandlerMapping;
    }
</b>



On Thursday, 8 January 2015 1:45 AM, "[hidden email]" <[hidden email]> wrote:


Try something like:

DwrController dwrController = new DwrController();
Configurator dwrSpringConfigurator = new SpringConfigurator();
List<Configurator> configurators = new ArrayList<Configurator>();
configurators.add(dwrSpringConfigurator);
dwrController.setConfigurators(configurators);

Doing this SHOULD get you past the initial error.  Now you need to get
the DWR annotated remote proxies, etc. into your Spring Container.  Your
current code isn't going to work (that will scan for Spring
annotations).  You need to use our stuff:

ClassPathBeanDefinitionScanner scanner = new
DwrClassPathBeanDefinitionScanner(yourAppContextHere);
// Set some properties on the scanner, see DWR's AnnotationScannerParser
for a few hints.
scanner.scan(""); // You likely want to pass in a base package here so
you don't scan the entire classpath

This is all untested but should help point you in the right direction. 
Please write back and let us know how it goes.



On 2015-01-07 11:12, Amit Sharma wrote:

> Thanks for your response. I will definitely give it a try.
> Until now, I can make a request to. dwr/engine.js and dwr/util.js but
> my DWR service class's js is not getting generating.
> I am  assuming the reason, DWR is not able to scan my remote classes.
> Can you tell me how can I add DWR component scan path in my
> configuration class. On 07-Jan-2015 7:14 PM, [hidden email]
> wrote:
>>
>> Amit,
>> I don't think this will be too hard.  If you want there are a few
>> things
>> you can try out.  If you pull down the DWR source you will see in
>> ConfigurationParser the following code where we register a
>> SpringConfigurator bean with Spring:
>>
>> public static BeanDefinition
>> registerConfigurationIfNecessary(BeanDefinitionRegistry registry)
>> {
>>      if
>> (!registry.containsBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID))
>>      {
>>         BeanDefinitionBuilder builder =
>> BeanDefinitionBuilder.rootBeanDefinition(SpringConfigurator.class);
>>         builder.addPropertyValue("creators", new ManagedMap());
>>         builder.addPropertyValue("converters", new ManagedMap());
>>         builder.addPropertyValue("filters", new ManagedList());
>>        
>> registry.registerBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID,
>> builder.getBeanDefinition());
>>      }
>>      return
>> registry.getBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID);
>> }
>>
>> If you can modify your Java Config class to register the
>> SpringConfigurator bean before you init DWRController it MAY solve
>> your
>> issue.  This would be a quick hack.  If it works report back and we
>> will
>> work on a more permanent solution.  Currently most of our Spring stuff
>> assumes xml/annotation config.
>>
>>
>> On 2015-01-07 05:44, David Marginian wrote:
>> > Amit,
>> >  Unfortunately we do not currently support Java based config.  I
>> > looked at our code and I am not sure how much work it would be to
>> > implement.  Can you create a feature request in Jira? 
>> > https://directwebremoting.atlassian.net/secure/Dashboard.jspa [1]
>> >
>> >  "We are not using XML based configurations here and so have to do
>> > every configuration in Java Configuration classes."
>> >
>> >  This is not mandated by Spring, you can mix and match (use XML and
>> > Java Configuration).  For now I would suggest you use XML config for
>> > the DWR stuff.
>> >
>> >  -David
>> >
>> >  On 01/07/2015 02:02 AM, Amit Sharma wrote:
>> >
>> >> Hello everyone,
>> >> I am trying to integerate DWR with one of our projects. We are not
>> >> using XML based configurations here and so have to do every
>> >> configuration in Java Configuration classes.
>> >>
>> >> for java based configurations I am using following lines of code in
>> >> MVCConfiguration.
>> >>
>> >>     @Bean
>> >>     public DwrController dwrController(){
>> >>         Map<String,String> configParam = new HashMap<String,
>> >> String>();
>> >>         configParam.put("activeReverseAjaxEnabled","true");
>> >>
>> >>         DwrController dwrController = new DwrController();
>> >>         dwrController.setDebug(true);
>> >>         dwrController.setConfigParams(configParam);
>> >> /*
>> >>         AnnotationsConfigurator annotationsConfigurator =
>> >> new AnnotationsConfigurator();
>> >>         annotationsConfigurator.configure();
>> >>         dwrController.setConfigurators(configurators);
>> >> */
>> >>         List<Configurator> configurators = new
>> >> ArrayList<Configurator>();
>> >>         configurators.add(annotationsConfigurator);
>> >>         return dwrController;
>> >>     }
>> >>     @Bean
>> >>     public BeanNameUrlHandlerMapping
>> >> beanNameUrlHandlerMapping(){
>> >>         BeanNameUrlHandlerMapping beanNameUrlHandlerMapping
>> >> = new BeanNameUrlHandlerMapping();
>> >>         return beanNameUrlHandlerMapping;
>> >>     }
>> >>     @Bean
>> >>     public DwrHandlerMapping dwrHandlerMapping(){
>> >>         Map<String,String> urlMap = new HashMap<String,
>> >> String>();
>> >>         urlMap.put("/dwr/**/*","dwrController");
>> >>
>> >>         DwrHandlerMapping dwrHandlerMapping = new
>> >> DwrHandlerMapping();
>> >>         dwrHandlerMapping.setAlwaysUseFullPath(true);
>> >>         dwrHandlerMapping.setUrlMap(urlMap);
>> >>         return dwrHandlerMapping;
>> >>     }
>> >> WebApplicationInitializer extending class i have added mapping for
>> >> dwr requests.
>> >>
>> >>         ServletRegistration.Dynamic dispatcher =
>> >> container.addServlet("dispatcher", new
>> >> DispatcherServlet(dispatcherContext));
>> >>         dispatcher.setLoadOnStartup(1);
>> >>         dispatcher.addMapping("/dwr/*");
>> >>         dispatcher.addMapping("/");
>> >>
>> >> But on deployment it shows error stating "The required
>> >> 'configurators' property should be set".
>> >> Can you please suggest if the configuration requires any
>> >> modifications also how to set the configurators.
>> >>
>> >> Thanks ,
>> >> Amit
>> >
>> >
>> >
>> > Links:
>> > ------
>> > [1] https://directwebremoting.atlassian.net/secure/Dashboard.jspa

Reply | Threaded
Open this post in threaded view
|

Re: DWR3.0 rc3 - Spring MVC 4.0.5 java based configuration

david@butterdev.com
AnnotationsConfigurator is for non-Spring set-ups - you don't need that.  What you need to do is scan the classpath and add the correct annotated classes into your Spring context.  For xml set-ups you will notice we register a bean definition parser in DwrSpringNamespacehandler. 
registerBeanDefinitionParser("annotation-scan", new AnnotationScannerParser());

AnnotationsScannerParser parses the xml, creates a DwrClassPathBeanDefiniationScanner, and calls scan on it.
We need to do something similar for you Spring context, I will research the Spring API on how to do that.


On 01/08/2015 03:22 AM, Amit Sharma wrote:
Hi David,
Tried the way you suggested but while accesssing m,y dwr service class as /dwr/testService.js it throws an exception stating Class not found : testService.

Seems like scanning is not perfomed at all.
I am a bit confused. I was looking at the class AnnotationsConfigurator & DwrClassPathBeanDefinitionScanner, seems like these are the classes responsible for component scanning. But

* Method registerBeanDefinition() in DwrClassPathBeanDefinitionScanner is never called as it is responsible for registering the respective Proxy,Converter classes
* Method configure() 's parameter context doesnt have my dwr service bean.

my currunt config method is :
<b>
@Bean
    public DwrController dwrController(ApplicationContext applicationContext){

        BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry)applicationContext.getAutowireCapableBeanFactory();
        Map<String,String> configParam = new HashMap<String, String>();
        configParam.put("activeReverseAjaxEnabled","true");

        ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(beanDefinitionRegistry);
        scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
        scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
        scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
        scanner.scan("in.til");

        DwrController dwrController = new DwrController();
        dwrController.setDebug(true);
        dwrController.setConfigParams(configParam);

        SpringConfigurator springConfigurator = new SpringConfigurator();
        List<Configurator> configurators = new ArrayList<Configurator>();
//        AnnotationsConfigurator annotationsConfigurator = new AnnotationsConfigurator();
//        configurators.add(annotationsConfigurator);
        configurators.add(springConfigurator);
        dwrController.setConfigurators(configurators);


        return dwrController;
    }
@Bean
    public DwrHandlerMapping dwrHandlerMapping(DwrController dwrController){
        Map<String,DwrController> urlMap = new HashMap<String, DwrController>();
        urlMap.put("/dwr/**/*",dwrController);

        DwrHandlerMapping dwrHandlerMapping = new DwrHandlerMapping();
        dwrHandlerMapping.setAlwaysUseFullPath(true);
        dwrHandlerMapping.setUrlMap(urlMap);
        return dwrHandlerMapping;
    }
</b>



On Thursday, 8 January 2015 1:45 AM, [hidden email] [hidden email] wrote:


Try something like:

DwrController dwrController = new DwrController();
Configurator dwrSpringConfigurator = new SpringConfigurator();
List<Configurator> configurators = new ArrayList<Configurator>();
configurators.add(dwrSpringConfigurator);
dwrController.setConfigurators(configurators);

Doing this SHOULD get you past the initial error.  Now you need to get
the DWR annotated remote proxies, etc. into your Spring Container.  Your
current code isn't going to work (that will scan for Spring
annotations).  You need to use our stuff:

ClassPathBeanDefinitionScanner scanner = new
DwrClassPathBeanDefinitionScanner(yourAppContextHere);
// Set some properties on the scanner, see DWR's AnnotationScannerParser
for a few hints.
scanner.scan(""); // You likely want to pass in a base package here so
you don't scan the entire classpath

This is all untested but should help point you in the right direction. 
Please write back and let us know how it goes.



On 2015-01-07 11:12, Amit Sharma wrote:
> Thanks for your response. I will definitely give it a try.
> Until now, I can make a request to. dwr/engine.js and dwr/util.js but
> my DWR service class's js is not getting generating.
> I am  assuming the reason, DWR is not able to scan my remote classes.
> Can you tell me how can I add DWR component scan path in my
> configuration class. On 07-Jan-2015 7:14 PM, [hidden email]
> wrote:
>>
>> Amit,
>> I don't think this will be too hard.  If you want there are a few
>> things
>> you can try out.  If you pull down the DWR source you will see in
>> ConfigurationParser the following code where we register a
>> SpringConfigurator bean with Spring:
>>
>> public static BeanDefinition
>> registerConfigurationIfNecessary(BeanDefinitionRegistry registry)
>> {
>>      if
>> (!registry.containsBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID))
>>      {
>>         BeanDefinitionBuilder builder =
>> BeanDefinitionBuilder.rootBeanDefinition(SpringConfigurator.class);
>>         builder.addPropertyValue("creators", new ManagedMap());
>>         builder.addPropertyValue("converters", new ManagedMap());
>>         builder.addPropertyValue("filters", new ManagedList());
>>        
>> registry.registerBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID,
>> builder.getBeanDefinition());
>>      }
>>      return
>> registry.getBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID);
>> }
>>
>> If you can modify your Java Config class to register the
>> SpringConfigurator bean before you init DWRController it MAY solve
>> your
>> issue.  This would be a quick hack.  If it works report back and we
>> will
>> work on a more permanent solution.  Currently most of our Spring stuff
>> assumes xml/annotation config.
>>
>>
>> On 2015-01-07 05:44, David Marginian wrote:
>> > Amit,
>> >  Unfortunately we do not currently support Java based config.  I
>> > looked at our code and I am not sure how much work it would be to
>> > implement.  Can you create a feature request in Jira? 
>> > https://directwebremoting.atlassian.net/secure/Dashboard.jspa [1]
>> >
>> >  "We are not using XML based configurations here and so have to do
>> > every configuration in Java Configuration classes."
>> >
>> >  This is not mandated by Spring, you can mix and match (use XML and
>> > Java Configuration).  For now I would suggest you use XML config for
>> > the DWR stuff.
>> >
>> >  -David
>> >
>> >  On 01/07/2015 02:02 AM, Amit Sharma wrote:
>> >
>> >> Hello everyone,
>> >> I am trying to integerate DWR with one of our projects. We are not
>> >> using XML based configurations here and so have to do every
>> >> configuration in Java Configuration classes.
>> >>
>> >> for java based configurations I am using following lines of code in
>> >> MVCConfiguration.
>> >>
>> >>     @Bean
>> >>     public DwrController dwrController(){
>> >>         Map<String,String> configParam = new HashMap<String,
>> >> String>();
>> >>         configParam.put("activeReverseAjaxEnabled","true");
>> >>
>> >>         DwrController dwrController = new DwrController();
>> >>         dwrController.setDebug(true);
>> >>         dwrController.setConfigParams(configParam);
>> >> /*
>> >>         AnnotationsConfigurator annotationsConfigurator =
>> >> new AnnotationsConfigurator();
>> >>         annotationsConfigurator.configure();
>> >>         dwrController.setConfigurators(configurators);
>> >> */
>> >>         List<Configurator> configurators = new
>> >> ArrayList<Configurator>();
>> >>         configurators.add(annotationsConfigurator);
>> >>         return dwrController;
>> >>     }
>> >>     @Bean
>> >>     public BeanNameUrlHandlerMapping
>> >> beanNameUrlHandlerMapping(){
>> >>         BeanNameUrlHandlerMapping beanNameUrlHandlerMapping
>> >> = new BeanNameUrlHandlerMapping();
>> >>         return beanNameUrlHandlerMapping;
>> >>     }
>> >>     @Bean
>> >>     public DwrHandlerMapping dwrHandlerMapping(){
>> >>         Map<String,String> urlMap = new HashMap<String,
>> >> String>();
>> >>         urlMap.put("/dwr/**/*","dwrController");
>> >>
>> >>         DwrHandlerMapping dwrHandlerMapping = new
>> >> DwrHandlerMapping();
>> >>         dwrHandlerMapping.setAlwaysUseFullPath(true);
>> >>         dwrHandlerMapping.setUrlMap(urlMap);
>> >>         return dwrHandlerMapping;
>> >>     }
>> >> WebApplicationInitializer extending class i have added mapping for
>> >> dwr requests.
>> >>
>> >>         ServletRegistration.Dynamic dispatcher =
>> >> container.addServlet("dispatcher", new
>> >> DispatcherServlet(dispatcherContext));
>> >>         dispatcher.setLoadOnStartup(1);
>> >>         dispatcher.addMapping("/dwr/*");
>> >>         dispatcher.addMapping("/");
>> >>
>> >> But on deployment it shows error stating "The required
>> >> 'configurators' property should be set".
>> >> Can you please suggest if the configuration requires any
>> >> modifications also how to set the configurators.
>> >>
>> >> Thanks ,
>> >> Amit
>> >
>> >
>> >
>> > Links:
>> > ------
>> > [1] https://directwebremoting.atlassian.net/secure/Dashboard.jspa


Reply | Threaded
Open this post in threaded view
|

Re: DWR3.0 rc3 - Spring MVC 4.0.5 java based configuration

amit.sharma
In reply to this post by amit.sharma
Hi, David thanks for your support I finally got the working configuration. Here is my cofiguration class's code

@Bean
    public DwrController dwrController(ApplicationContext applicationContext){

        BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry)applicationContext.getAutowireCapableBeanFactory();
        Map<String,String> configParam = new HashMap<String, String>();
        configParam.put("activeReverseAjaxEnabled","true");

        ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(beanDefinitionRegistry);
        scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
        scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
        scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
        scanner.scan("pachage.to.scan");

        DwrController dwrController = new DwrController();
        dwrController.setDebug(true);
        dwrController.setConfigParams(configParam);

        SpringConfigurator springConfigurator = new SpringConfigurator();
        List<Configurator> configurators = new ArrayList<Configurator>();
        configurators.add(springConfigurator);
        dwrController.setConfigurators(configurators);


        return dwrController;
    }
    @Bean
    public BeanNameUrlHandlerMapping beanNameUrlHandlerMapping(){
        BeanNameUrlHandlerMapping beanNameUrlHandlerMapping = new BeanNameUrlHandlerMapping();
        return beanNameUrlHandlerMapping;
    }
@Bean
    public DwrHandlerMapping dwrHandlerMapping(DwrController dwrController){
        Map<String,DwrController> urlMap = new HashMap<String, DwrController>();
        urlMap.put("/dwr/**/*",dwrController);

        DwrHandlerMapping dwrHandlerMapping = new DwrHandlerMapping();
        dwrHandlerMapping.setAlwaysUseFullPath(true);
        dwrHandlerMapping.setUrlMap(urlMap);
        return dwrHandlerMapping;
    }

Note :  DwrClassPathBeanDefinitionScanner will skip scan of @Controller,@Service,@Repository,@Component, so do not use @RemoteProxy along with anyone of these spring annotations.

Thanks