In sdk-3 how to test a customized class

cancel
Showing results for 
Search instead for 
Did you mean: 
renogarfield
Member II

In sdk-3 how to test a customized class

Hello,

I have a platform module,i try to update it to sdk-3 but can't test it on the maven build (only on maven), it work on "real" alfresco server.

i have a need to customise an existing alfresco java class (well i did'nt find any other way). On sdk-2 i could test it with the "virtualClasspath" and "searchVirtualFirst=true" but in sdk-3 it's said we don't need it, but i don't understand how to do it !

The module DO work, if i (simply) copy the jar file on an existing alfresco instance in a VM it work.On sdk-2 it work to.

But if i try it with sdk-3 the class used seem to be the original alfresco...

i try with hotswapagent (extraclasspath) and without but whatever is new class do work flawessly with a simple "mvn compile", but not the customized class. I did a lot "googleling" but find nothing.

Do someone know how to be sure a custom class can be read priorisise an existing class on maven sdk-3 ?

note: i too try to make it in amp and not an jar, same think...

8 Replies
douglascrp
Advanced II

Re: In sdk-3 how to test a customized class

Hello.

You will have to share more information in order to get any useful response from the community.

What exactly are you trying to test?

renogarfield
Member II

Re: In sdk-3 how to test a customized class

i have an maven all in one project,

in this project i have a module with a modified ScripNode.java class (alfresco java class).

if i run the project with the sdk-3 maven create a jar archive who is with the unpackaged platform war, so it is not compatible with the "true" jar of alfresco.

for exemple if i manualy rename the jar on aa-module it work (read before in linux). and in 'production' i can choose the tomcat classpath so it's okay.

on sdk-2 we could use the context-repo.xml of runner and change "virtualClasspath", on sdk-3 we can't.

hope it's clearer, i'm sorry i'm not fluent in english.

douglascrp
Advanced II

Re: In sdk-3 how to test a customized class

So, if I understood it well, what you have is a problem with the order the jar file is loaded?

But why does that import to you? If you are extending a OOTB class, then you should be using the extension mechanism to "replace" the implementation class for you, and not try to ovewrite the jar file.

I am just trying to give you some idea, but I am afraid I could not understand your problem exactly.

renogarfield
Member II

Re: In sdk-3 how to test a customized class

Well i'm not sure what you call "extension mechanism", may be i don't do it correctly ?

For this module i change the bean who do the labelpolicy , i have this :

<bean id="serialVersionLabelPolicy" class="xx.xx.xx.updated.UpdatedVersionLabelPolicy"  />

is that what you implit ?

What i do is extend the update mecanisme of the node with a public ScriptNode checkin(String history, boolean majorVersion, String customLabel) function.

basicly what i shoud do is to say 'don't use scriptnode use MY scriptnode implementation' but i don't know how to

thank for the help

douglascrp
Advanced II

Re: In sdk-3 how to test a customized class

Ok, that is exactly what I wanted to understand.

Please, share here the name of the context.xml file you are using to define that bean, the path you are using, and also, the full bean configuration.

renogarfield
Member II

Re: In sdk-3 how to test a customized class

well... there is no context bean for ScriptNode and that what not working...

bootstrap-context.xml

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!-- import du modèle pour l'envoi de message -->
<bean id="${project.artifactId}_dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
<property name="models">
<list>
<value>alfresco/module/${project.artifactId}/model/updatedModel.xml</value>
</list>
</property>
<!-- <property name="labels">
<list>
<value>alfresco/module/${project.artifactId}/messages/updatedModel</value>
<value>alfresco/module/${project.artifactId}/messages/updatedAction</value>
</list>
</property> -->
</bean>

<!-- remplace la classe par defaut de la gestion des versions -->
<!-- apparement il ne peut y avoir qu'un seul "versionLabel" donc on le change -->
<bean id="serialVersionLabelPolicy" class="fr.gouv.dgfip.venezia.updated.UpdatedVersionLabelPolicy" />


</beans>

and webscript-context.xml

<?xml version='1.0' encoding='UTF-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="updated-utils" parent="baseJavaScriptExtension" class="fr.gouv.dgfip.venezia.updated.UpdatedUtils">
<property name="extensionName" value="updatedUtils" />
<property name="behaviourFilter" ref="policyBehaviourFilter" />
<property name="nodeService" ref="nodeService" />
<property name="permissionService" ref="permissionService" />
</bean>

<!-- script downloadSite -->
<bean id="webscript.updated.downloadFile.get"
class="fr.gouv.dgfip.venezia.updated.UpdatedDownloadFile"
parent="webscript.org.alfresco.content.content.get">
<property name="repository" ref="repositoryHelper" />
<property name="serviceRegistry" ref="ServiceRegistry" />
<property name="contentService" ref="contentService" />
</bean>

</beans>

if i use the "normal" api/upload i see that the serialVersion do work :

[renaud] $ curl --noproxy renoven2 -k -u admin:admin -X POST -F filedata=@a -F "overwrite=true" -F "uploaddirectory=/" -F "siteId=topinenbourg" -F "containerid=documentLibrary" "http://localhost:8080/alfresco/service/api/upload"
{
"nodeRef": "workspace://SpacesStore/7a2d1bf3-57bb-44bc-9d1a-478ddf835ebf",
"fileName": "a",
"status":
{
"code": 200,
"name": "OK",
"description": "File uploaded successfully"
}
}

and in the log :

2017-09-07 10:25:09,831 DEBUG [venezia.updated.UpdatedVersionLabelPolicy] [http-bio-8080-exec-9] * updated version label policy : action *
2017-09-07 10:25:09,831 DEBUG [venezia.updated.UpdatedVersionLabelPolicy] [http-bio-8080-exec-9] * updated version label policy : valeur du custom label = null *
2017-09-07 10:25:09,832 DEBUG [venezia.updated.UpdatedVersionLabelPolicy] [http-bio-8080-exec-9] * updated version label policy : ancien version label *
2017-09-07 10:25:09,832 DEBUG [venezia.updated.UpdatedVersionLabelPolicy] [http-bio-8080-exec-9] * updated version label policy : application du mineur *
2017-09-07 10:25:09,832 DEBUG [venezia.updated.UpdatedVersionLabelPolicy] [http-bio-8080-exec-9] * updated version label policy : valeur résultante 1.1 *

so the serialVersion do work

if i use my update it fail :

[renaud] $ curl --noproxy renoven2 -k -u admin:admin -X POST -F filedata=@a -F "overwrite=true" -F "uploaddirectory=/" -F "siteId=topinenbourg" -F "containerid=documentLibrary" -F "author=rl" -F "customLabel=3.2" "http://localhost:8080/alfresco/service/updated/upload"
{
"status" :
{
"code" : 500,
"name" : "Internal Error",
"description" : "An error inside the HTTP server which prevented it from fulfilling the request."
},

"message" : "08070003 Unexpected error occurred during upload of new content.",
"exception" : "",

"callstack" :
[

],

"server" : "Community v5.2.0 (re21f2be5-b22) schema 10 057",
"time" : "7 sept. 2017 10:35:48"
}

and the log said

2017-09-07 10:35:48,138 DEBUG [venezia.updated.UpdatedUtils] [http-bio-8080-exec-8] *** upload.post.js : authoring, disabled behaviour
2017-09-07 10:35:48,171 DEBUG [venezia.updated.UpdatedUtils] [http-bio-8080-exec-8] ** upload.post.js : checkout file
2017-09-07 10:35:48,178 DEBUG [venezia.updated.UpdatedUtils] [http-bio-8080-exec-8] ** upload.post.js : write content

2017-09-07 10:35:48,179 DEBUG [venezia.updated.UpdatedUtils] [http-bio-8080-exec-8] ** upload.post.js : metadata extracted
2017-09-07 10:35:48,179 DEBUG [venezia.updated.UpdatedUtils] [http-bio-8080-exec-8] ** upload.post.js : checkin of file

2017-09-07 10:35:48,185 ERROR [extensions.webscripts.AbstractRuntime] [http-bio-8080-exec-8] Exception from executeScript: 08070003 Unexpected error occurred during upload of new content.
org.springframework.extensions.webscripts.WebScriptException: 08070003 Unexpected error occurred during upload of new content.
at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1124)
at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:519)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:464)
at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:587)
at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:656)
at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:428)
at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:308)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:399)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:210)
at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:68)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.mozilla.javascript.JavaScriptException: InternalError: Unexpected error occurred during upload of new content. (classpath*:alfresco/extension/templates/webscripts/updated/upload.post.js#917)
at org.mozilla.javascript.gen.classpath__alfresco_extension_templates_webscripts_updated_upload_post_js_5._c_main_4(classpath*:alfresco/extension/templates/webscripts/updated/upload.post.js:917)
at org.mozilla.javascript.gen.classpath__alfresco_extension_templates_webscripts_updated_upload_post_js_5.call(classpath*:alfresco/extension/templates/webscripts/updated/upload.post.js)
at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:74)
at org.mozilla.javascript.gen.classpath__alfresco_extension_templates_webscripts_updated_upload_post_js_5._c_script_0(classpath*:alfresco/extension/templates/webscripts/updated/upload.post.js:921)
at org.mozilla.javascript.gen.classpath__alfresco_extension_templates_webscripts_updated_upload_post_js_5.call(classpath*:alfresco/extension/templates/webscripts/updated/upload.post.js)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
at org.mozilla.javascript.gen.classpath__alfresco_extension_templates_webscripts_updated_upload_post_js_5.call(classpath*:alfresco/extension/templates/webscripts/updated/upload.post.js)
at org.mozilla.javascript.gen.classpath__alfresco_extension_templates_webscripts_updated_upload_post_js_5.exec(classpath*:alfresco/extension/templates/webscripts/updated/upload.post.js)
at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:509)
at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:207)
at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:219)
at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:181)
at org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:109)
at org.springframework.extensions.webscripts.AbstractWebScript.executeScript(AbstractWebScript.java:1376)
at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:86)
... 32 more

