> -----Original Message-----
> From: Eric Le Goff [mailto:[EMAIL PROTECTED]
> Sent: 2007年11月28日 17:26
> To: cxf-user@incubator.apache.org
> Subject: restful_jaxrs sample
> 
> I was trying to understand to jaxrs frontend provided by CXF and the
> restful_jaxrs demo helped a lot.
> 
> Then I tried to write my own demo using the following ressource class :
> 
> ====
> @javax.ws.rs.UriTemplate("/helloworld/{section}")
> public class HelloWorldRessource {
> 
>     @javax.ws.rs.HttpMethod("GET")
>     @javax.ws.rs.UriTemplate("/{id}")
>     public String findBySectionAndId(@javax.ws.rs.UriParam("section")
>     String section, @javax.ws.rs.UriParam("id")
>     int id) {
>         return "Hello World - section is " + section + ", id is " + id + "\n";
>     }
> 
> }
> =======
> 
> 
> If I hit the following url :  http://localhost:9000/helloworld/main/23
> I get
> <ns1:XMLFault>
> <ns1:faultstring>java.lang.NullPointerException</ns1:faultstring>
> </ns1:XMLFault>
> 
> as a response.
> 
> Here is the stack from the console :
> 
> [java] Nov 28, 2007 10:01:47 AM
> org.apache.cxf.phase.PhaseInterceptorChain doIntercept
>      [java] INFO: Interceptor has thrown exception, unwinding now
>      [java] java.lang.NullPointerException
>      [java]   at
> org.apache.cxf.jaxrs.interceptor.JAXRSDispatchInterceptor.handleMessage(J
> AXRSDispatchInterceptor.java:101)
>      [java]   at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
> hain.java:207)
>      [java]   at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiation
> Observer.java:74)
>      [java]   at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(Jet
> tyHTTPDestination.java:284)
>      [java]   at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHT
> TPDestination.java:240)
>      [java]   at
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHand
> ler.java:54)
>      [java]   at
> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:722)
>      [java]   at
> org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandler
> Collection.java:206)
>      [java]   at
> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
>      [java]   at org.mortbay.jetty.Server.handle(Server.java:324)
> [...]
> 
> 
> After a look at the source code, the class
> org.apache.cxf.jaxrs.interceptor.JAXRSDispatchInterceptor doesn't
> throw a Fault in its handleMessage method when no
> OperationResourceInfo  could be found
> (the line is actually commented )
> 
> [...]
> OperationResourceInfo ori = findTargetResource(resources, path,
> httpMethod, values);
> 
>         if (ori == null) {
>             //throw new Fault(new
> org.apache.cxf.common.i18n.Message("NO_OP", BUNDLE, method, path));
>         }
> [...]
> 
> So my questions are :
> 
> - Why is the handleMessage() method not  controlling whether the
> findTargetResource() returns null and give the newbie user like me an
> explicit explanation of the problem  ? ;)

There is still a lot of on-going work on the JAX-RS frontend. I started the 
exception part, but have not got this finished yet. See JIRA: 
http://issues.apache.org/jira/browse/CXF-1012


> - Why in my specific demo  the findTargetResource had returned null ?
> (I guess I will have to investigate with a step by step debug) ?
> 

I believe this is because you don’t have following lines in your demo:

    //FIXME: wont work if remove this method, has to set hasSubResource to true
    @UriTemplate("/anyURLWilldo")
    public String anyMethodNameWillDo() {
        return null;
    }

Actually this is a bug, just have not found time to fix it. Basically at the 
moment you need to have a resource method only marked with @UriTemplate (no     
@HttpMethod("") annotation). This tells jax-rs runtime this resource class has 
subResources. I hope I can have these hacks fixed next week.

> 
> In the restful_jaxrs examples (CustomerService class), we have the use
> of a JAXBElementProvider and of a JSONProvider.
> I wonder if my above problem is not related to a missing
> EntityProvider implementation since my method is returning a String ?
> 
String type can be handled by JAX-RS runtime by default. 

> Thanks for your help
> 
> 
> 
> 
> 
> --
> Eric Le Goff

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Reply via email to