Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Request from WebScript in Alfresco

I'm writing a WebScript in Alfresco using JS controller and I want to make a HTTP request to the local HTTP resource. This resource is a Java-based app and gives me its own REST API.

My WebScript is not a Share Component: so I don't have a remote object to call another webscript.

How can I make a HTTP request to the local resource (something like '/sdo/documents/getName?type=fl') from a WebScript?

like image 441
Alexey Avatar asked Sep 02 '11 11:09

Alexey


1 Answers

EDIT: Alfresco is overriding the Spring Surf webscripts.container bean removing the remote definition (in web-scripts-application-context.xml of remote-api):

<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>
         </map>
<!-- ..... -->
</bean>

I suggest you include it again as a custom Javascript API root level object.


The remote root object comes from the Spring Surf framework, meaning you have it regardless of being developing your Web Scripts against the Alfresco repository or Share. As a proof, here's the source for a Web Script available in the public Alfresco CMIS server (-> Alfresco repository instance, admin/admin if you are asked to login):

var serviceUrl = (args.service === null) ? "/api/repository" : args.service;
var conn = remote.connect("alfresco");
var result = conn.get(stringUtils.urlEncodeComponent(serviceUrl));

var service = atom.toService(result.response);
var workspace = service.workspaces.get(0);
model.repo = workspace.getExtension(atom.names.cmisra_repositoryInfo);

The following snippet is taken from spring-surf-application-context.xml as found inside spring-webscripts-1.0.0.CI-SNAPSHOT.jar of Alfresco 3.4.0, which is where the remote root object gets its definition:

   <bean id="webscripts.container" parent="webscripts.abstractcontainer" class="org.springframework.extensions.webscripts.LocalWebScriptRuntimeContainer">
      <property name="name"><value>Spring Surf Container</value></property>
      <property name="registry" ref="webscripts.registry" />
      <property name="searchPath" ref="webframework.webscripts.searchpath" />
      <property name="templateProcessorRegistry" ref="webframework.webscripts.registry.templateprocessor" />
      <property name="scriptProcessorRegistry" ref="webframework.webscripts.registry.scriptprocessor" />
      <property name="scriptParameterFactoryRegistry" ref="webscripts.web.scriptparameterfactoryregistry" />
      <property name="configService" ref="web.config" />
      <property name="scriptObjects">
         <map merge="true">
            <entry key="remote" value-ref="webframework.webscripts.scriptremote" />
         </map>
      </property>
      <property name="processorModelHelper" ref="processor.model.helper"/>
      <property name="extensibilityModuleHandler" ref="webscripts.extensibility.handler"/>
   </bean>

   <bean id="webframework.webscripts.scriptremote" class="org.springframework.extensions.webscripts.ScriptRemote">
      <property name="configService" ref="web.config"/>
      <property name="connectorProvider" ref="webframework.connector.provider"/>
   </bean>
like image 151
skuro Avatar answered Oct 26 '22 07:10

skuro