Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6664917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:40:00+00:00 2026-05-26T02:40:00+00:00

I have a Java web application that uses CometD. The workflow is simple: I

  • 0

I have a Java web application that uses CometD. The workflow is simple:

  1. I have defined a service that acts upon receiving messages on channel “/service/hello”. This service expects a parameter “name”. Based on this it creates a channel named: "/"+message.getDataAsMap().get("name"). To this channel it attaches a callback method that will send back a message to all subscribers.
  2. The Javascript client (uses dojo) publishes a message to the channel
    “/service/hello” and subscribes to the channel whose name has sent
    to the “/service/hello” as parameter. Lets take an example:
....
    cometd.subscribe('/1234', function(message)
    {
                    //do smth on message received;
     });

    cometd.publish('/service/hello', { name: '1234' });
....

This works fine. Now ,what I want to achieve is the following: to have the Javascript clients only as subscribers and a Java client that does the publishing.
I have tried this using the examples given in the CometD2 documentation for Java Client API, but it doesn’t work as expected. It seems that the service is called but the messages aren’t seen by the Javascript consumers.

Is it possible to achieve this? Any ideas of what is wrong? Thanks.

Here is the code on the server side:

public class HelloService extends AbstractService {
    public HelloService(BayeuxServer bayeux)
    {
        super(bayeux, "hello");
        addService("/service/hello", "processHello");
    }

    public void processHello(ServerSession remote, Message message)
    {
        Map<String, Object> input = message.getDataAsMap();
        String name = (String)input.get("name");
        String channelId = "/"+name;
        addService(channelId, "processId");
        processId(remote, message);

    }

    public void processId(ServerSession remote, Message message)
    {
        Map<String, Object> input = message.getDataAsMap();
        String name = (String)input.get("name");
        int i = 0;
        Map<String, Object> output = new HashMap<String, Object>();
        while(i<1){
            i++;
            output.put("greeting", "Hello, " + name);
            remote.deliver(getServerSession(), "/"+name, output, null);
            try {
                Thread.sleep(1000);             } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();            }
        }
    } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:40:01+00:00Added an answer on May 26, 2026 at 2:40 am

    remote.deliver() sends the “answer” to the remote session (i.e. the client) that published on the service channel.

    You should publish an unsolicited message to a normal channel (which on the server side does not exist yet). So, you should write something like

    String channelName = "whatever - not beginning with /service";
    getBayeux().createIfAbsent(channelName);
    getBayeux().getChannel(channelName).publish(getServerSession(), output, null); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a java web service application that uses log4j to do logging. An
I have a web application that uses java applet defined in a <applet> tag.
I have a java web application that generates and displays graphical pictures based upon
I have a Java web application that uses a plugin architecture. I would like
I have a Java enterprise application that provides a web service, has a domain
We have a Java web application that uses Spring and Hibernate and has a
I have a Java web application that uses the SLF4J logging facade. To date,
I have a Flex/Java web application that uses Maven as a build tool. Currently,
We have a desktop application written in Java Swing that currently uses Java Web
I have a Java web application that currently uses Log4J for logging. I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.