Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加3篇service的简单使用文档 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions webx-guide/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<fileset dir="${project.basedir}/src/main/docbook/tool">
<patternset refid="doc.resources" />
</fileset>
<fileset dir="${project.basedir}/src/main/docbook/userguide">
<patternset refid="doc.resources" />
</fileset>
</copy>
</preProcess>
</configuration>
Expand Down
6 changes: 6 additions & 0 deletions webx-guide/src/main/docbook/Webx3_Guide_Book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@
<xi:include href="tool/Tool_AutoConfig_Guide.xml" />
<xi:include href="tool/Tool_AutoExpand_Guide.xml" />
</part>
<part xml:id="webx.userguide">
<title>简单使用</title>
<xi:include href="userguide/Webx3_pipeline.xml" />
<xi:include href="userguide/Webx3_pullservice.xml" />
<xi:include href="userguide/Webx3_uribrokerService.xml" />
</part>
</book>
2 changes: 1 addition & 1 deletion webx-guide/src/main/docbook/form/Webx3_Form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ $group.mapTo($user) <co xml:id="co.form.modifydata.vm.mapto" />
source内容,在中文环境中(<code>locale=zh_CN</code>),将显示错误信息“<code>必须填写用户名</code>”;而在英文环境中(<code>locale=en_US</code>),将显示默认的错误信息“<code>User
ID is required</code>”。</para>
<para>系统的当前locale是由<code>SetLocaleRequestContext</code>来决定的。关于<code>SetLocaleRequestContext</code>的设定和使用,请参见<xref
linkend="webx.requestcontexts" />。</para>
linkend="webx.requestcontexts"/></para>
<para>此外,你还可以可以改变message source中key的前缀。</para>
<example>
<title>改变message source key的前缀</title>
Expand Down
97 changes: 97 additions & 0 deletions webx-guide/src/main/docbook/userguide/Webx3_pipeline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter[
<!ENTITY % placeholders SYSTEM "../../../../target/pom.ent">
%placeholders;
]>
<chapter xml:id="usergide.pipeline" xmlns="http://docbook.org/ns/docbook"
xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="zh-CN">
<?dbhtml filename="usergide_pipeline.html" ?>
<title>Pipeline 使用</title>
<section>
<title>功能介绍</title>
<para>pipeline是用来处理页面请求的。一个pipeline有多个valve组成,这些valve一般是按顺序执行,也就是一个请求进来,会经过一个个valve处理。
也有些valve有条件关系,如if/else,try,catch/finally类似有语义的valve组合,用于处理复杂的业务逻辑。</para>
</section>
<section>
<title>概念解释</title>
<para>valve:(阀门),页面请求的一个处理环节。如:analyzeURL,用来分析页面请求中所带参数,以方便业务代码中使用(target,action,actionEvent)。</para>
</section>
<section>
<title>使用</title>
<para>常见pipelline的配置:<programlisting language="xml"> &lt;services:pipeline xmlns="http://www.alibaba.com/schema/services/pipeline/valves">

&lt;!-- 初始化turbine rundata,并在pipelineContext中设置可能会用到的对象(如rundata、utils),以便valve取得。 -->
&lt;prepareForTurbine />

&lt;!-- 设置日志系统的上下文,支持把当前请求的详情打印在日志中。 -->
&lt;setLoggingContext />

&lt;!-- 分析URL,取得target。 -->
&lt;analyzeURL homepage="homepage" />

&lt;!-- 检查csrf token,防止csrf攻击和重复提交。假如request和session中的token不匹配,则出错,或显示expired页面。 -->
&lt;checkCsrfToken />

&lt;loop>
&lt;choose>
&lt;when>
&lt;!-- 执行带模板的screen,默认有layout。 -->
&lt;pl-conditions:target-extension-condition extension="null, vm, jsp, jspx" />
&lt;performAction />
&lt;performTemplateScreen />
&lt;renderTemplate />
&lt;/when>
&lt;when>
&lt;!-- 执行不带模板的screen,默认无layout。 -->
&lt;pl-conditions:target-extension-condition extension="do" />
&lt;performAction />
&lt;performScreen />
&lt;/when>
&lt;otherwise>
&lt;!-- 将控制交还给servlet engine。 -->
&lt;exit />
&lt;/otherwise>
&lt;/choose>

&lt;!-- 假如rundata.setRedirectTarget()被设置,则循环,否则退出循环。 -->
&lt;breakUnlessTargetRedirected />
&lt;/loop>

