Package com.bj58.spat.gaea.protocol.sfp.v1

Examples of com.bj58.spat.gaea.protocol.sfp.v1.Protocol


        List<KeyValuePair> listPara = new ArrayList<KeyValuePair>();
        for (Parameter p : paras) {
            listPara.add(new KeyValuePair(p.getSimpleName(), p.getValue()));
        }
        RequestProtocol requestProtocol = new RequestProtocol(typeName, methodName, listPara);
        Protocol sendP = new Protocol(createSessionId(),
            (byte) config.getServiceid(),
            SDPType.Request,
            CompressType.UnCompress,
            config.getProtocol().getSerializerType(),
            PlatformType.Java,
            requestProtocol);
       
        Protocol receiveP = null;
        Server server = null;
       
        for(int i = 0; i <= count; i++){
          server = dispatcher.GetServer();
            if (server == null) {
                logger.error("cannot get server");
                throw new Exception("cannot get server");
            }
            try{
              receiveP = server.request(sendP);
              break;
            } catch(IOException io){
              if(count == 0 || i == ioreconnect){
                throw io;
              }
              if(i < count && i < ioreconnect) {
                logger.error(server.getName()+" server has IOException,system will change normal server!");
                continue;
              }
            } catch(RebootException rb){
              this.createReboot(server);
              if(count == 0 || i == ioreconnect){
                throw new IOException("connect fail!");
              }
              if(i < count && i < ioreconnect) {
                logger.error(server.getName()+" server has reboot,system will change normal server!");
                continue;
              }
            }catch(TimeoutException te){
              if(count == 0 || i == requestTime){
                throw new TimeoutException("Receive data timeout or error!");
              }
              if(i < count && i < requestTime) {
                logger.error(server.getName()+" server has TimeoutException,system will change normal server!");
                continue;
              }
            } catch (Throwable ex){
              logger.error("invoke other Exception", ex);
              throw ex;
            }
      }
       
        if(receiveP == null){
          throw new Exception("userdatatype error!");
        }
       
        if (receiveP.getSDPType() == SDPType.Response) {
            ResponseProtocol rp = (ResponseProtocol)receiveP.getSdpEntity();
            logger.debug("invoke time:" + (System.currentTimeMillis() - watcher) + "ms");
            return new InvokeResult(rp.getResult(), rp.getOutpara());
        } else if(receiveP.getSDPType() == SDPType.Reset){ //服务重启
          logger.info(server.getName()+" server is reboot,system will change normal server!");
          this.createReboot(server);
          return invoke(returnType, typeName, methodName, paras);
        }else if (receiveP.getSDPType() == SDPType.Exception) {
            ExceptionProtocol ep = (ExceptionProtocol)receiveP.getSdpEntity();
            throw ThrowErrorHelper.throwServiceError(ep.getErrorCode(), ep.getErrorMsg());
        } else {
            throw new Exception("userdatatype error!");
        }
    }
View Full Code Here


     * @param data
     * @return Protocol
     * @throws Exception
     */
    public Protocol createProtocol(HandclaspProtocol hp) throws Exception{
      Protocol sendRightsProtocol = new Protocol(createSessionId(),
            (byte) config.getServiceid(),
            SDPType.Request,
            CompressType.UnCompress,
            config.getProtocol().getSerializerType(),
            PlatformType.Java,
View Full Code Here

              if(socket != null){
                socket.dispose();
              }
            }
            byte[] buffer = socket.receive(p.getSessionID(), currUserCount);
            Protocol result = Protocol.fromBytes(buffer,socket.isRights(),socket.getDESKey());
            if (this.state == ServerState.Testing) {
                relive();
            }
            return result;
        } catch (IOException ex) {
View Full Code Here

         
        //----发送客户端公钥去服务器端、并获取服务器端公钥--start---------------------
        SecureKey sk = new SecureKey();//生成客户端公/私 钥     
        ServiceProxy proxy = ServiceProxy.getProxy(serviceConfig.getServicename());
        HandclaspProtocol handclaspProtocol = new HandclaspProtocol("1",sk.getStringPublicKey());
        Protocol publicKeyProtocol = proxy.createProtocol(handclaspProtocol);
         
        try {
          scoket.registerRec(publicKeyProtocol.getSessionID());
          scoket.send(publicKeyProtocol.toBytes());//过程2
          logger.info("send client publicKey sucess!");
        } finally {
          //scoket.dispose();
        }
           
        handclaspProtocol = null;
        /**
        * 过程3,接收服务器端生成公钥
        */
        byte[] receivePublicBuffer = scoket.receive(publicKeyProtocol.getSessionID(), server.getCurrUserCount());
        if(null == receivePublicBuffer){
          logger.warn("获取服务器公钥失败!");
            return false;
        }
           
        Protocol serverPublicProtocol = publicKeyProtocol.fromBytes(receivePublicBuffer);
        HandclaspProtocol _handclaspProtocol = null;
           
        if (serverPublicProtocol.getSDPType() == SDPType.Handclasp) {
          _handclaspProtocol = (HandclaspProtocol)serverPublicProtocol.getSdpEntity();
            logger.debug("get server publicKey time:" + (System.currentTimeMillis() - startTime) + "ms");
               
        } else if (serverPublicProtocol.getSDPType() == SDPType.Exception) {
            ExceptionProtocol ep = (ExceptionProtocol)serverPublicProtocol.getSdpEntity();
            throw ThrowErrorHelper.throwServiceError(ep.getErrorCode(), ep.getErrorMsg());
        } else if(serverPublicProtocol.getSDPType() == SDPType.Reset){
          throw new RebootException("this server is reboot!");
        } else {
            throw new Exception("userdatatype error!");
        }
           
        logger.info("receive server publicKey sucess!");
        publicKeyProtocol = null;
           
        String keyInfo = serviceConfig.getSecureKey().getInfo();//授权文件
        if(null == keyInfo || "".equals(keyInfo)){
          logger.warn("获取授权文件失败!");
           return false;
        }
           
        String ciphertext = sk.encryptByPublicKeyString(keyInfo, _handclaspProtocol.getData());
        _handclaspProtocol = null;
        serverPublicProtocol = null;
        //----发送客户端公钥去服务器端、并获取服务器端公钥--end---------------------
        //---发送授权文件到服务器端认证--------------------start-------------------------------
        HandclaspProtocol handclaspProtocol_ = new HandclaspProtocol("2",ciphertext);
        Protocol protocol_mw = proxy.createProtocol(handclaspProtocol_);
         
        try {
          scoket.registerRec(protocol_mw.getSessionID());
          scoket.send(protocol_mw.toBytes());//过程4
          logger.info("send keyInfo sucess!");
        } finally {
            //scoket.dispose();
        }
           
        handclaspProtocol_ = null;
        /**
         * 过程5
         * 获取由客户端公钥加密后的DES密钥
         */
        byte [] receiveDESKey = scoket.receive(protocol_mw.getSessionID(), server.getCurrUserCount());
        if(null == receiveDESKey){
          logger.warn("获取DES密钥失败!");
          return false;
        }
        logger.info("receive DESKey sucess!");
          
        HandclaspProtocol handclaspProtocol_mw = null;
        Protocol serverDesKeyProtocol = Protocol.fromBytes(receiveDESKey);
        if (serverDesKeyProtocol.getSDPType() == SDPType.Handclasp) {
          handclaspProtocol_mw = (HandclaspProtocol)serverDesKeyProtocol.getSdpEntity();
        } else if (serverDesKeyProtocol.getSDPType() == SDPType.Exception) {
          ExceptionProtocol ep = (ExceptionProtocol)serverDesKeyProtocol.getSdpEntity();
            throw ThrowErrorHelper.throwServiceError(ep.getErrorCode(), ep.getErrorMsg());
        } else if(serverDesKeyProtocol.getSDPType() == SDPType.Reset){
          throw new RebootException("this server is reboot!");
        } else {
          throw new Exception("userdatatype error!");
        }
       
View Full Code Here

      }
     
      if(desKeyStr != null){
        desKeyByte = desKeyStr.getBytes("utf-8");
      }
      Protocol protocol = Protocol.fromBytes(context.getGaeaRequest().getRequestBuffer(),global.getGlobalSecureIsRights(),desKeyByte);
      context.getGaeaRequest().setProtocol(protocol);
      /**
       * 服务重启直接返回
       */ 
      if(Global.getSingleton().getServerState() == ServerStateType.Reboot && protocol.getPlatformType() == PlatformType.Java){
        GaeaResponse response = new GaeaResponse();
        ResetProtocol rp = new ResetProtocol();
        rp.setMsg("This server is reboot!");
        protocol.setSdpEntity(rp);
        response.setResponseBuffer(protocol.toBytes(global.getGlobalSecureIsRights(),desKeyByte));
        context.setGaeaResponse(response);
        context.setExecFilter(ExecFilterType.None);
        context.setDoInvoke(false);
      }
    }
View Full Code Here

        GaeaContext gaeaContext = new GaeaContext();
        gaeaContext.setServerType(ServerType.HTTP);
        gaeaContext.setServerHandler(this);
        gaeaContext.setChannel(new GaeaChannel(e.getChannel()));
      /**协议*/
      Protocol protocol = new Protocol();
      RequestProtocol request = new RequestProtocol();
      request.setLookup(action.getLookup());
      request.setMethodName(action.getMethodName());
      request.setParaKVList(paraKVList);
      protocol.setSdpEntity(request);
      gaeaContext.getGaeaRequest().setProtocol(protocol);
      /**HttpContext 上下文*/
      com.bj58.spat.gaea.server.contract.http.HttpContext httpcontext = new com.bj58.spat.gaea.server.contract.http.HttpContext();
      com.bj58.spat.gaea.server.contract.http.HttpRequest httpRequest = new com.bj58.spat.gaea.server.contract.http.HttpRequest();
      httpRequest.setContent(httpContext.getContentBuffer());
View Full Code Here

  public void TestUser() throws Exception {
    SESUser user = new SESUser();
    user.setUserID(1L);
    user.setState(1);

    Serializer serializer = new Serializer();
    byte[] buffer = serializer.Serialize(user);
    assertNotNull(buffer);
    Object obj = serializer.Derialize(buffer, SimpleClass.class);
    Object expect = obj;
    assertNotNull(expect);
  }
View Full Code Here

*/
public class SerializerTest {

  @Test
  public void testByte() throws Exception {
    Serializer serializer = new Serializer();
    Byte[] b = null;
    byte[] buffer = serializer.Serialize(b);

    Object obj1 = serializer.Derialize(buffer, Byte[].class);

    Short[] s = new Short[] { 1, 2, 3 };
    byte[] bs = serializer.Serialize(s);

    Map<Byte, Object> map = new HashMap<Byte, Object>();
    map.put((byte) 1, "abc");
    map.put((byte) 2, 123456L);
    map.put((byte) 3, s);
    map.put((byte) 4, 123);
    map.put((byte) 5, null);

    byte[] buf3 = serializer.Serialize(map);
    Map<Byte, Object> obj3 = (Map<Byte, Object>) serializer.Derialize(buf3,
        Map.class);
    System.out.println(obj3.get(5));
  }
View Full Code Here

   */
  @Test
  public void TestObject() throws Exception {
    SimpleClass sc = SimpleClass.Get();
    Object data = sc;
    Serializer serializer = new Serializer();
    byte[] buffer = serializer.Serialize(data);
    assertNotNull(buffer);
    Object obj = serializer.Derialize(buffer, SimpleClass.class);

    Object expect = obj;
    assertNotNull(expect);
  }
View Full Code Here

    Object expect = obj;
    assertNotNull(expect);
  }

  public void TestEqualObject() throws Exception {
    Serializer serializer = new Serializer();
    List<SimpleClass> scs = new ArrayList<SimpleClass>();
    SimpleClass sc = SimpleClass.Get();
    scs.add(sc);
    scs.add(sc);
    byte[] buffer = serializer.Serialize(scs);
    Object obj = serializer.Derialize(buffer, ArrayList.class);
    List<SimpleClass> scs2 = (List<SimpleClass>) obj;
    assertNotNull(scs2);
    assertTrue(scs2.get(0) == scs2.get(1));
  }
View Full Code Here

TOP

Related Classes of com.bj58.spat.gaea.protocol.sfp.v1.Protocol

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.