冲突

2016-09-30 127 views
1

我正在做一些休息和一些SOAP服务,为我使用FOSRestBundleREST者,为SOAP型我使用BeSimple Soap Bundle(这确实没有那么相关,因为问题出在FOSRest听众IMO,但我只是为了以防万一)。冲突

的事情是FOSRest提供了一个监听器来处理响应和序列化/使其像这样:

<?php 
/** 
* @Rest\View 
*/ 
public function getAction() 
{ 
    return $item; 
} 

,它处理其序列为JSON/XML或任何响应。 当我尝试调用我的SOAP服务时,冲突出现,并且侦听器对我说,它不支持SOAP作为格式(它支持JSON,XML等)。

发生这种情况时,我把view_response_listener: 'force'放到我的FOSRest yml配置文件中。如果我将其更改为view_response_listener: 'enabled',则SOAP服务可以正常工作,但我似乎失去了自动处理我的响应的FOSRest功能。

我怎样才能确定FOSRest view_response_listener只是处理了正确的回答,让SOAP Bundle处理肥皂类型的回应。

编辑:

fos_rest: 
    param_fetcher_listener: true 
    body_listener: true 
    format_listener: true 
    view: 
     view_response_listener: 'force' #This is the parameter that is driving me crazy. Value to 'force' Rest controllers work just fine SOAP don't, value to 'enabled' the other way around 
     formats: 
      xml: true 
      json : true 
     templating_formats: 
      html: true 
     force_redirects: 
      html: true 
     failed_validation: HTTP_BAD_REQUEST 
     default_engine: twig 
    routing_loader: 
     default_format: json 

这是FOSRestBundle配置。

这里是我的routing.yml休息端点和SOAP的人都:

#config/routing.yml 
rest_api: 
    resource: "@RESTBundle/Resources/config/api_routes.yml" 
    host:  "%host_front%" #api.myproject.local 
    type:  rest 

#api_routes.yml detail 
accounts: 
    resource: 'RESTBundle\Controller\AccountsController' 
    type:  rest 
    name_prefix: api_ 

#config/routing.yml 
soap_api: 
    resource: "@SOAPBundle/Resources/config/soap_routing.yml" 
    host:  "%host_ws%" 
    prefix: "%contexto_ws%" 

#soap_routing.yml detail 
_besimple_soap: 
    resource: "@BeSimpleSoapBundle/Resources/config/routing/webservicecontroller.xml" 
soap_ws: 
    resource: "@SOAPBundle/Controller/" 
    type: annotation 

RestController例如:

<?php 

namespace RESTBundle\Controller\API; 

use FOS\RestBundle\Controller\Annotations as Rest; 
use FOS\RestBundle\Controller\FOSRestController; 
use Nelmio\ApiDocBundle\Annotation\ApiDoc as ApiDoc; 
use Symfony\Component\HttpFoundation\Request; 

/** 
* @Rest\RouteResource("accounts", pluralize=false) 
*/ 
class AccountsController extends FOSRestController 
{ 
    /** 
    * @Rest\View 
    */ 
    public function getAction($userId) 
    { 
     return [ 
      ['name' => 'Example', 'pass'=> 'example'], 
      ['name' => 'Example2', 'pass'=> 'example2'] 
     ]; 
    } 
} 

SOAP控制器:

/** 
* @Soap\Header("user", phpType="string") 
* @Soap\Header("token", phpType="string") 
*/ 
class AccountsController implements ContainerAwareInterface 
{ 
    use ContainerAwareTrait; 

    /** 
    * @Soap\Method("getAccounts") 
    * @Soap\Param("account", phpType="SOAPBundle\DataType\AccountFilter") 
    * 
    * @Soap\Result(phpType="SOAPBundle\DataType\Account[]"") 
    */ 
    public function getAccountsAction(Request $request, AccountFilter $filter) 
    { 
     return [(new Account())->setName('Example')->setPass('example')] //This is just an example 
    } 
} 

编辑与错误:

request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException: "Format 'soap' not supported, handler must be implemented" at /home/teampro/Sites/corinto/vendor/friendsofsymfony/rest-bundle/View/ViewHandler.php line 292 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException(code: 0): Format 'soap' not supported, handler must be implemented at /.../vendor/friendsofsymfony/rest-bundle/View/ViewHandler.php:292)"} []

+0

请'config'更新您的问题路由配置,这是很难阅读各行:)另外,你可以分享你的代码吗? – Samundra

+0

@Samundra完成,它不是我的代码(不能在这里发布),但它是一个基于它的虚拟示例,所以它叫同样的东西。 – Astaroth

回答

1

您可以定义如何制定规则,听像fos_rest配置this

format_listener: 
     rules: 
     - { path: ^/, priorities: [ html, json, xml ], fallback_format: ~, prefer_extension: true } # default routes 
     - { path: '/soap', priorities: [xml], fallback_format: xml, prefer_extension: true } # your soap route 
     - { path: '^/rest', priorities: [xml, json], fallback_format: xml, prefer_extension: true } # your rest route 

希望这有助于!

+0

你有时间测试吗?我在服务器上制作了一个相同的API,并且这很好。 –

0

第一,明确地单独的路由与prefix财产

# app/config/routing.yml 
_besimple_soap: 
    resource: "@BeSimpleSoapBundle/Resources/config/routing/webservicecontroller.xml" 
    prefix: "%contexto_ws%" 

rest_api: 
    resource: "@RESTBundle/Resources/config/api_routes.yml" 
    host:  "%host_front%" #api.myproject.local 
    prefix:  /rest 
    type:  rest 

资源对于现在看起来,由于它重叠由configuraiton您的REST controlller处理WS路线。使用前缀分隔路由名称空间可以提供帮助。

其次,验证请求的主机,因为你的配置已经分裂基于请求主机变量

第三rouiting,请与

bin/console debug:router 
bin/console router:match 
+0

它们是分开的,其余的有一个前缀:'api'(我忘记把它放在OP上)。无论如何,他们也有自己的主人。这不是关于路由冲突,而是关于尝试处理所有**响应**的FOS侦听器,即使是那些SOAP。 – Astaroth