the line here "*** upload.post.js : authoring, disabled behaviour" mean it do this function :

updatedUtils.log("*** upload.post.js : authoring, set properties on file and disable behaviour");
updatedUtils.disableBehaviourAuditable(updateNode);

so my "updatedUtils" function do work, but not the checkin wich is :

updatedUtils.log("** upload.post.js : checkin of file");
existingFile = existingFile.checkin(description, majorVersion, customLabel); <- this fails

wich is defined in ScriptNode

if i do rename the jar (and mvn alfresco:run) :

[renaud] $ cp target/tomcat/webapps/plugins-alfresco-platform/WEB-INF/lib/updated-platform-jar-1.1-SNAPSHOT.jar target/tomcat/webapps/plugins-alfresco-platform/WEB-INF/lib/aa-updated-platform-jar-1.1-SNAPSHOT.jar

i don't have the problems :

[renaud] $ curl --noproxy renoven2 -k -u admin:admin -X POST -F filedata=@a -F "overwrite=true" -F "uploaddirectory=/" -F "siteId=topinenbourg" -F "containerid=documentLibrary" -F "author=rl" -F "customLabel=3.2" "http://localhost:8080/alfresco/service/updated/upload"
{
"nodeRef": "workspace://SpacesStore/7a2d1bf3-57bb-44bc-9d1a-478ddf835ebf",
"fileName": "a",
"status":
{
"code": 200,
"name": "OK",
"description": "File uploaded successfully"
}
}

