Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CustomContentHandler for ReEntry
#1
I'm trying to replace code that used to run under ReEntryURL with a Custom Content Handler.

I've created the handler and registered it.  When I call it, all the code executes properly.  If I use aReply.WriteString(), that works and is returned properly.

What I'm trying to do is display an updated form.  The session is already active and the form already created. The form is also the currently active form.  When the call is made, I manipulate the form using Delphi calls. I then simply return control back to the handler.  However, no content is written to the Reply/Response.  It's empty and generates a 'Uninitialized reply.' exception.  (although it displays as a blank page - I've reported the reason for that to Alex already)


Do I need to make an additional call to tell IW that my form needs to be re-sent, updated? 
Is what I'm trying to do even possible?

Thanks!
Pete

This is an app that gets called from a desktop (or another web)  app.  Basically REST is used to modify database content and then the desktop app opens a browser and displays the content.  I had it working fine in earlier versions of IW before ReEntry went away.
Reply
#2
Pete, when you create your contentHandle check Canstart and RequiresSession:

with THandlers.Add('/nfse/', '', TContentAPI_NFSe.Create ) do begin
  CanStartSession      := True;
  RequiresSessionStart := False;
end;
Reply
#3
This is actually how 17 hooks into 15 and serves much of its content.
Reply
#4
(04-03-2019, 10:53 PM)Jose Nilton Pace Wrote: Pete, when you create your contentHandle check Canstart and RequiresSession:

with THandlers.Add('/nfse/', '', TContentAPI_NFSe.Create ) do begin
  CanStartSession      := True;
  RequiresSessionStart := False;
end;

Hi Jose,

Thanks for answering. (again - you're on a streak today!)

I had RequiresSessionStart := true,  but either way it doesn't work. 
It can access my session and all the forms and everything.  It prepares the entire page properly. Every line of code that it should hit, gets hit when I make the request.  But at the very end, it doesn't render that code to the response. 
In THTTPServerIndy.DecodeReply(), the replyType returns rtNone.  But even if I force that to something else, there is no content in the stream to render.
Pete
Reply
#5
Have you checked how TContentForm works? TContentForm does something like what you described...
Reply
#6
(04-04-2019, 07:51 AM)Alexandre Machado Wrote: Have you checked how TContentForm works? TContentForm does something like what you described...

I think that worked.  OnURLRequest is key. Preparing to implement in my own code.  Thank you Alex!  

I'll have a slightly more interesting ContentHandlers demo for you shortly. 
You also might want to remove your local path from the CacheDir property.  Causes a failure when it runs.

Pete
Reply
#7
Urgent: Demo this afternoon. I'm using a TContentForm handler and it is working as desired.
HOWEVER: After executing such a call, the URL changes to the name of the content handler. All subsequent navigation in my app are now at that URL. It keeps working, but it now has a new URL base and any files referenced relative to the real base URL are not found.

Normal URL when navigating the app:
http://myserver/cm/cmo.dll/
ContentForm example call:
http://myserver/cm/cmo.dll/MyContentHandler?this=that&a=b
After ContentForm call, further navigation looks like this:
http://myserver/cm/cmo.dll/MyContentHandler/

As a result, a file that should be able to referenced as
http://myserver/cm/cmo.dll/files/test.html
when referenced relatively looks like this:
http://myserver/cm/cmo.dll/MyContentHandler/files/test.html
and is therefore not found.

Any ideas how to get rid of the content handler suffix?

Thanks,
Pete
Reply
#8
Same problem here. Also, if on ServerController the AllowMultipleSessionsPerUser is True, the Session ID is duplicated in URL.

Bug can easily be reproduced with ContentHandlers demo.
https://github.com/Atozed/IntraWeb/tree/...ntHandlers

Steps to reproduce:
  1. set AllowMultipleSessionsPerUser on ServerController
  2. Run ContentHandlers demo
  3. Click for example button "Call Red Form (uses TContentForm class)"
  4. Click button "Back to Main Form"
URL in browser contains Session ID twice.


In ContentHandlers demo the TContentForm is registered with an empty path parameter:
Code:
  THandlers.Add( '' , 'redform.html' , TContentForm.Create( TRedForm ) )

But, if AllowMultipleSessionsPerUser is false, and content handler is registered with non-empty path parameter, it results in 404 error.
Code:
  THandlers.Add( '/mypath/' , 'redform.html' , TContentForm.Create( TRedForm ) );


Custom Content Handlers is powerful feature in IntraWeb. In our project we have TContentForm descendant to dynamically show an IWForm depending on query string in URL. It is comparable with DynamicContentWithHandlers demo to show different kind of reports, but with TContentForm instead. Bugfix or workaround appreciated.
Reply
#9
(05-18-2019, 09:22 PM)Erwin_Mouthaan Wrote: Same problem here. Also, if on ServerController the AllowMultipleSessionsPerUser is True, the Session ID is duplicated in URL.

Bug can easily be reproduced with ContentHandlers demo.
https://github.com/Atozed/IntraWeb/tree/...ntHandlers

Steps to reproduce:
  1. set AllowMultipleSessionsPerUser on ServerController
  2. Run ContentHandlers demo
  3. Click for example button "Call Red Form (uses TContentForm class)"
  4. Click button "Back to Main Form"
URL in browser contains Session ID twice.


In ContentHandlers demo the TContentForm is registered with an empty path parameter:
Code:
  THandlers.Add( '' , 'redform.html' , TContentForm.Create( TRedForm ) )

But, if AllowMultipleSessionsPerUser is false, and content handler is registered with non-empty path parameter, it results in 404 error.
Code:
  THandlers.Add( '/mypath/' , 'redform.html' , TContentForm.Create( TRedForm ) );


Custom Content Handlers is powerful feature in IntraWeb. In our project we have TContentForm descendant to dynamically show an IWForm depending on query string in URL. It is comparable with DynamicContentWithHandlers demo to show different kind of reports, but with TContentForm instead. Bugfix or workaround appreciated.

Hi Erwin,

I can confirm that a bug exists if you set AllowMultipleSessionsPerUser and include a path to the form.

This is already fixed in our code base and we'll release an update soon. Not sure if a viable workaround exists, unless you modify IW.Content.Form.pas and build it yourself...
Reply
#10
(04-17-2019, 04:12 PM)pete@pdmagic.com Wrote: Urgent: Demo this afternoon.  I'm using a TContentForm handler and it is working as desired.
HOWEVER: After executing such a call, the URL changes to the name of the content handler. All subsequent navigation in my app are now at that URL.  It keeps working, but it now has a new URL base and any files referenced relative to the real base URL are not found.

Normal URL when navigating the app:
http://myserver/cm/cmo.dll/  
ContentForm example call:
http://myserver/cm/cmo.dll/MyContentHandler?this=that&a=b
After ContentForm call, further navigation looks like this:
http://myserver/cm/cmo.dll/MyContentHandler/

As a result, a file that should be able to referenced as
http://myserver/cm/cmo.dll/files/test.html
when referenced relatively looks like this:
http://myserver/cm/cmo.dll/MyContentHandler/files/test.html
and is therefore not found.

Any ideas how to get rid of the content handler suffix?

Thanks,
Pete

Hi Pete,

When you call the content handler your application url becomes the url of the content form. In your case:

http://myserver/cm/cmo.dll/MyContentHandler

Not sure how you close this form...

However seems that the address of the file is document-relative so it is appended to your current path.

If you reference your file starting with a slash, it will become root-relative, which is the correct file address.

So, the relative url of that file should be 

'/files/test.html'

This will fix the file issue, but not exactly sure about the form address though. You can release the form and navigate to the root of your
application using WebApplication.GotoURL('/'). Probably you can try this:

(example where a Button1 on your content form will close the form and go back to the root)

procedure TForm1.Button1Click(Sender: TObject);
begin
  Release;
  WebApplication.GoToUrl(WebApplication.SessionUrlBase);
end;



ContentForms have a nice feature which allows navigation through the application using URL addresses (just like shown in ContentHandlersDemo, mentioned below by Erwin), but this feature might not be desired in all scenarios.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)