Package com.bj58.spat.gaea.server.core.convert

Examples of com.bj58.spat.gaea.server.core.convert.JsonConvert


    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!");
View Full Code Here


       
        Global global = Global.getSingleton();
        if(global != null){
          //判断当前服务启用权限认证
          if(global.getGlobalSecureIsRights()){
            SecureContext securecontext = global.getGlobalSecureContext(context.getChannel().getNettyChannel());
            bool = securecontext.isRights();
            if(bool){
              desKeyStr = securecontext.getDesKey();
            }
          }
        }
       
        if(desKeyStr != null){
View Full Code Here

    }
  }

  @Override
  public void filter(GaeaContext context) throws Exception {
    StopWatch sw = context.getStopWatch();
    Collection<PerformanceCounter> pcList = sw.getMapCounter().values();
    for(PerformanceCounter pc : pcList) {
      if(pc.getExecuteTime() > minRecordTime) {
        StringBuilder sbMsg = new StringBuilder();
        sbMsg.append(serviceName);
        sbMsg.append("--");
        sbMsg.append(pc.getKey());
        sbMsg.append("--time: ");
        sbMsg.append(pc.getExecuteTime());
       
        sbMsg.append(" [fromIP: ");
        sbMsg.append(sw.getFromIP());
        sbMsg.append(";localIP: ");
        sbMsg.append(sw.getLocalIP()+"]");
       
        udpClient.send(sbMsg.toString());
      }
    }
  }
View Full Code Here

public class JsonConvertTest extends TestCase {

  public void testConvertToBoolean() throws Exception {
    String jsonStr = JsonHelper.toJsonExt(new Boolean(true));

    Boolean actual = new JsonConvert().convertToBoolean(jsonStr);
    Boolean expected = new Boolean(true);
    junit.framework.Assert.assertEquals(expected, actual);

  }
View Full Code Here

  public void testConvertToByte() throws Exception {
    for (int i = 0; i < 256; i++) {
      String jsonStr = JsonHelper.toJsonExt(new Byte((byte) i));

      Byte actual = new JsonConvert().convertToByte(jsonStr);
      Byte expected = new Byte((byte) i);
      junit.framework.Assert.assertEquals(expected, actual);
    }

    TestEntity te = TestEntity.createInstrance();
    String jsonStr = JsonHelper.toJsonExt(te);
    JSONObject jsonObj = new JSONObject(jsonStr);

    Byte actual = new JsonConvert().convertToByte(jsonObj.get("fByte"));
    junit.framework.Assert.assertEquals(te.getFByte(), actual);
  }
View Full Code Here

  }

  public void testConvertToCharacter() throws Exception {
    for (int i = 0; i < 1; i++) {
      String jsonStr = JsonHelper.toJsonExt(new Character((char) 'a'));
      Character actual = new JsonConvert().convertToCharacter(jsonStr);
      Character expected = new Character((char) 'a');
      junit.framework.Assert.assertEquals(expected, actual);
    }

    TestEntity te = TestEntity.createInstrance();
    String jsonStr = JsonHelper.toJsonExt(te);
    JSONObject jsonObj = new JSONObject(jsonStr);

    Character actual = new JsonConvert().convertToCharacter(jsonObj
        .get("fCharacter"));
    junit.framework.Assert.assertEquals(te.getFCharacter(), actual);
  }
View Full Code Here

  }

  public void testConvertToDouble() throws Exception {
    String jsonStr = JsonHelper.toJsonExt(new Double(123.123D));

    Double actual = new JsonConvert().convertToDouble(jsonStr);
    Double expected = new Double(123.123D);
    junit.framework.Assert.assertEquals(expected, actual);
  }
View Full Code Here

  }

  public void testConvertToFloat() throws Exception {
    String jsonStr = JsonHelper.toJsonExt(new Float(123.123F));

    Float actual = new JsonConvert().convertToFloat(jsonStr);
    Float expected = new Float(123.123F);
    junit.framework.Assert.assertEquals(expected, actual);
  }
View Full Code Here

  }

  public void testConvertToInteger() throws Exception {
    String jsonStr = JsonHelper.toJsonExt(new Integer(123456));

    Integer actual = new JsonConvert().convertToInteger(jsonStr);
    Integer expected = new Integer(123456);
    junit.framework.Assert.assertEquals(expected, actual);
  }
View Full Code Here

  }

  public void testConvertToLong() throws Exception {
    String jsonStr = JsonHelper.toJsonExt(new Long(123456789012345L));

    Long actual = new JsonConvert().convertToLong(jsonStr);
    Long expected = new Long(123456789012345L);
    junit.framework.Assert.assertEquals(expected, actual);
  }
View Full Code Here

TOP

Related Classes of com.bj58.spat.gaea.server.core.convert.JsonConvert

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.