Package com.google.gwt.user.server.rpc.impl

Examples of com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader


//                responsePayload, gzipEncode);
//    }

    protected Serializable deserialize(String data) {
        try {
            ServerSerializationStreamReader reader = new ServerSerializationStreamReader(getClass().getClassLoader(), cometSerializationPolicyProvider);
            reader.prepareToRead(data);
            return (Serializable) reader.readObject();
        } catch (SerializationException ex) {
            logger.error("Failed to deserialize message", ex);
            return null;
        }
    }
View Full Code Here


        ClassLoader classLoader = Thread.currentThread()
                .getContextClassLoader();

        try {
            ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader(
                    classLoader, serializationPolicyProvider);
            streamReader.prepareToRead(encodedRequest);

            // Read the name of the RemoteService interface
            String serviceIntfName = streamReader.readString();

            if (type != null) {
                if (!implementsInterface(type, serviceIntfName)) {
                    // The service does not implement the requested
                    // interface
                    throw new IncompatibleRemoteServiceException(
                            "Blocked attempt to access interface '"
                                    + serviceIntfName
                                    + "', which is not implemented by '"
                                    + printTypeName(type)
                                    + "'; this is either misconfiguration or a hack attempt");
                }
            }

            SerializationPolicy serializationPolicy = streamReader
                    .getSerializationPolicy();
            Class<?> serviceIntf;
            try {
                serviceIntf = getClassFromSerializedName(serviceIntfName,
                        classLoader);
                if (!RemoteService.class.isAssignableFrom(serviceIntf)) {
                    // The requested interface is not a RemoteService
                    // interface
                    throw new IncompatibleRemoteServiceException(
                            "Blocked attempt to access interface '"
                                    + printTypeName(serviceIntf)
                                    + "', which doesn't extend RemoteService; this is either misconfiguration or a hack attempt");
                }
            } catch (ClassNotFoundException e) {
                throw new IncompatibleRemoteServiceException(
                        "Could not locate requested interface '"
                                + serviceIntfName
                                + "' in default classloader", e);
            }

            String serviceMethodName = streamReader.readString();

            int paramCount = streamReader.readInt();
            Class<?>[] parameterTypes = new Class[paramCount];

            for (int i = 0; i < parameterTypes.length; i++) {
                String paramClassName = streamReader.readString();
                try {
                    parameterTypes[i] = getClassFromSerializedName(
                            paramClassName, classLoader);
                } catch (ClassNotFoundException e) {
                    throw new IncompatibleRemoteServiceException(
                            "Parameter " + i
                                    + " of is of an unknown type '"
                                    + paramClassName + "'", e);
                }
            }

            try {
                Method method = serviceIntf.getMethod(serviceMethodName,
                        parameterTypes);

                Object[] parameterValues = new Object[parameterTypes.length];
                for (int i = 0; i < parameterValues.length; i++) {
                    parameterValues[i] = streamReader
                            .deserializeValue(parameterTypes[i]);
                }

                return new RPCRequest(method, parameterValues,
                        serializationPolicy);
View Full Code Here

        }
        return data.toString();
    }

    public static Object deserialize(String data) throws SerializationException {
        ServerSerializationStreamReader reader = new ServerSerializationStreamReader(Thread.currentThread().getContextClassLoader(), GwtRpcUtil.getSerializationPolicyProvider());
        reader.prepareToRead(data);
        return reader.readObject();
    }
