News & Announcements
What's New
Hyland Announcements
Community News
Blogs & Forums
Content Innovation Cloud
OnBase
Alfresco
Nuxeo
Perceptive Content
Hyland Cloud
Additional Products
Industry Solutions
Resources
Welcome to Hyland Community
Product Resources
Support Resources
Services Resources
Hyland Cloud
All Hyland Resources
Groups
Partners
Help
Home
Alfresco
Alfresco Archive
Using remote endpoint in repository (not share) webscript
loftux
I need to fetch external data in the repository, that is call
http://example.com/fetch/some/json
.
I need this both for a webscript (trigger manually) and a scheduled action.
In Share this is easy for webscripts via declaring remote endpoints. But how do I in the best way fetch external data repository side? I would prefere a way to do this with javascript.
There seem to be an older "left over" script here
http://localhost:8080/alfresco/service/sample/cmis/repo?service=servername
It uses var conn = remote.connect("alfresco"); but throws an error org.mozilla.javascript.EcmaError - ReferenceError: "remote" is not defined.
So I guess remote object is not available, can it be enabled? If so, can it be made available to a scheduled action as well?
Find more posts tagged with
Accepted answers
afaust
Hello,
I think enhancing the webscripts.container bean should do the trick, e.g.
<blockcode>
<bean id="webscripts.container" class="org.alfresco.repo.web.scripts.RepositoryContainer" parent="webscripts.abstractcontainer">
<property name="name"><value>Repository</value></property>
<property name="scriptObjects">
<map merge="true">
<entry key="paging">
<ref bean="webscripts.js.paging"/>
</entry>
<entry key="remote">
<ref bean="webscripts.script.remote" />
</entry>
<entry key="cmis">
<ref bean="webscripts.js.cmis.client" />
</entry>
</map>
</property>
<!– more boring properties –>
</bean>
</blockcode>
I don't know about scheduled actions though, as the ScriptRemote class is not a valid processor extension and can not be added as a root object to the internal Rhino script processor.
Regards
Axel
All comments
afaust
Hello,
I think enhancing the webscripts.container bean should do the trick, e.g.
<blockcode>
<bean id="webscripts.container" class="org.alfresco.repo.web.scripts.RepositoryContainer" parent="webscripts.abstractcontainer">
<property name="name"><value>Repository</value></property>
<property name="scriptObjects">
<map merge="true">
<entry key="paging">
<ref bean="webscripts.js.paging"/>
</entry>
<entry key="remote">
<ref bean="webscripts.script.remote" />
</entry>
<entry key="cmis">
<ref bean="webscripts.js.cmis.client" />
</entry>
</map>
</property>
<!– more boring properties –>
</bean>
</blockcode>
I don't know about scheduled actions though, as the ScriptRemote class is not a valid processor extension and can not be added as a root object to the internal Rhino script processor.
Regards
Axel
loftux
Thanks, that makes the remote object available.
Since I'm developing a module I added this to my project
<code lang="xml">
<bean id="customSurfClientConfig" class="org.springframework.extensions.config.ConfigBootstrap" init-method="register">
<property name="configService" ref="web.config" />
<property name="configs">
<list>
<value>classpath:alfresco/module/mymodule/context/surf-config.xml</value>
</list>
</property>
</bean>
</code>
and then in surf-config.xml
<code lang="xml">
<alfresco-config>
<config evaluator="string-compare" condition="Remote">
<remote>
<!– Define the endpoint for Presss –>
<endpoint>
<id>myservice</id>
<name>Myservice service</name>
<description>External service webb to retrieve data from</description>
<connector-id>http</connector-id>
<endpoint-url>
http://www.examplecom
</endpoint-url>
<identity>none</identity>
</endpoint>
</remote>
</config>
</alfresco-config>
</code>
and then i can use [font=Courier]var conn = remote.connect("myservice");[/font]
As for scheduling, I can probably use cron and curl to call the webscript.