/** * Returns an {@link RPCRequest} that is built by decoding the contents of an * encoded RPC request and optionally validating that type can handle the * request. If the type parameter is not <code>null</code>, the * implementation checks that the type is assignable to the * {@link RemoteService} interface requested in the encoded request string. * * <p> * If the serializationPolicyProvider parameter is not <code>null</code>, * it is asked for a {@link SerializationPolicy} to use to restrict the set of * types that can be decoded from the request. If this parameter is * <code>null</code>, then only subtypes of * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or * types which have custom field serializers can be decoded. * </p> * * <p> * Invoking this method with <code>null</code> for the type parameter, * <code>decodeRequest(encodedRequest, null)</code>, is equivalent to * calling <code>decodeRequest(encodedRequest)</code>. * </p> * @param String $encodedRequest a string that encodes the {@link RemoteService} * interface, the service method, and the arguments to pass to the * service method * @param MappedClassLoader $mappedClassLoader * @param SerializationPolicyProvider $serializationPolicyProvider if not <code>null</code>, the * implementation asks this provider for a * {@link SerializationPolicy} which will be used to restrict the set * of types that can be decoded from this request * @return RPCRequest an {@link RPCRequest} instance * @throws NullPointerException if the encodedRequest is <code>null</code> * @throws IllegalArgumentException if the encodedRequest is an empty string * @throws IncompatibleRemoteServiceException if any of the following * conditions apply: * <ul> * <li>if the types in the encoded request cannot be deserialized</li> * <li>if the {@link ClassLoader} acquired from * <code>Thread.currentThread().getClassLoader()</code> * cannot load the service interface or any of the types specified * in the encodedRequest</li> * <li>the requested interface is not assignable to * {@link RemoteService}</li> * <li>the service method requested in the encodedRequest is not a * member of the requested service interface</li> * <li>the type parameter is not <code>null</code> and is not * assignable to the requested {@link RemoteService} interface * </ul> */ public static function decodeRequest($encodedRequest, MappedClassLoader $mappedClassLoader, SerializationPolicyProvider $serializationPolicyProvider) { $logger = LoggerManager::getLogger('gwtphp.rpc.RPC'); if ($encodedRequest === null) { throw new NullPointerException("encodedRequest cannot be null"); } if (strlen($encodedRequest) == 0) { throw new IllegalArgumentException("encodedRequest cannot be empty"); } try { /*ServerSerializationStreamReader*/ $streamReader = new ServerSerializationStreamReader($mappedClassLoader, $serializationPolicyProvider); //classLoader, serializationPolicyProvider); $streamReader->prepareToRead($encodedRequest); // Read the name of the RemoteService interface /*String*/ $serviceIntfName = $streamReader->readString(); $logger->info("serviceIntfName: " . $serviceIntfName); // TODO: wybrac metode sprawdzenia czy posiadamy obiekt ktory moze implementowac wybrany // do uruchomienia interface //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 = $streamReader->getSerializationPolicy(); //$gwtService = $classLoader->getMapManager()->getGWTServiceMap($serviceIntfName); /*MappedClass*/ $serviceIntf = null; try { $serviceIntf = RPC::getClassFromSerializedName($serviceIntfName, $mappedClassLoader); // 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) { class_exists('IncompatibleRemoteServiceException') || (require GWTPHP_DIR . '/../com/google/gwt/user/client/rpc/IncompatibleRemoteServiceException.class.php'); throw new IncompatibleRemoteServiceException("Could not locate requested interface '" + $serviceIntfName + "' in default classloader", $e); } $serviceMethodName = $streamReader->readString(); $logger->debug("serviceMethodName: " . $serviceMethodName); $paramCount = $streamReader->readInt(); $logger->debug("paramCount: " . $paramCount); /*MappedClass[]*/ $parameterTypes = array(); for ($i = 0; $i < $paramCount; ++$i) { $paramClassName = $streamReader->readString(); //$parameterTypes[$i] = $paramClassName; try { $parameterTypes[$i] = RPC::getClassFromSerializedName($paramClassName, $mappedClassLoader); } catch (ClassNotFoundException $e) { class_exists('IncompatibleRemoteServiceException') || (require GWTPHP_DIR . '/../com/google/gwt/user/client/rpc/IncompatibleRemoteServiceException.class.php'); throw new IncompatibleRemoteServiceException("Parameter " + $i + " of is of an unknown type '" + $paramClassName + "'", $e); } } $logger->info(print_r($parameterTypes, true)); $mappedMethod = RPC::findInterfaceMethod($serviceIntf, $serviceMethodName, $parameterTypes, true); if ($mappedMethod == null) { class_exists('IncompatibleRemoteServiceException') || (require GWTPHP_DIR . '/../com/google/gwt/user/client/rpc/IncompatibleRemoteServiceException.class.php'); throw new IncompatibleRemoteServiceException(RPC::formatMethodNotFoundErrorMessage($serviceIntf, $serviceMethodName, $parameterTypes)); } /*Object[]*/ $parameterValues = array(); for ($i = 0; $i < $paramCount; ++$i) { $parameterValues[$i] = $streamReader->deserializeValue($parameterTypes[$i]); } $logger->info(print_r($parameterValues, true)); //$gwtService->getServiceMethodMap(0)->getMethod(); // //$rpcResolver-> //$method = $rpcResolver->getRPCServiceMethod($serviceIntfName,$serviceMethodName); //$rpcRequest = new RPCRequest($method, $parameterValues, $serializationPolicy); //$rpcRequest->setClass($service); // $rpcRequest = $rpcResolver->getRPCRequest($serviceIntfName,$serviceMethodName,$parameterTypes); // $rpcRequest->setParameters($parameterValues); // $rpcRequest->setSerializationPolicy($serializationPolicy); return new RPCRequest($mappedMethod, $parameterValues, $serializationPolicy, $mappedClassLoader); } catch (SerializationException $ex) { class_exists('IncompatibleRemoteServiceException') || (require GWTPHP_DIR . '/../com/google/gwt/user/client/rpc/IncompatibleRemoteServiceException.class.php'); throw new IncompatibleRemoteServiceException($ex->getMessage(), $ex); } }
public static function init() { self::$CLASS_TO_VALUE_READER = new IdentityHashMap(); self::$CLASS_TO_VECTOR_READER = new IdentityHashMap(); self::$CLASS_TO_VECTOR_READER->put(ArrayType::clazz(Boolean::typeClass()), new SSSR_VectorReader_Boolean()); self::$CLASS_TO_VECTOR_READER->put(ArrayType::clazz(Byte::typeClass()), new SSSR_VectorReader_Byte()); self::$CLASS_TO_VECTOR_READER->put(ArrayType::clazz(Character::typeClass()), new SSSR_VectorReader_Char()); self::$CLASS_TO_VECTOR_READER->put(ArrayType::clazz(Double::typeClass()), new SSSR_VectorReader_Double()); self::$CLASS_TO_VECTOR_READER->put(ArrayType::clazz(Float::typeClass()), new SSSR_VectorReader_Float()); self::$CLASS_TO_VECTOR_READER->put(ArrayType::clazz(Integer::typeClass()), new SSSR_VectorReader_Int()); self::$CLASS_TO_VECTOR_READER->put(ArrayType::clazz(Long::typeClass()), new SSSR_VectorReader_Long()); self::$CLASS_TO_VECTOR_READER->put(ArrayType::clazz(Object::clazz()), new SSSR_VectorReader_Object()); self::$CLASS_TO_VECTOR_READER->put(ArrayType::clazz(Short::typeClass()), new SSSR_VectorReader_Short()); self::$CLASS_TO_VECTOR_READER->put(ArrayType::clazz(String::clazz()), new SSSR_VectorReader_String()); self::$CLASS_TO_VALUE_READER->put(Boolean::typeClass(), new SSSR_ValueReader_Boolean()); self::$CLASS_TO_VALUE_READER->put(Byte::typeClass(), new SSSR_ValueReader_Byte()); self::$CLASS_TO_VALUE_READER->put(Character::typeClass(), new SSSR_ValueReader_Char()); self::$CLASS_TO_VALUE_READER->put(Double::typeClass(), new SSSR_ValueReader_Double()); self::$CLASS_TO_VALUE_READER->put(Float::typeClass(), new SSSR_ValueReader_Float()); self::$CLASS_TO_VALUE_READER->put(Integer::typeClass(), new SSSR_ValueReader_Int()); self::$CLASS_TO_VALUE_READER->put(Long::typeClass(), new SSSR_ValueReader_Long()); self::$CLASS_TO_VALUE_READER->put(Object::clazz(), new SSSR_ValueReader_Object()); self::$CLASS_TO_VALUE_READER->put(Short::typeClass(), new SSSR_ValueReader_Short()); self::$CLASS_TO_VALUE_READER->put(String::clazz(), new SSSR_ValueReader_String()); }
private static function maybeDeobfuscate(ServerSerializationStreamReader $streamReader, $name) { if ($streamReader->hasFlags(AbstractSerializationStream::FLAG_ELIDE_TYPE_NAMES)) { $serializationPolicy = $streamReader->getSerializationPolicy(); if (!serializationPolicy instanceof TypeNameObfuscator) { throw new IncompatibleRemoteServiceException('RPC request was encoded with obfuscated type names, ' . 'but the SerializationPolicy in use does not implement ' . Classes::classOf(TypeNameObfuscator)->getName()); } $maybe = $serializationPolicy->getClassNameForTypeId($name); if (!is_null($maybe)) { return $maybe; } } else { if (($index = mb_strpos($name, '/')) !== false) { return mb_substr($name, 0, $index); } } return $name; }
protected function readSingleValue(ServerSerializationStreamReader $stream) { return $stream->readString(); }