Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-21053

REST v2: 403 error when using an empty FieldDefinition element in a JSON request

    XMLWordPrintable

Details

    • Aconcagua Sprint 1, Aconcagua Sprint 2

    Description

      When using a JSON request you try to create a new content type and you do not provide any fields definitions, you'l get a "403 Forbidden" which do not make sense.
      If using a XML request, you'll now correctly ( fixed in EZP-21016) get a "400 Bad request".

      However, the reason why you do not get this when sending a JSON request seems to be that the JSON parser malfunction in this case...

      Here you see the different reply with JSON vs XML
      JSON

      ################### - Client request BEGIN - #########################
      POST /api/ezp/v2/content/typegroups/1/types?publish=true HTTP/1.1
      Host: ezpublish5.rhel61.qa.ez.local:8080
      User-Agent: eZ REST QA Tester
      Content-Length: 742
      Accept:application/vnd.ez.api.ContentType+json
      Content-type:application/vnd.ez.api.ContentTypeCreate+json
      Authorization: Basic YWRtaW46cHVibGlzaA==
      
      {
          "ContentTypeCreate": {
              "identifier": "TContentType",
              "mainLanguageCode": "eng-GB",
              "urlAliasSchema": "<name>",
              "nameSchema": "<name>",
              "isContainer": "true",
              "defaultSortField": "PATH",
              "defaultSortOrder": "ASC",
              "defaultAlwaysAvailable": "true",
              "names": {
              "value": [
                  {
                  "_languageCode": "eng-GB",
                  "#text": "RESTv2DatatypeTest"
                  }
              ]
              },
              "descriptions": {
              "value": [
                  {
                  "_languageCode": "eng-GB",
                  "#text": "This is a description"
                  }
              ]
              },
              "FieldDefinitions": {
              "FieldDefinition": []
              }
          }
        }
      
      
      ##################### - Client request END - ##########################
      sending to target...done.
      Received from Target:
      ##################### - Target reply BEGIN - ##########################
      HTTP/1.1 403 Forbidden
      Date: Wed, 12 Jun 2013 13:57:36 GMT
      Server: Apache/2.2.15 (Red Hat)
      X-Powered-By: PHP/5.3.3
      Status: 403 Forbidden
      Cache-Control: no-cache
      Connection: close
      Transfer-Encoding: chunked
      Content-Type: application/vnd.ez.api.ErrorMessage+json
      
      c67
      {"ErrorMessage":{"_media-type":"application\/vnd.ez.api.ErrorMessage+json","errorCode":403,"errorMessage":"Forbidden","errorDescription":"Argument '$contentTypeCreateStruct' is invalid: Argument must contain at least one FieldDefinitionCreateStruct","trace":"#0 [internal function]: eZ\\Publish\\Core\\REST\\Server\\Controller\\ContentType->createContentType()\n#1 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpKernel.php(129): call_user_func_array(Array, Array)\n#2 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpKernel.php(73): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#3 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/DependencyInjection\/ContainerAwareHttpKernel.php(57): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#4 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/Kernel.php(199): Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#5 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpCache\/HttpCache.php(473): Symfony\\Component\\HttpKernel\\Kernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#6 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Bundle\/FrameworkBundle\/HttpCache\/HttpCache.php(60): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->forward(Object(Symfony\\Component\\HttpFoundation\\Request), true, NULL)\n#7 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpCache\/HttpCache.php(244): Symfony\\Bundle\\FrameworkBundle\\HttpCache\\HttpCache->forward(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#8 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpCache\/HttpCache.php(261): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->pass(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#9 \/var\/www\/apache2php53\/ezpublish5\/vendor\/ezsystems\/ezpublish-kernel\/eZ\/Bundle\/EzPublishCoreBundle\/HttpCache.php(38): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->invalidate(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#10 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpCache\/HttpCache.php(190): eZ\\Bundle\\EzPublishCoreBundle\\HttpCache->invalidate(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#11 \/var\/www\/apache2php53\/ezpublish5\/web\/index.php(59): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#12 {main}","file":"\/var\/www\/apache2php53\/ezpublish5\/vendor\/ezsystems\/ezpublish-kernel\/eZ\/Publish\/Core\/REST\/Server\/Controller\/ContentType.php","line":293}}
      0
      
      
      ###################### - Target reply END - ###########################
      

      XML:

      #################### - Client request BEGIN - #########################
      POST /api/ezp/v2/content/typegroups/1/types?publish=true HTTP/1.1
      Host: ezpublish5.rhel61.qa.ez.local:8080
      User-Agent: eZ REST QA Tester
      Content-Length: 741
      Accept:application/vnd.ez.api.ContentType+json
      Content-type:application/vnd.ez.api.ContentTypeCreate+xml
      Authorization: Basic YWRtaW46cHVibGlzaA==
      
      <?xml version="1.0" encoding="UTF-8"?>
      <ContentTypeCreate>
        <identifier>newContentType</identifier>
        <names>
          <value languageCode="eng-GB">New Content Type</value>
        </names>
        <descriptions>
          <value languageCode="eng-GB">This is a description</value>
        </descriptions>
        <remoteId>remoteId-qwert548</remoteId>
        <urlAliasSchema>&lt;title&gt;</urlAliasSchema>
        <nameSchema>&lt;title&gt;</nameSchema>
        <isContainer>true</isContainer>
        <mainLanguageCode>eng-GB</mainLanguageCode>
        <defaultAlwaysAvailable>true</defaultAlwaysAvailable>
        <defaultSortField>PATH</defaultSortField>
        <defaultSortOrder>ASC</defaultSortOrder>
        <FieldDefinitions>
          <FieldDefinition>
          </FieldDefinition>
         </FieldDefinitions>
      </ContentTypeCreate>
      
      
      ##################### - Client request END - ##########################
      sending to target...done.
      Received from Target:
      ##################### - Target reply BEGIN - ##########################
      HTTP/1.1 400 Bad Request
      Date: Wed, 12 Jun 2013 14:08:33 GMT
      Server: Apache/2.2.15 (Red Hat)
      X-Powered-By: PHP/5.3.3
      Status: 400 Bad Request
      Cache-Control: no-cache
      Connection: close
      Transfer-Encoding: chunked
      Content-Type: application/vnd.ez.api.ErrorMessage+json
      
      c33
      {"ErrorMessage":{"_media-type":"application\/vnd.ez.api.ErrorMessage+json","errorCode":400,"errorMessage":"Bad Request","errorDescription":"Invalid 'FieldDefinition' element for ContentTypeCreate.","trace":"#0 [internal function]: eZ\\Publish\\Core\\REST\\Server\\Controller\\ContentType->createContentType()\n#1 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpKernel.php(129): call_user_func_array(Array, Array)\n#2 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpKernel.php(73): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#3 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/DependencyInjection\/ContainerAwareHttpKernel.php(57): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#4 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/Kernel.php(199): Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#5 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpCache\/HttpCache.php(473): Symfony\\Component\\HttpKernel\\Kernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#6 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Bundle\/FrameworkBundle\/HttpCache\/HttpCache.php(60): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->forward(Object(Symfony\\Component\\HttpFoundation\\Request), true, NULL)\n#7 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpCache\/HttpCache.php(244): Symfony\\Bundle\\FrameworkBundle\\HttpCache\\HttpCache->forward(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#8 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpCache\/HttpCache.php(261): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->pass(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#9 \/var\/www\/apache2php53\/ezpublish5\/vendor\/ezsystems\/ezpublish-kernel\/eZ\/Bundle\/EzPublishCoreBundle\/HttpCache.php(38): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->invalidate(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#10 \/var\/www\/apache2php53\/ezpublish5\/vendor\/symfony\/symfony\/src\/Symfony\/Component\/HttpKernel\/HttpCache\/HttpCache.php(190): eZ\\Bundle\\EzPublishCoreBundle\\HttpCache->invalidate(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#11 \/var\/www\/apache2php53\/ezpublish5\/web\/index.php(59): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#12 {main}","file":"\/var\/www\/apache2php53\/ezpublish5\/vendor\/ezsystems\/ezpublish-kernel\/eZ\/Publish\/Core\/REST\/Server\/Controller\/ContentType.php","line":301}}
      0
      
      
      ###################### - Target reply END - ###########################
      
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            vidar.langseid@ibexa.co Vidar Langseid
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 5 hours, 45 minutes
                5h 45m