basicly the problem is i need to surcharge the org.alfresco.repo.jscript.ScriptNode and i have no way to override it "easyly"

well, the sdk-3 is probably  to new for now and none has this problems for now.

I use a awfuly wrong to resolve, i use a fake plugin juste for renaming the jar (worst solution ever, lol)

part of local-share-jar/pom.xml

<!-- test pour ajout dans le rep -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="${targetPlatform}"/>
<copy file="${pluginRep}/oic-platform-jar/target/oic-platform-jar-1.1-SNAPSHOT.jar" tofile="${targetPlatform}/aa1-oic-platform-jar-1.1-SNAPSHOT.jar"/>
<copy file="${pluginRep}/updated-platform-jar/target/updated-platform-jar-1.1-SNAPSHOT.jar" tofile="${targetPlatform}/aa2-updated-platform-jar-1.1-SNAPSHOT.jar"/>
<mkdir dir="${targetShare}"/>
<copy file="${pluginRep}/oic-share-jar/target/oic-share-jar-1.1-SNAPSHOT.jar" tofile="${targetShare}/aa1-oic-share-jar-1.1-SNAPSHOT.jar"/>
<copy file="${pluginRep}/updated-share-jar/target/updated-share-jar-1.1-SNAPSHOT.jar" tofile="${targetShare}/aa2-updated-share-jar-1.1-SNAPSHOT.jar"/>
<copy file="${pluginRep}/venezia-share-jar/target/venezia-share-jar-1.1-SNAPSHOT.jar" tofile="${targetShare}/aa0-venezia-share-jar-1.1-SNAPSHOT.jar"/>
</target>
</configuration>
</execution>
</executions>
</plugin>

thank for the help, i will do this for now until i found a better way...

douglascrp
Advanced II

Re: In sdk-3 how to test a customized class

What do you have in the line 917 in the file alfresco/extension/templates/webscripts/updated/upload.post.js ?

renogarfield
Member II

Re: In sdk-3 how to test a customized class

just the catch of the try :

} catch (e) {
// NOTE: Do not clean formdata temp files to allow for retries. It's possible for a temp file
// to remain if max retry attempts are made, but this is rare, so leave to usual temp
// file cleanup.

// capture exception, annotate it accordingly and re-throw
if (e.message && e.message.indexOf("AccessDeniedException") != -1) {
e.code = 403;
}
else if (e.message && e.message.indexOf("org.alfresco.service.cmr.usage.ContentQuotaException") == 0) {
e.code = 413;
} else if (e.message && e.message.indexOf("org.alfresco.repo.content.ContentLimitViolationException") == 0) {
e.code = 409;
} else {
e.code = 500;
e.message = "Unexpected error occurred during upload of new content.";
}
throw e;
}
} <-------- ligne 917

main();