当前位置: 首页>>代码示例>>Java>>正文


Java ProtocolDecoderException类代码示例

本文整理汇总了Java中org.apache.mina.filter.codec.ProtocolDecoderException的典型用法代码示例。如果您正苦于以下问题:Java ProtocolDecoderException类的具体用法?Java ProtocolDecoderException怎么用?Java ProtocolDecoderException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProtocolDecoderException类属于org.apache.mina.filter.codec包,在下文中一共展示了ProtocolDecoderException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: byOrderedParam

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
private Request byOrderedParam(int protocol, String message) throws ProtocolDecoderException {
	String argLength = message.substring(0, 2);
	message = message.substring(2);
	String[] msgs = message.split(Protocols.LINE_SPLIT, -1);
	if (msgs.length < 2) {
		throw new ProtocolDecoderException("error ordered param req");
	}
	Request req = GsonUtil.fromJson(msgs[0], Request.class);
	int len = Integer.parseInt(argLength);
	if (len > 0) {
		String[] params = new String[len];
		for (int i = 0; i < len; i++) {
			params[i] = msgs[i + 1];
		}
		req.setParamArray(params);
	}
	req.protocol = protocol;
	return req;
}
 
开发者ID:youtongluan,项目名称:sumk,代码行数:20,代码来源:MessageDeserializer.java

示例2: decodeBody

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
protected Object decodeBody(IoSession session, IoBuffer in) throws Exception {
	// 跳过消息头
	int nLen = in.getShort();// 包长(包括消息头)
	int cmdId = in.getShort();
	// 跳过 版本 预留3个字节
	in.skip(3);
	int bodyLen = nLen - MessageCodec.HEAD_LENGTH;
	byte[] bodys = new byte[bodyLen];
	in.get(bodys);

	Packet packet = Packet.parseFrom(bodys);
	if (cmdId != packet.getCmdId()) {
		log.warn("head CMDid {} != body CMDid {}", cmdId, packet.getCmdId());
		throw new ProtocolDecoderException("head CMDid " + cmdId + " != body CMDid " + packet.getCmdId());
	}
	return packet;
}
 
开发者ID:East196,项目名称:maker,代码行数:18,代码来源:ProtobufMessageDecoder.java

示例3: exceptionCaught

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
/**
 * 异常处理
 */
public void exceptionCaught(IoSession ioSession, Throwable cause) throws Exception {
	if (cause instanceof IOException) {
		log.info("IOException异常 session= " + ioSession, cause);
	} else if (cause instanceof ProtocolDecoderException) {
		log.error("关闭session由于协议解码异常:" + ioSession, cause);
		ioSession.close(true);
	} else {
		log.error("未知异常session= " + ioSession, cause);
	}
	UserSession session = (UserSession) ioSession.getAttribute("session");
	if (null != session) {
		StringBuffer logBuf = new StringBuffer(256);
		logBuf.append(
				"由于异常 session 关闭! userId=" + session.getUserId() + " ioSession=" + ioSession.getRemoteAddress());
		boolean bIsClose = ioSession.isClosing();
		boolean bIsConnect = ioSession.isConnected();
		session.close();
		logBuf.append(" isClosing:(" + bIsClose + "," + ioSession.isClosing() + ") isConnect:(" + bIsConnect + ","
				+ ioSession.isConnected() + ")\n");
		log.info(logBuf.toString());
	}
}
 
开发者ID:East196,项目名称:maker,代码行数:26,代码来源:MinaMessageHandler.java

示例4: exceptionCaught

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
@Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
       if (cause instanceof IOException) {
           // TODO Verify if there were packets pending to be sent and decide what to do with them
           Log.info("ConnectionHandler reports IOException for session: " + session, cause);
       }
       else if (cause instanceof ProtocolDecoderException) {
           Log.warn("Closing session due to exception: " + session, cause);
           
           // PIO-524: Determine stream:error message.
           final StreamError error;
           if (cause.getCause() != null && cause.getCause() instanceof XMLNotWellFormedException) {
           	error = new StreamError(StreamError.Condition.xml_not_well_formed);
           } else {
           	error = new StreamError(StreamError.Condition.internal_server_error);
           }
           
           final Connection connection = (Connection) session.getAttribute(CONNECTION);
           connection.deliverRawText(error.toXML());
           session.close();
       }
       else {
           Log.error("ConnectionHandler reports unexpected exception for session: " + session, cause);
       }
   }
 
开发者ID:igniterealtime,项目名称:Openfire-connectionmanager,代码行数:26,代码来源:ConnectionHandler.java

