CometD 2 Java Client Sample – open project in NetBeans based on Maven pom file, modify sources and run Java Based Comet Client

Lucas Jellema 1
0 0
Read Time:2 Minute, 18 Second

On the heels of previous articles that described setting up NetBeans (https://technology.amis.nl/blog/14661/first-experiences-and-getting-started-with-glassfish-3-1-and-netbeans-7-x-its-a-breeze), Tomcat 7 (https://technology.amis.nl/blog/14688/installing-tomcat-7-and-configuring-as-server-in-netbeans) and the CometD 2 environment (https://technology.amis.nl/blog/14709/running-cometd-2-examples-locally-on-tomcat-using-maven-and-netbeans), this article describes how I opened the Java Client Examples from the CometD project in NetBeans (creating a NetBeans project based on the Maven pom.xml included in the CometD distribution), made a few changes to the source and ran the sample from within NetBeans. Within minutes, the sample was running and ready for further manipulation.

The option to create a NetBeans project based on a pom.xml is very useful. The overall speed and responsiveness of NetBeans is also very pleasant.

The steps:

Start NetBeans.

From the File menu, pick the option Open project.

Image

 

Navigate to the directory where CometD was installed. Browse to [C:\java\]cometd-2.3.1\cometd-java. Notice how NetBeans recognizes and interprets the pom files.

Image

Select the cometd-java-examples directory/maven based project. Press Open project.

The project is now opened in NetBeans. All sources, configuration files and dependencies ready for inspection and manipulation.

Image

To see one of the samples in action – the Java Chat Client that will communicate in a Comet style fashion with users of the Web Based Chat Client – open the source file ConsoleChatClient.java in package org.cometd.examples.

Before we can meaningfully run the ConsoleChatClient, better first run Tomcat. Then check whether the chat demo is available – as well as the port number on which the Tomcat server is to be accessed:

Image

Here we learn that the Tomcat server is listening on port 8085 (configured in the Tomcat server.xml file) and that the chat application is accessible through the cometSamplesFromWAR context path.

Now open the ConsoleChatClient. Locate the line where the defaultURL is set and use http://host:port/applicationContextPath/cometd as the default URL. In my case that means: “http://localhost:8085/cometSamplesFromWAR/cometd

Image

Now we can run this class – through its main main method. The class will register a listener on the Chat channel. The initial messages seem a little unnerving, but it all turns out well:

Image

 

In the browser user Nick will see the Java Client entering the chat:

Image

After Nick types a welcome message, the console in NetBeans will read:

Image

Now respond from the console in NetBeans:

Image

And the response arrives promptly in the browser window:

Image

 

With the sources set up in NetBeans, nothing will stop us from further investigating the options available in the CometD framework.

About Post Author

Lucas Jellema

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director and Oracle Developer Champion. Solution architect and developer on diverse areas including SQL, JavaScript, Kubernetes & Docker, Machine Learning, Java, SOA and microservices, events in various shapes and forms and many other things. Author of the Oracle Press book Oracle SOA Suite 12c Handbook. Frequent presenter on user groups and community events and conferences such as JavaOne, Oracle Code, CodeOne, NLJUG JFall and Oracle OpenWorld.
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%
Next Post

Business Validation in Oracle SOA Suite 11g using Schematron

In a previous post I’ve explained the Schematron standard, how it works and how to use it. In the Oracle SOA Suite you can ‘Validate Semantic’ on the input (request) of a routing rule in a Mediator component by selecting a Schematron file. This is the Schemtron xml file in […]
%d bloggers like this: