Hi!
I have to develop a chat on a Tapestry5 app and I have to include WebSockets.
To do it i put the config below:
I create a ChatServlet class outside Tapestry5 packages
my.package.
chat -> ChatServlet
web.
pages
components
services
mixins
ChatServlet.java :
package mypackage.chat;
@ServerEndpoint(value = "/chat")
public class ChatServlet extends HttpServlet {
@OnOpen
public void onOpen(Session session) throws Exception {
…
@OnMessage
public void onMessage(Session session, String message) throws Exception
{
…
AppModule.java:
public static void contributeIgnoredPathsFilter(final Configuration<String>
configuration) {
configuration.add("/chat.*");
}
web.xml
<servlet>
<servlet-name>chat-servlet</servlet-name>
<servlet-class>mypackage.chat.ChatServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>chat-servlet</servlet-name>
<url-pattern>/chat</url-pattern>
</servlet-mapping>
And after to add this config, you can connect directly. With javascript is:
new WebSocket("ws://"+ baseUrl +"/chat”);
I hope the configuration for webapp helps you.
Regards
Carlos Montero Canabal
> El 7/6/2018, a las 8:10, Christopher Dodunski
> <[email protected]> escribió:
>
> Thanks Eugen, and where did you place the server-side class decorated with
> @ServerEndpoint("/ws")? Perhaps it doesn't matter whether it is placed in
> 'pages' or 'services', as Tomcat finds it regardless.
>
> Is it necessary to invoke new threads (multi-threading) within each of the
> methods decorated with @OnOpen, @OnClose, @OnMessage and @OnError, or does
> Tomcat automatically handle cases of multiple, simultaneous client
> connections?
>
> I found the below 'howto' on using Tomcat WebSockets, but the client side
> code is implemented in HTML and JavaScript, not Java. It would be useful
> to find some sample, client-side Java code for connecting and
> communicating via a Tomcat WebSocket.
>
> https://examples.javacodegeeks.com/enterprise-java/tomcat/apache-tomcat-websocket-tutorial/
>
> Regards,
>
> Chris.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>