cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF Documentation > JAX-RS Redirection
Date Mon, 31 Jan 2011 21:43:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2036/9/1/_/styles/combined.css?spaceKey=CXF20DOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CXF20DOC/JAX-RS+Redirection">JAX-RS
Redirection</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~dkulp">Daniel
Kulp</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h1. With CXFServlet <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Please see the &quot;Redirection&quot;
section on the [Servlet <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">Transport|http://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport]</span>
<span class="diff-added-words"style="background-color: #dfd;">Transport|Servlet Transport]</span>
page. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>Note that both CXFServlet
and JAXRS RequestDispatcherProvider can work together effectively on executing the redirection
requests as described at that page. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p><span style="font-size:2em;font-weight:bold"> JAX-RS : Redirection
</span></p>

<div>
<ul>
    <li><a href='#JAX-RSRedirection-WithRequestDispatcherProvider'>With RequestDispatcherProvider</a></li>
    <li><a href='#JAX-RSRedirection-WithCXFServlet'>With CXFServlet</a></li>
    <li><a href='#JAX-RSRedirection-CustomRedirection'>Custom Redirection</a></li>
</ul></div>

<h1><a name="JAX-RSRedirection-WithRequestDispatcherProvider"></a>With RequestDispatcherProvider</h1>

<p><a href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java"
class="external-link" rel="nofollow">RequestDispatcherProvider</a> is a JAXRS MessageBodyWriter
which can redirect to JSP pages, named or default servlets. It can be used to serve all the
responses from a given resource class or restricted to serving a limited set of classes only
using a classResources map property. Note that this classResources property can also be used
to specify the name of the key which JSP pages or other downstream servlets will use to access
a response object.</p>

<p>At the moment, this provider is statically configured to support text/html content
types, but it can be easily configured to support other content types if needed.  </p>

<p>Please see this <a href="http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/beans.xml"
class="external-link" rel="nofollow">beans.xml</a>. As you can see, it is possible
to redirect to either to static resources such as book.html (possibly for providing some default
response) or dynamic resources such as JSP pages. It is also possible to redirect to named
servlets. </p>

<p>Note that the only required property is a 'requestPath' one and its value should
start with a forward slash but it does not have to point to an existing web application resource
such as book.html; it can also have values like "/other/services/", possibly in a combination
with a 'dispatcherName' property.</p>

<p>Finally, a servletContextPath property can be used to have some other ServletContext
(as opposed to the current one) be used for RequestDispatcher look-ups. If set then the current
ServletContext.getContext(servletContextPath) will be used to get the needed ServletContext.</p>



<h1><a name="JAX-RSRedirection-WithCXFServlet"></a>With CXFServlet</h1>

<p>Please see the "Redirection" section on the <a href="/confluence/display/CXF20DOC/Servlet+Transport"
title="Servlet Transport">Servlet Transport</a> page.</p>

<p>Note that both CXFServlet and JAXRS RequestDispatcherProvider can work together effectively
on executing the redirection requests as described at that page.</p>

<p>If you have CXFServlet listening on "/" (thus effectively catching all the requests)
and also would like to use RequestDispatcher, then make sure that a 'dispatcherName' property
is also set, for example :</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">"dispatcherName"</span>
value=<span class="code-quote">"jsp"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"resourcePath"</span>
value=<span class="code-quote">"/WEB-INF/jsp/test.jsp"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"scope"</span>
value=<span class="code-quote">"request"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span> 
</pre>
</div></div>

<p>If resources which are redirected to can be made public (i.e, moved out of /WEB-INF)
then alternative option (instead of adding a 'dispatcherName' property to RequestDispatcherProvider
and still have CXFServlet listening on '/') is to configure both RequestDispatcherProvider
and CXFServlet to redirect to resources such as "/jsp/test.jsp".</p>

<h1><a name="JAX-RSRedirection-CustomRedirection"></a>Custom Redirection</h1>

<p>One can borrow some of the code from RequestDispatcherProvider and do the custom
redirection from CXF in interceptors or custom invokers, if you will try to do it then you
will also need to set an AbstractHTTPDestination.REQUEST_REDIRECTED property with a 'true'
value on a current input message.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/JAX-RS+Redirection">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24190950&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/JAX-RS+Redirection?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message