示例5: exceptionCaught

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
public void exceptionCaught(final FtpIoSession session,
        final Throwable cause) throws Exception {
    
    if(cause instanceof ProtocolDecoderException &&
            cause.getCause() instanceof MalformedInputException) {
        // client probably sent something which is not UTF-8 and we failed to
        // decode it
        
        LOG.warn(
                "Client sent command that could not be decoded: {}",
                ((ProtocolDecoderException)cause).getHexdump());
        session.write(new DefaultFtpReply(FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "Invalid character in command"));
    } else if (cause instanceof WriteToClosedSessionException) {
        WriteToClosedSessionException writeToClosedSessionException = 
            (WriteToClosedSessionException) cause;
        LOG.warn(
                        "Client closed connection before all replies could be sent, last reply was {}",
                        writeToClosedSessionException.getRequest());
        session.close(false).awaitUninterruptibly(10000);
    } else {
        LOG.error("Exception caught, closing session", cause);
        session.close(false).awaitUninterruptibly(10000);
    }


}
 
开发者ID:saaconsltd,项目名称:mina-ftpserver,代码行数:27,代码来源:DefaultFtpHandler.java

示例6: decode

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    if (buffer == null) {
        buffer = IoBuffer.allocate(256).setAutoExpand(true);
    }

    if (buffer.position() + in.remaining() > maxLength) {
        throw new ProtocolDecoderException("Received data exceeds " + maxLength + " byte(s).");
    }
    buffer.put(in);
    return this;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:ConsumeToEndOfSessionDecodingState.java

示例7: decode

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    boolean found = false;
    boolean finished = false;
    while (in.hasRemaining()) {
        byte b = in.get();
        if (!hasCR) {
            if (b == CR) {
                hasCR = true;
            } else {
                if (b == LF) {
                    found = true;
                } else {
                    in.position(in.position() - 1);
                    found = false;
                }
                finished = true;
                break;
            }
        } else {
            if (b == LF) {
                found = true;
                finished = true;
                break;
            }

            throw new ProtocolDecoderException("Expected LF after CR but was: " + (b & 0xff));
        }
    }

    if (finished) {
        hasCR = false;
        return finishDecode(found, out);
    }

    return this;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:40,代码来源:CrLfDecodingState.java

示例8: byJsonParam

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
private Request byJsonParam(int protocol, String message) throws ProtocolDecoderException {
	String[] msgs = message.split(Protocols.LINE_SPLIT, -1);
	if (msgs.length < 2) {
		throw new ProtocolDecoderException("error jsoned param req");
	}
	Request req = GsonUtil.fromJson(msgs[0], Request.class);
	req.setJsonedParam(msgs[1]);
	req.protocol = protocol;
	return req;
}
 
开发者ID:youtongluan,项目名称:sumk,代码行数:11,代码来源:MessageDeserializer.java

示例9: deserialize

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
public Object deserialize(int protocol, String message) throws ProtocolDecoderException {
	if (Protocols.hasFeature(protocol, Protocols.REQ_PARAM_JSON)) {
		return this.byJsonParam(protocol, message);
	}
	if (Protocols.hasFeature(protocol, Protocols.REQ_PARAM_ORDER)) {
		return this.byOrderedParam(protocol, message);
	}
	if (Protocols.hasFeature(protocol, Protocols.RESPONSE_JSON)) {
		return this.parseResponse(protocol, message);
	}
	throw new ProtocolDecoderException("error req protocol:" + Integer.toHexString(protocol));
}
 
开发者ID:youtongluan,项目名称:sumk,代码行数:13,代码来源:MessageDeserializer.java

示例10: doDecodeString

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
protected boolean doDecodeString(IoSession session, IoBuffer in, ProtocolDecoderOutput out)
		throws CharacterCodingException, ProtocolDecoderException {
	int pos = in.position();
	int protocol = in.getInt();
	int prefixLength = 0, maxDataLength = 0;
	if ((protocol & Protocols.ONE) != 0) {
		prefixLength = 1;
		maxDataLength = 0xFF;
	} else if ((protocol & Protocols.TWO) != 0) {
		prefixLength = 2;
		maxDataLength = 0xFFFF;
	} else if ((protocol & Protocols.FOUR) != 0) {
		prefixLength = 4;
		maxDataLength = Protocols.MAX_LENGTH;
	} else {
		throw new ProtocolDecoderException("error transport protocol," + Integer.toHexString(protocol));
	}
	if (in.prefixedDataAvailable(prefixLength, maxDataLength)) {
		String msg = in.getPrefixedString(prefixLength, charset.newDecoder());
		if (msg == null || msg.isEmpty()) {
			return true;
		}
		out.write(msgDeserializer.deserialize(protocol, msg));
		return true;
	}
	in.position(pos);
	return false;
}
 
