cancel
Showing results for 
Search instead for 
Did you mean: 

POST request becomes GET request after authentication using

ajansen
Champ in-the-making
Champ in-the-making
I am using web scripts to create content in Alfresco:

<webscript>
  <shortname>Content Create Sample</shortname>
  <description>Sample</description>
  <url>/test/createcontent</url>
  <format default="html">extension</format>
  <authentication>user</authentication>
  <transaction>required</transaction>
</webscript>

This is working OK, when a user is not logged the basic browser prompt is hown and the script continues.
Now I  customized the login to use the webclient instead of basic authentication in the web.xml:

   <servlet>
      <servlet-name>apiServlet</servlet-name>
      <servlet-class>org.alfresco.web.scripts.WebScriptServlet</servlet-class>
      <init-param>
         <param-name>authenticator</param-name>
         <param-value>webscripts.authenticator.webclient</param-value>
      </init-param>
   </servlet>

What happens when a user is not logged in the standard alfresco login page is displayed but the web script is not running correctly after successful login. From the log I retrieved this error:

13:45:05,044 DEBUG [org.alfresco.web.scripts.WebScriptServlet] Processing request (POST) http://localhost:8080/alfresco/service/test/createcontent
13:45:05,054 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Processing script url (POST) /test/createcontent
13:45:05,054 DEBUG [org.alfresco.web.scripts.DeclarativeWebScriptRegistry] Web Script index lookup for uri /test/createcontent took 0ms
13:45:05,054 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Agent: Firefox
13:45:05,054 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Format style: extension, Default format: html
13:45:05,054 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Invoking Web Script org/alfresco/repository/poc/createcontent.post (unauthenticated)
13:45:05,064 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Begin transaction: required
13:45:05,064 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Current authentication: unauthenticated
13:45:05,064 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Authentication required: user
13:45:05,064 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Guest login: false
13:45:05,064 DEBUG [org.alfresco.web.scripts.WebClientAuthenticator] Alfresco ticket provided: false
13:45:05,064 DEBUG [org.alfresco.web.scripts.WebClientAuthenticator] Authenticating session
13:45:05,084 DEBUG [org.alfresco.web.scripts.WebClientAuthenticator] Redirecting to Alfresco Login
13:45:05,084 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Authentication reset: unauthenticated
13:45:05,084 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] End transaction: required
13:45:05,084 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Web Script org/alfresco/repository/poc/createcontent.post executed in 30ms
13:45:05,084 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Processed script url (POST) /test/createcontent in 40ms
13:45:11,974 DEBUG [org.alfresco.web.scripts.WebScriptServlet] Processing request (GET) http://localhost:8080/alfresco/service/test/createcontent
13:45:11,974 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Processing script url (GET) /test/createcontent
13:45:11,974 DEBUG [org.alfresco.web.scripts.DeclarativeWebScriptRegistry] Web Script index lookup for uri /test/createcontent took 0ms
13:45:11,974 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Script url /test/createcontent does not support the method GET
13:45:12,584 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Force success status header in response: false
13:45:12,584 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Sending status 405 (Template: /status.ftl)
13:45:12,584 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Rendering response: content type=text/html
13:45:12,655 DEBUG [org.alfresco.web.scripts.WebScriptRuntime] Processed script url (GET) /test/createcontent in 681ms

Is this a bug or am I missing something ?
8 REPLIES 8

kevinr
Star Contributor
Star Contributor
If you want to use the web-client login you should go through the /wcservice url rather than the /service url then it will use the correct authenticator for the webscript.

Thanks,

Kevin

suleyman
Champ in-the-making
Champ in-the-making
I also have to add content to alfresco with webscripts.
Can you tell me how your webscript works or post your webscript here?

Thanks in advance

kevinr
Star Contributor
Star Contributor
We have some really neat example webscripts in the as Alfresco iGoogle Gadgets - they are small and easy to understand webscripts with features including file Upload.

Download them from here - take a look at the upload.* files.
http://downloads.sourceforge.net/alfresco/alfresco-aggadget.zip?modtime=1197385320&big_mirror=0

Thanks,

Kevin

suleyman
Champ in-the-making
Champ in-the-making
Thanks for your reply Kevin. I think that these examples will help me but I can't get them to work. I have tried the folder create example. I call it with:
http://localhost:8080/alfresco/service/aggadget/createfolder?fdrnodeid=85ff2f36-a955-11dc-9587-63885...

I get the form. When I post the form I get this error message that formdata is not defined.

Message: Failed to execute script 'workspace://SpacesStore//Company Home/Data Dictionary/Web Scripts/org/alfresco/aggadget/createfolder.post.js': Failed to execute script 'workspace://SpacesStore//Company Home/Data Dictionary/Web Scripts/org/alfresco/aggadget/createfolder.post.js': ReferenceError: "formdata" is not defined. (AlfrescoScript#7)  
  
Exception: org.mozilla.javascript.EcmaError - ReferenceError: "formdata" is not defined. (AlfrescoScript#7) 
   
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3226) 
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3216) 
org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3289) 
org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1567) 
org.mozilla.javascript.gen.c8._c0(AlfrescoScript:7) 
org.mozilla.javascript.gen.c8.call(AlfrescoScript) 
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337) 
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755) 
org.mozilla.javascript.gen.c8.call(AlfrescoScript) 
org.mozilla.javascript.gen.c8.exec(AlfrescoScript) 
org.mozilla.javascript.Context.evaluateString(Context.java:1144) 
org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:510) 
org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:112) 
org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:242) 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
java.lang.reflect.Method.invoke(Method.java:597) 
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281) 
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187) 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154) 
org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40) 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176) 
org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49) 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176) 
org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256) 
org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191) 
org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69) 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176) 
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107) 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176) 
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210) 
$Proxy48.executeScript(Unknown Source) 
org.alfresco.web.scripts.ScriptProcessor.executeScript(ScriptProcessor.java:108) 
org.alfresco.web.scripts.AbstractWebScript.executeScript(AbstractWebScript.java:537) 
org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:115) 
org.alfresco.web.scripts.WebScriptRuntime.wrappedExecute(WebScriptRuntime.java:342) 
org.alfresco.web.scripts.WebScriptRuntime.authenticatedExecute(WebScriptRuntime.java:308) 
org.alfresco.web.scripts.WebScriptRuntime$1.execute(WebScriptRuntime.java:163) 
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:225) 
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:155) 
org.alfresco.web.scripts.WebScriptRuntime.executeScript(WebScriptRuntime.java:174) 
org.alfresco.web.scripts.WebScriptServlet.service(WebScriptServlet.java:109) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210) 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151) 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870) 
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) 
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) 
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685) 
java.lang.Thread.run(Thread.java:619) 

suleyman
Champ in-the-making
Champ in-the-making
I found it. Formdata is only avaible for 2.1 enterprise. I was using the 2.1 community.
Is this object availble in an other community version or only in the enterprise?

kevinr
Star Contributor
Star Contributor
It is available in any of the 2.9 builds up on sourceforge (or a nightly build).

Thanks,

Kevin

steve_tekell
Champ in-the-making
Champ in-the-making
so formdata isn't available as a javascript root object  in community 2.1
Is there a workaround to get at this some other way?

thx

kevinr
Star Contributor
Star Contributor
No, just to grab a more recent build.

Kevin