Tomcat 7 + CometD 2 getting error java.lang.IllegalStateException: Not supported

1,329 views
Skip to first unread message

Aown Shirazi

unread,
Jul 18, 2011, 11:18:01 AM7/18/11
to cometd-users
Hi,

i running CometD2 on Tomcat 7 with following configuration in web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometdServlet</servlet-class>
<async-supported>true</async-supported>
<init-param>
<param-name>timeout</param-name>
<param-value>60000</param-value>
</init-param>
<init-param>
<param-name>interval</param-name>
<param-value>5000</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>cometdConfiguration</servlet-name>
<servlet-
class>com.softech.webTradingTerminal.cometdConfigurationServlet</
servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>continuation</filter-name>
<filter-
class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>continuation</filter-name>
<url-pattern>/cometd/*</url-pattern>
</filter-mapping>
</web-app>

At runtime i am getting following error : can you explain why i am
getting this error ?

Jul 18, 2011 8:08:15 PM org.apache.catalina.core.StandardWrapperValve
invoke
SEVERE: Servlet.service() for servlet [cometd] in context with path [/
webTradingTerminal] threw exception
java.lang.IllegalStateException: Not supported.
at org.apache.catalina.connector.Request.startAsync(Request.java:
1605)
at org.apache.catalina.connector.Request.startAsync(Request.java:
1598)
at
org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:
1024)
at
org.eclipse.jetty.continuation.Servlet3Continuation.suspend(Servlet3Continuation.java:
171)
at
org.cometd.server.transport.LongPollingTransport.handle(LongPollingTransport.java:
268)
at org.cometd.server.CometdServlet.service(CometdServlet.java:191)
at org.cometd.server.CometdServlet.service(CometdServlet.java:160)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
304)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
210)
at
org.eclipse.jetty.continuation.ContinuationFilter.doFilter(ContinuationFilter.java:
111)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
210)
at
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:
393)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
240)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
164)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:
498)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
164)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
100)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
562)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
394)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
243)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint
$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

Simone Bordet

unread,
Jul 22, 2011, 1:29:23 PM7/22/11
to cometd...@googlegroups.com
Hi,

On Mon, Jul 18, 2011 at 17:18, Aown Shirazi <aown.m...@gmail.com> wrote:
> Hi,
>
> i running CometD2 on Tomcat 7 with following configuration in web.xml

Please search the documentation and the mail list archives (sorry
little time to expand on this).

Simon
--
http://bordet.blogspot.com
---
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz

gumutianqi

unread,
May 10, 2012, 5:22:46 AM5/10/12
to cometd...@googlegroups.com

Hi,
I also encountered this problem, I to run cometD spring3.1 mvc + hibernate
Run Tomcat 7 + CometD 2 getting error java.lang.IllegalStateException: Not supported

My log:

2012-5-10 16:32:43 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [cometd] in context with path [] threw exception
java.lang.IllegalStateException: Not supported.
at org.apache.catalina.connector.Request.startAsync(Request.java:1663)
at org.apache.catalina.connector.Request.startAsync(Request.java:1656)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1022)
at org.eclipse.jetty.continuation.Servlet3Continuation.suspend(Servlet3Continuation.java:172)
at org.cometd.server.transport.LongPollingTransport.handle(LongPollingTransport.java:288)
at org.cometd.server.CometdServlet.service(CometdServlet.java:181)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.eclipse.jetty.continuation.ContinuationFilter.doFilter(ContinuationFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:169)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1805)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)


On the Internet without the solution of this problem, I eagerly awaited the solution Thank you very much 


在 2011年7月23日星期六UTC+8上午1时29分23秒,Simone Bordet写道:
在 2011年7月23日星期六UTC+8上午1时29分23秒,Simone Bordet写道:

Matthew Tyson

unread,
May 10, 2012, 12:25:39 PM5/10/12
to cometd...@googlegroups.com
Comet on Tomcat 7 is not recommended. Tomcat 7 comet support is
extremely buggy, especially with NIO connector and/or under load.

At the very least, make sure you are using the very latest tomcat
release. Even so - my experience recommends you use Jetty for this
application.

Matt
> --
> You received this message because you are subscribed to the Google Groups
> "cometd-users" group.
> To post to this group, send email to cometd...@googlegroups.com
> To unsubscribe from this group, send email to
> cometd-users...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/cometd-users
>
> Visit the CometD website at http://www.cometd.org

Matthew Tyson

unread,
May 10, 2012, 12:30:11 PM5/10/12
to cometd...@googlegroups.com
It looks like you are using the APR. I wouldn't be surprised if it
suffers from the same problems are NIO.

古木天琪

unread,
May 11, 2012, 6:39:28 AM5/11/12
to cometd...@googlegroups.com
Thanks.

 I have to replace Jetty7.6.3, but when I the run publist (), hava a error.

No authorizers, CREATE for channel / service / message granted
2012-05-11 18:31:49 -55238 [qtp28263924-21] [INFO] [114] org.cometd.server.BayeuxServerImpl.24282826 - Added channel / service
2012-05-11 18:31:49 -55254 [qtp28263924-21] [INFO] [114] org.cometd.server.BayeuxServerImpl.24282826 - Added channel / service / message
2012-05-11 18:31:49 -55254 [qtp28263924-21] [INFO] [114] org.cometd.server.BayeuxServerImpl.24282826 - No authorizers, PUBLISH for channel / service / message granted

I ask this question how to solve it?
I was channel authorized

bayeux.createIfAbsent ("/ service / message",
                new ConfigurableServerChannel.Initializer () {
                       public void configureChannel (ConfigurableServerChannel channel) {
                           channel.addAuthorizer (new Authorizer () {
                                @ Override
                                        public Result authorize (Operation operation, ChannelId channel, ServerSession                        session, ServerMessage message) {
                                                 System.out.println ("users to the Session:" + session.getAttribute ("user"));
                                                 return session.getAttribute ("user")! = null? Result.grant (): Result.deny ("no user in session");
                                        }
                          });
                  }
});


2012/5/11 Matthew Tyson <matthewc...@gmail.com>

Simone Bordet

unread,
May 11, 2012, 6:42:04 AM5/11/12
to cometd...@googlegroups.com
Hi,

On Fri, May 11, 2012 at 12:39 PM, 古木天琪 <gumut...@gmail.com> wrote:
> Thanks.
>
>  I have to replace Jetty7.6.3, but when I the run publist (), hava a error.

What error ?

Simon
--
http://cometd.org
http://intalio.com
http://bordet.blogspot.com
----

gumutianqi

unread,
May 11, 2012, 6:46:04 AM5/11/12
to cometd...@googlegroups.com
this Error!

No authorizers, CREATE for channel / chat / test granted

Added channel  /service
Added channel  /service/message
No authorizers, SUBSCRIBE for channel / chat / test granted 

在 2012年5月11日星期五UTC+8下午6时42分04秒,Simone Bordet写道:

Simone Bordet

unread,
May 11, 2012, 11:02:39 AM5/11/12
to cometd...@googlegroups.com
Hi,

On Fri, May 11, 2012 at 12:46 PM, gumutianqi <gumut...@gmail.com> wrote:
> this Error!
>
> No authorizers, CREATE for channel / chat / test granted
> Added channel  /service
> Added channel  /service/message
> No authorizers, SUBSCRIBE for channel / chat / test granted

There are no errors, both create and subscribe are granted.

古木天琪

unread,
May 11, 2012, 11:16:49 AM5/11/12
to cometd...@googlegroups.com

but my service not publish to the browse.!!!

Simone Bordet

unread,
May 11, 2012, 12:27:06 PM5/11/12
to cometd...@googlegroups.com
Hi,

On Fri, May 11, 2012 at 5:16 PM, 古木天琪 <gumut...@gmail.com> wrote:
> but my service not publish to the browse.!!!

Well, you did not show us your code, so we can't help you.
This may help you: http://www.catb.org/~esr/faqs/smart-questions.html#before

gumutianqi

unread,
May 11, 2012, 9:27:00 PM5/11/12
to cometd...@googlegroups.com

Thanks, this is my service code,

public class EchoService extends AbstractService {

@PostConstruct
public void init() {
System.out.println("Echo Service Initialized: CometD init");
}

public EchoService(BayeuxServer bayeux) {
super(bayeux, "message");
bayeux.createIfAbsent("/message/demo",
new ConfigurableServerChannel.Initializer() {
public void configureChannel(ConfigurableServerChannel channel) {
channel.addAuthorizer(GrantAuthorizer.GRANT_ALL);
}
});
bayeux.createIfAbsent("/service/message",
new ConfigurableServerChannel.Initializer() {
public void configureChannel(ConfigurableServerChannel channel) {
channel.addAuthorizer(GrantAuthorizer.GRANT_ALL);
}
});

addService("/message/demo", "processEcho");
addService("/service/message", "privateChat");
}

public void processEcho(ServerSession remote, Map<String, Object> data) {
try {
System.out.println("Start Process Echo");
getBayeux().getChannel("/message/demo").publish( remote, "Hello", null);
System.out.println("End Process Echo");
} catch (Exception exp) {
exp.printStackTrace();
}
}
/**
* @param source
* @param channel
* @param data
* @param messageId
*/
public void privateChat(ServerSession source, String channel, Map<String, Object> data, String messageId) {
String toUid = (String) data.get("msg");
String toChannel = (String) data.get("room");
System.out.println("channel:" + toChannel);
source.deliver(source, toChannel, "This is a test message!", messageId);
}

}

