cancel
Showing results for 
Search instead for 
Did you mean: 

ServiceRegistry

tejaswini
Champ in-the-making
Champ in-the-making
i am trying to read a node using contentReader. for that i should have a ServiceRegistry. what i am doing is getting that with help of injection in .xml but after that i am getting exceptions. will anybody help me out?
thanks in advance.
15 REPLIES 15

flopez
Champ in-the-making
Champ in-the-making
Hi there,

I'm having trouble importing the service registry for a java backed (share) webscript that implements ApplicationContextAware:

import org.alfresco.service.ServiceRegistry;

What jar is it located, or did it change for the 3.4b version of alfresco community, can't resolve 'ServiceRegistry' which I intend to use for content/workflow services

Anyone can please give me a clue?

Thank you in advance

mrogers
Star Contributor
Star Contributor
If you are using a "Java Backed WebScript" then you don't need it, use spring injection instead.

Its in the Repository Project.

flopez
Champ in-the-making
Champ in-the-making
If you are using a "Java Backed WebScript" then you don't need it, use spring injection instead.

Its in the Repository Project.

Hello mrogers, thanks for answering! I'll take a look at that

flopez
Champ in-the-making
Champ in-the-making
Hello again, indeed I've tried to inyect it but it seems I'm missing something or I'm just misunderstanding it, here is a simplified version of what I'm trying to do:

I have my java class TestWebScript.java which Im making application context aware so that I can inject the context and get from it ServiceRegistry like this:


import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import org.alfresco.service.ServiceRegistry;

public class TestWebScript extends AbstractWebScript implements ApplicationContextAware {

    private ServiceRegistry serviceRegistry;
    private ApplicationContext applicationContext; 
   
    @Override
    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
       this.applicationContext = applicationContext;   
    }

    public void execute(WebScriptRequest req, WebScriptResponse res){

       this.serviceRegistry=(ServiceRegistry)applicationContext.getBean("serviceRegistry");   
       // serviceRegistry.getAnyServices and use them
    }
   
}
To make this class compile in share, I had to add the 'alfresco-repository-3.4.c.jar' from the repository project as you suggested so that it recognizes the
import org.alfresco.service.ServiceRegistry;

I include the definition for my bean in the slingshot-application-context.xml in share, like this:
   <bean id="webscript.org.alfresco.components.package.testwebscript.get" 
      class="package.TestWebScript "
      parent="webscript">
        <property name="serviceRegistry" ref="ServiceRegistry" />
   </bean>
Like suggested in most other places, but context can't bes initializad because share don't seem to resolve/find the 'ServiceRegistry' bean the only one available is referenced as: <property name="serviceRegistry" ref="webframework.service.registry" /> But that's not the one… what am I missing?

Thank you in advance.

mrogers
Star Contributor
Star Contributor
Ah….    You can't access the Service Registry or any of the Java API's from Share   What you have to do is call one of Alfresco's remote imterfaces.

waynejiang
Champ in-the-making
Champ in-the-making
If you need get the current user in java backed webscript frm Share. Code as below,
import org.springframework.extensions.surf.RequestContext;
import org.springframework.extensions.surf.support.ThreadLocalRequestContext;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
import org.springframework.extensions.webscripts.connector.User;

public class DemoAction extends AbstractWebScript {
    @Override
    public void execute(WebScriptRequest request, WebScriptResponse response) {
        RequestContext context = ThreadLocalRequestContext.getRequestContext();
        User user = context.getUser();
    }
}