Alfresco 如果两个webscript位于同一存储库中,如何在java控制器中的webscript中调用另一个webscript

Alfresco 如果两个webscript位于同一存储库中,如何在java控制器中的webscript中调用另一个webscript,alfresco,alfresco-share,alfresco-webscripts,Alfresco,Alfresco Share,Alfresco Webscripts,如果两个webscript位于同一存储库中,如何在java控制器中的一个webscript中调用另一个webscript //hellowebscript public void execute(WebScriptRequest request, WebScriptResponse response) { //need to call another webscript } 听起来您正试图调用同一层上的web脚本,而该web脚本没有Java控制器。如果它确实有一个Java控制器,您可能只

如果两个webscript位于同一存储库中,如何在java控制器中的一个webscript中调用另一个webscript

//hellowebscript
 public void execute(WebScriptRequest request, WebScriptResponse response)
{

 //need to call another webscript
}

听起来您正试图调用同一层上的web脚本,而该web脚本没有Java控制器。如果它确实有一个Java控制器,您可能只想从Java类中调用该逻辑

我同意评论者的观点,最好的做法是将该逻辑移植到Java类并调用它

但是,如果您不能或不想这样做,请抓取一个HTTP客户机()并调用URL,就像调用Java类中的任何其他URL一样。根据您调用的web脚本,您可能需要获取用户的当前票证(请参阅AuthenticationUtils.getTicket()),并使用alf_票证参数将其传递给web脚本。

我的解决方案:

两个WebScript,一个调用作为重定向到第二个

文件:RedirectHelloWorldWebScript.java:

public class RedirectHelloWorldWebScript extends AbstractWebScript {
@Override
public void execute(WebScriptRequest wsreq, WebScriptResponse wsres)
        throws IOException {
    HttpServletResponse httpResponse = WebScriptServletRuntime
            .getHttpServletResponse(wsres);

    httpResponse.sendRedirect("/alfresco/service/helloworld");
}
}
public class HelloWorldWebScript extends AbstractWebScript {
@Override
public void execute(WebScriptRequest req, WebScriptResponse res)
        throws IOException {
    try {
        JSONObject obj = new JSONObject();
        obj.put("message", "Hello Word!");
        String jsonString = obj.toString();
        res.getWriter().write(jsonString);
    } 

    catch (JSONException e) {
        throw new WebScriptException("Unable to serialize JSON");
    }

    catch (org.json.JSONException e) {
        e.printStackTrace();
    }
}
}
文件:HelloWorldWebScript.java:

public class RedirectHelloWorldWebScript extends AbstractWebScript {
@Override
public void execute(WebScriptRequest wsreq, WebScriptResponse wsres)
        throws IOException {
    HttpServletResponse httpResponse = WebScriptServletRuntime
            .getHttpServletResponse(wsres);

    httpResponse.sendRedirect("/alfresco/service/helloworld");
}
}
public class HelloWorldWebScript extends AbstractWebScript {
@Override
public void execute(WebScriptRequest req, WebScriptResponse res)
        throws IOException {
    try {
        JSONObject obj = new JSONObject();
        obj.put("message", "Hello Word!");
        String jsonString = obj.toString();
        res.getWriter().write(jsonString);
    } 

    catch (JSONException e) {
        throw new WebScriptException("Unable to serialize JSON");
    }

    catch (org.json.JSONException e) {
        e.printStackTrace();
    }
}
}
描述符:

文件:redirecthelloworld.get.desc.xml:

<webscript>
   <shortname>RedirectHelloWorld</shortname>
   <description>Redirect to Hello World</description>
   <url>/redirecthelloworld</url>
   <authentication>none</authentication>
   <family>Java-Backed WebScripts</family>
</webscript>
<webscript>
   <shortname>helloworld</shortname>
   <description>Hello World</description>
   <url>/helloworld</url>
   <url>/helloworld.json</url>
   <authentication>none</authentication>
   <family>Java-Backed WebScripts</family>
</webscript>

重定向HelloWorld
重定向到Hello World
/重定向HelloWorld
没有一个
Java支持的WebScript
文件:helloworld.get.desc.xml:

<webscript>
   <shortname>RedirectHelloWorld</shortname>
   <description>Redirect to Hello World</description>
   <url>/redirecthelloworld</url>
   <authentication>none</authentication>
   <family>Java-Backed WebScripts</family>
</webscript>
<webscript>
   <shortname>helloworld</shortname>
   <description>Hello World</description>
   <url>/helloworld</url>
   <url>/helloworld.json</url>
   <authentication>none</authentication>
   <family>Java-Backed WebScripts</family>
</webscript>

地狱世界
你好,世界
/地狱世界
/helloworld.json
没有一个
Java支持的WebScript
还有,Spring的上下文:

文件:webscript-context.xml:

<bean id="webscript.helloworld.get"
  class="com.fegor.HelloWorldWebScript"
  parent="webscript">       
</bean>

<bean id="webscript.redirecthelloworld.get"
  class="com.fegor.RedirectHelloWorldWebScript"
  parent="webscript">       
</bean>


祝你好运

它在同一层吗?或者您正在尝试从共享层调用回购webscript?第二个webscript的作用是什么?您应该将逻辑重构为一个服务类,然后两个WebScript都可以使用该服务类。从另一个存储库webscript调用存储库webscript没有简单的方法。如果它们在同一层中,您可以随时获取另一个webscript的Java bean并调用它,但重构更是推荐的方法!第二个webscript只有get.desc.xml文件和ftl文件。第二个webscript没有Java控制器和JS控制器。在这种情况下,如何从第一个webscript调用第二个webscript。两者都在同一层中。如果我的第二个脚本看起来有点像在这个url中定义的,没有java/js控制器;这是如何调用第一个webscript java控制器;