public static function decodeRequest($encodedRequest, ClientOracle $clientOracle) { if ($encodedRequest == null) { throw new NullPointerException('encodedRequest cannot be null'); } if ($encodedRequest == '') { throw new IllegalArgumentException('encodedRequest cannot be empty'); } try { $decoder = null; try { $decoder = new SimplePayloadDecoder($clientOracle, $encodedRequest); } catch (ClassNotFoundException $e) { throw new IncompatibleRemoteServiceException('Server does not have a type sent by the client', $e); } $streamReader = new CommandServerSerializationStreamReader(); if ($decoder->getThrownValue() != null) { $streamReader->prepareToRead(array($decoder->getThrownValue())); throw new RemoteException($streamReader->readObject()); } else { $streamReader->prepareToRead($decoder->getValues()); } $serviceIntfName = $streamReader->readString(); //$servicePhpName = self::serviceInterfaceToPhpService($serviceIntfName); $serviceIntf = self::getClassForSerializedName($serviceIntfName); if (!Classes::classOf('RemoteService')->isAssignableFrom($serviceIntf)) { throw new IncompatibleRemoteServiceException('Blocked attempt to access interface "' . $serviceIntf->getName() . '" which does not extends RemoteService'); } $servicePhpName = $serviceIntf->getName(); $serviceObject = null; try { $serviceObject = new $servicePhpName(); } catch (Exception $e) { throw new IncompatibleRemoteServiceException('Could not locate requested service "' . $serviceIntfName . '"', $e); } $serviceMethodName = $streamReader->readString(); $paramCount = $streamReader->readInt(); $parameterTypes = array(); for ($i = 0; $i < $paramCount; $i++) { $paramClassName = $streamReader->readString(); try { $parameterTypes[] = self::getClassForSerializedName($paramClassName, $clientOracle); } catch (ClassNotFoundException $e) { throw new IncompatibleRemoteServiceException('Parameter ' . $i . ' of is of an unknown type ' . $paramClassName, $e); } } $method = $serviceIntf->getMethod($serviceMethodName); if ($method == null) { throw new IncompatibleRemoteServiceException('Cound not find the method ' . $serviceMethodName . ' in service ' . $serviceIntfName); } $parameterValues = array(); for ($i = 0; $i < $paramCount; $i++) { $parameterValues[] = Accessors::get($parameterTypes[$i])->readNext($streamReader); } return new RpcRequest($serviceObject, $method, $parameterValues); } catch (SerializationException $e) { throw new IncompatibleRemoteServiceException($e->getMessage(), $e); } }
public function visitInvoke(InvokeCustomFieldSerializerCommand $x, Context $ctx) { if ($this->maybePushBackRef($x)) { $subReader = new CommandServerSerializationStreamReader($this->backRefs); $subReader->prepareToRead($x->getValues()); $serializerClass = $x->getSerializerClass(); assert($serializerClass != null); // For transform Integer into int by example s $trans = $serializerClass->getMethod('transform'); if ($trans != null) { assert($trans->isStatic()); $value = $trans->invoke($subReader); $this->pushValue($value); return false; } $instantiate = null; $deserialize = null; foreach ($serializerClass->getMethods() as $m) { if ($m->getName() == 'instanciate') { $instantiate = $m; } else { if ($m->getName() == 'deserialize') { $deserialize = $m; } } if ($instantiate != null && $deserialize != null) { break; } } assert($deserialize != null); $instance = null; if ($instantiate != null) { assert($instantiate->isStatic()); $instance = $instantiate->invoke($subReader); } else { $instance = $x->getTargetClass()->newInstance(); } assert($instance != null); $this->push($x, $instance); $this->acceptArray($x->getSetters()); $deserialize->invoke($subReader, $instance); } return false; }