[英]Liferay - Call a controller of a remote portlet
我試圖調用屬於遠程門戶的portlet的控制器。 我嘗試了這個教程,但它有很多額外的東西,這些都會導致我的構建錯誤。
我在遠程portlet中有一個類似下面的控制器。
@Controller
public class SampleRestController {
@RequestMapping(value = "/helloSample", method=RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody String helloSample() {
return "Finally!";
}
}
為了使用休息呼叫調用上述方法,我該怎么辦? 也就是說,我應該對基本的spring liferay portlet進行哪些更改,以獲取http://localhost:port/.../.../helloSample
的輸出為http://localhost:port/.../.../helloSample
Finally!
您可以在portlet中使用休息控制器。 鏈接的文章使用LifeFray服務和Liferay很好地解釋了它。 這只是摘要。
portlet中的自定義servlet
您需要做的是實現一個包裝在portlet應用程序中的servlet。 您需要在web.xml中配置Liferay的PortalDelegateServlet
。 servlet將請求處理委托給Spring的DispatcherServlet
。
<servlet>
<servlet-name>restful</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortalDelegateServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>org.springframework.web.servlet.DispatcherServlet</param-value>
</init-param>
<init-param>
<param-name>sub-context</param-name>
<param-value>restful</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>restful</servlet-name>
<url-pattern>/services/*</url-pattern>
<servlet-mapping>
restful servlet需要單獨的應用程序上下文,其中包含AnnotationMethodHandlerAdapter
,視圖解析器和JSON映射器。
給出你的例子中的其余控制器
@Controller
public class SampleRestController {
@RequestMapping(value = "/helloSample", method=RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody String helloSample() {
return "Finally!";
}
}
產生的URL隨后組成
http://host:port/<<context path>>/services/helloSample
| | |
| Context path of your application (eg. test-1.0-SNAPSHOT)
| |
| Defined by servlet mapping in web.xml
|
| Defined by @RequestMapping in the controller
Tomcat部署的示例網址: http:// localhost:8080 / test-1.0-SNAPSHOT / services / helloSample
有關詳細信息,請參閱鏈接的文章 。
Liferay JIRA問題在ROOT上下文中運行的自定義servlet總結了此功能的最初構思。
因為你的控制器不屬於一個portlet,你可以簡單地調用
http://localhost:port/_context path of your war_/helloSample
正如鏈接教程所說:
所以在我的示例項目中,我將生成將由自定義portlet使用的RESTFul服務......
他沒有創建包含控制器的portlet - 你也不是。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.