坚信科学,分享技术

>>>尝试更加利于阅读的2014版科学院,以后都在新版上写。

rose手册第三章七节:controller层:门户必备portal支持

rose

3.7.1 什么是portal?
--------------------

*字面意思,做门户用的。
*简单来说,把一个网页分成了N个区域,每个区域由不同的action去执行,多线程并行提高cpu使用率。

3.7.2 使用例子
-----------

*要使用portal,必须先在web.xml里声明所使用的线程池大小:

  1. <context-param>  
  2.         <param-name>portalExecutorCorePoolSize</param-name>  
  3.         <param-value>1024</param-value>  
  4. </context-param>  

*然后看示例代码:

  1. @Get("/3.7")  
  2. public String portal(Portal portal) {  
  3.     portal.addWindow("p1""/wp1");  
  4.     portal.addWindow("p2""/wp2");  
  5.     return "portal";  
  6. }  
  7.   
  8. @Get("/wp1")  
  9. public String portal1() {  
  10.     return "@this is p1";  
  11. }  
  12.   
  13. @Get("/wp2")  
  14. public String portal2() {  
  15.     return "@this is p2";  
  16. }  

*然后在第一个action中的portal.jsp中写到:

  1. <%@ page contentType="text/html;charset=UTF-8"%>  
  2. portal演示信息:  
  3. <br>  
  4. ${p1}  
  5. <br>  
  6. ${p2}  

*当我们部属好了之后,访问http://127.0.0.1/3.7
*将从浏览器中得到:
*portal演示信息:
*this is p1
*this is p2

3.7.3 这样子做的好处
--------------------

*更加充分地使用多核cpu。
*更加方便多人协作时对项目进行模块划分,搞的时候,按照url一分,一个url一个模块,>所有的页面都可以切成小的豆腐块,所以,你懂的。

3.7.4 过去的经典事迹
--------------------

* 2010年的6月9日晚上7点"圣战"
* http://www.54chen.com/architecture/rose-open-source-portal-framework.html

