users@tyrus.java.net

Re: Encoder/decoders in Client

From: Arun Gupta <arun.p.gupta_at_oracle.com>
Date: Sun, 17 Feb 2013 07:19:19 -0800

Pavel,

Yes, handleError is appropriately called and throws the correct trace.

But I think the exception should still be thrown, at least if the
message is not sent to the endpoint. What do you think ?

Arun

On 2/17/13 1:25 AM, Pavel Bucek wrote:
> 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
>>
>

-- 
http://twitter.com/arungupta
http://blogs.oracle.com/arungupta