2

I've for a REST endpoint that will be accepting a POST in the form of XML. Currently it's throwing an "Invalid xml message received" in vendor/friendsofsymfony/rest-bundle/EventListener/BodyListener.php (line 115) when it attempts to decode the content.

Here's the first three lines of code. Note the XML itself validates.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE SupplierSyncMessage SYSTEM "http://integrations.sciquest.com/app_docs/dtd/supplier/TSMSupplier.dtd">
<SupplierSyncMessage version="1.0">

Best I can tell the offending part is:

<!DOCTYPE SupplierSyncMessage SYSTEM "http://integrations.sciquest.com/app_docs/dtd/supplier/TSMSupplier.dtd">

If I remove this line from my test post the request goes through.

I won't have the latitude to receive the XML without this string in it, so is there a config or something that will tell the decoder to ignore it? Is there some other config that tells it to use the .dtd to validate the XML?

Any idea what I'm missing.. Not real sure where to start looking.

Adding the controller code.


use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

class DefaultController
{
    /**
     * Retrieves data via POST
     *
     * @Route("/api/import", methods={"POST"})
     *
     *
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     * @throws \Exception
     */
    public function getXML(Request $request) {

        print_r($request); exit;

    }
}
RustedBucket
  • 23
  • 1
  • 5
  • Your question is not a MCVE. Try to improve it as suggested in [SO help pages](/help/mcve). – LMC Apr 16 '19 at 23:24
  • Can you show us how you are retrieving the request data in your controller? – NDZIE Patrick Joel Apr 17 '19 at 04:24
  • @NDZIEPatrickJoel I'm posting the XML via Postman as raw text/xml. I've added the controller portion to the original post. – RustedBucket Apr 17 '19 at 11:37
  • @NDZIEPatrickJoel From what I can tell is the a bombing before the post request is passed to the controller as the print_r never executes. Tracing it, it appears to die in the FOSRestBundle decoding the request. The error message there states an Invalid DocType but that's never part of the thrown stack trace. What I can't figure out is if there is a way to define allowed DocTypes. – RustedBucket Apr 17 '19 at 11:45
  • try this and tell me what you have inside the file : file_put_contents("test.txt", print_r($request->getContent(), true)); – NDZIE Patrick Joel Apr 17 '19 at 11:56
  • @NDZIEPatrickJoel file never gets created. It looks like symfony/serializer is explicitly throwing an exception in /vendor/symfony/serializer/Encoder/XmlEncoder on line 150 of the decode function. If I replace symfony/serializer with jms/serializer-bundle then it works fine. – RustedBucket Apr 17 '19 at 12:53

0 Answers0