/**
  * Advice used to encode the response data.
  *
  * @param \AppserverIo\Psr\MetaobjectProtocol\Aop\MethodInvocationInterface $methodInvocation Initially invoked method
  *
  * @return void
  */
 public function intercept(MethodInvocationInterface $methodInvocation)
 {
     // load the method invocation parameters
     $this->setParameters($methodInvocation->getParameters());
     // load the servlet instance
     $servlet = $methodInvocation->getContext();
     // query whether we've to validate the servlet or not
     if ($servlet instanceof ValidationAwareInterface) {
         // create a reflection object instance
         $reflectionObject = new ReflectionObject($servlet);
         // iterate over all methods to one with the apropriate validation annotations
         foreach ($reflectionObject->getMethods() as $reflectionMethod) {
             // prepare the request method name
             $requestMethod = ucfirst(strtolower($this->getServletRequest()->getMethod()));
             // invoke the valiation method only on the Doppelgaenger methods
             if ($reflectionMethod->hasAnnotation(sprintf('ValidateOn%s', $requestMethod)) && stripos($reflectionMethod->getMethodName(), 'DOPPELGAENGEROriginal') === false) {
                 $reflectionMethod->invoke($servlet);
             }
         }
     }
     // proceed method invocation
     return $methodInvocation->proceed();
 }
예제 #2
0
 /**
  * Iterates over all servlet request parameters and tries to find and
  * invoke a setter with the param that matches the setters name.
  *
  * @param AppserverIo\Psr\MetaobjectProtocol\Aop\MethodInvocationInterface $methodInvocation Initially invoked method
  *
  * @return string|null The action result
  */
 public function intercept(MethodInvocationInterface $methodInvocation)
 {
     // load the method invocation parameters
     $this->setParameters($methodInvocation->getParameters());
     // load the servlet instance
     $servlet = $methodInvocation->getContext();
     // get the servlet's methods
     $methods = get_class_methods($servlet);
     // try to inject the request parameters by using the class setters
     foreach ($this->getServletRequest()->getParameterMap() as $key => $value) {
         // prepare the setter method name
         $methodName = sprintf('set%s', ucfirst($key));
         // query whether the class has the setter implemented
         if (in_array($methodName, $methods) === false) {
             continue;
         }
         try {
             // set the value by using the setter
             $servlet->{$methodName}($value);
         } catch (\Exception $e) {
             $servlet->addError(array($key => $e->getMessage()));
         }
     }
     // proceed method invocation
     return $methodInvocation->proceed();
 }
 /**
  * Advice used to encode the response data.
  *
  * @param \AppserverIo\Psr\MetaobjectProtocol\Aop\MethodInvocationInterface $methodInvocation Initially invoked method
  *
  * @return void
  */
 public function intercept(MethodInvocationInterface $methodInvocation)
 {
     // load the method invocation parameters
     $this->setParameters($methodInvocation->getParameters());
     // load the servlet instance
     $servlet = $methodInvocation->getContext();
     // query whether or not we've to process errors
     if ($servlet instanceof ValidationAwareInterface && $servlet->hasErrors()) {
         $servlet->processErrors($this->getServletRequest(), $this->getServletResponse());
     }
     // query whether or not we've to encode the request
     if ($servlet instanceof EncodingAwareInterface) {
         $servlet->encode($this->getServletRequest(), $this->getServletResponse());
     }
 }
예제 #4
0
 /**
  * Method that implements the interceptors functionality.
  *
  * @param AppserverIo\Psr\MetaobjectProtocol\Aop\MethodInvocationInterface $methodInvocation Initially invoked method
  *
  * @return string|null The action result
  */
 public function intercept(MethodInvocationInterface $methodInvocation)
 {
     try {
         // load the action instance
         $this->setAction($methodInvocation->getContext());
         // load the method invocation parameters
         $this->setParameters($methodInvocation->getParameters());
         // execute the custom interceptor functionality
         return $this->execute($methodInvocation);
     } catch (\Exception $e) {
         // add the catched exception
         $this->getAction()->addFieldError('unknown', $e->getMessage());
         // return the key for a failed action invocation
         return ActionInterface::FAILURE;
     }
 }