<div dir="ltr">Thanks Stuart,<div><br></div><div>I think that&#39;s exactly what I need, since annotation as you say might not be necessary.</div><div><br></div><div>Can you specify which version I would need to include in the pom please? Since the one I am using (1.0.14.Final) doesn&#39;t seem to include it and maven doesn&#39;t seem to know about 1.2.0.Beta1-SNAPSHOT.</div><div><br></div><div>Cheers</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 25, 2014 at 2:00 AM, Stuart Douglas <span dir="ltr">&lt;<a href="mailto:sdouglas@redhat.com" target="_blank">sdouglas@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Undertow is intended to be a lightweight web server rather than a container, so it does not really have any annotation processing facilities built in, however it should be fairly easy to implement something similar on top of Undertow.<br>
<br>
Undertow has a handler called io.undertow.server.<u></u>RoutingHandler, that routes requests based on method and path. If you use this handler it should be possible to build a handler chain based on annotations on the handler classes.<br>
<br>
Note that you don&#39;t want to be using reflection in the handleRequest method, as reflection is relatively slow. Instead the best approach is to read the annotations and boot time and build up the routing map while the server is starting.<br>
<br>
Stuart<br>
<br>
Luke Ambrogio wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
So I&#39;ve decided to start using Undertow, both as an experiment and due<br>
to the great results it achieved in benchmark tests. And while I think<br>
it&#39;s fantastic there&#39;s a feature which is either missing or I can&#39;t find.<br>
<br>
I want to develop a RESTful web service so it&#39;s important for me to<br>
identify which HTTP method is being called. Now I can get this from<br>
RequestMethod in the HttpServerExchange parameter but if had to that for<br>
every handler that would become tedious.<br>
<br>
My solution, which works but feels wrong, is this:<br>
<br>
Created an annotation interface called HTTPMethod:<br>
<br>
|@Retention(RetentionPolicy.<u></u>RUNTIME)<br>
@Target(ElementType.METHOD)<br>
public  @interface  HTTPMethod  {<br>
<br>
public  enum  Method  {<br>
<br>
     OTHER,  GET,  PUT,  POST,  DELETE<br>
}<br>
<br>
Method  method()  default  Method.OTHER;|<br>
<br>
an &quot;abstract&quot; class (which is not abstract):<br>
<br>
|public  abstract  class  RESTfulHandler  implements  HttpHandler  {<br>
<br>
@Override<br>
public  void  handleRequest(<u></u>HttpServerExchange  hse)  throws  Exception  {<br>
<br>
     for  (Method  method:  this.getClass().<u></u>getDeclaredMethods())  {<br>
<br>
         // if method is annotated with @Test<br>
         if  (method.isAnnotationPresent(<u></u>HTTPMethod.class))  {<br>
<br>
             Annotation  annotation=  method.getAnnotation(<u></u>HTTPMethod.class);<br></span>
             HTTPMethod  test=  (HTTPMethod)  annotation;<div><div class="h5"><br>
<br>
             switch  (test.method())  {<br>
                 case  PUT:<br>
                     if  (hse.getRequestMethod().<u></u>toString().equals(&quot;PUT&quot;))  {<br>
                         method.invoke(this);<br>
                     }<br>
                     break;<br>
<br>
                 case  POST:<br>
                     if  (hse.getRequestMethod().<u></u>toString().equals(&quot;POST&quot;))  {<br>
                         method.invoke(this);<br>
                     }<br>
                     break;<br>
<br>
                 case  GET:<br>
                     if  (hse.getRequestMethod().<u></u>toString().equals(&quot;GET&quot;))  {<br>
                         method.invoke(this);<br>
                     }<br>
                     break;<br>
<br>
                 case  DELETE:<br>
                     if  (hse.getRequestMethod().<u></u>toString().equals(&quot;DELETE&quot;))  {<br>
                         method.invoke(this);<br>
                     }<br>
                     break;<br>
                 case  OTHER:<br>
                     if  (hse.getRequestMethod().<u></u>toString().equals(&quot;OTHER&quot;))  {<br>
                         method.invoke(this);<br>
                     }<br>
                     break;<br>
             }<br>
             if  (test.method()  ==  HTTPMethod.Method.PUT)  {<br>
                 method.invoke(this);<br>
             }<br>
         }<br>
     }<br>
}|<br>
<br>
}<br>
<br>
and an implementation of both the above:<br>
<br>
|public  class  ItemHandler  extends  RESTfulHandler{<br>
<br>
@HTTPMethod(method=GET)<br>
public  void  getAllItems()<br>
{<br>
     System.out.println(&quot;GET&quot;);<br>
}<br>
<br>
@HTTPMethod(method=POST)<br>
public  void  addItem()<br>
{<br>
     System.out.println(&quot;POST&quot;);<br>
}<br>
<br>
@HTTPMethod<br>
public  void  doNothing()<br>
{<br>
     System.out.println(&quot;OTHERS&quot;);<br>
}|<br>
<br>
}<br>
<br>
Now as I said, it works, but I&#39;m sure that the abstract class and it&#39;s<br>
implementation have something missing so that they glue correctly. So my<br>
question is two fold:<br>
<br>
1) Is there a better / proper way to filter HTTP requests in Undertow?<br>
2) What is the correct way of using annotations correctly correctly in<br>
the above case?<br>
<br>
Thanks<br>
<br>
<br></div></div>
______________________________<u></u>_________________<br>
undertow-dev mailing list<br>
<a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" target="_blank">https://lists.jboss.org/<u></u>mailman/listinfo/undertow-dev</a><br>
</blockquote>
<br>
</blockquote></div><br></div>