Announcement Announcement Module
Collapse
No announcement yet.
Problem with http post through proxy Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with http post through proxy

    I configured a proxy to execute Alfresco webscripts in the backend. When I send a form with method get the arguments are recevied by the backend, when I use a post method the webscript takes a long time to respond and does not receive any arguments from the frontend webscript.

    I use the quickstart project as a starting point (version 1.0.0.CI-SNAPSHOT). The backend is Alfresco Community 3.3.

    First I added a remote endpoint in surf.xml:

    <config evaluator="string-compare" condition="Remote">
    <remote>
    <endpoint>
    <id>alfresco-noauth</id>
    <name>HTTP access</name>
    <description>Generic HTTP connector</description>
    <connector-id>http</connector-id>
    <endpoint-url>http://localhost:8080/alfresco/service</endpoint-url>
    <identity>declared</identity>
    <username>admin</username>
    <password>admin</password>
    </endpoint>
    </remote>
    </config>

    Then I added a component:

    proxytest.get.desc.xml

    <webscript>
    <shortname>proxytest</shortname>
    <description>Post Test</description>
    <url>/test/proxy</url>
    </webscript>

    proxytest.get.html.ftl

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Proxy Test</title>
    </head>
    <body>
    <form method="post" action="${url.context}/proxy/alfresco-noauth/sample/args">
    <div>
    <input type="text" name="firstname" value="Charles"/>
    <input type="text" name="lastname" value="Dickens"/>
    <input type="submit"/>
    </div>
    </form>
    </body>
    </html>

    The /sample/args webscript in the backend simply logs the args and argsM name value pairs and returns them in the response.

    With form method get the arguments are returned, when I set the method to post nothing is returned.

    When I run the proxy test in the backend (without the proxy in the action url) both get and post work fine.

    What is missing from my configuration?

    Thanks,

    Bas

  • #2
    Silly question, but I assume that you have similar scripts setup that are geared towards post requests.

    e.g.

    proxytest.get.desc.xml = proxytest.post.desc.xml

    Comment


    • #3
      Not a silly question. To test the post I simply used a webscript that outputs the arguments. The scripts are on the backend (Alfresco Community 3.3):

      args.post.desc.xml:

      <webscript>
      <shortname>Argument Handling Sample</shortname>
      <description>Demonstrate access to single and multi-valued arguments</description>
      <url>/sample/args</url>
      <authentication>user</authentication>
      </webscript>

      args.post.js:

      for (arg in args)
      {
      logger.log(arg + "=" + args[arg]);
      }

      for (arg in argsM)
      {
      for each (val in argsM[arg])
      {
      logger.log(arg + "=" + val);
      }
      }

      args.post.html.ftl:

      <#list args?keys as arg>
      ${arg}=${args[arg]}
      </#list>

      <#list argsM?keys as arg>
      <#list argsM[arg] as val>
      ${arg}=${val}
      </#list>
      </#list>

      This is the log for the backend when processing the form:

      17:15:54,916 DEBUG [org.springframework.extensions.webscripts.servlet. WebScriptServlet] Processing request (POST) http://localhost:8080/alfresco/s/sample/args

      17:16:15,426 DEBUG [org.springframework.extensions.webscripts.Abstract Runtime] (Runtime=ServletRuntime, Container=Repository) Processing script url (POST) /sample/args

      17:16:15,429 DEBUG [org.springframework.extensions.webscripts.Declarat iveRegistry] Web Script index lookup for uri /sample/args took 2.078407ms

      17:16:15,431 DEBUG [org.springframework.extensions.webscripts.Declarat iveRegistry] Web Script index lookup for uri /sample/args took 0.444261ms

      17:16:15,436 DEBUG [org.springframework.extensions.webscripts.servlet. WebScriptServletRequest] Content Type: application/x-www-form-urlencoded

      17:16:15,440 DEBUG [org.springframework.extensions.webscripts.Abstract Runtime] Agent: null

      17:16:15,440 DEBUG [org.springframework.extensions.webscripts.Abstract Runtime] Invoking Web Script args.post (format html, style: any, default: html)

      17:16:15,444 DEBUG [org.alfresco.repo.web.scripts.RepositoryContainer] Current authentication: unauthenticated

      17:16:15,448 DEBUG [org.alfresco.repo.web.scripts.RepositoryContainer] Authentication required: user

      17:16:15,452 DEBUG [org.alfresco.repo.web.scripts.RepositoryContainer] Guest login requested: false

      17:16:15,456 DEBUG [org.alfresco.repo.web.scripts.servlet.BasicHttpAut henticatorFactory$BasicHttpAuthenticator] HTTP Authorization provided: true

      17:16:15,459 DEBUG [org.alfresco.repo.web.scripts.servlet.BasicHttpAut henticatorFactory$BasicHttpAuthenticator] URL ticket provided: false

      17:16:15,468 DEBUG [org.alfresco.repo.web.scripts.servlet.BasicHttpAut henticatorFactory$BasicHttpAuthenticator] Authenticating (BASIC HTTP) user admin

      17:16:15,485 DEBUG [org.alfresco.repo.web.scripts.RepositoryContainer] Authentication: authenticated as admin

      17:16:15,488 DEBUG [org.alfresco.repo.web.scripts.RepositoryContainer] Begin retry transaction block: required,readwrite

      17:16:15,489 DEBUG [org.alfresco.repo.web.scripts.RepositoryContainer] Creating Transactional Response for ReadWrite transaction; buffersize=4096

      17:16:15,511 DEBUG [org.springframework.extensions.webscripts.Abstract WebScript] Caching script classpath*:alfresco/extension/templates/webscripts/args.post.js for web script args.post and request mimetype application/x-www-form-urlencoded

      17:16:15,513 DEBUG [org.springframework.extensions.webscripts.Declarat iveWebScript] Executing script classpath*:alfresco/extension/templates/webscripts/args.post.js

      17:16:15,529 DEBUG [org.springframework.extensions.webscripts.ScriptCo nfigModel] org.springframework.extensions.webscripts.ScriptCo nfigModel@1914233 created:
      config service: org.springframework.extensions.config.xml.XMLConfi gService@1914a0d
      global config: {}
      script config: null

      17:16:15,539 DEBUG [org.alfresco.repo.jscript.RhinoScriptProcessor] Resolving and compiling script path: file:/C:/alfresco-community-tomcat-3.3/tomcat/shared/classes/alfresco/extension/templates/webscripts/args.post.js

      17:16:15,545 DEBUG [org.alfresco.repo.jscript.RhinoScriptProcessor] Imports resolved, adding resource '_root

      17:16:15,686 DEBUG [org.alfresco.repo.jscript.RhinoScriptProcessor] Time to execute script: 47.844067ms

      17:16:15,687 DEBUG [org.springframework.extensions.webscripts.Abstract WebScript] Executed script classpath*:alfresco/extension/templates/webscripts/args.post.js in 149.59311ms

      17:16:15,722 DEBUG [org.springframework.extensions.webscripts.Template ConfigModel] org.springframework.extensions.webscripts.Template ConfigModel@968282 created:
      config service: org.springframework.extensions.config.xml.XMLConfi gService@1914a0d
      global config: {}
      script config: null

      17:16:15,731 DEBUG [org.springframework.extensions.webscripts.servlet. WebScriptServletResponse] Cache - set response header Cache-Control: no-cache

      17:16:15,734 DEBUG [org.springframework.extensions.webscripts.servlet. WebScriptServletResponse] Cache - set response header Pragma: no-cache

      17:16:15,738 DEBUG [org.springframework.extensions.webscripts.Declarat iveWebScript] Rendering response: content type=text/html, status=200

      17:16:15,742 DEBUG [org.springframework.extensions.webscripts.Declarat iveWebScript] Rendering template 'args.post.html'

      17:16:16,068 DEBUG [org.springframework.extensions.webscripts.Abstract WebScript] Rendered template args.post.html in 322.5315ms

      17:16:16,068 DEBUG [org.alfresco.repo.web.scripts.RepositoryContainer] End retry transaction block: required,readwrite

      17:16:16,074 DEBUG [org.alfresco.repo.web.scripts.RepositoryContainer] Authentication reset: unauthenticated

      17:16:16,075 DEBUG [org.springframework.extensions.webscripts.Abstract Runtime] Web Script args.post executed in 635.0244ms

      17:16:16,079 DEBUG [org.springframework.extensions.webscripts.Abstract Runtime] Processed script url (POST) /sample/args in 21157.031ms

      Comment


      • #4
        Although I have to run some more test, I think there is an error in RemoteClient. In the source (revision 381) I changed line 714 from:

        if (req != null && contentLength == 0 && method instanceof PostMethod)

        to

        if (req != null && contentLength != 0 && method instanceof PostMethod)

        And now the post parameters are passed to the backend. It makes sense since when posting data the parameters are added to the request body and the content length contains the length of the request body.

        Comment


        • #5
          Does any one have any idea if the proxy configuration was designed to handle http posts including multi-part file uploads? We managed to use a proxy to do these things with older versions of the Surf framework that were developed by Alfresco, but this stuff does not seem to work any more. Is this by design, or are these bugs?

          Comment


          • #6
            Hi,

            Yes that does look like a bug. I will take a look.

            The proxy (RemoteClient) is designed to handle all types of requests and is responsible for all the remote calls made from Surf to remote servers. This case looks like an issue, probably because in Alfresco for the 99% case we only POST body content (normally a slab of JSON) which will work given the current code.

            Thanks,

            Kev

            Comment


            • #7
              I have fixed the issue. Rev 407 in the trunk.

              Thanks,

              Kev

              Comment


              • #8
                Thanks Kev,

                svn update throws an SSL error at the moment, but as soon as I can update the code I will give it a try.

                Bas

                Comment


                • #9
                  Simple http post data is now properly send to the backend, but the Remoteclient does not send the multipart content, only the parameters. I tested it using revision 407 with Alfresco 3.2R E on the backend with the simple /sample/upload webscript to test the upload capabilities (see Webscript Examples).

                  I also checked the Alfresco Surf RemoteClient code and it seems to me that hardly anything changed. At the same time: using Alfresco Surf we where able to use the proxy configuration (Remoteclient) to send multipart data to the backend. Can this be related to the way spring is processing the request?

                  Bas

                  Comment


                  • #10
                    Hi,

                    OK, I'll try your test and modify the code to handle all cases correctly. It's possible it's related to how Spring is processing the request (if as you say, it's different in Alfresco Surf to SpringSurf - as you are the right the code is basically the same), so i'll investigate that today.

                    Thanks,

                    Kev

                    Comment


                    • #11
                      Hello,

                      I have refactored the RemoteClient support for application/x-www-form-urlencoded forms so that it correctly submits the posted paramaters.

                      I used something very similar to your test case:
                      Code:
                      <html xmlns="http://www.w3.org/1999/xhtml">
                         <head>
                            <title>Proxy Test</title>
                         </head>
                         <body>
                            <form method="post" action="${url.context}/proxy/alfresco-admin/sample/args" accept-charset="UTF-8">
                               <div>
                                  <input type="text" name="firstname" value="Charles"/>
                                  <input type="text" name="lastname" value="Dickens"/>
                                  <input type="submit"/>
                               </div>
                            </form>
                         </body>
                      </html>
                      and I created a multipart/form-data version of the same test with a file upload element:
                      Code:
                      <html xmlns="http://www.w3.org/1999/xhtml">
                         <head>
                            <title>Proxy Test</title>
                         </head>
                         <body>
                            <form method="post" action="${url.context}/proxy/alfresco-admin/sample/args" enctype="multipart/form-data" accept-charset="UTF-8">
                               <div>
                                  <input type="text" name="firstname" value="Charles"/>
                                  <input type="text" name="lastname" value="Dickens"/>
                                  <input type="file" name="fileupload"/>
                                  <input type="submit"/>
                               </div>
                            </form>
                         </body>
                      </html>
                      Both tests now work correctly, I used your sample args webscript at the backend also.

                      rev 408

                      Thanks,

                      Kevin

                      Comment


                      • #12
                        Hi Kev,

                        Thank you very much for your help. I tried to run the upload, but still receive a 400 error from the sample/upload backend script (http://wiki.alfresco.com/wiki/Web_Sc...es#File_Upload) that I use to test the multipart data.

                        Have you been able to post the multipart form to the sample/upload backend webscript, or do I need to use a different approach to retrieve the file data in the backend?

                        Kind regards,

                        Bas

                        Comment


                        • #13
                          Hi,

                          That is exactly the sample upload webscript I used to test the backend of multi-part form file upload - so yes it should work

                          The only changes I made to your web-tier sample, were to set the form to multipart:
                          Code:
                          enctype="multipart/form-data"
                          and obviously change the field names to match those expected by the backend:
                          Code:
                                      <input type="text" name="title" value="the file title"/>
                                      <input type="text" name="desc" value="the file description"/>
                                      <input type="file" name="file"/>
                          Then you will see the result:
                          Code:
                          Alfresco  	Upload Web Script Sample
                          	Alfresco Community v3.3.0 (beta @build-number@)
                          	
                          	Uploaded upload9_01-gold-bar.jpg of size 76,151.
                          So the key point here is that multipart must be set on your upload form if it is to be used to transfer file content - that is the only mechanism supported for binary uploads, and the field names expected by the destination web-script must match those in your source form.

                          Cheers,

                          Kev

                          Comment


                          • #14
                            In that case I must be doing something wrong since I keep receiving the following response from the backend:

                            ========
                            Alfresco Web Script Status 400 - Bad Request

                            The Web Script /alfresco/service/sample/upload has responded with a status of 400 - Bad Request.

                            400 Description: Request sent by the client was syntactically incorrect.

                            Message: Uploaded file cannot be located in request
                            Server: Alfresco Community v3.3.0 (2765) schema 4.009
                            Time: 28-mei-2010 16:12:38

                            Diagnostics: Inspect Web Script (upload.post)
                            ========

                            I am using Spring Surf revision 414 on the frontend (did an svn update, mvn clean and install for surf), created a quick start application and modified surf.xml according to the attached file and added the upload.get.desc.xml and upload.get.html.ftl (see attachment).

                            On the backend I use Alfresco Community 3.3 with the upload post script from the sample webscripts page.

                            Any idea what the difference might be?

                            Kind regards,

                            Bas

                            Comment


                            • #15
                              have just the same problem. thank you for trying to help us

                              Comment

                              Working...
                              X