users@tyrus.java.net

Re: Encoder/decoders in Client

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Mon, 18 Feb 2013 09:18:21 +0100

On 2/17/13 4:19 PM, Arun Gupta wrote:
> 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 ?

where you would expect this exception to be caught? I might agree, but
there is nothing in the spec which would support this statement - all
runtime errors are handled by @WebSocketError annotated methods and
that's it.

What is currently missing on Tyrus part is better logging in regards to
message/exception severity - we are going to improve that a little.
Otherwise it's up to spec to come with something better if this
mechanism is not sufficient for some cases.

Pavel

>
> 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
>>>
>>
>