vahidhedayati / grails-wschat-plugin

Grails websocket chat Plugin provides a multi-chat room add-on to an existing grails based site. provides: Private Messaging/WebRTC/Offline PM + room booking/reservations. Websocket TicTactoe. Add Live Chat to your Grails application
http://grails.org/plugin/wschat
Apache License 2.0
22 stars 10 forks source link

Object Casting Exception #25

Open vijayshukla30 opened 8 years ago

vijayshukla30 commented 8 years ago

I am using wschat:1.26 and getting this error I have created three ChatRoomList object in bootstrap and when I am hittinghttp://127.0.0.1:8080/myProject/wsChat/chat then this error occurred

Cannot cast object '[grails.plugin.wschat.ChatRoomList : 1, grails.plugin.wschat.ChatRoomList : 2, grails.plugin.wschat.ChatRoomList : 3]' with class 'java.util.ArrayList' to class 'grails.plugin.wschat.ChatRoomList' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: grails.plugin.wschat.ChatRoomList(grails.plugin.wschat.ChatRoomList, grails.plugin.wschat.ChatRoomList, grails.plugin.wschat.ChatRoomList). Stacktrace follows: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[grails.plugin.wschat.ChatRoomList : 1, grails.plugin.wschat.ChatRoomList : 2, grails.plugin.wschat.ChatRoomList : 3]' with class 'java.util.ArrayList' to class 'grails.plugin.wschat.ChatRoomList' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: grails.plugin.wschat.ChatRoomList(grails.plugin.wschat.ChatRoomList, grails.plugin.wschat.ChatRoomList, grails.plugin.wschat.ChatRoomList) at grails.plugin.wschat.rooms.WsChatRoomService.$tt__returnRoom(WsChatRoomService.groovy:27) at grails.plugin.wschat.WsChatController.chat(WsChatController.groovy:39) at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195) at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

grails runtime exception

vahidhedayati commented 8 years ago

It is likely there was an issue with version hence the updates

The current latest is 1.31-SNAPSHOT

I would highly recommend using latest

So far as the room exception. Have you added a default room configuration to your app ?

In the earlier versions of the plugin this configuration was rather more compulsory, since in that segment the flaw was that it looked for config.rooms in line 25 if it didn't find none, it then fell back to the DB and tried to look up a room. In you case a brand new start nothing by that type already added. No need to say it is highly unlikely you added any clause in your BootStrap.groovy to add a chatRoom by the roomType of 'chat' hence the fall out / stack trace.

If you add that default config room to your configuration + probably a load others that is defined in the documentation for adding configuration items then it should be good to go.

To also explain why it is best to use the latest is probably because those things that were a flaw become a thing of the past. In the latest code:

List dbrooms = (config?.rooms.collect{it}  +ChatRoomList?.findAllByRoomType(ChatRoomList.DEFAULT_ROOM_TYPE)*.room?.unique()?.collect{it}) ?: ChatRoomList.DEFAULT_ROOM
        if (displayString) {
            return dbrooms[0] as String
        }else{
            return dbrooms
        }

That segment that was causing a problem should no longer actually be a problem.

I am curious to know why version 1.26 was there something done in that version that no longer works in the later version. (I know things got chopped and changed)

If it is I can look at what has changed and maybe introduce new calls to do that missing thing

vijayshukla30 commented 8 years ago

The problem with latest version is that I am using older version of spring security and using latest version asking to change the spring security which is causing a lot of changes in my project. Is there any way to use my older version of spring security.

vahidhedayati commented 8 years ago

you can use the exclude feature to disable plugins within plugins, The first disables spring security core you can then install your own version in your BuildConfig.groovy and the second is an example disabling multiple plugins installed by this plugin which you can then override..

compile (":wschat:1.31-SNAPSHOT") {
   excludes ('spring-security-core')
    //excludes('spring-security-core','hibernate')
}

http://stackoverflow.com/questions/18924347/grails-is-it-possible-to-exclude-a-plugin-dependency-of-another-plugin

vijayshukla30 commented 8 years ago

then in that case you spring security will not work.

plugins/wschat-1.30/grails-app/controllers/grails/plugin/wschat/WsChatAdminController.groovy: 3: unable to resolve class grails.plugin.springsecurity.annotation.Secured @ line 3, column 1. import grails.plugin.springsecurity.annotation.Secured ^

vahidhedayati commented 8 years ago

fair point - I can remove annotations from both those controllers and you will then have to use InterceptMap or something for springsecurity to work for those bits.

Please try 1.31-SNAPSHOT2 see how that goes

How to secure the plugin after this update - please refer to below link

https://github.com/vahidhedayati/grails-wschat-plugin/wiki/Config-Grails-2-1.31-SNAPSHOT2--Spring-Security-Annotation-change