@Override protected DecodingState finishDecode(final ByteBuffer readData, final ProtocolDecoderOutput out) throws Exception { LOG.debug("Returning SIP message with body..."); final SipMessage message = m_messageFactory.createSipMessage(m_headers, readData); out.write(message); return null; } }
@Override public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception { // Call finishDecode() first when a connection is closed. ProtocolDecoder decoder = getDecoder(session); ProtocolDecoderOutput decoderOut = getDecoderOut(session, nextFilter); try { decoder.finishDecode(session, decoderOut); } catch (Throwable t) { ProtocolDecoderException pde; if (t instanceof ProtocolDecoderException) { pde = (ProtocolDecoderException) t; } else { pde = new ProtocolDecoderException(t); } throw pde; } finally { // Dispose all. disposeEncoder(session); disposeDecoder(session); disposeDecoderOut(session); decoderOut.flush(); } nextFilter.sessionClosed(session); }
decoderOut.flush();
@Override protected DecodingState finishDecode(final ByteBuffer product, final ProtocolDecoderOutput out) throws Exception { final String reasonPhrase = product.getString(m_asciiDecoder); out.write(reasonPhrase); return null; } }
@Override protected DecodingState finishDecode(final ByteBuffer product, final ProtocolDecoderOutput out) throws Exception { final String version = product.getString(m_asciiDecoder); out.write(version); return null; } };
@Override protected DecodingState finishDecode(final boolean foundCrlf, final ProtocolDecoderOutput out) throws Exception { if (foundCrlf) { out.write(m_headers); // Reset the state. return null; } else { return new HeaderNameDecodingState(); } } }
@Override protected DecodingState finishDecode(final byte foundTerminator, final ByteBuffer product, final ProtocolDecoderOutput out) throws Exception { final String uri = product.getString(m_utf8Decoder); out.write(new URI(uri)); return new ReadSipVersionState(); } };
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception { if (!in.prefixedDataAvailable(4, maxObjectSize)) { return false; } out.write(in.getObject(classLoader)); return true; } }
@Override protected DecodingState finishDecode(final ByteBuffer readData, final ProtocolDecoderOutput out) throws Exception { // This copy is not ideal, but passing around ByteBuffers was // causing issues. final byte[] transactionId = MinaUtils.toByteArray(readData); m_log.debug("Read transaction id..."); if (this.m_messageLength > 0) { return new ReadBody(this.m_messageType, this.m_messageLength, transactionId); } else { m_log.debug("Handling empty body"); final StunMessage message = createMessage(this.m_messageType, transactionId, EMPTY_ATTRIBUTES); out.write(message); return null; } } }
@Override protected DecodingState finishDecode(final byte foundTerminator, final ByteBuffer product, final ProtocolDecoderOutput out) throws Exception { final String statusCodeString = product.getString(m_asciiDecoder); if (!NumberUtils.isNumber(statusCodeString)) { LOG.warn("Bad status code: "+statusCodeString); throw new IllegalArgumentException( "Bad status code: "+statusCodeString); } final Integer statusCode = Integer.decode(statusCodeString); out.write(statusCode); return new ReadResponseReasonPhraseState(); } }
@Override protected DecodingState finishDecode(final ByteBuffer readData, final ProtocolDecoderOutput out) throws Exception { if (readData.remaining() != m_length) { m_log.error("Read body of unexpected length." + "\nExpected length: "+m_length+ "\nRemaining length: "+readData.remaining()); } final TcpFrame message = new TcpFrame(readData); m_log.debug("Writing TCP Frame message to IoHandler..."); out.write(message); return null; } }
@Override protected DecodingState finishDecode(final List<Object> childProducts, final ProtocolDecoderOutput out) throws Exception { final Map<String, SipHeader> headers = (Map<String, SipHeader>) childProducts.get(0); final int length = SipMessageUtils.extractContentLength(headers); if (length > 0) { LOG.debug("Reading body with length: {}", length); return new ReadBodyState(headers, length); } else { LOG.debug("Returning SIP message with NO body..."); final SipMessage message = m_messageFactory.createSipMessage(headers, EMPTY_BODY); out.write(message); // We return null here to give back control to the outer // decoding state machine. return null; } } }
out.write(doubleCrlf); return null; case UNKNOWN:
@Override protected DecodingState finishDecode(final ByteBuffer readData, final ProtocolDecoderOutput out) throws Exception { if (readData.remaining() != m_length) { m_log.error("Read body of unexpected length." + "\nExpected length: "+m_length+ "\nRemaining length: "+readData.remaining()); } final StunAttributesFactory factory = new StunAttributesFactoryImpl(); // This decodes the entire body into an attributes map. final Map<StunAttributeType, StunAttribute> attributes = factory.createAttributes(readData); final StunMessage message = createMessage(this.m_type, this.m_transactionId, attributes); out.write(message); return null; } }
@Override protected DecodingState finishDecode(final byte terminator, final ByteBuffer product, final ProtocolDecoderOutput out) throws Exception { final SipMessageType messageType = determineMessageType(terminator, product); LOG.debug("Found message type: {}", messageType); out.write(messageType); switch (messageType) { case SIP_2_0: return new ReadResponseStatusCodeState(); case REGISTER: return new ReadRequestUriState(); case INVITE: return new ReadRequestUriState(); case DOUBLE_CRLF: // Read the final LF CR LF return new ReadLfCrlfDecodingState(); case UNKNOWN: // Maybe it's a method we don't know about? Assume it's // some sort of request and process it as such. return new ReadRequestUriState(); default: return new ReadRequestUriState(); } }
buf.limit(buf.limit() - matchCount); try { out.write(buf.getString(ctx.getDecoder())); } finally { buf.clear();
buf.limit(buf.limit() - matchCount); try { out.write(buf.getString(ctx.getDecoder())); } finally { buf.clear();