HTTP request from WebScript in Alfresco

I am writing WebScript in Alfresco using a JS controller, and I want to make an HTTP request to a local HTTP resource. This resource is a Java application and provides me with its own REST API.

My WebScript is not a Share component: therefore, I do not have a remote object to call another website.

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

+4
source share
1 answer

EDIT: Alfresco overrides 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 enable it again as a custom Javascript API at the root object level.


The root object of the remote comes from the framework of Spring Surf , which means that you have it no matter how you develop your web scripts against Alfresco Repository or Share. As a proof, here is the source of the Web Script available on the Alfresco CMIS public server (-> Alfresco repository instance, admin / admin if you are asked to log in):

 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 it is found inside spring-webscripts-1.0.0.CI-SNAPSHOT.jar Alfresco 3.4.0, where the remote 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> 
+4
source

All Articles