Problem with REST client for Queues

247 views
Skip to first unread message

Murty, Sudarshan

unread,
Apr 26, 2013, 10:39:00 AM4/26/13
to haze...@googlegroups.com

Hi Hazelcast gurus,

I am trying to “offer” a string value into a Queue using a REST client and take() it from within a running java client.

With offer() and take() both in java, it works fine.

 

Exception I get in the blocking java client is:

Exception in thread "main" java.lang.ClassCastException: com.hazelcast.impl.ascii.rest.RestValue cannot be cast to java.lang.String

       at com.mhfi.notification.distribution.NotifTestClient.main(NotifTestClient.java:23)

 

The java client code that is blocking on the queue is:

    public static void main(String[] args) {

                                ClientConfig clientConfig = new ClientConfig();

                                clientConfig.addAddress("127.0.0.1:5701");

                                HazelcastClient client = HazelcastClient.newHazelcastClient(clientConfig);

                                IQueue<String> queue = client.getQueue("MyQueue");

                                System.out.println("Queue size: " + queue.size());

                               

                                try {

                                                for(;;) {

                                                                String qItem = queue.take();

                                                                System.out.println("Queue item: " + qItem);

                                                }

                                } catch (InterruptedException e) {

                                                // TODO Auto-generated catch block

                                                e.printStackTrace();

                                }

    }

 

The server sets up the queue like so:

                IQueue<String> queue = hInst.getQueue("MyQueue");

                queue.offer("Hello");

                queue.offer("World");

                System.out.println("Queue size: " + queue.size());

 

 

I am sending the REST request from chrome using the REST plugin as follows:

URL: http://localhost:5701/hazelcast/rest/queues/MyQueue

Method: POST

Headers: Content-Type: text/plain

Data: “HelloZZZ”

 

 

What am I doing wrong? Your help is really appreciated.

 

regards

- sudarshan

 

S&P Capital IQ Architecture

 

Everything should be made as simple as possible, but not simpler.

-- Albert Einstein

 



The information contained in this message is intended only for the recipient, and may be a confidential attorney-client communication or may otherwise be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, please be aware that any dissemination or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify us by replying to the message and deleting it from your computer. The McGraw-Hill Companies, Inc. reserves the right, subject to applicable local law, to monitor, review and process the content of any electronic message or information sent to or from McGraw-Hill e-mail addresses without informing the sender or recipient of the message. By sending electronic message or information to McGraw-Hill e-mail addresses you, as the sender, are consenting to McGraw-Hill processing any of your personal data therein.

Murty, Sudarshan

unread,
Apr 26, 2013, 11:06:00 AM4/26/13
to haze...@googlegroups.com

Here’s another observation – I am using Hazelcast v2.5:

Using REST for both ways works – ie - POST into Queue and GET from queue.

… the docs say use “You can offer a new item into the queue via HTTP POST and take and item from the queue via HTTP DELETE.

 

If I do a HTTP DELETE, the server throws this exception (all inside Hazelcast) :

WARNING: [10.143.3.178]:5701 [dev] String index out of range: -24

java.lang.StringIndexOutOfBoundsException: String index out of range: -24

       at java.lang.String.substring(String.java:1911)

       at com.hazelcast.impl.ascii.rest.HttpDeleteCommandProcessor.handle(HttpDeleteCommandProcessor.java:40)

       at com.hazelcast.impl.ascii.rest.HttpDeleteCommandProcessor.handle(HttpDeleteCommandProcessor.java:22)

       at com.hazelcast.impl.ascii.TextCommandServiceImpl$CommandExecutor.run(TextCommandServiceImpl.java:198)

       at com.hazelcast.impl.executor.ParallelExecutorService$ParallelExecutorImpl$ExecutionSegment.run(ParallelExecutorService.java:212)

       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

       at java.lang.Thread.run(Thread.java:722)

       at com.hazelcast.impl.ExecutorThreadFactory$1.run(ExecutorThreadFactory.java:38)

Murty, Sudarshan

unread,
Apr 26, 2013, 2:06:36 PM4/26/13
to haze...@googlegroups.com

Ok, I solved the original problem re: the ClassCastException this way, after getting a cue from googlegroups.

 

       IQueue<RestValue> qRest = client.getQueue("MyQueue");

       RestValue restValue = qRest.take();

       byte[] postedBytes = restValue.getValue();

       System.out.println(new String(postedBytes, "UTF-8"));

 

But the same queue “MyQueue” cannot now be used for both java clients as well as REST clients.

Now the java client throws the ClasscastException L

 

Is there a better way to do this w/o resorting to instanceOf or similar ?

Mustafa Sancar Koyunlu

unread,
Apr 30, 2013, 8:11:42 AM4/30/13
to haze...@googlegroups.com
Hi Sudarshan,
About your original problem, there is no other way right now. Your workaround is OK.

The second problem:
You are getting that exception because delete waits for timeout value(in seconds). 
Correct syntax




--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages