Package com.bj58.spat.gaea.server.util

Examples of com.bj58.spat.gaea.server.util.UtilTest


      localProxyAry.add((IProxyStub)cls.newInstance());
    }
   
    Class<?> proxyFactoryCls = classLoader.findClass(cfProxyFactory.getClsName(), cfProxyFactory.getClsByte(), null);
    Constructor<?> constructor = proxyFactoryCls.getConstructor(List.class);
    IProxyFactory pfInstance = (IProxyFactory)constructor.newInstance(localProxyAry);
    logger.info("crate ProxyFactory instance!!!");
    return pfInstance;
  }
View Full Code Here


     
      logger.debug(sbInvokerMsg.toString());
      logger.debug("begin get proxy factory");
     
      // get local proxy
      IProxyStub localProxy = Global.getSingleton().getProxyFactory().getProxy(request.getLookup());
      logger.debug("proxyFactory.getProxy finish");

      if (localProxy == null) {
        ServiceFrameException sfe = new ServiceFrameException(
            "method:ProxyHandle.invoke--msg:" + request.getLookup() + "." + request.getMethodName() + " not fond",
            context.getChannel().getRemoteIP(),
            context.getChannel().getLocalIP(),
            request,
            ErrorState.NotFoundServiceException,
            null);
        response = ExceptionHelper.createError(sfe);
        logger.error("localProxy is null", sfe);
      } else {
        logger.debug("begin localProxy.invoke");
        String swInvoderKey = "InvokeRealService_" + request.getLookup() + "." + request.getMethodName();
        sw.startNew(swInvoderKey, sbInvokerMsg.toString());
        sw.setFromIP(context.getChannel().getRemoteIP());
        sw.setLocalIP(context.getChannel().getLocalIP());
       
        //invoker real service
        GaeaResponse gaeaResponse = localProxy.invoke(context);
       
        sw.stop(swInvoderKey);
       
        logger.debug("end localProxy.invoke");
        context.setGaeaResponse(gaeaResponse);
View Full Code Here

    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

         
          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

    Protocol p = context.getGaeaRequest().getProtocol();
    GaeaResponse response = new GaeaResponse();
   
    if(p.getPlatformType() == PlatformType.Java && context.getServerType() == ServerType.TCP){
      //当前服务启动权限认证,并且当前channel通过校验,则进行方法校验
      SecureContext securecontext = global.getGlobalSecureContext(context.getChannel().getNettyChannel());
      if(global.getGlobalSecureIsRights()){
        //当前服务启用权限认证,判断当前channel是否通过授权
        if(securecontext.isRights()){
          RequestProtocol request = (RequestProtocol)p.getSdpEntity();
          if(request != null){
            StringBuffer buff = new StringBuffer(request.getLookup() + "." +request.getMethodName());//接口实现类.方法名(参数序列)
            buff.append("(");
            List<KeyValuePair> list = request.getParaKVList();
            if(list != null){
              int i=0;
              for(KeyValuePair k : list){
                if(k != null){
                  if(i > 0){
                    buff.append(",");
                  }
                  buff.append(k.getKey());
                  ++i;
                }
              }
            }
            buff.append(")");
           
            boolean bool = true;
            Map map = global.getSecureMap();
            if(map != null){
              Iterator<Map.Entry<String, List<String>>> iter = map.entrySet().iterator();
              while(iter.hasNext()){
                Map.Entry<String, List<String>> enty = (Map.Entry<String, List<String>>)iter.next();
                for(String str:enty.getValue()){
                  if(str.equalsIgnoreCase(buff.toString())){
                    bool = false;
                    break;
                  }
                }
              }
            }
           
            if(bool){
              logger.error("当前调用方法没有授权!");
              this.ContextException(context, p, response, "当前调用方法没有授权!",global.getGlobalSecureIsRights(),securecontext.getDesKey().getBytes("utf-8"));
            }
          }
        }else{
          logger.error("当前连接没有通过权限认证!");
          this.ContextException(context, p, response, "当前连接没有通过权限认证!");
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

   */
  void doInvoke(GaeaContext context) {
    logger.debug("------------------------------ begin request-----------------------------");

    StringBuffer sbInvokerMsg = new StringBuffer();
    StopWatch sw = context.getStopWatch();
    Object response = null;
    Protocol protocol = null;
   
    try {
        protocol = context.getGaeaRequest().getProtocol();
      RequestProtocol request = (RequestProtocol)protocol.getSdpEntity();
     
      sbInvokerMsg.append("protocol version:");
      sbInvokerMsg.append(protocol.getVersion());
      sbInvokerMsg.append("\nfromIP:");
      sbInvokerMsg.append(context.getChannel().getRemoteIP());
      sbInvokerMsg.append("\nlookUP:");
      sbInvokerMsg.append(request.getLookup());
      sbInvokerMsg.append("\nmethodName:");
      sbInvokerMsg.append(request.getMethodName());
      sbInvokerMsg.append("\nparams:");
     
      if(request.getParaKVList() != null){
        for (KeyValuePair kv : request.getParaKVList()) {
          if(kv != null) {
            sbInvokerMsg.append("\n--key:");
            sbInvokerMsg.append(kv.getKey());
            sbInvokerMsg.append("\n--value:");
            sbInvokerMsg.append(kv.getValue());
          } else {
            logger.error("KeyValuePair is null  Lookup:" + request.getLookup() + "--MethodName:" + request.getMethodName());
          }
        }
      }
     
      logger.debug(sbInvokerMsg.toString());
      logger.debug("begin get proxy factory");
     
      // get local proxy
      IProxyStub localProxy = Global.getSingleton().getProxyFactory().getProxy(request.getLookup());
      logger.debug("proxyFactory.getProxy finish");

      if (localProxy == null) {
        ServiceFrameException sfe = new ServiceFrameException(
            "method:ProxyHandle.invoke--msg:" + request.getLookup() + "." + request.getMethodName() + " not fond",
            context.getChannel().getRemoteIP(),
            context.getChannel().getLocalIP(),
            request,
            ErrorState.NotFoundServiceException,
            null);
        response = ExceptionHelper.createError(sfe);
        logger.error("localProxy is null", sfe);
      } else {
        logger.debug("begin localProxy.invoke");
        String swInvoderKey = "InvokeRealService_" + request.getLookup() + "." + request.getMethodName();
        sw.startNew(swInvoderKey, sbInvokerMsg.toString());
        sw.setFromIP(context.getChannel().getRemoteIP());
        sw.setLocalIP(context.getChannel().getLocalIP());
       
        //invoker real service
        GaeaResponse gaeaResponse = localProxy.invoke(context);
       
        sw.stop(swInvoderKey);
       
        logger.debug("end localProxy.invoke");
        context.setGaeaResponse(gaeaResponse);
        response = createResponse(gaeaResponse);
        logger.debug("localProxy.invoke finish");
View Full Code Here

 
  private static String jarPath = "E:\\javaproject\\bj58.gaea.server\\lib";
 
  @Test
  public void testContract() {
    ClassInfo ciMulti = ScanClass.contract(IMulti.class);
    List<MethodInfo> miList1 = ciMulti.getMethodList();
    Assert.assertEquals("loadByID", miList1.get(0).getMethod().getName());
    Assert.assertEquals("loadByName", miList1.get(1).getMethod().getName());

   
    ClassInfo ciSingle = ScanClass.contract(ISingle.class);
    List<MethodInfo> miList2 = ciSingle.getMethodList();
    Assert.assertEquals("loadByID", miList2.get(0).getMethod().getName());
  }
View Full Code Here

  @SuppressWarnings("rawtypes")
  @Test
  public void testGetContractInfo() throws Exception {
    DynamicClassLoader classLoader = new DynamicClassLoader();
    classLoader.addFolder(jarPath);
    ContractInfo ci = ScanClass.getContractInfo(jarPath, classLoader);
    for(SessionBean sb : ci.getSessionBeanList()) {
     
      Assert.assertEquals("com.bj58.spat.servicedemo.contract.INewsService", sb.getInterfaceName());
     
      Map<String, String> map = sb.getInstanceMap();
      Iterator it = map.entrySet().iterator();
View Full Code Here

TOP

Related Classes of com.bj58.spat.gaea.server.util.UtilTest

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.