cancel
Showing results for 
Search instead for 
Did you mean: 

Call a webscript within an Evaluator

drocco88
Champ in-the-making
Champ in-the-making
Hi all,

I need to call a custom web script from my evaluator (java).

I'm having some problems with authentication (calling a URL directly from Java). I tried with /alfresco/service, /alfresco/wcservice and /share/proxy/alfresco.

Have someone done this before or have an idea on how to do it?

Many thanks
R
15 REPLIES 15

ddraper
World-Class Innovator
World-Class Innovator
What sort of evaluator are you referring to? A doc lib evaluator, a sub-component evaluator or an extension module evaluator? (or some other evaluator). For those 3 the solution will largely be the same. Get the the RequestContext (this is provided as an argument to the sub-component and extension module evaluators) or can be retrieved by calling ThreadLocalRequestContext.getRequestContext(); in a doc lib evaluator.

Then call:

Connector connector = context.getServiceRegistry().getConnectorService().getConnector("alfresco", userName, ServletUtil.getSession());
Response res = connector.call("<some-url>");

I'm assuming that you want to make a request to a WebScript on the repository?

Regards,
Dave

drocco88
Champ in-the-making
Champ in-the-making
Is a doc lib evaluator.

I tried your suggestion (and also extending ServiceBasedEvaluator which basically calls the same) but I'm getting:

Web Script Status 500 - Internal Error
09050456 Access Denied.  You do not have the appropriate permissions to perform this operation.

ddraper
World-Class Innovator
World-Class Innovator
Slightly obvious question this one….. but DO you have the permissions to perform the operation? 😉

What WebScript are you calling and does the user you've logged in with have the authority to call the WebScript. Has the user actually been through an authentication step before the evaluator is called?

Regards,
Dave

drocco88
Champ in-the-making
Champ in-the-making
Thanks Dave,

This is the flow:

The user login to share –> when he navigates the document library a custom evaluator is fired –> this evaluator calls a custom webscript (this webscript only check if a user belongs to a particular group).

What am I missing?

ddraper
World-Class Innovator
World-Class Innovator
This seems to be a popular activity at the moment… I'm actually just writing exactly the same evaluator (with the logic shared between SubComponent, Module and DocLib evaluators). It will eventually make it's way onto HEAD but I'm not sure when… which WebScript are you calling to check group membership?

Regards,
Dave

drocco88
Champ in-the-making
Champ in-the-making
One that I created which takes as parameters a username and groupname (must be called from different parts of share).

Can you please anticipate me how to get it working?

Many thanks,
Rocco

ddraper
World-Class Innovator
World-Class Innovator
I'm using a repository WebScript accessed via:

/api/people/<user-name>?groups=true

This seems to be working fine. You can try it out by calling http://<share-server>:<share-port>/share/proxy/alfresco/api/people/<user-name>?groups=true (you need to have logged into Share before of course) to see how the membership information is returned. Why not try with that one rather than writing your own?

Regards,
Dave

drocco88
Champ in-the-making
Champ in-the-making
I didn't know about that webscript Smiley Happy

I tried but is not working either. The thing is that inside the evaluator I'm manually calling a java URL pointing to this webscript but I get the same 401 error for authentication.

ddraper
World-Class Innovator
World-Class Innovator
If you're just creating a Java URL then how are you providing authentication credentials? Why not just use the code snippet I provided earlier in this thread as this will handle all the authentication issues for you.

Regards,
Dave