|
From: Dave M. <da...@pa...> - 2013-01-18 16:10:01
|
Ah, ok. So, I stand corrected. RESTeasy *can* do this. It's the Spring
RequestDispatcher that was barfing on the unfamiliar method. For anyone
else wanting to commit this sin...
I created the following controller to see what would actually be handled by
Spring itself:
@Controller
@RequestMapping("/reset")
public class ResetController {
@RequestMapping
public void reset(final HttpServletRequest request, final
HttpServletResponse response) throws Exception {
final String method = request.getMethod();
final PrintWriter writer = response.getWriter();
writer.write(String.format("<html><body><p>%s</p></body></html>", method));
writer.flush();
}
}
Contrary to my expectation that failed with the Tomcat error message. So a
little rummaging produced the following Spring forum posting:
http://forum.springsource.org/showthread.php?53472-DispatcherServlet-ServletWrappingController-with-JackRabbit-SimpleWevdavServlet&p=178514#post178514
I pretty much cribbed that as follows:
public class PromiscuousDispatcherServlet extends DispatcherServlet {
private static final long serialVersionUID = 3006276017308264614L;
@Override
protected void service(final HttpServletRequest req, final
HttpServletResponse resp) throws ServletException, java.io.IOException {
try {
doService(req, resp);
} catch (final Exception e) {
throw new ServletException("Failure during servlet dispatch", e);
}
}
}
By substituting the PromiscuousDispatcherServlet for the real Spring ones I
now find my @RESET annotation is honoured in the RESTeasy controller.
Now to get a cuppa tea and consider the morality of actually using it... :-)
Thanks.
On Fri, Jan 18, 2013 at 3:01 PM, Dave Minter <da...@pa...> wrote:
> (Hands off to RESTeasy, not JaxRS I should have said)
>
>
> On Fri, Jan 18, 2013 at 3:00 PM, Dave Minter <da...@pa...> wrote:
>
>> But this is hooked up via Spring so I'm actually using a Spring
>> DispatcherServlet which hands off to JaxRS to handle the actual request via
>> the default configuration in springmvc-resteasy.xml
>>
>> I'm fairly sure Spring DispatcherServlet can field non-default HTTP verbs
>> but I'll double-check.
>>
>>
>> On Fri, Jan 18, 2013 at 2:55 PM, Bill Burke <bb...@re...> wrote:
>>
>>> Resteasy does override the service method. see HttpServletDispatcher
>>>
>>> On 1/18/2013 9:47 AM, Dave Minter wrote:
>>> > No, that's just the default behaviour if you don't override the service
>>> > method in a servlet. If you hook up the following servlet in web.xml
>>> you
>>> > get the outputs that you'd hope for:
>>> >
>>> > public class ResetServlet extends HttpServlet {
>>> > private static final long serialVersionUID = 1L;
>>> >
>>> > public ResetServlet() {
>>> > super();
>>> > }
>>> >
>>> > @Override
>>> > protected void service(final HttpServletRequest request, final
>>> > HttpServletResponse response) throws ServletException, IOException {
>>> > if ("RESET".equals(request.getMethod())) {
>>> > response.getWriter().write("<html><body><p>Received a RESET
>>> > request!</p></body></html>");
>>> > } else {
>>> > response.getWriter().write(String.format("<html><body><p>Received some
>>> > other (%s) request.</p></body></html>", request.getMethod()));
>>> > }
>>> > }
>>> > }
>>> >
>>> >
>>> >
>>> >
>>> > On Fri, Jan 18, 2013 at 1:54 PM, Bill Burke <bb...@re...
>>> > <mailto:bb...@re...>> wrote:
>>> >
>>> > I agree with Robert's earlier post, but are you sure this isn't
>>> Tomcat
>>> > barfing on you? There's really nothing I can do about that.
>>> >
>>> > On 1/18/2013 5:23 AM, Dave Minter wrote:
>>> > >
>>> > > res...@li...
>>> > <mailto:res...@li...>
>>> > > <mailto:res...@li...
>>> > <mailto:res...@li...>>
>>> > >
>>> > > I'd like to use custom HTTP verbs with resteasy running under
>>> > Tomcat. Is
>>> > > this possible? If it is possible is it sensible?
>>> > >
>>> > > I'm using resteasy 2.3.4.Final with Spring 3.1.2-RELEASE and
>>> I've
>>> > > created a custom HttpMethod annotation for the new verb:
>>> > >
>>> > > @Target({ ElementType.METHOD })
>>> > > @Retention(RetentionPolicy.RUNTIME)
>>> > > @HttpMethod("RESET")
>>> > > public @interface RESET {
>>> > > }
>>> > >
>>> > > Spring is configured in the servlet application context with the
>>> > default
>>> > > resteasy config thus:
>>> > >
>>> > > <tx:annotation-driven />
>>> > > <import resource="classpath:springmvc-resteasy.xml" />
>>> > >
>>> > > The new method in the controller is implemented thus:
>>> > >
>>> > > @RESET
>>> > > @Path("/{uuid}")
>>> > > public void reset(@PathParam("uuid") final String uuid) {
>>> > > // Reset the model state...
>>> > > }
>>> > >
>>> > > My other controller methods work fine for the normal
>>> > GET,PUT,POST,DELETE
>>> > > verbs but for the custom verb I get the following error message
>>> > from Tomcat:
>>> > >
>>> > > HTTP Status 501 - Method RESET is not defined in RFC 2068 and
>>> is not
>>> > > supported by the Servlet API
>>> > >
>>> > > That message seems to be the same one that you get with a
>>> default
>>> > > servlet implementation so I presume I need to configure the
>>> > > ResteasyHandlerMapping somehow...?
>>> > >
>>> > >
>>> > >
>>> > >
>>> >
>>> ------------------------------------------------------------------------------
>>> > > Master HTML5, CSS3, ASP.NET <http://ASP.NET>, MVC, AJAX,
>>> > Knockout.js, Web API and
>>> > > much more. Get web development skills now with LearnDevNow -
>>> > > 350+ hours of step-by-step video tutorials by Microsoft MVPs and
>>> > experts.
>>> > > SALE $99.99 this month only -- learn more at:
>>> > > http://p.sf.net/sfu/learnmore_122812
>>> > >
>>> > >
>>> > >
>>> > > _______________________________________________
>>> > > Resteasy-developers mailing list
>>> > > Res...@li...
>>> > <mailto:Res...@li...>
>>> > >
>>> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
>>> > >
>>> >
>>> > --
>>> > Bill Burke
>>> > JBoss, a division of Red Hat
>>> > http://bill.burkecentral.com
>>> >
>>> >
>>> ------------------------------------------------------------------------------
>>> > Master HTML5, CSS3, ASP.NET <http://ASP.NET>, MVC, AJAX,
>>> > Knockout.js, Web API and
>>> > much more. Get web development skills now with LearnDevNow -
>>> > 350+ hours of step-by-step video tutorials by Microsoft MVPs and
>>> > experts.
>>> > SALE $99.99 this month only -- learn more at:
>>> > http://p.sf.net/sfu/learnmore_122812
>>> > _______________________________________________
>>> > Resteasy-developers mailing list
>>> > Res...@li...
>>> > <mailto:Res...@li...>
>>> > https://lists.sourceforge.net/lists/listinfo/resteasy-developers
>>> >
>>> >
>>> >
>>> >
>>> >
>>> ------------------------------------------------------------------------------
>>> > Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
>>> > much more. Get web development skills now with LearnDevNow -
>>> > 350+ hours of step-by-step video tutorials by Microsoft MVPs and
>>> experts.
>>> > SALE $99.99 this month only -- learn more at:
>>> > http://p.sf.net/sfu/learnmore_122812
>>> >
>>> >
>>> >
>>> > _______________________________________________
>>> > Resteasy-developers mailing list
>>> > Res...@li...
>>> > https://lists.sourceforge.net/lists/listinfo/resteasy-developers
>>> >
>>>
>>> --
>>> Bill Burke
>>> JBoss, a division of Red Hat
>>> http://bill.burkecentral.com
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
>>> much more. Get web development skills now with LearnDevNow -
>>> 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
>>> SALE $99.99 this month only -- learn more at:
>>> http://p.sf.net/sfu/learnmore_122812
>>> _______________________________________________
>>> Resteasy-developers mailing list
>>> Res...@li...
>>> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
>>>
>>
>>
>
|