-
Apr 22nd, 2010, 03:27 PM
#1
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
-
Apr 23rd, 2010, 08:57 AM
#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
-
Apr 23rd, 2010, 10:27 AM
#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
-
Apr 25th, 2010, 02:57 PM
#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.
-
Apr 27th, 2010, 02:41 PM
#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?
-
May 19th, 2010, 08:13 AM
#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
-
May 19th, 2010, 10:05 AM
#7
I have fixed the issue. Rev 407 in the trunk.
Thanks,
Kev
-
May 19th, 2010, 12:47 PM
#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
-
May 20th, 2010, 01:39 AM
#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
-
May 20th, 2010, 03:43 AM
#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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules