2

I know I may get down-voted for this trivial question...

In Javascript it is easy (even magical): remote.call("/api/...")

How do I get this in Java?

I read a lots of posts like this one, where the Alfresco (repository) URL is either hard coded http://localhost:8080/alfresco, either undefined (exemple : REPO_WEB_SERVICE_URL).

Is there a helper that could give me the URL of the repository? Is there a class that do the same as the remote Javascript root object?

I’m sorry if the answer is obvious, I just can’t see it, I’m searching for hours already and I'm starting going crazy about it as it should be a no-brainer...

Mardoz
  • 1,617
  • 1
  • 13
  • 26
boumbh
  • 2,010
  • 1
  • 19
  • 21
  • Ok I am stupid, REPO_WEB_SERVICE_URL may not be an absolute url of Alfresco repository but a relative one... I’ll test this snippet and I’ll answer my own question if I get it right... – boumbh Oct 09 '14 at 09:27

2 Answers2

5

In order to make the remote available in your Share script you need to inject the remote using Spring.

Set a context file to set your remote variable:

<bean id="MyEvaluator" class="org.me.MyEvaluator">
    <property name="remote" ref="webframework.webscripts.scriptremote" />
</bean>

Then you need to create the variable in your Java class. Given that you can use it as you like:

public class MyEvaluator extends BaseEvaluator {

    private ScriptRemote remote;

    public void setRemote(ScriptRemote remote) {
        this.remote = remote;
    }

    public void doScriptCall() {
        Response response = remote.call("/api/...");
    }

}
Mardoz
  • 1,617
  • 1
  • 13
  • 26
  • Thank you, I could inject the `ScriptRemote` class, it answers my question but I finally did an other way because I don’t like to have `ScriptXXX` methods on my Java classes (I don’t know if my ). I was missing the repository url and I managed to get it by searching in the source. – boumbh Oct 10 '14 at 16:11
1

Partial answer, in order to get the Alfresco Repository base path.

Inject the connectorService into the bean:

<bean id="MyEvaluator" class="org.me.MyEvaluator">
    <property name="connectorService" ref="connector.service" />
</bean>

Then in the class, retrieve the Alfresco endpoint:

String alfrescoEndPoint = connectorService.getConnector("alfresco").getEndpoint();

alfrescoEndPoint will be something like http://host:port/alfresco/s according to what was set in alfresco-global.properties.

boumbh
  • 2,010
  • 1
  • 19
  • 21