js code, This is only publish code.

var message = {};
message.user = "system";
message.msg = "my CometD Test";
function(message){
       $.cometd.publish('/service/message', {
            room : "/message/demo",
            user : message.user,
                msg : message.msg
       });
}

Can you help me?Thank very much!


在 2012年5月12日星期六UTC+8上午12时27分06秒,Simone Bordet写道:

Simone Bordet

unread,
May 12, 2012, 2:20:53 PM5/12/12
to cometd...@googlegroups.com
Hi,

On Sat, May 12, 2012 at 3:27 AM, gumutianqi <gumut...@gmail.com> wrote:
>
> Thanks, this is my service code,
>
> public class EchoService extends AbstractService {
>
> @PostConstruct
> public void init() {
> System.out.println("Echo Service Initialized: CometD init");
> }
>
> public EchoService(BayeuxServer bayeux) {

You're mixing the inherited style with the annotated style, not
recommended. Choose one only. See
http://docs.cometd.org/reference/#java_server_services.

> super(bayeux, "message");
> bayeux.createIfAbsent("/message/demo",
> new ConfigurableServerChannel.Initializer() {
> public void configureChannel(ConfigurableServerChannel channel) {
> channel.addAuthorizer(GrantAuthorizer.GRANT_ALL);
> }
> });
> bayeux.createIfAbsent("/service/message",
> new ConfigurableServerChannel.Initializer() {
> public void configureChannel(ConfigurableServerChannel channel) {
> channel.addAuthorizer(GrantAuthorizer.GRANT_ALL);
> }
> });
>
> addService("/message/demo", "processEcho");
> addService("/service/message", "privateChat");
> }
>
> public void processEcho(ServerSession remote, Map<String, Object> data) {
> try {
> System.out.println("Start Process Echo");
> getBayeux().getChannel("/message/demo").publish( remote, "Hello", null);

Should be:

getBayeux().getChannel("/message/demo").publish(getServerSession(),
"Hello", null);



> System.out.println("End Process Echo");
> } catch (Exception exp) {
> exp.printStackTrace();
> }
> }
> /**
> *
> * @param source
> * @param channel
> * @param data
> * @param messageId
> */
> public void privateChat(ServerSession source, String channel, Map<String,
> Object> data, String messageId) {
> String toUid = (String) data.get("msg");
> String toChannel = (String) data.get("room");
> System.out.println("channel:" + toChannel);
> source.deliver(source, toChannel, "This is a test message!", messageId);

Should be:

source.deliver(getServerSession(), toChannel, "This is a test message!", null);

古木天琪

unread,
May 13, 2012, 11:02:19 AM5/13/12
to cometd...@googlegroups.com
Thanks.
I use  annotated services , with jetty7 and springmvc3.1。

my web.xml code:
<servlet>
        <servlet-name>cometd</servlet-name>
        <servlet-class>org.cometd.java.annotation.AnnotationCometdServlet</servlet-class>
        <!-- <servlet-class>org.cometd.server.CometdServlet</servlet-class> -->
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>cometd</servlet-name>
        <url-pattern>/cometd/*</url-pattern>
    </servlet-mapping> 

and the spring-config.xml config:
<!-- Spring CometD config -->
    <bean id="nonLazyService" class="com.aosatech.j2ee.nms.service.nonLazyService" />
    <bean id="bayeux" class="org.cometd.server.BayeuxServerImpl" init-method="start" destroy-method="stop">
        <property name="options">
            <map>
                <entry key="logLevel" value="3" />
                <entry key="timeout" value="15000" />
            </map>
        </property>
    </bean>
    <bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
   <property name="attributes">
    <map>
    <entry key="org.cometd.bayeux">
    <ref local="bayeux" />                
    </entry>            
    </map>        
   </property>    
    </bean>
    <bean id="EchoService" class="com.aosatech.j2ee.nms.service.EchoService" lazy-init="true">
        <constructor-arg><ref local="bayeux" /></constructor-arg>
        <constructor-arg><ref local="nonLazyService" /></constructor-arg>
    </bean>


EchoService.java:

@Log4j
@Service("echoService")
public class EchoService {

@Inject
private BayeuxServer server;

@Session
private ServerSession serverSession;
@PostConstruct
void init() {
server.addListener(new BayeuxServer.SessionListener() {
@Override
public void sessionRemoved(ServerSession session, boolean timeout) {
System.out.println("sessionRemoved!!!");
server.getChannel("/message").publish(serverSession, "disconnected !", null);
session.removeAttribute("user");
}
@Override
public void sessionAdded(ServerSession session) {
System.out.println("sessionAddd!!!");
session.setAttribute("user", server.getContext().getHttpSessionAttribute("user"));
server.getChannel("/message").publish(serverSession, "connected !", null);
}
});
}
@Configure("/**")
void configure(ConfigurableServerChannel channel) {
channel.addAuthorizer(GrantAuthorizer.GRANT_ALL);
}

@Subscription("/message")
public void echo(Message message) {
log.debug(" Echo Message: " + message);
}
@Listener("/message")
void appendUser(ServerSession remote, ServerMessage.Mutable message) {
remote.setAttribute("user", "mutou");
System.out.println("my chatRoom!");
message.setData("[" + remote.getAttribute("user") + "] " + message.getData());
}
}

run the web application, the EchoService not works. My own log and "system.out" is not print.
I use jetty7 and the spring3.1mvc.
I see my spring config with cometD is error, bug I not found the error.

I'm so sorry, I distrub you. I like the cometD. I hope you can help me. 
Run cometD service on the jetty7 and spring3.1mvc.

In addition, I hope that the official website provide springmvc3.x and  annotated services examples code,
In this way, to make learming easier. Will have a lot of people use.

Thank very much.


2012/5/13 Simone Bordet <sbo...@intalio.com>

Simone Bordet

unread,
May 14, 2012, 4:59:20 AM5/14/12
to cometd...@googlegroups.com
Hi,
You do not really want to have both a @Listener and a @Subscriber for
the same channel.
Use either, not both.

> run the web application, the EchoService not works. My own log and
> "system.out" is not print.

Where is your client code ?

古木天琪

unread,
May 14, 2012, 5:27:15 AM5/14/12
to cometd...@googlegroups.com
Thanks,  Bordet .

I seem to have run successfully.
I removed the spring-config.xml configuration.
But the inexplicable emergence of: sessionRemoved operation. 
I would now like to to use cometD in springmvc controller inside, how can I use it.

Here is my code:
EchoService code:
@Service
public class EchoService {

@Inject
private BayeuxServer bayeux;

@Session
private ServerSession serverSession;

@PostConstruct
void init() {
System.out.println("Echo Service Initialized!!!");
bayeux.addListener(new BayeuxServer.SessionListener() {
@Override
public void sessionRemoved(ServerSession session, boolean timeout) {
String user = (String) session.getAttribute("user");
session.deliver(serverSession, "/message/demo", user + "disconnected !", null);
session.removeAttribute("user");
}
@Override
public void sessionAdded(ServerSession session) {
session.setAttribute("user", bayeux.getContext().getHttpSessionAttribute("user"));
String user = (String) session.getAttribute("user");
session.deliver(serverSession, "/message/demo", user + "disconnected !", null);
}
});
}

@Configure("/**")
void configure(ConfigurableServerChannel channel) {
channel.addAuthorizer(GrantAuthorizer.GRANT_NONE);
}
@Configure({"/message/**", "/service/**"})
void configureMsg(ConfigurableServerChannel channel) {
channel.addAuthorizer(GrantAuthorizer.GRANT_ALL);
}
@Listener("/service/message")
void deliverReceive(ServerSession remote, ServerMessage.Mutable message){
@SuppressWarnings("unchecked")
Map<String, String> data = (Map<String, String>) message.getData();
String userName = (String) remote.getAttribute("user");
remote.deliver(serverSession, data.get("room"), userName + " 说:" +data.get("msg"), null);
}
}

web.xml code:
<filter> 
        <filter-name>continuation</filter-name> 
        <filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class> 
    </filter> 
    <filter-mapping> 
        <filter-name>continuation</filter-name> 
        <url-pattern>/cometd/*</url-pattern> 
    </filter-mapping> 
    
    <servlet>
        <servlet-name>cometd</servlet-name>
        <!-- <servlet-class>org.cometd.server.CometdServlet</servlet-class>  -->
        <servlet-class>org.cometd.java.annotation.AnnotationCometdServlet</servlet-class>
        <init-param>
        <param-name>timeout</param-name>
        <param-value>30000</param-value>
   </init-param>
   <init-param>
       <param-name>logLevel</param-name>
       <param-value>3</param-value>
   </init-param>
   <init-param>
       <param-name>services</param-name>
       <param-value>com.aosatech.j2ee.nms.service.EchoService</param-value>
   </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>cometd</servlet-name>
        <url-pattern>/cometd/*</url-pattern>
    </servlet-mapping>

I used the above code, run successfully cometD. You think is right?
1.  I would now like to to use cometD in springmvc controller inside, how can I use it?

For example: I query the database and return some data to the page in this controller.
@Controller
@RequestMapping(value="/user")
public class UserController {
     @RequestMapping(value="/test", method={RequestMethod.GET})
public String test(Model model){
//coding ....use cometD EchoService?
                //EchoService.publishReceive(? , ?);  //how to write this parameter
}
}

2.  I‘s provided using lombok.jar use in EchoService, the @Log4j is not print log. is bug?

Thank you very much for your help


2012/5/14 Simone Bordet <sbo...@intalio.com>

Simone Bordet

unread,
May 14, 2012, 5:43:20 AM5/14/12
to cometd...@googlegroups.com
Hi,

On Mon, May 14, 2012 at 11:27 AM, 古木天琪 <gumut...@gmail.com> wrote:
> 1.  I would now like to to use cometD in springmvc controller inside, how
> can I use it?
>
> For example: I query the database and return some data to the page in this
> controller.
> @Controller
> @RequestMapping(value="/user")
> public class UserController {
>      @RequestMapping(value="/test", method={RequestMethod.GET})
> public String test(Model model){
> //coding ....use cometD EchoService?
>                 //EchoService.publishReceive(? , ?);  //how to write this
> parameter
> }
> }

Not sure why you removed the Spring config. If you keep it, you can
inject the EchoService into this controller, which I think it's the
best way to go.

> 2.  I‘s provided using lombok.jar use in EchoService, the @Log4j is not
> print log. is bug?

Not a CometD bug for sure, we do not use @Log4j annotations.

古木天琪

unread,
May 14, 2012, 5:56:09 AM5/14/12
to cometd...@googlegroups.com
this is my Spring config:

<!-- Spring CometD config -->
    <bean id="nonLazyService" class="com.aosatech.j2ee.nms.service.nonLazyService" />
    <bean id="bayeux" class="org.cometd.server.BayeuxServerImpl" init-method="start" destroy-method="stop">
        <property name="options">
            <map>
                <entry key="logLevel" value="3" />
                <entry key="timeout" value="15000" />
            </map>
        </property>
    </bean>
    <bean id="echoService" class="com.aosatech.j2ee.nms.service.EchoService">
        <constructor-arg><ref local="bayeux" /></constructor-arg>
        <constructor-arg><ref local="nonLazyService" /></constructor-arg>
    </bean>
    <bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
   <property name="attributes">
    <map>
    <entry key="org.cometd.bayeux">
    <ref local="bayeux" />                
    </entry>            
    </map>        
   </property>    
    </bean>

I reserve Spring conf, I do not know nonLazyService what the use.
So, how to the write the Spring Controller?

2012/5/14 Simone Bordet <sbo...@intalio.com>

Simone Bordet

unread,
May 14, 2012, 6:00:34 AM5/14/12
to cometd...@googlegroups.com
Hi,
I am not that familiar with Spring MVC, so should perhaps asks in Spring forums.

I think you can just @AutoWire your EchoService in your Spring
controller, but I never tried.

古木天琪

unread,
May 14, 2012, 6:08:02 AM5/14/12
to cometd...@googlegroups.com
Thanks
I will then try to run in springmvc with cometD .
I will tell you my test results, and then help others.

One day, to obtain I think I could create a cometD the Chinese community. 
Help more people use cometD.


2012/5/14 Simone Bordet <sbo...@intalio.com>

gumutianqi

unread,
May 15, 2012, 5:06:31 AM5/15/12
to cometd...@googlegroups.com
If I were in the other servlet use the EchoService the then serverSession how to obtain it?

在 2012年5月14日星期一UTC+8下午6时00分34秒,Simone Bordet写道:

Simone Bordet

unread,
May 15, 2012, 5:15:36 AM5/15/12
to cometd...@googlegroups.com
Hi,

On Tue, May 15, 2012 at 11:06 AM, gumutianqi <gumut...@gmail.com> wrote:
> If I were in the other servlet use the
> EchoService the then serverSession how to obtain it?

Not sure I understand, however: you have the problem of obtaining the
EchoService reference in another servlet.

You have several solutions for this:

A) use Spring injection
B) store the EchoService instance in the ServletContext as an
attribute, and retrieve it where you need it.

There are others, but these two are the ones I recommend.

Solution A is if you're using annotated services with Spring.
Solution B is if you're using inherited services.

Have you tried to @Autowire the EchoService in Spring MVC controller ?

古木天琪

unread,
May 15, 2012, 5:24:18 AM5/15/12
to cometd...@googlegroups.com
I remove spring config ,use annotated services at EchoService
@Named
@Singleton
@Lazy

I use @Autowire the EchoService in Spring mvc controller.
bug have a error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.aosatech.j2ee.nms.service.EchoService com.aosatech.j2ee.nms.web.controller.UserController.echoService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'echoService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.cometd.bayeux.server.BayeuxServer com.aosatech.j2ee.nms.service.EchoService.bayeux; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.cometd.bayeux.server.BayeuxServer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:241)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:463)
at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:283)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:771)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1222)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:676)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:455)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:36)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:183)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:491)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:138)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:142)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:53)
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:604)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:535)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:398)
at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:332)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:118)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:552)
at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:227)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:63)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:53)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:91)
at org.eclipse.jetty.server.Server.doStart(Server.java:260)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1215)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:457)
at org.eclipse.jetty.start.Main.start(Main.java:602)
at org.eclipse.jetty.start.Main.main(Main.java:82)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.aosatech.j2ee.nms.service.EchoService com.aosatech.j2ee.nms.web.controller.UserController.echoService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'echoService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.cometd.bayeux.server.BayeuxServer com.aosatech.j2ee.nms.service.EchoService.bayeux; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.cometd.bayeux.server.BayeuxServer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
... 57 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'echoService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.cometd.bayeux.server.BayeuxServer com.aosatech.j2ee.nms.service.EchoService.bayeux; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.cometd.bayeux.server.BayeuxServer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:269)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 59 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.cometd.bayeux.server.BayeuxServer com.aosatech.j2ee.nms.service.EchoService.bayeux; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.cometd.bayeux.server.BayeuxServer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
... 72 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.cometd.bayeux.server.BayeuxServer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 74 more


2012/5/15 Simone Bordet <sbo...@intalio.com>

Simone Bordet

unread,
May 15, 2012, 5:34:08 AM5/15/12
to cometd...@googlegroups.com
Hi,

On Tue, May 15, 2012 at 11:24 AM, 古木天琪 <gumut...@gmail.com> wrote:
> I remove spring config ,use annotated services at EchoService
> @Named
> @Singleton
> @Lazy
>
> I use @Autowire the EchoService in Spring mvc controller.
> bug have a error:
>
> org.springframework.beans.factory.BeanCreationException: Error creating bean
> with name 'userController': Injection of autowired dependencies failed;
> nested exception is org.springframework.beans.factory.BeanCreationException:
> Could not autowire field: private com.aosatech.j2ee.nms.service.EchoService
> com.aosatech.j2ee.nms.web.controller.UserController.echoService; nested
> exception is org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'echoService': Injection of autowired dependencies
> failed; nested exception is
> org.springframework.beans.factory.BeanCreationException: Could not autowire
> field: private org.cometd.bayeux.server.BayeuxServer
> com.aosatech.j2ee.nms.service.EchoService.bayeux; nested exception is

Your error is below:

> org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching
> bean of type [org.cometd.bayeux.server.BayeuxServer] found for dependency:
> expected at least 1 bean which qualifies as autowire candidate for this
> dependency. Dependency annotations: {@javax.inject.Inject()}

It is all written above, you have a Spring configuration problem.

Really, you can't expect us to help without knowing your exact code
and configuration.
Please try to spend a bit more time understanding Spring and how it works...
None of your problems is a CometD problem, so far.

The first Google hit for "spring mvc inject bean" is:
http://stackoverflow.com/questions/3735762/how-do-you-inject-a-bean-into-a-controller-class,
which like I said, allows you to autowire the EchoService.

Figure this out, and you'll see that CometD will work.

古木天琪

unread,
May 15, 2012, 5:41:01 AM5/15/12
to cometd...@googlegroups.com
if I use the Spring config,

hava a this error:

Error creating bean with name 'echoService' defined in class path resource [spring-config.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)


this is my spring config code:

<!-- Spring CometD config -->
    <bean id="nonLazyService" class="com.aosatech.j2ee.nms.service.nonLazyService" />
    <bean id="bayeux" class="org.cometd.server.BayeuxServerImpl" init-method="start" destroy-method="stop">
        <property name="options">
            <map>
                <entry key="logLevel" value="3" />
                <entry key="timeout" value="30000" />
            </map>
        </property>
    </bean>
    <bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
   <property name="attributes">
    <map>
    <entry key="org.cometd.bayeux">
    <ref local="bayeux" />                
    </entry>            
    </map>        
   </property>    
    </bean>
    <bean id="echoService" class="com.aosatech.j2ee.nms.service.EchoService" lazy-init="true" >
        <constructor-arg><ref local="bayeux" /></constructor-arg>
        <constructor-arg><ref local="nonLazyService" /></constructor-arg>
    </bean>

2012/5/15 Simone Bordet <sbo...@intalio.com>

Simone Bordet

unread,
May 15, 2012, 5:45:26 AM5/15/12
to cometd...@googlegroups.com
Hi,

On Tue, May 15, 2012 at 11:41 AM, 古木天琪 <gumut...@gmail.com> wrote:
> if I use the Spring config,
>
> hava a this error:
>
> Error creating bean with name 'echoService' defined in class path resource
> [spring-config.xml]: Could not resolve matching constructor (hint: specify
> index/type/name arguments for simple parameters to avoid type ambiguities)

The problem is written clearly above, in the error message.
Please google for it.
Reply all
Reply to author
Forward
0 new messages