来自Alfresco中WebScript的HTTP请求 [英] HTTP Request from WebScript in Alfresco

查看:101
本文介绍了来自Alfresco中WebScript的HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JS控制器在Alfresco中编写WebScript,我想向本地HTTP资源发出HTTP请求。此资源是一个基于Java的应用程序,并为我提供了自己的REST API。

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.

我的WebScript不是共享组件:因此我没有远程对象来调用另一个网页脚本。

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

如何向本地资源发出HTTP请求(例如'/ sdo / documents / getName?type = fl')来自WebScript?

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

推荐答案

编辑:Alfresco覆盖了Spring Surf webscripts.container bean删除了远程定义(在 web-scripts-application-context.xml 远程api ):

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>

我建议您再次将其作为自定义Javascript API 根级对象。

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

远程根对象来自 Spring Surf 框架,这意味着无论使用Alfresco存储库或Share开发Web脚本,都可以使用。作为证明,这是网络脚本的来源在公开的Alfresco CMIS服务器中可用(-> Alfresco存储库实例,如果需要登录,则为admin / admin):

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);

以下摘录摘自 spring-surf-application-context.xml ,位于Alfresco 3.4.0的 spring-webscripts-1.0.0.CI-SNAPSHOT.jar 内,在远程根对象得到其定义:

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>

这篇关于来自Alfresco中WebScript的HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