View Full Code Here

    if (encodedRequest.length() == 0) {
      throw new IllegalArgumentException("encodedRequest cannot be empty");
    }

    try {
      ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader(
          serializableTypeOracle);
      streamReader.prepareToRead(encodedRequest);

      String serviceIntfName = streamReader.readString();

      if (type != null) {
        if (!implementsInterface(type, serviceIntfName)) {
          // The service does not implement the requested interface
          throw new IncompatibleRemoteServiceException(
              "Blocked attempt to access interface '" + serviceIntfName
                  + "', which is not implemented by '" + printTypeName(type)
                  + "'; this is either misconfiguration or a hack attempt");
        }
      }

      Class serviceIntf;
      try {
        serviceIntf = getClassFromSerializedName(serviceIntfName);
        if (!RemoteService.class.isAssignableFrom(serviceIntf)) {
          // The requested interface is not a RemoteService interface
          throw new IncompatibleRemoteServiceException(
              "Blocked attempt to access interface '"
                  + printTypeName(serviceIntf)
                  + "', which doesn't extend RemoteService; this is either misconfiguration or a hack attempt");
        }
      } catch (ClassNotFoundException e) {
        throw new IncompatibleRemoteServiceException(
            "Could not locate requested interface '" + serviceIntfName
                + "' in default classloader", e);
      }

      String serviceMethodName = streamReader.readString();

      int paramCount = streamReader.readInt();
      Class[] parameterTypes = new Class[paramCount];

      for (int i = 0; i < parameterTypes.length; i++) {
        String paramClassName = streamReader.readString();
        try {
          parameterTypes[i] = getClassFromSerializedName(paramClassName);
        } catch (ClassNotFoundException e) {
          throw new IncompatibleRemoteServiceException("Parameter " + i
              + " of is of an unknown type '" + paramClassName + "'", e);
        }
      }

      Method method = findInterfaceMethod(serviceIntf, serviceMethodName,
          parameterTypes, true);

      if (method == null) {
        throw new IncompatibleRemoteServiceException(
            formatMethodNotFoundErrorMessage(serviceIntf, serviceMethodName,
                parameterTypes));
      }

      Object[] parameterValues = new Object[parameterTypes.length];
      for (int i = 0; i < parameterValues.length; i++) {
        parameterValues[i] = streamReader.deserializeValue(parameterTypes[i]);
      }

      return new RPCRequest(method, parameterValues);

    } catch (SerializationException ex) {
View Full Code Here

        }

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

        try {
            ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader(classLoader,
                    serializationPolicyProvider);
            streamReader.prepareToRead(encodedRequest);

            // Read the name of the RemoteService interface
            String serviceIntfName = streamReader.readString();

            //            if (type != null) {
            //                if (!implementsInterface(type, serviceIntfName)) {
            //                    // The service does not implement the requested interface
            //                    throw new IncompatibleRemoteServiceException(
            //                        "Blocked attempt to access interface '" +
            //                        serviceIntfName + "', which is not implemented by '" +
            //                        printTypeName(type) +
            //                        "'; this is either misconfiguration or a hack attempt");
            //                }
            //            }
            SerializationPolicy serializationPolicy = streamReader.getSerializationPolicy();

            //            Class<?> serviceIntf;

            //            try {
            //                serviceIntf = getClassFromSerializedName(serviceIntfName,
            //                        classLoader);
            //
            //                if (!RemoteService.class.isAssignableFrom(serviceIntf)) {
            //                    // The requested interface is not a RemoteService interface
            //                    throw new IncompatibleRemoteServiceException(
            //                        "Blocked attempt to access interface '" +
            //                        printTypeName(serviceIntf) +
            //                        "', which doesn't extend RemoteService; this is either misconfiguration or a hack attempt");
            //                }
            //            } catch (ClassNotFoundException e) {
            //                throw new IncompatibleRemoteServiceException(
            //                    "Could not locate requested interface '" + serviceIntfName +
            //                    "' in default classloader", e);
            //            }
            String serviceMethodName = streamReader.readString();

            int paramCount = streamReader.readInt();
            Class<?>[] parameterTypes = new Class[paramCount];

            for (int i = 0; i < parameterTypes.length; i++) {
                String paramClassName = streamReader.readString();

                try {
                    parameterTypes[i] = getClassFromSerializedName(paramClassName,
                            classLoader);
                } catch (ClassNotFoundException e) {
                    throw new IncompatibleRemoteServiceException("Parameter " +
                        i + " of is of an unknown type '" + paramClassName +
                        "'", e);
                }
            }

            try {
                Method method = type.getMethod(serviceMethodName, parameterTypes);

                Object[] parameterValues = new Object[parameterTypes.length];

                for (int i = 0; i < parameterValues.length; i++) {
                    parameterValues[i] = streamReader.deserializeValue(parameterTypes[i]);
                }

                return new RPCRequest(method, parameterValues,
                    serializationPolicy, 0);
            } catch (NoSuchMethodException e) {
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public T getObject() {
        if ((this.object == null) && (getText() != null)) {
            try {
                ServerSerializationStreamReader objectReader = new ServerSerializationStreamReader(
                        Engine.getInstance().getClassLoader(),
                        new SimpleSerializationPolicyProvider());
                String encodedString = getText();

                if (encodedString.indexOf('|') == -1) {
                    encodedString = AbstractSerializationStream.SERIALIZATION_STREAM_VERSION
                            + "|1|0|0|0|" + getText() + '|';
                }

                objectReader.prepareToRead(encodedString);
                this.object = (T) objectReader
                        .deserializeValue(this.targetClass);
            } catch (Exception e) {
                this.object = null;
                e.printStackTrace();
            }
View Full Code Here

                "The encodedRequest parameter cannot be empty.");
        }
        ClassLoader classLoader =
            Thread.currentThread().getContextClassLoader();
        try {
            ServerSerializationStreamReader streamReader =
                new ServerSerializationStreamReader(classLoader, this);
            streamReader.prepareToRead(encodedRequest);
            String interfaceName = readClassName(streamReader);
            Class<?> serviceClass = getServiceClass(interfaceName);
            Object service = getService(serviceClass);
            SerializationPolicy serializationPolicy =
                streamReader.getSerializationPolicy();
            String methodName = streamReader.readString();
            int paramCount = streamReader.readInt();
            Class<?>[] parameterTypes = new Class[paramCount];
            for (int i = 0; i < parameterTypes.length; i++) {
                String paramClassName = readClassName(streamReader);
                parameterTypes[i] = getClass(paramClassName);
            }
            try {
                Method method =
                    serviceClass.getMethod(methodName, parameterTypes);
                Object[] parameterValues = new Object[parameterTypes.length];
                for (int i = 0; i < parameterValues.length; i++) {
                    parameterValues[i] =
                        streamReader.deserializeValue(parameterTypes[i]);
                }
                return new S3RPCRequest(service, new RPCRequest(
                    method,
                    parameterValues,
                    serializationPolicy,
                    streamReader.getFlags()));

            } catch (NoSuchMethodException e) {
                throw new IncompatibleRemoteServiceException(e.getMessage(), e);
            }
        } catch (SerializationException ex) {
View Full Code Here

    }

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

    try {
      ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader(
          classLoader, serializationPolicyProvider);
      streamReader.prepareToRead(encodedRequest);

      // Read the name of the RemoteService interface
      String serviceIntfName = streamReader.readString();

      if (type != null) {
        if (!implementsInterface(type, serviceIntfName)) {
          // The service does not implement the requested interface
          throw new IncompatibleRemoteServiceException(
              "Blocked attempt to access interface '" + serviceIntfName
                  + "', which is not implemented by '" + printTypeName(type)
                  + "'; this is either misconfiguration or a hack attempt");
        }
      }

      SerializationPolicy serializationPolicy = streamReader.getSerializationPolicy();
      Class<?> serviceIntf;
      try {
        serviceIntf = getClassFromSerializedName(serviceIntfName, classLoader);
        if (!RemoteService.class.isAssignableFrom(serviceIntf)) {
          // The requested interface is not a RemoteService interface
          throw new IncompatibleRemoteServiceException(
              "Blocked attempt to access interface '"
                  + printTypeName(serviceIntf)
                  + "', which doesn't extend RemoteService; this is either misconfiguration or a hack attempt");
        }
      } catch (ClassNotFoundException e) {
        throw new IncompatibleRemoteServiceException(
            "Could not locate requested interface '" + serviceIntfName
                + "' in default classloader", e);
      }

      String serviceMethodName = streamReader.readString();

      int paramCount = streamReader.readInt();
      Class<?>[] parameterTypes = new Class[paramCount];

      for (int i = 0; i < parameterTypes.length; i++) {
        String paramClassName = streamReader.readString();
        try {
          parameterTypes[i] = getClassFromSerializedName(paramClassName,
              classLoader);
        } catch (ClassNotFoundException e) {
          throw new IncompatibleRemoteServiceException("Parameter " + i
              + " of is of an unknown type '" + paramClassName + "'", e);
        }
      }

      try {
        Method method = serviceIntf.getMethod(serviceMethodName, parameterTypes);

        Object[] parameterValues = new Object[parameterTypes.length];
        for (int i = 0; i < parameterValues.length; i++) {
          parameterValues[i] = streamReader.deserializeValue(parameterTypes[i]);
        }

        return new RPCRequest(method, parameterValues, serializationPolicy);

      } catch (NoSuchMethodException e) {
View Full Code Here

    }

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

    try {
      ServerSerializationStreamReader streamReader =
          new ServerSerializationStreamReader(classLoader, serializationPolicyProvider);
      streamReader.prepareToRead(encodedRequest);

      RpcToken rpcToken = null;
      if (streamReader.hasFlags(AbstractSerializationStream.FLAG_RPC_TOKEN_INCLUDED)) {
        // Read the RPC token
        rpcToken = (RpcToken) streamReader.deserializeValue(RpcToken.class);
      }

      // Read the name of the RemoteService interface
      String serviceIntfName = maybeDeobfuscate(streamReader, streamReader.readString());

      if (type != null) {
        if (!implementsInterface(type, serviceIntfName)) {
          // The service does not implement the requested interface
          throw new IncompatibleRemoteServiceException("Blocked attempt to access interface '"
              + serviceIntfName + "', which is not implemented by '" + printTypeName(type)
              + "'; this is either misconfiguration or a hack attempt");
        }
      }

      SerializationPolicy serializationPolicy = streamReader.getSerializationPolicy();
      Class<?> serviceIntf;
      try {
        serviceIntf = getClassFromSerializedName(serviceIntfName, classLoader);
        if (!RemoteService.class.isAssignableFrom(serviceIntf)) {
          // The requested interface is not a RemoteService interface
          throw new IncompatibleRemoteServiceException(
              "Blocked attempt to access interface '"
                  + printTypeName(serviceIntf)
                  + "', which doesn't extend RemoteService; this is either "
                  + "misconfiguration or a hack attempt");
        }
      } catch (ClassNotFoundException e) {
        throw new IncompatibleRemoteServiceException("Could not locate requested interface '"
            + serviceIntfName + "' in default classloader", e);
      }

      String serviceMethodName = streamReader.readString();

      int paramCount = streamReader.readInt();
      if (paramCount > streamReader.getNumberOfTokens()) {
        throw new IncompatibleRemoteServiceException("Invalid number of parameters");
      }
      Class<?>[] parameterTypes = new Class[paramCount];

      for (int i = 0; i < parameterTypes.length; i++) {
        String paramClassName = maybeDeobfuscate(streamReader, streamReader.readString());

        try {
          parameterTypes[i] = getClassFromSerializedName(paramClassName, classLoader);
        } catch (ClassNotFoundException e) {
          throw new IncompatibleRemoteServiceException("Parameter " + i
              + " of is of an unknown type '" + paramClassName + "'", e);
        }
      }

      try {
        Method method = serviceIntf.getMethod(serviceMethodName, parameterTypes);

        // The parameter types we have are the non-parameterized versions in the
        // RPC stream. For stronger message verification, get the parameterized
        // types from the method declaration.
        Type[] methodParameterTypes = method.getGenericParameterTypes();
        DequeMap<TypeVariable<?>, Type> resolvedTypes = new DequeMap<TypeVariable<?>, Type>();

        TypeVariable<Method>[] methodTypes = method.getTypeParameters();
        for (TypeVariable<Method> methodType : methodTypes) {
          SerializabilityUtil.resolveTypes(methodType, resolvedTypes);
        }

        Object[] parameterValues = new Object[parameterTypes.length];
        for (int i = 0; i < parameterValues.length; i++) {
          parameterValues[i] = streamReader.deserializeValue(parameterTypes[i],
              methodParameterTypes[i], resolvedTypes);
        }

        return new RPCRequest(method, parameterValues, rpcToken, serializationPolicy, streamReader
            .getFlags());
      } catch (NoSuchMethodException e) {
        throw new IncompatibleRemoteServiceException(formatMethodNotFoundErrorMessage(serviceIntf,
            serviceMethodName, parameterTypes));
      }
View Full Code Here

      }
    }, A_method1, null);
  }

  public void testSerializationStreamDequote() throws SerializationException {
    ServerSerializationStreamReader reader = new ServerSerializationStreamReader(
        null, null);
    reader.prepareToRead(STRING_QUOTE_REQUEST);
    assertEquals("Raw backslash \\", reader.readString());
    assertEquals("Quoted separator " + RPC_SEPARATOR_CHAR, reader.readString());
    assertEquals("\uffff\\!\\0\u0000", reader.readString());
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader

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.