1

In the specification Java API for WebSocket 1.0, also known as JSR-356, it says on page 16:

On Decoder implementations that have it, the implementation must use the willDecode() method on the decoder to determine if the Decoder will match the incoming message.

.. and on page 17:

If the Decoder implementation has the method, the implementation must use the willDecode() method on the decoder to determine if the Decoder will match the incoming message

Clearly then, it is optional for me as a developer to provide that method or not. However, if you look at the Java EE 7 API, the interface Decoder.Binary and Decoder.Text declares this method. Thus when I write a decoder class that implements one of these interfaces, then I must also provide an implementation for willDecode(). The way I see it, there's no free choice any more. Am I wrong?

Martin Andersson
  • 18,072
  • 9
  • 87
  • 115
  • 1
    The first quote is for server side and the second is for client. So there is no issue about server side. It is ambiguous sentence on the client side in page 17. I assume that you would need to implement `willDecode` since you must provide a way to specify if your decoder can decode for this endpoint and the `if ... has the method` I think means that the list of decoders is not empty. But my core assumption is that the english is bad in the doc and you are right the sentencing is ambiguous – Cratylus Jun 16 '13 at 09:42
  • The way I interpret the @ServerEndpoint decoder description makes it optional for the server too. Page 16 says `On Decoder implementations that have it [..]`. Thus it is not a requirement? You wrote that there's "no issue on the server side". Do you mean that for the server endpoint, willDecode() is a requirement? Whether or not it is required by either end point, the way the Java EE API works, both sides must provide a method implementation if one implements the interface. Anyways, I think you're on the right track here. You should refactor your comment to an answer and I'll accept it. – Martin Andersson Jun 16 '13 at 10:00
  • Oh and you might want to look into another "related" question I posted here: http://stackoverflow.com/q/17131946/1268003 – Martin Andersson Jun 16 '13 at 10:01
  • `on Decoder implementations that have it`. My interpretation is that `it` refers to an existing Decoder implementation (i.e. that a decoder is provided) rather than a specific method provided (in this case `willDecode`). But the english syntax is bad IMHO. – Cratylus Jun 16 '13 at 10:34

1 Answers1

-2

Yes. These are optional. Encode and Decode use for security purpose in data transmission.

Masudul
  • 21,823
  • 5
  • 43
  • 58
  • Okay nice, though the Java EE 7 API kind of makes it not optional since the interfaces declare this method. But I guess I can always return true. Still, there's a problem with GlassFish 4. He calls the willDecode() method twice in a row! See this question: http://stackoverflow.com/q/17131946/1268003 – Martin Andersson Jun 20 '13 at 11:58