Package com.bj58.spat.gaea.serializer.component

Examples of com.bj58.spat.gaea.serializer.component.ClassItem


public class ProtocolHelperTest {

  @Test
  public void testFromBytes() throws Exception {
    RequestProtocol rp = new RequestProtocol("lookup", "methodname", null);
    Protocol p = new Protocol(101001, (byte)1, SDPType.Request, rp);
   
    byte[] buffer = p.toBytes();
   
    Protocol p2 = (Protocol)ProtocolHelper.fromBytes(buffer);
    Assert.assertEquals(rp.getLookup(), ((RequestProtocol)p2.getSdpEntity()).getLookup());
    Assert.assertEquals(rp.getMethodName(), ((RequestProtocol)p2.getSdpEntity()).getMethodName());
  }
View Full Code Here


  }
 
 
  @Test
  public void testToBytes() throws Exception {
    RequestProtocol rp = new RequestProtocol("lookup", "methodname", null);
    Protocol p = new Protocol(101001, (byte)1, SDPType.Request, rp);
   
    byte[] buffer = p.toBytes();
    StringBuilder sbBuf = new StringBuilder();
    for(byte b : buffer) {
View Full Code Here

    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
View Full Code Here

  }

  public void setGaeaRequest(GaeaRequest gaeaRequest) {
    this.gaeaRequest = gaeaRequest;
   
    RequestProtocol r = (RequestProtocol)gaeaRequest.getProtocol().getSdpEntity();
    this.stopWatch.setLookup(r.getLookup());
    this.stopWatch.setMethodName(r.getMethodName());
  }
View Full Code Here

      //当前服务启动权限认证,并且当前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){
View Full Code Here

      int outParaSize = gaeaResponse.getOutParaList().size();
      Object[] objArray = new Object[outParaSize];
      for(int i=0; i<outParaSize; i++) {
        objArray[i] = gaeaResponse.getOutParaList().get(i).getOutPara();
      }
            return new ResponseProtocol(gaeaResponse.getReturnValue(), objArray);
        } else {
            return new ResponseProtocol(gaeaResponse.getReturnValue(), null);
        }
  }
View Full Code Here

    public static void InitTypeMap() {
        TypeIdMap.clear();
        IdTypeMap.clear();
        ArrayList<ClassItem> ClassList = new ArrayList<ClassItem>();
        ClassList.add(new ClassItem(1, DBNull.class));
        ClassList.add(new ClassItem(2, Object.class));
        ClassList.add(new ClassItem(3, Boolean.class, boolean.class));
        ClassList.add(new ClassItem(4, Character.class, char.class));
        ClassList.add(new ClassItem(5, Byte.class, byte.class));
        ClassList.add(new ClassItem(7, Short.class, short.class));
        ClassList.add(new ClassItem(9, Integer.class, int.class));
        ClassList.add(new ClassItem(11, Long.class, long.class));
        ClassList.add(new ClassItem(13, Float.class, float.class));
        ClassList.add(new ClassItem(14, Double.class, double.class));
        ClassList.add(new ClassItem(15, BigDecimal.class));
        ClassList.add(new ClassItem(16, Date.class, java.sql.Date.class, java.sql.Time.class, java.sql.Timestamp.class));
        ClassList.add(new ClassItem(18, String.class));
        ClassList.add(new ClassItem(19, List.class));
        ClassList.add(new ClassItem(22, GKeyValuePair.class));
        ClassList.add(new ClassItem(23, Array.class));
        ClassList.add(new ClassItem(24, Map.class));
        for (ClassItem item : ClassList) {
            int id = item.getTypeId();
            Class[] types = item.getTypes();
            for (Class c : types) {
                TypeIdMap.put(c, item);
View Full Code Here

                    String name = ann.name();
                    if (name.equals(StrHelper.EmptyString)) {
                        name = c.getSimpleName();
                    }
                    int typeId = StrHelper.GetHashcode(name);
                    TypeIdMap.put(c, new ClassItem(typeId, c));
                    IdTypeMap.put(typeId, new ClassItem(typeId, c));
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
View Full Code Here

            typeId = 19;
        }else if(typeId == 25){
            typeId = 24;
        }
        /**************************************************/
        ClassItem ci = IdTypeMap.get(typeId);
        if (ci != null) {
            return ci.getType();
        }
        return null;
    }
View Full Code Here

        } else if (Map.class.isAssignableFrom(type)) {
            type = Map.class;
        } else if (List.class.isAssignableFrom(type)) {
            type = List.class;
        }
        ClassItem ci = TypeIdMap.get(type);
        if (ci != null) {
            typeId = ci.getTypeId();
        } else {
            GaeaSerializable ann = (GaeaSerializable) type.getAnnotation(GaeaSerializable.class);
            if (ann == null) {
                throw new DisallowedSerializeException(type);
            }
View Full Code Here

TOP

Related Classes of com.bj58.spat.gaea.serializer.component.ClassItem

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.