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

Examples of com.bj58.spat.gaea.serializer.component.annotation.GaeaSerializable


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

        }
        Set<Class> classes = cs.scan(basePakage.split(";"));
        for (Class c : classes) {
            System.out.println("scaning " + c.getPackage().getName() + "." + c.getName());
            try {
                GaeaSerializable ann = (GaeaSerializable) c.getAnnotation(GaeaSerializable.class);
                if (ann != null) {
                    String name = ann.name();
                    if (name.equals(StrHelper.EmptyString)) {
                        name = c.getSimpleName();
                    }
                    int typeId = StrHelper.GetHashcode(name);
                    TypeIdMap.put(c, new ClassItem(typeId, c));
View Full Code Here

        }
        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);
            }
            String name = ann.name();
            if (name.equals(StrHelper.EmptyString)) {
                name = type.getSimpleName();
            }
            typeId = StrHelper.GetHashcode(name);
            setTypeMap(type, typeId);
View Full Code Here

    private TypeInfo GetTypeInfo(Class<?> type) throws ClassNotFoundException, DisallowedSerializeException {
        if (TypeInfoMap.containsKey(type)) {
            return TypeInfoMap.get(type);
        }
        GaeaSerializable cAnn = type.getAnnotation(GaeaSerializable.class);
        if (cAnn == null) {
            throw new DisallowedSerializeException();
        }
        int typeId = TypeHelper.GetTypeId(type);
        TypeInfo typeInfo = new TypeInfo(typeId);
        ArrayList<Field> fields = new ArrayList<Field>();
        Class temType = type;
        while (true) {
            Field[] fs = temType.getDeclaredFields();
            for (Field f : fs) {
                fields.add(f);
            }
            Class superClass = temType.getSuperclass();
            if (superClass == null) {
                break;
            }
            temType = superClass;
        }

        Map<Integer, Field> mapFildes = new HashMap<Integer, Field>();
        List<Integer> indexIds = new ArrayList<Integer>();
        if (cAnn.defaultAll()) {
            for (Field f : fields) {
                GaeaNotMember ann = f.getAnnotation(GaeaNotMember.class);
                if (ann != null) {
                    continue;
                }
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

TOP

Related Classes of com.bj58.spat.gaea.serializer.component.annotation.GaeaSerializable

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.