[文中所提及代码均在 https://github.com/XiaoMi/rose/tree/master/rose-example 提供。]

常期更新版本在:https://github.com/XiaoMi/rose/tree/master/chapter_3_7


原创文章如转载,请注明:转载自五四陈科学院[http://www.54chen.com]
本文链接: http://www.54chen.com/java-ee/rose-3-7.html

This entry was posted in java and tagged . Bookmark the permalink.

11 Responses to “rose手册第三章七节:controller层:门户必备portal支持”

  1. david.wang 说:

    这个例子在jetty7.5上测试通不过,addWindow这个方法内部报错,不知道github上维护的jar是否为最新的,以前从google code上下载的jar针对这个例子是没问题的,所以请确认一下,谢谢

    • 54chen 说:

      rose-example 的代码都在resin下运行测试,没对jetty进行测试,建议使用tomcat或者resin。

      • david.wang 说:

        为什么会和容器耦合呢?

        • david.wang 说:

          情况是这样的,最早,我使用http://code.google.com/p/paoding-rose/downloads/list上提供的jar,运行portal的例子正常,但是将相关的jar切换到你这边中央仓库上的,就会产生问题
          2012-07-02 14:54:07,046 ERROR [net.paoding.rose.web.portal.impl.WindowTask] -
          java.lang.NullPointerException
          at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:214)
          at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:115)
          at net.paoding.rose.web.portal.impl.WindowTask.run(WindowTask.java:81)
          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
          at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
          at java.util.concurrent.FutureTask.run(FutureTask.java:138)
          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
          at java.lang.Thread.run(Thread.java:619)

      • david.wang 说:

        应该是你这边在中央仓库维护的jar并不是最新的jar,类似的问题在tomcat有人提过bug,请升级下中央仓库的jar包呗,呵呵

        • 54chen 说:

          中央仓库的portal的代码和google code是同一个版本的,你遇到的问题与google code里有朋友遇到的tomcat的问题并非同一个问题。
          downloads上提供的jar包更新比较慢,看上去当时为了兼容tomcat,改了setListeners之后,jetty认不出来了。
          提供一下你使用的jetty版本,我有空修复一下。

        • 54chen 说:

          hi, 这是由于jetty默认使用了nio的connector的原因,请更换启动时使用bio的connector。
          给你一个maven-jetty-plugin的例子,测试通过。

          1. <configuration>  
          2.                     <connector implementation="org.mortbay.jetty.bio.SocketConnector">  
          3.                     </connector>  
          4.                     <scanIntervalSeconds>10</scanIntervalSeconds>   
          5.                     <stopKey>foo</stopKey>  
          6.                     <stopPort>9999</stopPort>  
          7.                 </configuration>  

          但是在生产环境我们只进行过tomcat与resin的测试,jetty可以在开发环境中使用。

  2. stormli 说:

    你好,使用portal时报异常,AbstractMethodError,麻烦help一下

    ava.lang.AbstractMethodError
    at javax.servlet.ServletRequestWrapper.getServletContext(ServletRequestWrapper.java:370)
    at com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:116)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
    at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:298)
    at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:116)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:236)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
    at net.paoding.rose.web.instruction.ViewInstruction.doRender(ViewInstruction.java:85)
    at net.paoding.rose.web.instruction.AbstractInstruction.render(AbstractInstruction.java:44)
    at net.paoding.rose.web.instruction.InstructionExecutorImpl.render(InstructionExecutorImpl.java:46)
    at net.paoding.rose.web.impl.thread.RootEngine.execute(RootEngine.java:140)
    at net.paoding.rose.web.impl.thread.LinkedEngine.execute(LinkedEngine.java:69)
    at net.paoding.rose.web.impl.thread.Rose.doNext(Rose.java:121)
    at net.paoding.rose.web.impl.thread.Rose.innerStart(Rose.java:256)
    at net.paoding.rose.web.impl.thread.Rose.start(Rose.java:109)
    at net.paoding.rose.RoseFilter.doFilter(RoseFilter.java:346)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)
    at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:838)
    at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1345)
    at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1301)
    at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1285)
    at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1193)
    at com.caucho.network.listen.TcpSocketLink.handleAcceptTaskImpl(TcpSocketLink.java:992)
    at com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:117)
    at com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:93)
    at com.caucho.network.listen.SocketLinkThreadLauncher.handleTasks(SocketLinkThreadLauncher.java:169)
    at com.caucho.network.listen.TcpSocketAcceptThread.run(TcpSocketAcceptThread.java:61)
    at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
    at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)
    [14-11-14 15:36:39.171] {resin-port-8080-49} WebApp[production/webapp/default/ROOT] GET /portal
    java.lang.AbstractMethodError
    at javax.servlet.ServletRequestWrapper.getServletContext(ServletRequestWrapper.java:370)
    at com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:116)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
    at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:298)
    at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:116)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:236)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
    at net.paoding.rose.web.instruction.ViewInstruction.doRender(ViewInstruction.java:85)
    at net.paoding.rose.web.instruction.AbstractInstruction.render(AbstractInstruction.java:44)
    at net.paoding.rose.web.instruction.InstructionExecutorImpl.render(InstructionExecutorImpl.java:46)
    at net.paoding.rose.web.impl.thread.RootEngine.execute(RootEngine.java:140)
    at net.paoding.rose.web.impl.thread.LinkedEngine.execute(LinkedEngine.java:69)
    at net.paoding.rose.web.impl.thread.Rose.doNext(Rose.java:121)
    at net.paoding.rose.web.impl.thread.Rose.innerStart(Rose.java:256)
    at net.paoding.rose.web.impl.thread.Rose.start(Rose.java:109)
    at net.paoding.rose.RoseFilter.doFilter(RoseFilter.java:346)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)
    at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:838)
    at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1345)
    at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1301)
    at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1285)
    at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1193)
    at com.caucho.network.listen.TcpSocketLink.handleAcceptTaskImpl(TcpSocketLink.java:992)
    at com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:117)
    at com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:93)
    at com.caucho.network.listen.SocketLinkThreadLauncher.handleTasks(SocketLinkThreadLauncher.java:169)
    at com.caucho.network.listen.TcpSocketAcceptThread.run(TcpSocketAcceptThread.java:61)
    at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
    at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)

    [14-11-14 15:36:39.173] {resin-port-8080-49} org.springframework.web.util.NestedServletException: GET /portal; nested exception is java.lang.AbstractMethodError
    at net.paoding.rose.RoseFilter.throwServletException(RoseFilter.java:551)
    at net.paoding.rose.RoseFilter.doFilter(RoseFilter.java:349)
    at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)
    at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:838)
    at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1345)
    at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1301)
    at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1285)
    at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1193)
    at com.caucho.network.listen.TcpSocketLink.handleAcceptTaskImpl(TcpSocketLink.java:992)
    at com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:117)
    at com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:93)
    at com.caucho.network.listen.SocketLinkThreadLauncher.handleTasks(SocketLinkThreadLauncher.java:169)
    at com.caucho.network.listen.TcpSocketAcceptThread.run(TcpSocketAcceptThread.java:61)
    at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
    at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)
    Caused by: java.lang.AbstractMethodError
    at javax.servlet.ServletRequestWrapper.getServletContext(ServletRequestWrapper.java:370)
    at com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:116)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
    at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:298)
    at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:116)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:236)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
    at net.paoding.rose.web.instruction.ViewInstruction.doRender(ViewInstruction.java:85)
    at net.paoding.rose.web.instruction.AbstractInstruction.render(AbstractInstruction.java:44)
    at net.paoding.rose.web.instruction.InstructionExecutorImpl.render(InstructionExecutorImpl.java:46)
    at net.paoding.rose.web.impl.thread.RootEngine.execute(RootEngine.java:140)
    at net.paoding.rose.web.impl.thread.LinkedEngine.execute(LinkedEngine.java:69)
    at net.paoding.rose.web.impl.thread.Rose.doNext(Rose.java:121)
    at net.paoding.rose.web.impl.thread.Rose.innerStart(Rose.java:256)
    at net.paoding.rose.web.impl.thread.Rose.start(Rose.java:109)
    at net.paoding.rose.RoseFilter.doFilter(RoseFilter.java:346)
    ... 16 more

    • 兴趣e族 说:

      我也出现了这个问题,现在已经解决,是因为使用的是tomcat7才导致的,换成tomcat6就没有问题,你可以试试!

  3. stormli 说:

    mvn仓库中的版本不更新了么,code-google-com上这个bug已经解决,但mvn仓库中的还是旧的

  4. 别说我out 说:

    请问这个问题在tomcat7上解决了吗?

Leave a Reply