Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring boot + cometd , no handshake request. #865

Open
Lisa09Liu opened this issue Jun 5, 2019 · 10 comments

Comments

Projects
None yet
2 participants
@Lisa09Liu
Copy link

commented Jun 5, 2019

I try to use cometd in the spring boot version 1.5.13 and cometd is 3.0.9
Here is application.java code :

@SpringBootApplication
@ImportResource({
				 //webapp
				 "classpath:META-INF/realtime/pf-realtime-webapp-context.xml",
				 "classpath:WEB-INF/realtime/comet-config.xml",
				 "classpath:WEB-INF/realtime/webmvc-config.xml",
				 "classpath:pfGFIConfigSrvc.xml",
				 //core
	 			 "classpath:META-INF/realtime/pf-realtime-core-context.xml",
				 //security
				 "classpath:META-INF/realtime/pf-realtime-security-context.xml",
				//prime-locate
				 "classpath:META-INF/realtime/prime-locate-integration-context.xml",
				 "classpath:META-INF/realtime/prime-locate-jndi-context.xml",
				 //prime-locate-cometd
				 "classpath:META-INF/realtime/prime-locate-cometd-integration-context.xml",
				 "classpath:META-INF/realtime/prime-locate-cometd-jndi-context.xml",
				 //prime-notification
				 "classpath:META-INF/realtime/prime-notification-cometd-integration-context.xml",
				 "classpath:META-INF/realtime/prime-notification-cometd-jndi-context.xml",
				 //prime-query
				 "classpath:META-INF/realtime/prime-query-integration-context.xml",
				 "classpath:META-INF/realtime/prime-query-jndi-context.xml",
				 //prime-wire
				 "classpath:META-INF/realtime/prime-wire-integration-context.xml",
				 "classpath:META-INF/realtime/prime-wire-jndi-context.xml"
				 })
@ServletComponentScan
@ComponentScan
@EnableAutoConfiguration(exclude= { 
		DataSourceAutoConfiguration.class,
		JmsAutoConfiguration.class, 
		MongoAutoConfiguration.class, 
		MongoDataAutoConfiguration.class, 
		MultipartAutoConfiguration.class, 
		SecurityAutoConfiguration.class, 
		SecurityAutoConfiguration.class, 
		FallbackWebSecurityAutoConfiguration.class,
		OAuth2AutoConfiguration.class})
public class PFRealtimeServicesApplication extends SpringBootServletInitializer{

	private static final Logger logger = LoggerFactory.getLogger(PFRealtimeServicesApplication.class);
	
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(PFRealtimeServicesApplication.class);
	}
	
	public static void main(String[] args) {
		ENVUtils.registerEnvName("env"); 
	    ENVUtils.registerRunningSystem("REALTIME");
		logger.info("Enter Realtime services application.");
		SpringApplication.run(PFRealtimeServicesApplication.class,args);
	}
	
	@Override
	public void onStartup(ServletContext servletContext) {
		ServletRegistration.Dynamic cometdServlet = servletContext.addServlet("cometd", AnnotationCometDServlet.class);
		cometdServlet.addMapping("/cometd/*");
		cometdServlet.setAsyncSupported(true);
		cometdServlet.setLoadOnStartup(1);
		cometdServlet.setInitParameter("PrimeLocateCometDService", PrimeLocateCometDService.class.getName());
		cometdServlet.setInitParameter("PrimeNotificationCometDService", PrimeNotificationCometDService.class.getName());
	}
}

Here is a problem : /cometd/handshake can not be listen . I use tomcat not jetty. Could anyone know about spring boot with cometd ? Do I need to use comed 4.0.4 or something need to config ?

@sbordet

This comment has been minimized.

Copy link
Member

commented Jun 5, 2019

I obviously cannot reproduce your issue since it contains files and classes that are part of your project.
You do not even specify what error are you getting, no stack trace, nothing.
You state that "/cometd/handshake can not be listen" but you give no evidence.
Unless you provide a simple reproducible case it's difficult to help you.

There is a fully working example of Spring Boot 2 and CometD 4 in the documentation: https://docs.cometd.org/current/reference/#_java_server_services_integration_spring_boot.

@Lisa09Liu

This comment has been minimized.

Copy link
Author

commented Jun 5, 2019

@sbordet Sorry to make you confused, I just want to know is there must to use CometD 4 with spring boot ? Use CometD 3 is OK or not ?

@sbordet

This comment has been minimized.

Copy link
Member

commented Jun 5, 2019

@Lisa09Liu I did not try to use Spring Boot 1.x with CometD 3.0.x, but I don't see why it would not work. CometD is a standard web application written using the Servlet API, so it should work fine in any container or library - we just cannot test all the possible combinations.

@Lisa09Liu

This comment has been minimized.

Copy link
Author

commented Jun 6, 2019

@sbordet OK , thank you . I will try to use spring boot 1.5.13 with CometD 3.0.9.

@Lisa09Liu

This comment has been minimized.

Copy link
Author

commented Jun 6, 2019

@sbordet
Today the handshake request has been sent every 1 minute, the url is https://test/PrimeFinance/Realtime/cometd/handshake. But it throws 404.
However the url https://test/PrimeFinance/Realtime/login returns 200 and can return a token.
I use Spring Boot 1.5.13 with CometD 3.0.9 and Spring Security 4.2.6.
Here is no any exceptions and errors. I really don't know what's problem here.
Could you give me some suggestions about this , some directions are OK for me.
Thanks a lot !

@sbordet

This comment has been minimized.

Copy link
Member

commented Jun 6, 2019

Please have a look at the troubleshooting guide.
Enable DEBUG logging in both client and server and you should have additional information about what's going wrong.

Also, try to write a super-simple Spring Boot application with CometD, that does nothing else that start the CometD server.
If you get that running, then step by step you add your logic until you have a fully working application.

@Lisa09Liu

This comment has been minimized.

Copy link
Author

commented Jun 6, 2019

@sbordet OK Thanks !

@Lisa09Liu

This comment has been minimized.

Copy link
Author

commented Jun 11, 2019

@sbordet Good news my project cometd works well with spring boot . However , I have one more question , do you know how to use comdtd js with spring boot , like 'cometd-adapter.js' , I add these js into /src/main/resources/static/js. It seems doesn't work , when I send one message , no message will be returned. Do you know how configure cometd js with spring boot ?

@sbordet

This comment has been minimized.

Copy link
Member

commented Jun 11, 2019

Good news my project cometd works well with spring boot

Glad you made it work. Do you mind to share your experience here so that others that may have issues with Spring Boot will find the solution? What was the problem and how did you solve it?

What's cometd-adapter.js? It's not something that is provided by the CometD project.

@Lisa09Liu

This comment has been minimized.

Copy link
Author

commented Jun 12, 2019

My project use Spring Boot 1.5.19 with CometD 3.0.9 and Tomcat 8.5.37.
(1) @ImportResource import all the xml files to the Application.java
(2) Remove (in xml file)

                <bean id="websocketTransport" class="org.cometd.websocket.server.WebSocketTransport">
                    <constructor-arg ref="bayeux" />
                </bean>

(3)Application extends SpringBootServletInitializer implements ServletContextInitializer

       @Override
	public void onStartup(ServletContext servletContext) {
		ServletRegistration.Dynamic cometdServlet = servletContext.addServlet("cometd", 
                AnnotationCometDServlet.class);
		cometdServlet.addMapping("/cometd/*");
		cometdServlet.setAsyncSupported(true);
		cometdServlet.setLoadOnStartup(1);
	}

(4)pom.xml
Remove:

                        <dependency>
				<groupId>org.cometd.java</groupId>
				<artifactId>cometd-java-websocket-javax-server</artifactId>
				<version>3.0.9</version>
			</dependency>

Add:

                       <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>bayeux-api</artifactId>
        </dependency>

These are all I think will impact CometD with Spring Boot. Hope these will help someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.