Package com.bj58.spat.gaea.server.core.communication.http

Examples of com.bj58.spat.gaea.server.core.communication.http.KeyValue


    assertTrue(scs2.get(0) == scs2.get(1));
  }

  @Test
  public void TesteInt32() throws Exception {
    Serializer serializer = new Serializer();
    byte[] buffer = serializer.Serialize(123);
    assertNotNull(buffer);
    int num = (Integer) serializer.Derialize(buffer, Integer.class);
    assertEquals(123, num);
  }
View Full Code Here


    assertEquals(123, num);
  }

  @Test
  public void TestDate() throws Exception {
    Serializer serializer = new Serializer();
    Object data = new Date();
    byte[] buffer = serializer.Serialize(data);
    assertNotNull(buffer);
    Object obj = serializer.Derialize(buffer, Date.class);
    Object expect = data;
    assertEquals(expect, obj);
  }
View Full Code Here

    assertEquals(expect, obj);
  }

  @Test
  public void TestInt() throws Exception {
    Serializer serializer = new Serializer();
    Object data = (int) 32;
    byte[] buffer = serializer.Serialize(data);
    assertNotNull(buffer);
    Object obj = serializer.Derialize(buffer, int.class);
    Object expect = data;
    assertEquals(expect, obj);
  }
View Full Code Here

    assertEquals(expect, obj);
  }

  @Test
  public void SerizlizeSqlDate() throws Exception {
    Serializer serializer = new Serializer();
    Object data = new java.sql.Date((new Date()).getTime());
    byte[] buffer = serializer.Serialize(data);
    assertNotNull(buffer);
    Object obj = serializer.Derialize(buffer, java.sql.Date.class);
    Object expect = data;
    assertEquals(expect, obj);
  }
View Full Code Here

    assertEquals(expect, obj);
  }

  @Test
  public void SerizlizeSqlTimestamp() throws Exception {
    Serializer serializer = new Serializer();
    Object data = new java.sql.Timestamp((new Date()).getTime());
    byte[] buffer = serializer.Serialize(data);
    assertNotNull(buffer);
    Object obj = serializer.Derialize(buffer, java.sql.Timestamp.class);
    Object expect = data;
    assertEquals(expect, obj);
  }
View Full Code Here

    assertEquals(expect, obj);
  }

  @Test
  public void SerizlizeSqlTime() throws Exception {
    Serializer serializer = new Serializer();
    Object data = new java.sql.Time((new Date()).getTime());
    byte[] buffer = serializer.Serialize(data);
    assertNotNull(buffer);
    Object obj = serializer.Derialize(buffer, java.sql.Time.class);
    Object expect = data;
    assertEquals(expect, obj);
  }
View Full Code Here

*/
public class SerializerClassInit implements IInit {

  @Override
  public void init() {
    new Serializer();
  }
View Full Code Here

   * @return
   */
  private String getLogMsg(String msg) {
    StringBuilder sbLog = new StringBuilder();
    sbLog.append(msg);
    GaeaContext context = GaeaContext.getFromThreadLocal();
    if(context != null) {
      sbLog.append("--");
      sbLog.append("remoteIP:");
      sbLog.append(context.getChannel().getRemoteIP());
      sbLog.append("--remotePort:");
      sbLog.append(context.getChannel().getRemotePort());
    }
   
    return sbLog.toString();
  }
View Full Code Here

      public void messageReceived(Object obj) {
        if(context.getServerType() == ServerType.HTTP){
          httpThreadLocal.remove();
        }
        if(obj != null) {
          GaeaContext ctx = (GaeaContext)obj;
          ctx.getServerHandler().writeResponse(ctx);
        } else {
          logger.error("context is null!");
        }
      }
     
View Full Code Here

  @Override
  public void filter(GaeaContext context) throws Exception {
   
    Protocol protocol = context.getGaeaRequest().getProtocol();   
    if(protocol.getPlatformType() == PlatformType.Java && context.getServerType() == ServerType.TCP){//java 客户端支持权限认证
      GaeaResponse response = new GaeaResponse();
      Global global = Global.getSingleton();
      //是否启用权限认证
      if(Global.getSingleton().getGlobalSecureIsRights()){
        SecureContext sc = global.getGlobalSecureContext(context.getChannel().getNettyChannel());
        //判断当前channel是否通过认证
        if(!sc.isRights()){
          //没有通过认证
          if(protocol != null && protocol.getSdpEntity() instanceof HandclaspProtocol){
            SecureKey sk = new SecureKey();
            HandclaspProtocol handclaspProtocol = (HandclaspProtocol)protocol.getSdpEntity();
            /**
             * 接收 客户端公钥
             */
            if("1".equals(handclaspProtocol.getType())){
              sk.initRSAkey();
              //客户端发送公钥数据
              String clientPublicKey = handclaspProtocol.getData();
              if(null == clientPublicKey || "".equals(clientPublicKey)){
                logger.warn("get client publicKey warn!");
              }
              //java 客户端
              if(protocol.getPlatformType() == PlatformType.Java){
                //服务器生成公/私钥,公钥传送给客户端
                sc.setServerPublicKey(sk.getStringPublicKey());
                sc.setServerPrivateKey(sk.getStringPrivateKey());
                sc.setClientPublicKey(clientPublicKey);
                handclaspProtocol.setData(sk.getStringPublicKey());//服务器端公钥
              }
             
              protocol.setSdpEntity(handclaspProtocol);
              response.setResponseBuffer(protocol.toBytes());
              context.setGaeaResponse(response);
              this.setInvokeAndFilter(context);
              logger.info("send server publieKey sucess!");
            }
            /**
             * 接收权限文件
             */
            else if("2".equals(handclaspProtocol.getType())){
              //客户端加密授权文件
              String clientSecureInfo = handclaspProtocol.getData();
              if(null == clientSecureInfo || "".equals(clientSecureInfo)){
                logger.warn("get client secureKey warn!");
              }
              //授权文件客户端原文(服务器私钥解密)
              String sourceInfo = sk.decryptByPrivateKey(clientSecureInfo, sc.getServerPrivateKey());
              //校验授权文件是否相同
              //判断是否合法,如果合法服务器端生成DES密钥,通过客户端提供的公钥进行加密传送给客户端
              if(global.containsSecureMap(sourceInfo)){
                logger.info("secureKey is ok!");
                String desKey = StringUtils.getRandomNumAndStr(8);
                //设置当前channel属性
                sc.setDesKey(desKey);
                sc.setRights(true);
                handclaspProtocol.setData(sk.encryptByPublicKey(desKey, sc.getClientPublicKey()));
                protocol.setSdpEntity(handclaspProtocol);
                response.setResponseBuffer(protocol.toBytes());
                context.setGaeaResponse(response);
              }else{
                logger.error("It's bad secureKey!");
                this.ContextException(context, protocol, response, "授权文件错误!");
              }
View Full Code Here

TOP

Related Classes of com.bj58.spat.gaea.server.core.communication.http.KeyValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.