Cakephp 3.x и прием сторонних xml-данных

Наши клиенты отправляют документы третьим лицам и хранят их. Как только третья сторона получает документы, они отправляют XML-данные на наш URL-адрес, который мы им предоставляем (например, https://example.com/Documents/receive). Наша третья сторона требует, чтобы мы отправили им ответ о том, что мы получили их запрос. Мы создали библиотеку поставщиков и автоматически загружаем ее в наше приложение. По какой-то причине, когда мы подделываем запрос от третьей стороны, мы получаем перенаправление обратно на нашу страницу входа в систему, как будто ничего не произошло. Это наш контроллер.

class DocumentsController extends AppController {

    public function beforeFilter(Event $event) {
        parent::beforeFilter($event);
        $this->Security->config('unlockedActions', ['receive']);
        $this->Auth->allowedActions = (['receive']);
    }
   public function receive()
    {
        $this->request->allowMethod(['post']);
        $this->autoRender = false;
        $doc = new \Document\Document(false);
        $doc->set_user_name("username");
        $doc->set_user_password("password");
        $xml = $this->request->data['xml'];
        try {
            if($doc->parse_inbound_message($xml)) {
                $parsed = $doc->getContent();
                $file = new File('files/playground/test_file.xml', true, 0644);
                $file->open();
                //$file->write(print_r($parsed, true));
                $file->write('Hey, I parsed!');
                $file->close();
            } else {
                $file = new File('files/playground/test_file.xml', true, 0644);
                $file->open();
                $file->write('we got a false');
                $file->close();
            }
        } catch(\Document\DocumentException $e){
            $file = new File('files/playground/test_file.xml', true, 0644);
            $file->open();
            $file->write($e->getMessage());
            $file->close();
        }
    }
}

person chrisShick    schedule 21.01.2015    source источник


Ответы (1)


Кажется, что-то не так с кулинарной книгой. Попробуй это:

public function beforeFilter(Event $event) {
  parent::beforeFilter($event);
  $this->Auth->allow(['receive']);
}
person rrd    schedule 22.01.2015