[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tomcat-user
Subject:    =?UTF-8?Q?Re=3A_Tomcat_throws_IllegalStateException_=E2=80=9CThe_remot?= =?UTF-8?Q?e_endpoint_was_in
From:       Farzad Panahi <farzad.panahi () gmail ! com>
Date:       2015-10-28 2:33:37
Message-ID: CACueeY0hJjM8WFEZ-ifOCqfaSuL-AZa_c8CEzsQQvQrKwEbONw () mail ! gmail ! com
[Download RAW message or body]

Thanks Mark for your quick response.

But how do I know the previous message is finished? RemoteEndpoint
does not expose the state.

On Tue, Oct 27, 2015 at 7:30 PM, Mark Thomas <markt@apache.org> wrote:
> On 27/10/2015 19:15, Farzad Panahi wrote:
>> Hi,
>>
>> I am using tomcat 8.0.23 to terminate my websocket connections. I have
>> the following code to take care of the incoming messages:
>>
>> @OnMessage
>> public void onMsg(Session session, byte[] request) {
>>         executorService.execute(() ->
>>                 session.getAsyncRemote().sendBinary(
>>                         ByteBuffer.wrap(getResponse(session,
>> request)), result -> {
>>                             if (!result.isOK()) {
>>                                 LOGGER.catching(result.getException());
>>                             }
>>                         }
>>                 ));
>> }
>>
>> But I get the following exception:
>>
>> Exception in thread "pool-6-thread-10160"
>> java.lang.IllegalStateException: The remote endpoint was in state
>> [BINARY_FULL_WRITING] which is an invalid state for called method
>>     at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine=
.checkState(WsRemoteEndpointImplBase.java:1148)
>>     at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine=
.binaryStart(WsRemoteEndpointImplBase.java:1101)
>>     at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendBytesByC=
ompletion(WsRemoteEndpointImplBase.java:152)
>>     at org.apache.tomcat.websocket.WsRemoteEndpointAsync.sendBinary(WsRe=
moteEndpointAsync.java:65)
>>
>> From what I understand from java doc, RemoteEndpoint.Async.sendBinary
>> should not throw IllegalStateException:
>>
>>> sendBinary void sendBinary(ByteBuffer data, SendHandler handler)
>>> Throws: IllegalArgumentException - if either the data or the handler ar=
e null.
>>
>> It is also good to note that RemoEndpoint.Basic (not
>> RemoteEndpoint.Async) has the following paragraph in java doc:
>>
>>> If the websocket connection underlying this RemoteEndpoint is busy send=
ing a  message when a call is made to send another one, for example if two =
threads  attempt to call a send method concurrently, or if a developer atte=
mpts to send a new message while in the middle of sending an existing one, =
the send method called while the connection is already busy may throw an Il=
legalStateException.
>>
>>
>> Is this expected behaviour from tomcat or a possible implementation bug?
>
> The behaviour is expected. You can't start a new message until the
> previous one has finished.
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic