cancel
Showing results for 
Search instead for 
Did you mean: 

SimpleWebScript and Alfresco 3.4 ... broken?

exel88
Champ in-the-making
Champ in-the-making
Alfresco version: Community v3.4.0 (both C and D version) (with tomcat and mysql installation bundle)
OS: Windows 7 Professional - English
IDE: Eclipse Helios


Hello to everyone.

In the last days, you're seen, I've had some problems with a Java Backend Web Script development.
For ensure wich wasn't me the problem, I've tried to follow the tutorial on http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples for deploy the SimpleWebScript.
I followed instructions to the letter (for Alfresco 3.3 and beyond)! But, this is the result:


Community v3.4.0 (c 3335) schema 4,113
1 Web Scripts

Back to Web Scripts Home

Up to package /org/alfresco

The World's Simplest Webscript
GET /alfresco/service/demo/simple
Description:   Hands back a little bit of JSON
Authentication:   none
Transaction:   none
Format Style:   argument
Default Format:   Determined at run-time
Id:   org/alfresco/demo/simple.get
Description:   classpath:alfresco/templates/webscripts/org/alfresco/demo/simple.get.desc.xml


Web Script: org/alfresco/demo/simple.get
Generated from /alfresco/service/script/org/alfresco/demo/simple.get on Mar 1, 2011 10:14:40 AM

Script Properties
Id:   org/alfresco/demo/simple.get
Short Name:   The World's Simplest Webscript
Description:   Hands back a little bit of JSON
Authentication:   none
Transaction:   none
Method:   GET
URL Template:   /demo/simple
Format Style:   argument
Default Format:   [undefined]
Negotiated Formats:   [undefined]
Implementation:   class org.springframework.extensions.webscripts.DeclarativeWebScript
Extensions:   [undefined]

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:extensionwebscripts

[No implementation files]

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:webscripts

[No implementation files]

Store: classpath:alfresco/templates/webscripts

File: org/alfresco/demo/simple.get.desc.xml

<webscript>
  <shortname>The World's Simplest Webscript</shortname>
  <description>Hands back a little bit of JSON</description>
  <url>/demo/simple</url>
  <authentication>none</authentication>
  <format default="">argument</format>
</webscript>

Store: classpath:webscripts

[No implementation files]


http://localhost:8081/alfresco/service/demo/simple

The Web Script /alfresco/service/demo/simple has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   02010002 Web Script format '' is not registered
   
Exception:   org.springframework.extensions.webscripts.WebScriptException - 02010002 Web Script format '' is not registered
   
   org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:58)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:336)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:466)
   org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:263)
   org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:333)
   org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:189)
   org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
   org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
   org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
   org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
   java.lang.Thread.run(Thread.java:619)
   
Server:   Community v3.4.0 (c 3335) schema 4,113
Time:   Mar 1, 2011 10:14:35 AM
   
Diagnostics:   Inspect Web Script (org/alfresco/demo/simple.get)

http://localhost:8081/share/page/script/org/alfresco/module/demoscripts/simple.get

Web Script Status 500 - Internal Error

The Web Script /share/page/script/org/alfresco/module/demoscripts/simple.get has responded with a status of 500 - Internal Error.

500 Description:    An error inside the HTTP server which prevented it from fulfilling the request.

Message:   02010000 Web Script Id 'org/alfresco/module/demoscripts/simple.get' not found

Exception:   org.springframework.extensions.webscripts.WebScriptException - 02010000 Web Script Id 'org/alfresco/module/demoscripts/simple.get' not found

org.springframework.extensions.webscripts.bean.ServiceDump.executeImpl(ServiceDump.java:61)
org.springframework.extensions.webscripts.DeclarativeWebScript.executeImpl(DeclarativeWebScript.java:235)
org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64)
org.springframework.extensions.webscripts.PresentationContainer.executeScript(PresentationContainer.java:69)
org.springframework.extensions.webscripts.LocalWebScriptRuntimeContainer.executeScript(LocalWebScriptRuntimeContainer.java:231)
org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:333)
org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:189)
org.springframework.extensions.webscripts.servlet.mvc.WebScriptView.renderMergedOutputModel(WebScriptView.java:99)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.alfresco.web.site.servlet.MTAuthenticationFilter.doFilter(MTAuthenticationFilter.java:74)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.alfresco.web.site.servlet.SSOAuthenticationFilter.doFilter(SSOAuthenticationFilter.java:301)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
java.lang.Thread.run(Thread.java:619)

Server:   Spring WebScripts - v1.0.0 (Release Candidate 2 739) schema 1,000
Time:   Mar 1, 2011 10:12:37 AM

This is the files tree:

.jar file in <Alfresco>/tomcat/webapps/alfresco/WEB-INF/lib or class files in <Alfresco>/tomcat/webapps/alfresco/WEB-INF/classes
web-scripts-application-context.xml - <Alfresco>/tomcat/webapps/alfresco/WEB-INF/classes/alfresco
simple.get.desc.xml  - <Alfresco>/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/demo

And, this is the manifest.mf inside the JAR:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 19.0-b09 (Sun Microsystems Inc.)


What I've missed?  :cry: Is my Alfresco installation broken?

Regards,


Andrea
5 REPLIES 5

exel88
Champ in-the-making
Champ in-the-making
If I add a template file (simple.get.html.ftl) as this:

<html>
   <body>
      <p>${status.code}</p>
      <p>${status.message}</p>
   </body>
</html>   

And
<format default="html">argument</format>
into simple.get.desc.xml.

This is the response:

<html>
   <body>
      <p>200</p>
      <p></p>
   </body>
</html>   

For one moment, I was very Happy for this, but… if I change some data, if I make any operation, if I launch exception (e.g. webscript exception with 400 code), AND if I delete my JAR, the response is still the same!!!

I think the problem is in Alfresco. It doesn't recognize the class files and it manages the Java backend webscript as a simple webscript without java code. How … ?  Smiley Surprisedops:

Anyone have the same problem?

mrogers
Star Contributor
Star Contributor
The web script implementation is rock solid, otherwise Share would not work and there would be hundreds of unit test failures.  

I find your description unclear but I do note that I don't see your Java Backed Web Script being registered anywhere.

exel88
Champ in-the-making
Champ in-the-making
Thank you for your reply mrogers. Smiley Very Happy

I find your description unclear but I do note that I don't see your Java Backed Web Script being registered anywhere.

Me too. Smiley Happy Off course, this is the problem.
I'm new on Alfresco Web Script development, but I've only one problem: deployment!

I followed the Alfresco Wiki and "Alfresco 3 Web Services" book where is described step by step webscript deployment. The problem is in the directory path I used (I think).

Where I can put the files?   :shock:

This morning I've traied another example.

HelloworldJavaWebScript.java

package com.packtpub.a3ws.samples.ch07;

import java.util.HashMap;
import java.util.Map;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;


public class HelloWorldJavaWebScript extends DeclarativeWebScript {
   @Override
   protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
      Map<String, Object> model = new HashMap<String, Object>();
      model.put("message", "Hello, world");
      return model;
   }
}

jhello-context.xml

<bean id="webscript.com.packtpub.a3ws.samples.ch07.jhello.get"
   class="com.packtpub.a3ws.samples.ch07.HelloWorldJavaWebScript"
   parent="webscript" />

jhello.get.desc.xml

<webscript>
  <shortname>jhello</shortname>
  <description>Another try</description>
  <url>/jhello</url>
  <authentication>none</authentication>
  <format default="html">argument</format>
</webscript>

jhello.get.html.ftl

<html>
<body>
<p>If it doesn't work, it will be a tragedy!</p>
<p>${message}</p>
</body>
</html>

I think files are correct. It's wrong?

I've compiled JAVA into CLASS and this is my directory:

com/packtpub/a3ws/samples/ch07/HelloWorldJavaWebScript.class

Now, the problem is the files' location. I founded many location, many classpath and more. But, none is the correct place.

WHERE? XD I don't understand this. Where I could put che class file? JAR file (WEB-INF/lib doesn't work)? Descriptor and template files? Which what folder tree?

Actually, this is my situation:

…\WEB-INF\classes\alfresco\templates\webscripts\com\packtpub\a3ws\samples\ch07
                                                                . jhello.get.desc.xml
                                                                . jhello.get.html.ftl
                                                                . jhello-context.xml

…\WEB-INF\classes\com\packtpub\a3ws\samples\ch07\HelloWorldJavaWebScript.class

And this is the result:

jhello
GET /alfresco/service/jhello
Description:   Another try
Authentication:   none
Transaction:   none
Format Style:   argument
Default Format:   html
Id:   com/packtpub/a3ws/samples/ch07/jhello.get
Description:   classpath:alfresco/templates/webscripts/com/packtpub/a3ws/samples/ch07/jhello.get.desc.xml


Web Script: com/packtpub/a3ws/samples/ch07/jhello.get
Generated from /alfresco/service/script/com/packtpub/a3ws/samples/ch07/jhello.get on Mar 2, 2011 11:53:23 AM

Script Properties
Id:   com/packtpub/a3ws/samples/ch07/jhello.get
Short Name:   jhello
Description:   Another try
Authentication:   none
Transaction:   none
Method:   GET
URL Template:   /jhello
Format Style:   argument
Default Format:   html
Negotiated Formats:   [undefined]
Implementation:   class org.springframework.extensions.webscripts.DeclarativeWebScript
Extensions:   [undefined]

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:extensionwebscripts

[No implementation files]

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:webscripts

[No implementation files]

Store: classpath:alfresco/extension/templates/webscripts

[No implementation files]

Store: classpath:alfresco/templates/webscripts

File: com/packtpub/a3ws/samples/ch07/jhello.get.desc.xml

<webscript>
  <shortname>jhello</shortname>
  <description>Another try</description>
  <url>/jhello</url>
  <authentication>none</authentication>
  <format default="html">argument</format>
</webscript>

File: com/packtpub/a3ws/samples/ch07/jhello.get.html.ftl

<html>
<body>
<p>If it doesn't work, it will be a tragedy!</p>
<p>${message}</p>
</body>
</html>

Store: classpath:webscripts

[No implementation files]


The Web Script /alfresco/service/jhello has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   02020005 Wrapped Exception (with status template): 02020003 Errore durante lelaborazione del modello '{0}'. Contattare lamministratore di sistema.
   
Exception:   freemarker.core.NonStringException - Error on line 4, column 6 in com/packtpub/a3ws/samples/ch07/jhello.get.html.ftl Expecting a string, date or number here, Expression message is instead a org.springframework.extensions.webscripts.MessageMethod
   
   freemarker.core.Expression.getStringValue(Expression.java:126)
   freemarker.core.Expression.getStringValue(Expression.java:93)
   freemarker.core.DollarVariable.accept(DollarVariable.java:76)
   freemarker.core.Environment.visit(Environment.java:210)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:210)
   freemarker.core.Environment.process(Environment.java:190)
……..

Thank's a lot.

exel88
Champ in-the-making
Champ in-the-making
In addition to my last post, I already know which Alfresco needs to be restarted for see the new jar file.

Web Script doesn't work also if I used .jar instead .class files.
I used ANT project to build this jar, and here it is:

       […]
   
        <!– Execute: ant -f build.xml  –>

       […]

   <target name="compile" depends="init">
      <javac srcdir="${basedir}/src" destdir="${basedir}/build" classpathref="libs">
      </javac>
   </target>

   <path id="libs">
      <fileset dir="../alfresco-community-sdk-3.4.b/lib" includes="**/*.jar" />
   </path>

   <target name="archive" depends="compile">
      <jar destfile="${basedir}/deploy/jar/jhello.jar" basedir="${basedir}/build" compress="true" update="true" />
   </target>

</project>


At this stage, I put the jhello.jar into …\tomcat\webapps\alfresco\WEB-INF\lib, I restart Tomcat.
Alfresco starts correctly but at this point … .jar are unrecognized.
:?:

exel88
Champ in-the-making
Champ in-the-making
Any suggestion?