/**
  * This method process an AJAX request
  *
  */
 public function processRequest(__IRequest &$request, __IResponse &$response)
 {
     try {
         $return_value = $this->_resolveAndCallRemoteService($request);
         if ($return_value !== null) {
             if (function_exists('json_encode')) {
                 $return_value = json_encode($return_value);
             } else {
                 $services_json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
                 $return_value = $services_json->encode($return_value);
             }
         }
         $response->addContent($return_value);
     } catch (Exception $e) {
         $response->addHeader("HTTP/1.0 500 Internal Server Error");
         $response->addContent(json_encode($e->getMessage()));
     }
 }
 public function write(__IResponse &$response)
 {
     switch ($this->_position) {
         case self::POSITION_TOP:
             $response->dockContentOnTop($this->getContent(), $this->getId());
             break;
         case self::POSITION_BOTTOM:
             $response->dockContentAtBottom($this->getContent(), $this->getId());
             break;
         case self::POSITION_EMBEDDED:
             $response->placeContentAfterElement($this->getContent(), $this->getElementToPlaceContentAfter(), $this->getId());
             break;
         default:
             $response->addContent($this->getContent(), $this->getId());
             break;
     }
 }