users@tyrus.java.net

Re: Encoder/decoders in Client

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Sun, 17 Feb 2013 10:25:20 +0100

Try adding following method to your client endpoint:

         @WebSocketError
         public void handleError(Throwable throwable) {
             throwable.printStackTrace();

         }

and see whether it will be called.

Pavel

On 2/17/13 7:53 AM, Arun Gupta wrote:
> Client is defined as:
>
> @WebSocketClient(encoders = {MyMessageEncoder.class},
> decoders={MyMessageDecoder.class})
> public class MyClient {
> @WebSocketOpen
> public void onOpen(Session session) {
> System.out.println("Connected to endpoint: " +
> session.getRemote());
> try {
> MyMessage message = new MyMessage("{ \"foo\" : \"bar\"}");
> session.getRemote().sendObject(message);
> } catch (IOException | EncodeException ex) {
> Logger.getLogger(MyClient.class.getName()).log(Level.SEVERE, null, ex);
> }
> }
> //. . .
> }
>
> MyMessage is defined as:
>
> public class MyMessage {
>
> private JsonObject jsonObject;
>
> public MyMessage() {
> }
>
> public MyMessage(String string) {
> jsonObject = new JsonReader(new
> StringReader(string)).readObject();
> }
> //. . .
> }
>
> The above mentioned code works. But if { foo : "bar" } is used to
> initialize MyMessage in the client then neither an exception is
> reported on the client side nor the message is sent to the server.
>
> Bug ?
>
> Arun
>