users@jersey.java.net

[Jersey] Re: Forward to Servlet

From: cmdotmani <cmdotmani_at_gmail.com>
Date: Wed, 15 Dec 2010 16:13:35 -0800 (PST)

Hi Paul,

Sorry I am may not be able to share my company code due to NDA :)
I tried the below and it worked perfectly.

<servlet>
   <servlet-name>MyWebApplication</servlet-name>
   <servlet-class>com.myproj.servlet.UiResourceServlet</servlet-class>
   <init-param>
     <param-name>com.sun.jersey.config.feature.Redirect</param-name>
     <param-value>true</param-value>
   </init-param>
   <init-param>
    
<param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
     <param-value>/views/</param-value>
   </init-param>
   <init-param>
    
<param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
     <param-value>/(images|css|jsp)/.*</param-value>
   </init-param>
 </servlet>

 <servlet-mapping>
   <servlet-name>MyWebApplication</servlet-name>
   <url-pattern>/myproj/*</url-pattern>
 </servlet-mapping>


@Component
@Path ("/myproj")
public class AdminUiResource extends AbstractResource {

  private static final Logger LOG =
LoggerFactory.getLogger(AdminUiResource.class);

  @GET
  @Path("/signup")
  @Produces("text/html")
  public Viewable getSignUp() {
    return new Viewable("/public/signup", "Test");
  }

--------------

Now my question is while doing a POST like below, I want to throw exception
from at request pojo

 @POST
  @Path("/signup")
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  public Response postSignUp(MyRequestObject request) throws Exception {
....

"MyRequestObject" pojo does some validation and responses with error message
which would look some thing like this...

<error><code>0003</code><message>Incorrect request. [Email Address
invalid].</message></error>

I saw your example from "Devoxx2010_JAX_RS_Samples" in which you have some
thing like this..

@Provider
public class RuntimeExceptionMapper implements
ExceptionMapper<RuntimeException> {
    @Override
    public Response toResponse(RuntimeException exception) {
        return Response.status(500).
                entity(new Viewable("/exception", exception)).
                build();
    }
}
which will call exception page with some scriplet in JSP page
 <% Exception e = (Exception)request.getAttribute("it");
..... %>

do we have better way to catch the exception in same page. I can put the
scriplet in my /signup page, but using scriplet sounds old way, is there are
better approach ?

See its just not about form validation errors, might be some other bad
request error.

Thanks
Chandra
-- 
View this message in context: http://jersey.576304.n2.nabble.com/Forward-to-Servlet-tp5351731p5838644.html
Sent from the Jersey mailing list archive at Nabble.com.