package com.shinemo.mpush.common.handler;


import com.shinemo.mpush.api.Constants;
import com.shinemo.mpush.api.Message;
import com.shinemo.mpush.api.MessageHandler;
import com.shinemo.mpush.api.connection.Connection;
import com.shinemo.mpush.api.exception.CryptoException;
import com.shinemo.mpush.api.protocol.Packet;

/**
 * Created by ohun on 2015/12/22.
 */
public abstract class BaseMessageHandler<T extends Message> implements MessageHandler {
    public abstract T decode(Packet packet, Connection connection);

    public abstract void handle(T message);

    public void handle(Packet packet, Connection connection) {
    	if(checkCrypto(packet)){
    		T t = decode(packet, connection);
            if (t != null) {
                handle(t);
            }
    	}
    }
    
    public boolean checkCrypto(Packet packet){
    	if(packet.hasFlag(Constants.CRYPTO_FLAG)){
    		return true;
    	}else{
    		throw new CryptoException("need crypto");
    	}
    }
}

@@ -41,48 +41,8 @@
 ;%0A%0A%0A
-import com.shinemo.mpush.api.Constants;%0A
 impo
@@ -75,16 +75,16 @@
 essage;%0A
+
 import c
@@ -176,64 +176,8 @@
 on;%0A
-import com.shinemo.mpush.api.exception.CryptoException;%0A
 impo
@@ -534,40 +534,12 @@
     
-%09if(checkCrypto(packet))%7B%0A
     
-%09%09
 T t 
@@ -576,20 +576,16 @@
         
-  
-  
 if (t !=
@@ -605,20 +605,16 @@
         
-    
 handle(t
@@ -628,211 +628,8 @@
     
-  
-  %7D%0A    %09%7D%0A    %7D%0A    %0A    public boolean checkCrypto(Packet packet)%7B%0A    %09if(packet.hasFlag(Constants.CRYPTO_FLAG))%7B%0A    %09%09return true;%0A    %09%7Delse%7B%0A    %09%09throw new CryptoException(%22need crypto%22);%0A    %09
 %7D%0A  

add http proxy