Author Topic: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9 With proposed solution  (Read 1053 times)

welrachid

  • Jr. Member
  • **
  • Posts: 260
  • 3rd party plugin developer
  • Skype Name: wel.rachid
  • VirtueMart Version: Always LATEST stable
Joomla 3.4.5

components/com_virtuemart/controllers/plugin.php Line: 72 + 76

jExit();

makes the joomla exit with outputted data. This means no headers are set before output.

Im using example with parameters format=json
Best regards,
Wel

welrachid

  • Jr. Member
  • **
  • Posts: 260
  • 3rd party plugin developer
  • Skype Name: wel.rachid
  • VirtueMart Version: Always LATEST stable
Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9
« Reply #1 on: December 02, 2015, 12:16:15 pm »
And this should be confirming that headers are not SENT before jexit();
they are just prepared

http://joomla.stackexchange.com/questions/1126/return-json-using-the-joomla-framework
Best regards,
Wel

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9942
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9
« Reply #2 on: December 03, 2015, 11:38:30 am »
So what do you suggest? We used jExit instead of die. So how do we sent the header?
should we use someting like
$this->app->mimeType = 'application/json';
??
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

welrachid

  • Jr. Member
  • **
  • Posts: 260
  • 3rd party plugin developer
  • Skype Name: wel.rachid
  • VirtueMart Version: Always LATEST stable
Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9
« Reply #3 on: December 04, 2015, 08:27:43 am »
Hi Milbo
Sry for the late reply. Im not sure why im not being notified for new entries in my thread. anyway - ill make sure ill check up a couple of times during day

Im not that much into the Joomla platform, but from what i can read around the web the problem that occours is that joomla exists without sending the headers. so the solution is to send the headers yourself.
Doing that lead me to an other problem. The mimetype was not printed either. so i have to manually set the content-type header
See my working code:
         if ($format == 'json') {
            $document->setMimeEncoding ('application/json');
            // Change the suggested filename.
            JResponse::setHeader ('Content-Disposition', 'attachment;filename="' . $type . '.json"');
            JResponse::setHeader("Content-type","application/json");
            JResponse::sendHeaders();
            echo json_encode ($render);
            jExit();
         }

reading the platform api says that this method is deprecated:
https://api.joomla.org/cms-3/classes/JResponse.html#method_sendHeaders

They write that we should :
4.0 Use JApplicationWeb::sendHeaders() instead

However when i write that in that place the JApplicationWeb is not defined or instantiated or something..it fails.. but again i think the whole JResponse class will be deprecated and replaced by JApplicationWeb - so when VM is updated at some point in the future this will be handled by the new class i guess?

Again.. i dont know "much" about what happens in the core of VM, so i cannot say if everything is being dealt with with my code. but please feel free to change it the way you want and let me know if i can be of any assistance.

Have a great friday
Best regards,
Wel

welrachid

  • Jr. Member
  • **
  • Posts: 260
  • 3rd party plugin developer
  • Skype Name: wel.rachid
  • VirtueMart Version: Always LATEST stable
Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9
« Reply #4 on: December 07, 2015, 22:14:35 pm »
perhaps someone from the development team can confirm this bug and tell me if the proposed fix is good enough, so i can go ahead and upgrade production på newest versions and make those hack (that will be overwritten once u release the next version)
Best regards,
Wel

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9942
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9 With proposed solution
« Reply #5 on: December 11, 2015, 01:29:23 am »
oh sorry, I thought I answered you already. Yes your fix is quite adequate. I added almost the same now. You may check the svn at http://dev.virtuemart.net/projects/virtuemart/repository
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

welrachid

  • Jr. Member
  • **
  • Posts: 260
  • 3rd party plugin developer
  • Skype Name: wel.rachid
  • VirtueMart Version: Always LATEST stable
Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9 With proposed solution
« Reply #6 on: December 12, 2015, 09:44:14 am »
Great

Thanks
Best regards,
Wel