kapok

          垃圾桶,嘿嘿,我藏的這么深你們還能找到啊,真牛!

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            455 隨筆 :: 0 文章 :: 76 評論 :: 0 Trackbacks
          http://dev2dev.bea.com.cn/techdoc/webplat/2005051905.html

           BEA WebLogic Portal 8.1? 框架的核心任務(wù)之一是創(chuàng)建一致且正確的 URL , 以便用戶在門戶頁面環(huán)境中與各種 portlet 進(jìn)行 交互。撰寫本文的目的是為了向讀者介紹 WebLogic Portal 中 URL 創(chuàng)建過程的基礎(chǔ)結(jié)構(gòu)。本文介紹 WebLogic Portal 如何創(chuàng)建 URL , 可以創(chuàng)建的各種 URL , URL 背 后的 API 和 層 , 以及使用 Web Services for Remote Portlets ( WSRP ) 提供或消費(fèi) portlet 時(shí) URL 將會發(fā)生什么變化。在介紹 URL 創(chuàng)建過程的同時(shí),我還將重點(diǎn)強(qiáng)調(diào)一些最佳實(shí)踐。閱讀本文之后,您將有能力避免大多數(shù)常見的 URL 缺陷,并且可以利用 portlet 提供一致的用戶體驗(yàn)。

          問題

            為什么創(chuàng)建 URL 是 WebLogic Portal 的核心任務(wù) ? 為什么 portlet 不能像在 HTML/JSP 頁面中創(chuàng)建 URL 那樣在以下示例代碼中創(chuàng)建 URL ?

            Click <a href="next.jsp">here</a> to continue.

            當(dāng)用戶點(diǎn)擊與此類似的鏈接時(shí) , 下面的某種情況將發(fā)生 :

          • 用戶將看到未經(jīng)門戶頁面聚合的 next.jsp 內(nèi)容。

          • 用戶將看到錯(cuò)誤頁面,帶有可怕的異常堆棧跟蹤。

          • 如果門戶調(diào)用 portlet 使用的是 WSRP ,但是用戶不具有與 WSRP Producer 直接交互的權(quán)限,則該用戶的瀏覽器上將顯示一個(gè) DNS 或安全性錯(cuò)誤。

            要避免這些情況的發(fā)生 , portlet 必須要求 WebLogic Portal 創(chuàng)建 URL 。為什么 portlet 將此任務(wù)委派給 WebLogic Portal ? 原因如下 : 

          提示 在創(chuàng)建 portlet 時(shí) , 不要假定關(guān)于 URL 結(jié)構(gòu)的任何事情。實(shí)際結(jié)構(gòu)不僅可以由部署在 portlet 的 Web 應(yīng)用程序中的模板確定,而且也可以由客戶確定,比如 WSRP 。

          • 門戶是訪問 portlet 的網(wǎng)關(guān) —— 當(dāng)用戶與 portlet 交互(即提交表單或點(diǎn)擊鏈接)時(shí),門戶接收用戶請求,查找負(fù)責(zé)處理該請求的 portlet ,然后調(diào)用 portlet 。門戶還可提供附加服務(wù),如個(gè)性化、權(quán)利等。因此, portlet 創(chuàng)建的鏈接必須指向門戶,而不是指向 portlet 的 JSP 、 servlet 或頁面流。

          • Portlet 從門戶中去耦 ——Portlet 是可重用單元,可以將其聚合到多個(gè)門戶和桌面。因此, Portlet 不能對門戶頁面的 URL 假定太多。聚合 portlet 的門戶可以位于: (a) 本地,在同一 Web 應(yīng)用程序中, (b) 在同一服務(wù)器上的不同 Web 應(yīng)用程序中,或者 (c) 物理遠(yuǎn)程位置。在 (b) 和 (c) 兩種情況下,門戶可以使用 WSRP 在頁面中聚合 portlet 。實(shí)際上,可以同時(shí)將同一 portlet 聚合到這三種類型的門戶頁面中。

          • Portlet 不知道部署 —— 更重要的是, portlet 對于如何部署它們無法假定太多。部署細(xì)節(jié)包括代理服務(wù)器、域名稱、端口,等等。 Portlet 對這些無法做出任何假定 。

            當(dāng)您將 URL 的創(chuàng)建委托給 WebLogic Portal 時(shí) , 它將對 portlet 屏蔽門戶頁面 URL 、域名稱、代理服務(wù)器等。門戶管理員和部署人員可以控制細(xì)節(jié),無需破壞 portlet 中的任何 URL 。

            如果您非常想知道上述鏈接的創(chuàng)建方式(假定您要在簡單 JSP portlet 中創(chuàng)建這一鏈接),下面就是一個(gè)例子:

            Click <a href="<render:jspContentUrl contentUri="next.jsp"/>">here</a> to continue .

            現(xiàn)在 , 我們來檢查 WebLogic Portal 的 URL 的基礎(chǔ)結(jié)構(gòu)

          URL模板

            WebLogic Portal 使用稱為 “ URL 模板 ” 的簡短 URL 片斷創(chuàng)建 URL 。它們不是有效的 URL , 需要進(jìn)一步處理才能使用。要查看 URL 模板,需要?jiǎng)?chuàng)建門戶項(xiàng)目并檢查其 WEB-INF 目錄。在此目錄中,您將發(fā)現(xiàn)一個(gè) url-templates-config.xml 文件。該文件中包含大量的默認(rèn) URL 模板。每個(gè) URL 模板的外觀如下所示:

          <url-template name="default">
               {url:scheme}://{url:domain}:{url:port}/{url:path}?{url:queryString}{url:currentPage}
          </url-template> to continue.

          提示 : 您可以使用已知值替換任何可選標(biāo)志。例如 , 如果您認(rèn)為永遠(yuǎn)不會通過 HTTP 訪問門戶頁面 , 則可以在所有 URL 模板中使用 “ http ” 替換“url:scheme” 。

            您將發(fā)現(xiàn)該文件不只是列出一個(gè)模板 , 而是列出多個(gè)模板。在討論為何需要多個(gè)模板之前,我們先看一看 URL 模板的結(jié)構(gòu)。

          剖析URL模板

            URL 模板是帶有一個(gè)或多個(gè)標(biāo)志的 URL 。這些標(biāo)志由 WebLogic Portal 預(yù)定義,在使用遠(yuǎn)程 portlet 的情況下,是 WSRP 1.0 規(guī)范規(guī)定的。所有標(biāo)志均由大括號包圍 ( { , } ) 。使用 URL 模板創(chuàng)建 URL 時(shí), WebLogic Portal 使用相應(yīng)的值替代這些標(biāo)志,這些值或者由 URL API 或者由 JSP 標(biāo)記指定,或者從部署門戶的方式自動(dòng)派生。

            每個(gè) URL 模板中可以具有一個(gè)或多個(gè)下面的標(biāo)志 :

          • url:scheme: 這是一個(gè)可選的標(biāo)志,用于指定訪問該 URL 所需的 HTTP 方案。該值可以是“ http ”或“ https ”。如果在使用此 URL 模板時(shí)沒有為該標(biāo)志指定值, WebLogic Portal 將使用可用于生成該模板在其中發(fā)揮使用的頁面的任一方案。例如,如果使用“ https ”訪問包含具有模板的 URL 的頁面,則它會將這一標(biāo)志替換為“ https ”。

          • url:domain : 這是一個(gè)可選標(biāo)志 , 用于指定訪問該門戶時(shí)使用的域的名稱。在大多數(shù)情況下,它就是在 WebLogic Portal 之前部署的代理服務(wù)器的域名稱。如果在使用 URL 模板時(shí)沒有為該標(biāo)志指定值, WebLogic Portal 將使用傳入的 HttpServletRequest 的 getServerName() 的值。

          • url:port : 這是一個(gè)可選標(biāo)志 , 用于指定訪問門戶時(shí)使用的端口號。在大多數(shù)情況下,它將是代理服務(wù)器的端口號。如果未指定值,則 WebLogic Portal 將使用傳入的 HttpServletRequest 的 getServerPort() 的值。

          • url:securePort : 這是一個(gè)可選標(biāo)志 , 用于指定訪問門戶時(shí)使用的 SSL 端口號。在大多數(shù)情況下,它將是代理服務(wù)器的 SSL 端口號。如果未指定值,則 WebLogic Portal 將從服務(wù)器 / 代理配置獲取值。

          • url:prefix: 這是一個(gè)可選標(biāo)志,如果您在代理服務(wù)器設(shè)置中使用路徑前綴,則需指定該標(biāo)志 。

          • url:path : 所有 URL 模板都必須包括此標(biāo)志。 WebLogic Portal 根據(jù)頁面是門戶的一部分還是桌面的一部分 , 使用相應(yīng)的值替換它。

          • url:contextualPath : 此標(biāo)志是可選的 , 應(yīng)用于指向與 Web 應(yīng)用程序上下文根相關(guān)的路徑的 URL 。一個(gè)示例是到與 Web 應(yīng)用程序上下文根相關(guān)的圖像或文件的鏈接。

          • url:queryString : 所有 URL 模板都必須包括此標(biāo)志。 WebLogic Portal 使用很多保留查詢參數(shù) , 使用該標(biāo)志替換那些查詢參數(shù)。實(shí)際替換的參數(shù)取決于如何和在何處使用這一模板。要查找有關(guān)這些保留查詢參數(shù)的更多信息,請參考 WebLogic Portal 框架中的 白皮書

          • url:currentPage : 這是一個(gè)可選項(xiàng) , 用于在生成的 URL 中嵌入當(dāng)前的頁面標(biāo)簽。

          提示 記住使用用于設(shè)置代理服務(wù)器的路徑前綴替換url:prefix標(biāo)志。

            創(chuàng)建門戶項(xiàng)目時(shí)創(chuàng)建的 url-templates-config.xml 文件中包含的模板列表 , 可以滿足大多數(shù)常見開發(fā)需求。

          URL的類型

            WebLogic Portal 使用三種 URL

          • 操作 URL : 這些 URL 可用于提交用戶互操作 ( 如表單提交和查詢鏈接 ), 可以由任何 portlet 創(chuàng)建。

          • 資源 URL : 資源 URL 可用于生成到靜態(tài)內(nèi)容 ( 如圖像、樣式表、 JavaScript 文件、 pdf 文件等 ) 的鏈接。任何 portlet 都可以創(chuàng)建這些 URL 。

          • 呈現(xiàn) URL 。呈現(xiàn) URL 是一種特殊類型的 URL , 供 Java ( 符合 JSR168 的 ) portlet 和遠(yuǎn)程 ( 使用 WSRP 的 ) portlet 使用。

            稍后我們將討論在 JSP 中如何創(chuàng)建這些類型的 URL 。

            參照前面的 url-templates-config.xml 文件 , 您將發(fā)現(xiàn)該文件具有兩個(gè)主要部分。第一部分定義大量模板。

            第二部分定義 Java 和 Page Flow portlet 如何使用這些模板。

            文件中定義的每個(gè) url-template 具有一個(gè)名稱和一個(gè)字符串值。任何兩個(gè) URL 模板的名稱都不能相同。

            字符串值是帶有一個(gè)或多個(gè)標(biāo)志的 URL 模板字符串。

            此文件的第二部分為 Java 和 / 或 Page Flow portlet 定義一個(gè)或多個(gè) url-template-ref 元素。使用這些元素可以指定要用于給定 URL 的 URL 模板。例如 , 以下片斷指定 , 名為 jpf-action 的 URL 模板可用于創(chuàng)建在頁面流中使用的操作 URL , 而名為 jpf-secure-action 的 URL 模板 可用于在頁面流中創(chuàng)建安全操作 URL :

           <jpf-url-templates>
             <url-template-ref type="action" name="jpf-action"/>
             <url-template-ref type="secure-action" name="jpf-secure-action"/>
             ...
          </jpf-url-templates>

          使用URL模板

            WebLogic Portal 提供了很多使用在前一節(jié)中定義的 URL 模板的方法。

          顯式使用URL模板

            利用 URL 模板 , 您可以使用 com.bea.portlet.GenericURL 及其子類創(chuàng)建 URL 。下面是一個(gè)示例 :

           <% 
              ResourceURL url = ResourceURL.createResourceURL(request, response);
              url.setScheme("http");
              url.setDomain("my.domain.com");
              url.setPort(8001);
              url.setPathPrefix("/static");
              url.setTemplate("my-resource-template");
              url.setPath("/images/my.jpg");
          %>
          <img src="<%=url.toString()%>"/>  

            此片斷使用 my-resource-template 創(chuàng)建到圖像的鏈接。執(zhí)行時(shí) , 該 JSP 生成以下代碼 :

          <img src="http://my.domain.com:8001/static/images/my.jpg"/>

          提示 確保正在使用的 URL 模板具有與 setter 方法相對應(yīng)的標(biāo)志。如果沒有 , WebLogic Portal 將忽略到 setter 的調(diào)用。

            注意 , 模板必須存在于 my-resource-template 文件中 , 此片斷才能生效。模板還必須具有一個(gè)指定的 url:prefix 標(biāo)志 , setPathPrefix() 方法將替換 該標(biāo)志。

          com.bea.portlet.GenericURL 或其子類的位置 , 您可以使用在呈現(xiàn)標(biāo)記庫中可用的 URL 標(biāo)記創(chuàng)建 URL 來代替。例如 , 可以使用 renderUrl JSP 標(biāo)記來重寫上述 JSP 片斷 :
          <%@ taglib uri="render.tld" prefix="render" %>
          <img src="<render:resourceUrl port="8001" template="default-complete" 
                scheme="http" domain="my.domain.com" 
                pathPrefix="/static" path="/images/my.jpg"/> "/>

            注意 , 所有的框架主干 JSP 均使用呈現(xiàn)標(biāo)記創(chuàng)建到窗口模式 / 狀態(tài)按鈕的鏈接、到頁面的鏈接 , 等等。

          在Portlet中使用URL模板

            使用 Page Flow 和 Struts 標(biāo)記在 Page Flow 和 Struts portlet 中創(chuàng)建表單、鏈接等時(shí) , 這些 JSP 標(biāo)記通過 URL 重寫程序?qū)?URL 創(chuàng)建委派給 WebLogic Portal 。這些 URL 重寫程序使用 jpf-url-templates 指定的 URL 模板創(chuàng)建 URL 。

            WebLogic Portal 中的 portlet 容器使用類似的方法處理 Java portlet 。創(chuàng)建 javax.portlet.PortletURL 時(shí), portlet 容器使用在 url-templates-config.xml 文件中指定的 java-portlet-url-templates 。下面是一個(gè)示例:

          <%
             PortletURL actionURL = renderResponse.createActionURL();
             PortletURL renderURL = renderResponse.createRenderURL();
          %>

            WebLogic Portal 將分別使用 “ 操作 ” 和 “ 資源 ” 類型的 URL 模板生成這兩個(gè) URL 的字符串值。

          遠(yuǎn)程Portlet中的URL

            當(dāng)您使用WSRP消費(fèi)遠(yuǎn)程portlet時(shí),確保遠(yuǎn)程portlet返回的標(biāo)記引用門戶至關(guān)重要(WSRP Consumer)。使用遠(yuǎn)程portlet時(shí),Consumer充當(dāng)最終用戶和WSRP Producer上部署的portlet的中間件。一般情況下,Producer可能設(shè)置安全性策略,限制最終用戶對部署在Producer上的資源的訪問權(quán)限。所以,未使用WebLogic Portal創(chuàng)建的鏈接在遠(yuǎn)程portlet上可能失敗。

            WSRP 1.0規(guī)范為URL創(chuàng)建指定了兩種方法:“producer writing”和“consumer rewriting”。下面簡要介紹一下這兩種方法。

          Producer Writing

            此方法包括以下步驟:

          • Consumer 將一組 URL 模板發(fā)送給 Producer 。這些 URL 模板在結(jié)構(gòu)上類似于上面討論的模板 , 不同的是它們包含由 WSRP 1.0 規(guī)范指定的標(biāo)記。

          • Producer 使用這些 URL 模板創(chuàng)建 URL , 并向 Consumer 返回標(biāo)記。

          • 如果需要 , Consumer 可以進(jìn)一步處理 URL 以便 URL 引用 Consumer 。

            在這三個(gè)步驟中 , 只有第三步依賴于 WSRP Consumer 的實(shí)現(xiàn)方式。如果 WebLogic Portal 就是 Consumer , 則 Producer 的 URL 的編寫包括以下步驟 :

          • WebLogic Portal 使用一組用于遠(yuǎn)程 portlet 的 URL 模板。這些模板連同其他 URL 模板一起在 url-templates-config.xml 文件中聲明。門戶 Web 應(yīng)用程序的 WEB-INF 目錄中的 wsrp-producer-registry.xml 文件指定了必須用于遠(yuǎn)程 portlet 的 URL 模板的名稱。注意這些模板中出現(xiàn)的額外標(biāo)志。例如, wsrp-default 模板具有類似 {wsrp-interactionState} 、 {wsrp-navigationalState} 和 {wsrp-mode} 的標(biāo)志。 WSRP 1.0 規(guī)范描述這些標(biāo)志的意義。

          • Producer 使用這些模板創(chuàng)建 URL 。注意 , Producer 不一定是 WebLogic Portal 。使用其他實(shí)現(xiàn)也可以處理這些 URL 模板 , 因?yàn)檫@些標(biāo)志是由 WSRP 1.0 規(guī)范定義的。

          • WebLogic Portal 聚合 Producer 返回的標(biāo)記而不進(jìn)一步處理。

          • 將 WebLogic Portal 設(shè)置為 Producer 時(shí) , 它將使用 URL 模板 , 這一點(diǎn)與本地使用 portlet 的 情況類似。惟一的區(qū)別是 , 它使用 Consumer 發(fā)送的模板 , 而不使用在 Producer 本地部署的模板。

            下面是一個(gè)示例。我們假定您使用以下 JSP 部署 Page Flow portlet :

           <%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
           <netui:anchor action="next">Next</netui:anchor>

          當(dāng)您在 WebLogic Portal Consumer 中消費(fèi)此 portlet 時(shí) , 它將發(fā)送以下 SOAP 請求以獲取該 portlet 的標(biāo)記 :

          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <soapenv:Body>
              <urn:getMarkup xmlns:urn="urn:oasis:names:tc:wsrp:v1:types">
                <urn:portletContext>
                  <urn:portletHandle>portlet_1</urn:portletHandle>
                </urn:portletContext>
                <urn:runtimeContext>
                  <urn:userAuthentication>wsrp:none</urn:userAuthentication>
                  <urn:portletInstanceKey>portlet_1_2_1</urn:portletInstanceKey>
                  <urn:namespacePrefix>portlet_1_2_1</urn:namespacePrefix>
                  <urn:templates>
                    <urn:defaultTemplate>
                      http://localhost:7001/consumer/hello.portal?_nfpb=true&amp;
                      _windowLabel=portlet_1_2_1&amp;_pageLabel=hello_page_2&amp;
                      wsrp-urlType={wsrp-urlType}&amp;wsrp-url={wsrp-url}&amp;
                      wsrp-requiresRewrite={wsrp-requiresRewrite}&amp;
                      wsrp-navigationalState={wsrp-navigationalState}&amp;
                      wsrp-interactionState={wsrp-interactionState}&amp;
                      wsrp-mode={wsrp-mode}&amp;wsrp-windowState={wsrp-windowState}
                    </urn:defaultTemplate>
                    <urn:blockingActionTemplate>
                      http://localhost:7001/consumer/hello.portal?_nfpb=true&amp;
                      _windowLabel=portlet_1_2_1&amp;_pageLabel=hello_page_2&amp;
                      wsrp-urlType=blockingAction&amp;wsrp-url={wsrp-url}&amp;
                      wsrp-requiresRewrite={wsrp-requiresRewrite}&amp;
                      wsrp-navigationalState={wsrp-navigationalState}&amp;
                      wsrp-interactionState={wsrp-interactionState}&amp;
                      wsrp-mode={wsrp-mode}&amp;wsrp-windowState={wsrp-windowState}
                    </urn:blockingActionTemplate>
                    <urn:renderTemplate>
                      http://localhost:7001/consumer/hello.portal?_nfpb=true&amp;
                      _windowLabel=portlet_1_2_1&amp;_pageLabel=hello_page_2&amp;
                      wsrp-urlType=render&amp;wsrp-url={wsrp-url}&amp;
                      wsrp-requiresRewrite={wsrp-requiresRewrite}&amp;
                      wsrp-navigationalState={wsrp-navigationalState}&amp;
                      wsrp-interactionState={wsrp-interactionState}&amp;
                      wsrp-mode={wsrp-mode}&amp;wsrp-windowState={wsrp-windowState}
                    </urn:renderTemplate>
                    <urn:resourceTemplate>
                      http://localhost:7001/consumer/resource?_windowLabel=portlet_1_2_1&amp;
                      wsrp-urlType=resource&amp;wsrp-url={wsrp-url}&amp;
                      wsrp-requiresRewrite={wsrp-requiresRewrite}
                    </urn:resourceTemplate>
                    <urn:secureDefaultTemplate>
                      http://localhost:7002/consumer/hello.portal?_nfpb=true&amp;
                      _windowLabel=portlet_1_2_1&amp;_pageLabel=hello_page_2&amp;
                      wsrp-urlType={wsrp-urlType}&amp;wsrp-url={wsrp-url}&amp;
                      wsrp-requiresRewrite={wsrp-requiresRewrite}&amp;
                      wsrp-navigationalState={wsrp-navigationalState}&amp;
                      wsrp-interactionState={wsrp-interactionState}&amp;
                      wsrp-mode={wsrp-mode}&amp;wsrp-windowState={wsrp-windowState}
                    </urn:secureDefaultTemplate>
                    <urn:secureBlockingActionTemplate><![CDATA[
                      https://localhost:7002/consumer/hello.portal?_nfpb=true&
                      _windowLabel=portlet_1_2_1&_pageLabel=hello_page_2&
                      wsrp-urlType=blockingAction&wsrp-secureURL=true&
                      wsrp-url={wsrp-url}&wsrp-requiresRewrite={wsrp-requiresRewrite}&
                      wsrp-navigationalState={wsrp-navigationalState}&
                      wsrp-interactionState={wsrp-interactionState}&
                      wsrp-mode={wsrp-mode}&wsrp-windowState={wsrp-windowState}]]>
                    </urn:secureBlockingActionTemplate>
                    <urn:secureRenderTemplate><![CDATA[
                      https://localhost:7002/consumer/hello.portal?_nfpb=true&
                      _windowLabel=portlet_1_2_1&_pageLabel=hello_page_2&
                      wsrp-urlType=render&wsrp-secureURL=true&wsrp-url={wsrp-url}&
                      wsrp-requiresRewrite={wsrp-requiresRewrite}&
                      wsrp-navigationalState={wsrp-navigationalState}&
                      wsrp-interactionState={wsrp-interactionState}&
                      wsrp-mode={wsrp-mode}&wsrp-windowState={wsrp-windowState}]]>
                    </urn:secureRenderTemplate>
                    <urn:secureResourceTemplate>
                      https://localhost:7002/consumer/resource?_windowLabel=portlet_1_2_1&amp;
                      wsrp-urlType=resource&amp;wsrp-secureURL=true&amp;
                      wsrp-url={wsrp-url}&amp;wsrp-requiresRewrite={wsrp-requiresRewrite}
                    </urn:secureResourceTemplate>
                  </urn:templates>
                <urn:runtimeContext>
                <urn:userContext xsi:nil="true" 
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                <urn:markupParams>
                  <urn:secureClientCommunication>false</urn:secureClientCommunication>
                  <urn:locales>en-US</urn:locales>
                  <urn:mimeTypes>text/html</urn:mimeTypes>
                  <urn:mimeTypes>*/*</urn:mimeTypes>
                  <urn:mode>wsrp:view</urn:mode>
                  <urn:windowState>wsrp:normal</urn:windowState>
                  <urn:clientData>
                    <urn:userAgent>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; 
                       SV1; .NET CLR 1.1.4322; FDM)</urn:userAgent>
                  </urn:clientData>
                <urn:markupCharacterSets>UTF-8</urn:markupCharacterSets>
              </urn:markupParams>
            </urn:getMarkup>
          </soapenv:Body>
          </soapenv:Envelope>

            在此請求中 , 要注意的主要細(xì)節(jié)是模板元素。將 URL 模板發(fā)送到任何 Producer 之前 , WebLogic Portal Consumer 會將 URL 模板中的所有 Consumer 特定的標(biāo)志替換掉 , 僅留下 WSRP 1.0 特定的標(biāo)志。替換 WSRP 1.0 特定的標(biāo)志由 Producer 來完成。注意,出于可讀性方面的考慮,上述消息中的模板的多個(gè)行被強(qiáng)制換行。

          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <soapenv:Body>
              <urn:getMarkupResponse xmlns:urn="urn:oasis:names:tc:wsrp:v1:types">
                <urn:markupContext>
                  <urn:mimeType>text/html; charset=UTF-8</urn:mimeType>
                  <urn:markupString><![CDATA[
                    <a href="http://localhost:7001/consumer/hello.portal?_nfpb=true&
                        _windowLabel=portlet_1_2_1&_pageLabel=hello_page_2&
                        wsrp-urlType=blockingAction&wsrp-url=&wsrp-requiresRewrite=&
                        wsrp-navigationalState=&
                        wsrp-interactionState=_action%3D%252Fhello%252FHelloWorld%252Fbegin&
                        wsrp-mode=&wsrp-windowState=">Next</a>
               ]]></urn:markupString>
                  <urn:locale>en-US</urn:locale>
                  <urn:requiresUrlRewriting>false</urn:requiresUrlRewriting>
                </urn:markupContext>
              </urn:getMarkupResponse>
            </soapenv:Body>
          </soapenv:Envelope>

          提示 WebLogic Portal Producer 可以將 URL 模板存儲在 HTTP 會話中 , 所以 , WebLogic Portal Consumer 每個(gè)會話發(fā)送一次 URL 模板。

            注意 , Producer 使用 blockingActionTemplate 創(chuàng)建 netui:anchor 標(biāo)記的鏈接。由于在這次響應(yīng)中返回的 portlet 標(biāo)記完全合格 , 不需要在 Consumer 上對其進(jìn)行進(jìn)一步地處理。

            如果您有意了解關(guān)于這些 SOAP 消息內(nèi)容的更多信息 , 請?jiān)L問 OASIS WSRP TC 主頁 , 并下載最新版本的 WSRP 1.0 Primer 。

          Consumer Rewriting

            在此方法中 , Consumer 不發(fā)送 URL 模板 , 而是執(zhí)行以下步驟 :

            Consumer 為 portlet 標(biāo)記發(fā)出請求。該請求不包括 URL 模板。

            Producer 創(chuàng)建鏈接 , 這些鏈接被封裝在由 WSRP 1.0 規(guī)范指定的特殊標(biāo)記中。

            Consumer 分析該標(biāo)記 , 并使用適當(dāng)?shù)?URL 替換這些標(biāo)記中的鏈接。

            對于上述示例 portlet , Producer 返回如下響應(yīng) :

          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <soapenv:Body>
              <urn:getMarkupResponse xmlns:urn="urn:oasis:names:tc:wsrp:v1:types">
                <urn:markupContext>
                  <urn:mimeType>text/html; charset=UTF-8</urn:mimeType>
                  <urn:markupString>Hello World 
                     &lt;a href="wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-secureURL=false
                     &wsrp-interactionState=_action%3D%252Fhello%252FHelloWorld%252Fbegin/wsrp_rewrite">Begin
                     &lt;/a></urn:markupString>
                  <urn:locale>en-US</urn:locale>
                  <urn:requiresUrlRewriting>true</urn:requiresUrlRewriting>
                </urn:markupContext>
              </urn:getMarkupResponse>
            </soapenv:Body>
          </soapenv:Envelope>

            注意 , 鏈接的 href 值被封裝在 wsrp_rewrite? 和 /wsrp_rewrite 標(biāo)記之間。然后 , WebLogic Portal Consumer 分析這些記號中的標(biāo)記 , 并使用部署在 Consumer 上的 URL 模板創(chuàng)建 URL 。 

          提示 : 如果將 WebLogic Portal 用作 Consumer , 則可以嘗試對 Producer 進(jìn)行設(shè)置 , 以便更好地使用 URL 模板。

          Producer Writing還是Consumer Rewriting?

            URL 創(chuàng)建的兩種方法的主要不同點(diǎn)在于 URL 模板的使用。由 WebLogic Portal Consumer 發(fā)送給 Producer 的那種模板不需要對 Producer 返回的標(biāo)記進(jìn)行進(jìn)一步地處理。因此,將 WebLogic Portal 用作 Consumer 時(shí),此方法執(zhí)行地較好。

            WebLogic Portal Producer ( 無論簡單還是復(fù)雜 ) 默認(rèn)的設(shè)置是使用 Producer writing 生成 URL 。您可以通過更新 Producer 的 WEB-INF 目錄下的 wsrp-producer-config.xml文件改用 Consumer rewriting 。請參考 關(guān)于 WSRP 的 WebLogic Portal 文檔資料 以獲取更多細(xì)節(jié)。

          結(jié)束語

            在本文中 , 我的目的之一是想指出為什么創(chuàng)建 URL 對于提供一致的用戶體驗(yàn)是關(guān)鍵一步。當(dāng)您使用 WebLogic Portal 提供的 API 和 JSP 標(biāo)記、 Page Flow 或 Struts 標(biāo)記、或者 Java Portlet API 或標(biāo)記時(shí), URL 創(chuàng)建過程依賴于 URL 模板。 WebLogic Portal 具有消費(fèi)本地部署的模板和遠(yuǎn)程 Consumer 發(fā)送的模板的能力。這些功能在設(shè)計(jì)上允許 URL 模板控制所有創(chuàng)建的鏈接,以聲明的方式即可調(diào)整,無需更改代碼。

            反向工程生成的 URL 結(jié)構(gòu)以手動(dòng)創(chuàng)建鏈接 ( 即不使用任何 WebLogic Portal API 或標(biāo)簽 ), 也是很可能實(shí)現(xiàn)的。這種鏈接在有些情況下可以使用,但是當(dāng)部署配置變更或使用 WSRP 時(shí),則很可能失敗。下面是最新的準(zhǔn)則。始終使用以下標(biāo)簽創(chuàng)建鏈接:

          • 在框架主干 JSP 和 portlet JSP 中 : com.bea.portlet.GenericURL 或其子類或者呈現(xiàn)標(biāo)簽庫中的 URL 標(biāo)簽

          • 在 Page Flow portlet 中 : Page Flow HTML 標(biāo)記

          • 在 Struts portlet 中 : Struts HTML 標(biāo)記

          • 在 Java Portlet 中 : Java Portlet API 或 portlet 標(biāo)記庫中的 URL 標(biāo)記

            您完全可以不使用這些標(biāo)記 , 而按照自己的意思創(chuàng)建 URL 。但這樣的 URL 有時(shí)可能不可用。

          參考資料

          關(guān)于 WSRP 的 WebLogic Portal 文檔資料

          WebLogic Portal GenericURL 文檔資料

          描述 WebLogic Portal Framework 的白皮書

          OASIS WSRP TC 主頁

          關(guān)于作者

            Subbu Allamaraju 是 BEA Systems 的 WebLogic Portal 開發(fā)團(tuán)隊(duì)的專職軟件工程師。從事 WSRP 標(biāo)準(zhǔn)及其 WebLogic Portal 實(shí)現(xiàn)方面的工作。此外他還在 subbu.org 上扮演一個(gè)技術(shù)博客的角色。

          原文出處

          http://dev2dev.bea.com/products/wlportal81/articles/urls_in_portal.jsp

          posted on 2005-05-19 19:28 笨笨 閱讀(654) 評論(0)  編輯  收藏 所屬分類: J2EE 、ALLWeblogic Portal
          主站蜘蛛池模板: 泾川县| 珲春市| 鄱阳县| 会理县| 大英县| 张掖市| 长乐市| 蕉岭县| 庆阳市| 盐津县| 旬阳县| 郸城县| 扶沟县| 大石桥市| 惠水县| 麻江县| 海安县| 刚察县| 布拖县| 辛集市| 武夷山市| 金堂县| 宝应县| 水城县| 满城县| 建昌县| 伊金霍洛旗| 叙永县| 琼结县| 娄烦县| 互助| 塘沽区| 科尔| 肃宁县| 徐水县| 康乐县| 内黄县| 城步| 天门市| 民县| 库车县|