&lt;/services:pipeline>
</programlisting></para>
</section>
<section>
<title>原理</title>
<para>pipeline的配置表明了页面处理顺序:</para>
<para> 如果是一个target后缀为null, vm, jsp,
jspx,则先执行action请求,再处理带模板的screen请求,最后才是渲染模板。所以不管是post表单提交也好,还是简单的页面请求也好,都是走这个顺序。
如果target后缀为do,则跟上面稍微有区别,不需要渲染模板,它在json请求等会有很大作用。</para>
</section>
<section>
<title>扩展</title>
<para>
<orderedlist>
<listitem>
<para><emphasis role="bold">增加一个valve</emphasis></para>
<para> 需要继承AbstractValve,并在配置文件配置,这样即可 </para>
<para>
<programlisting language="xml">&lt;valve class="*.*" /></programlisting>
</para>
</listitem>
<listitem>
<para><emphasis role="bold">增加一个后缀处理</emphasis></para>
<para>如:</para>
<para>
<programlisting language="xml">&lt;pl-conditions:target-extension-condition extension="json" /></programlisting>
</para>
<para> 后面跟上要扩展的业务逻辑。</para>
</listitem>
<listitem>
<para><emphasis role="bold">业务逻辑扩展</emphasis></para>
<para> 如csrftoken校验;页面权限校验。这些都可以通过pipeline来解决。 </para>
<para> 建议:增加的valve放到analyzeURL valve后面。前面几个valve涉及环境初始化工作。 </para>
</listitem>
</orderedlist>
</para>
</section>
</chapter>
113 changes: 113 additions & 0 deletions webx-guide/src/main/docbook/userguide/Webx3_pullservice.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter[
<!ENTITY % placeholders SYSTEM "../../../../target/pom.ent">
%placeholders;
]>
<chapter xml:id="usergide.pullservice" xmlns="http://docbook.org/ns/docbook"
xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="zh-CN">
<?dbhtml filename="usergide_pullservice.html" ?>
<title>Pipeline使用</title>
<section>
<title>介绍</title>
<para>pullService提供了一个自动组装template context的机制。除了框架提供的工具类之外,也可以自己做扩展。 </para>
</section>
<section>
<title>使用</title>
<section>
<title>框架自带的tool</title>
<section>
<title> &lt;utils /&gt;</title>
<para>
注入了arrayUtil,classLoaderUtil,classUtil,exceptionUtil,fileUtil,localeUtil,messageUtil,objectUtil,streamUtil,stringEscapeUtil,stringUtil,systemUtil,mathUtil,这些工具类。
 </para>
<caution>
<para>StringUtil类webx2时候差别蛮大的,使用前最好先查下类</para>
</caution>
</section>
<section>
<title> &lt;rundata-tool /&gt; </title>
<para> 注入了rundata,rundata对应的实例是:TurbineRunData </para>
</section>
<section>
<title> &lt;csrfToken /&gt; </title>
<para> 注入了csrfToken,csrfToken对应的实例是:CsrfToken </para>
</section>
<section>
<title> &lt;form-tool /&gt; </title>
<para> 注入了form </para>
</section>
<section>
<title> &lt;control-tool /&gt; </title>
<para> 注入了ControlTool </para>
</section>
<section>
<title> &lt;uris-tool /&gt; </title>
<para> 注入了所有uriBrokerService里面配的uriBroker。 </para>
</section>
</section>
<section>
<title>toolName的生成规则顺序</title>
<para>
<orderedlist>
<listitem>
<para> refName </para>
</listitem>
<listitem>
<para> 根据class名字生成,如果类带后缀(Tool, ToolFactory, ToolSet,
ToolSetFactory),先去掉后缀,再变成camel case。如注入AbcTooFactory类,则页面可以引用abc。
</para>
</listitem>
<listitem>
<para> 根据配置文件名称生成:如果配置带后缀(-tool, -tool-factory, -tool-set,
-tool-set-factory),先去掉后缀,再变成camel case。如rundata-tool,页面引入的是rundata。
</para>
</listitem>
</orderedlist>
</para>
</section>
</section>
<section>
<title>扩展</title>
<section>
<title> 引入多个bean</title>
<programlisting language="xml">&lt;context-exposer>
     &lt;tool id="bean1" />
     &lt;tool id="bean2" />
     &lt;tool id="bean3" />
     &lt;tool id="bean4" />
&lt;/context-exposer></programlisting>
</section>
<section>
<title> 注入类的常量(指的是public,static,finally的那些field),配置举例: </title>
<programlisting language="xml">&lt;constants id="myconst" constantClass="javax.servlet.http.HttpServletResponse" exposed="true/false"/></programlisting>
<para> 这样页面上就可以这么用常量,$myconst.SC_OK,$myconst.SC_FOUND  </para>
<para>
默认exposed=true,这样模板上甚至可以这么用:$SC_OK,当然也可以这么$myconst.SC_OK,建议用后者。如果exposed=false,那模板上只能这么用:$myconst.SC_FOUND </para>
</section>
<section>
<title> 注入一个类,举例: </title>
<programlisting language="xml">&lt;bean-tool id="beanName" class="com.alibaba...XXX" scope="global/request" autowire="true" /&gt;</programlisting>
</section>
<section>
<title> 将静态util类的方法组合在一起,举例</title>
<para>
<programlisting>&lt;mixin id="myUtils"&gt;
&lt;!-- 引进class中所有public static方法 --&gt;
&lt;class name="com.alibaba.citrus.util.StringUtil" /&gt;

&lt;!-- 引进class中部分public static方法 --&gt;
&lt;class name="com.alibaba.citrus.util.StringEscapeUtil"&gt;

&lt;!-- 引进指定的public static方法 --&gt;
&lt;method name="escapeHtml" /&gt;

&lt;!-- 引进指定的public static方法,并改名 --&gt;
&lt;method name="escapeURL" renameTo="escapeUrl" /&gt;

&lt;/class&gt;
&lt;/mixin&gt;</programlisting>
这样在页面上可以这样使用:$myUtils.isEmpty("$ddd"),$myUtils.escapeHtml("$avar")
</para>
</section>
</section>
</chapter>
Loading