Re: How get nodeService in project All-in-One?

Showing results for 
Search instead for 
Did you mean: 
Active Member

Re: How get nodeService in project All-in-One?

I created project All-in-One by instruction

my project

start ./ build_start

go to link  http://localhost:8080/alfresco/service/sample/helloworld

in log you can see 

        at testpackage.platformsample.DemoComponent.getCompanyHome(
        at testpackage.platformsample.DemoComponent.executeInternal(
        at testpackage.platformsample.HelloWorldWebScript.executeImpl(
        at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(
        at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(
        at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(
        at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(


how get nodes from Alfresco in my project?

thank for any help


1 Reply

Re: How get nodeService in project All-in-One?

The issue is not with generated code, issue is with the code you have written in HelloWorldWebScript class.

DemoComponent class is instantiated using Sprint IOC container and all its dependencies (such as NodeService, NodeLocatorService) are satisfied by the container. 

Now you want to use DemoComponent in your HelloWorldWebScript, you need to inject the testpackage.DemoComponent bean in webscript.alfresco.tutorials.helloworld.get bean in order to use DemoComponent. 

You can not simply create instance as you have done in your webscript class. 


When you do this, setter methods in the DemoComponent class has no effect and it wont set any object reference. In this case they become raw java methods. And you may be already aware that if there are instance variables in a class and if you don't set the values/references via any means, then they by default get null value/reference if the object created.

Consider reading this blog for more details on dependency injection:

Now coming to the fix, here is what you need to do:

In your HelloWorldWebScript class, see the fix as highlighted:

public class HelloWorldWebScript extends DeclarativeWebScript {
    private static Log logger = LogFactory.getLog(HelloWorldWebScript.class);
    private static final String ADMIN_USER_NAME = "admin";
    private DemoComponent demo;
	public void setDemo(DemoComponent demo) {
		this.demo = demo;

	protected Map<String, Object> executeImpl(
            WebScriptRequest req, Status status, Cache cache) {
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("fromJava", "HelloFromJava");      
        logger.debug("        _____  ___  ____  _____    ");
        logger.debug("  ___  |_   _|| __|/  __||_   _|   ");
        logger.debug(" / _ |   | |  | _| \\__  \\  | |     ");
        logger.debug(" \\___|   |_|  |___||____/  |_|     ");

        model.put("fromAD", "from AD");              
        //logger.debug("-- TEST1 DEMO -- "+ demo);
        try {
		} catch (Throwable e) {
			// TODO Auto-generated catch block
        model.put("fromAlfresco",  model.get("fromJava"));        
        logger.debug("Your 'TEST' Web Script was called! =======================");
        return model;

Update the webscript bean definition:

<beans xmlns=""
	<bean id="webscript.alfresco.tutorials.helloworld.get"
		  <property name="demo" ref="testpackage.DemoComponent" />



(ACSCE, AWS SAA, Azure Admin)