org.apache.mina.filter.codec.ProtocolEncoderException Java Examples
The following examples show how to use
org.apache.mina.filter.codec.ProtocolEncoderException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SumkProtocolEncoder.java From sumk with Apache License 2.0 | 6 votes |
@Override public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { if (message == null) { return; } if (String.class.isInstance(message)) { encodeString(0, session, (String) message, out); return; } Class<?> clz = message.getClass(); for (SumkMinaEncoder encoder : this.encoders) { if (encoder.accept(clz)) { encoder.encode(session, message, out); return; } } throw new ProtocolEncoderException(message.getClass().getName() + " not support in ProtocolEncoder"); }
Example #2
Source File: SumkProtocolEncoder.java From sumk with Apache License 2.0 | 6 votes |
private static void putProtocol(int code, IoBuffer buffer, int prefixLength) throws ProtocolEncoderException { switch (prefixLength) { case 1: buffer.putInt(Protocols.ONE | code | Protocols.MAGIC); break; case 2: buffer.putInt(Protocols.TWO | code | Protocols.MAGIC); break; case 4: buffer.putInt(Protocols.FOUR | code | Protocols.MAGIC); break; default: throw new ProtocolEncoderException("error size"); } }
Example #3
Source File: LdapNetworkConnection.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Handle the exception we got. * * @param session The session we got the exception on * @param cause The exception cause * @throws Exception If we have had another exception */ @Override public void exceptionCaught( IoSession session, Throwable cause ) throws Exception { if ( LOG.isWarnEnabled() ) { LOG.warn( cause.getMessage(), cause ); } session.setAttribute( EXCEPTION_KEY, cause ); if ( cause instanceof ProtocolEncoderException ) { Throwable realCause = ( ( ProtocolEncoderException ) cause ).getCause(); if ( realCause instanceof MessageEncoderException ) { int messageId = ( ( MessageEncoderException ) realCause ).getMessageId(); ResponseFuture<?> response = futureMap.get( messageId ); response.cancel( true ); response.setCause( realCause ); } } session.closeNow(); }
Example #4
Source File: SumkProtocolEncoder.java From sumk with Apache License 2.0 | 5 votes |
public static void encodeString(int code, IoSession session, CharSequence message, ProtocolEncoderOutput out) throws CharacterCodingException, ProtocolEncoderException { code = code | Protocols.FORMAT_JSON; int size = message.length(); int prefixLength = size <= (Protocols.MAX_ONE / CHAR_BYTE) ? 1 : size <= (Protocols.MAX_TWO / CHAR_BYTE) ? 2 : 4; IoBuffer buffer = IoBuffer.allocate((int) (size * 1.5) + 10).setAutoExpand(true); putProtocol(code, buffer, prefixLength); buffer.putPrefixedString(message, prefixLength, Profile.UTF8.newEncoder()); buffer.flip(); out.write(buffer); }