cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r836902 - in /websites/production/cxf/content: cache/docs.pageCache docs/jax-rs-redirection.html
Date Thu, 01 Nov 2012 16:48:29 GMT
Author: buildbot
Date: Thu Nov  1 16:48:28 2012
New Revision: 836902

Log:
Production update by buildbot for cxf

Modified:
    websites/production/cxf/content/cache/docs.pageCache
    websites/production/cxf/content/docs/jax-rs-redirection.html

Modified: websites/production/cxf/content/cache/docs.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/cxf/content/docs/jax-rs-redirection.html
==============================================================================
--- websites/production/cxf/content/docs/jax-rs-redirection.html (original)
+++ websites/production/cxf/content/docs/jax-rs-redirection.html Thu Nov  1 16:48:28 2012
@@ -238,10 +238,101 @@ Note that RequestDispatcherProvider can 
 </pre>
 </div></div>
 
-<p>Given that the same ReservationStatus bean is returned in both cases, it is actually
the original request URI fragments which are used to match which view handler will deal with
a given ReservationStatus.</p>
+<p>Given that the same ReservationStatus bean is returned in both cases, it is actually
the original request URI fragments which are used to match which view handler will deal with
a given ReservationStatus, example, a response to request URI "http://localhost:8080/reservations/reserve/complete"
will be handled by "/forms/reservationConfirm.jsp".  </p>
 
 <p>Note that RequestDispatcherProvider has a 'dispatcherName' property - that can be
handy when redirecting to named servlets (example, MyServlet) including<br clear="none">
-such ones as "jsp" or "default", especially when CXFServlet handling a given invocation has
a uri pattern that may also capture the redirection requestwell-known servlets such as "default",
see the next section for more information. </p>
+such ones as "jsp" or "default", especially when CXFServlet handling a given invocation has
a uri pattern (typically, wildcard) that may also capture the redirection request,  see the
next section for more information. </p>
+
+<p>Next, imagine a scenario like this: we have a single resource method accepting some
data and the response view will need to be different depending on the status of the request
processing. Using enumerations is the most effective option in this case:</p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+<span class="code-keyword">package</span> resource;
+
+<span class="code-keyword">public</span> class Status {
+    UPDATE_SUCCESS,
+    UPDATE_FAILURE
+}
+
+@Path(<span class="code-quote">"/"</span>)
+<span class="code-keyword">public</span> class Resource {
+
+  @PUT
+  @Produces(<span class="code-quote">"text/html"</span>)
+  <span class="code-keyword">public</span> Response update(SomeData data) {
+     <span class="code-keyword">if</span> (update(data)) {
+         <span class="code-keyword">return</span> Response.ok(Status.UPDATE_SUCCESS).build();
+     } <span class="code-keyword">else</span> {
+         <span class="code-keyword">return</span> Response.ok(Status.UPDATE_FAILURE).build();
 
+     }
+  } 
+} 
+</pre>
+</div></div>
+
+
+<p>Next, you may have a single JSP handler which will check whether it is Status.UPDATE_SUCCESS
or Status.UPDATE_FAILURE and format the response accordingly. In this case a basic RequestDispatcherProvider
configuration will do:</p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-xml">
+
+<span class="code-tag">&lt;bean id=<span class="code-quote">"dispatchProvider"</span>
class=<span class="code-quote">"org.apache.cxf.jaxrs.provider.RequestDispatcherProvider"</span>&gt;</span>
+      <span class="code-tag">&lt;property name=<span class="code-quote">"resourcePath"</span>
value=<span class="code-quote">"/updateStatus.jsp"</span>/&gt;</span>
+<span class="code-tag">&lt;/bean&gt;</span>
+
+</pre>
+</div></div>
+
+<p>Alternatively you may have a dedicated view handler dealing with the specific status,
in this case either:   </p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-xml">
+<span class="code-tag">&lt;bean id=<span class="code-quote">"reserveRegistrationViews"</span>
class=<span class="code-quote">"org.apache.cxf.jaxrs.provider.RequestDispatcherProvider"</span>&gt;</span>
+         <span class="code-tag">&lt;property name=<span class="code-quote">"classResources"</span>&gt;</span>
+            <span class="code-tag">&lt;map&gt;</span>
+              <span class="code-tag">&lt;entry key=<span class="code-quote">"resource.Status.UPDATE_SUCCESS"</span>
value=<span class="code-quote">"/forms/updateSuccess.jsp"</span>/&gt;</span>
+              <span class="code-tag">&lt;entry key=<span class="code-quote">"resource.Status.UPDATE_FAILURE"</span>
value=<span class="code-quote">"/forms/updateFailure.jsp"</span>/&gt;</span>
+            <span class="code-tag">&lt;/map&gt;</span>
+         <span class="code-tag">&lt;/property&gt;</span>
+<span class="code-tag">&lt;/bean&gt;</span>
+</pre>
+</div></div>
+
+<p>or, starting from CXF 2.7.1,</p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-xml">
+&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
+      <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
+      <span class="code-keyword">xmlns:util</span>=<span class="code-quote">"http://www.springframework.org/schema/util"</span>
+      xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"&gt;
+
+<span class="code-tag">&lt;bean id=<span class="code-quote">"reserveRegistrationViews"</span>
class=<span class="code-quote">"org.apache.cxf.jaxrs.provider.RequestDispatcherProvider"</span>&gt;</span>
+         <span class="code-tag">&lt;property name=<span class="code-quote">"enumResources"</span>&gt;</span>
+            <span class="code-tag">&lt;map&gt;</span>
+              &lt;entry 
+                 <span class="code-tag">&lt;key&gt;</span>
+                    <span class="code-tag">&lt;util:constant static-field=<span
class="code-quote">"resource.Status.UPDATE_SUCCESS"</span>/&gt;</span>
+                 <span class="code-tag">&lt;/key&gt;</span> 
+                 <span class="code-tag">&lt;value&gt;</span>/forms/updateSuccess.jsp<span
class="code-tag">&lt;/value&gt;</span>
+              <span class="code-tag">&lt;/entry&gt;</span>
+              &lt;entry 
+                 <span class="code-tag">&lt;key&gt;</span>
+                    <span class="code-tag">&lt;util:constant static-field=<span
class="code-quote">"resource.Status.UPDATE_FAILURE"</span>/&gt;</span>
+                 <span class="code-tag">&lt;/key&gt;</span> 
+                 <span class="code-tag">&lt;value&gt;</span>/forms/updateFailure.jsp<span
class="code-tag">&lt;/value&gt;</span>
+              <span class="code-tag">&lt;/entry&gt;</span> 
+            <span class="code-tag">&lt;map&gt;</span>
+         <span class="code-tag">&lt;/property&gt;</span>
+<span class="code-tag">&lt;/bean&gt;</span>
+<span class="code-tag">&lt;/beans&gt;</span>
+</pre>
+</div></div>
+
+<p>will help.</p>
+
 
 <p>Starting from CXF 2.6.1 it is possible to configure the provider to check if the
current class has an associated view handler or not, for example:</p>
 



Mime
View raw message