开发者ID:youtongluan,项目名称:sumk,代码行数:29,代码来源:SumkProtocolDecoder.java

示例11: exceptionCaught

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
@Override
public void exceptionCaught(IoSession session, Throwable throwable) throws Exception
{
    if(throwable instanceof ProtocolDecoderException)
    {
        Throwable cause = ((ProtocolDecoderException) throwable).getCause();

        if(cause instanceof HttpException &&
            ((HttpException) cause).getStatusCode() == HttpStatus.CLIENT_ERROR_LENGTH_REQUIRED.code())
        {
            //Ignore - Icecast 2.4 sometimes doesn't send any headers with their HTTP responses.  Mina expects a
            //content-length for HTTP responses.
        }
        else
        {
            mLog.error("HTTP protocol decoder error", throwable);
            setBroadcastState(BroadcastState.TEMPORARY_BROADCAST_ERROR);
            disconnect();
        }
    }
    else
    {
        mLog.error("Broadcast error", throwable);
        setBroadcastState(BroadcastState.TEMPORARY_BROADCAST_ERROR);
        disconnect();
    }

    mConnecting.set(false);
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:30,代码来源:IcecastHTTPAudioBroadcaster.java

示例12: exceptionCaught

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
public void exceptionCaught(IoSession ioSession, Throwable cause) throws Exception {
    boolean disconnectNeeded = false;
    Session quickFixSession = findQFSession(ioSession);
    Throwable realCause = cause;
    if (cause instanceof ProtocolDecoderException && cause.getCause() != null) {
        realCause = cause.getCause();
    }
    String reason;
    if (realCause instanceof IOException) {
        if (quickFixSession != null && quickFixSession.isEnabled()) {
            reason = "Socket exception (" + ioSession.getRemoteAddress() + "): " + cause;
        } else {
            reason = "Socket (" + ioSession.getRemoteAddress() + "): " + cause;
        }
        disconnectNeeded = true;
    } else if (realCause instanceof CriticalProtocolCodecException) {
        reason = "Critical protocol codec error: " + cause;
        disconnectNeeded = true;
    } else if (realCause instanceof ProtocolCodecException) {
        reason = "Protocol handler exception: " + cause;
    } else {
        reason = cause.toString();
    }
    if (disconnectNeeded) {
        if (quickFixSession != null) {
            quickFixSession.disconnect(reason, true);
        } else {
            log.error(reason, cause);
            ioSession.close();
        }
    } else {
        log.error(reason, cause);
    }
}
 
开发者ID:fix-protocol-tools,项目名称:STAFF,代码行数:35,代码来源:AbstractIoHandler.java

示例13: decode

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
public void decode(IoSession session, IoBuffer in,
		ProtocolDecoderOutput out) throws Exception {
	if (in == null) {
		throw new ProtocolDecoderException("IoBuffer is null");
	}
	//
	byte[] buff = new byte[in.limit()];
	in.get(buff);
	out.write(buff);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:11,代码来源:HorseServiceImpl.java

示例14: exceptionCaught

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
@Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
       if (cause instanceof IOException) {
           // TODO Verify if there were packets pending to be sent and decide what to do with them
           Log.debug("ConnectionHandler: ",cause);
       }
       else if (cause instanceof ProtocolDecoderException) {
           Log.warn("Closing session due to exception: " + session, cause);
           session.close();
       }
       else {
           Log.error(cause.getMessage(), cause);
       }
   }
 
开发者ID:coodeer,项目名称:g3server,代码行数:15,代码来源:ConnectionHandler.java

示例15: exceptionCaught

import org.apache.mina.filter.codec.ProtocolDecoderException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * 
 * @see org.apache.mina.core.service.IoHandlerAdapter#exceptionCaught(org.apache.mina.core.session.IoSession,
 *      java.lang.Throwable)
 */
@Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
    super.exceptionCaught(session, cause);
    if (cause instanceof ProtocolDecoderException) {
        session.close(true);
    }
}
 
开发者ID:dinstone,项目名称:com.dinstone.rpc,代码行数:14,代码来源:MinaServerHandler.java


注:本文中的org.apache.mina.filter.codec.ProtocolDecoderException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。