/** * 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 function readSingleValue(ServerSerializationStreamReader $stream) { return $stream->readString(); }