Hi
Looks lile what is causing the issue is that in hello() method a sub-resource,
at the introspection time, is an interface.
I'm not sure yet if it's allowed by JAX-RS, probably yes...
Try to move
@GET
@Path("/age")
annotations from the HelloeImpl.getAge() to the corresponding interface method
for a start. It may not fix the problem initially as
the runtime currently expects that a method to be invoked actually belongs to
the implementation class (except for AOP cases where
it actually will work fine)... Possibly a minor fix would need to be applied to
handle this scenario too.
As a temporarily workaround please return HelloeImpl in a hello() signature and
it will work...
Cheers, Sergey
----- Original Message -----
From: "Olivier" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, May 19, 2008 6:44 AM
Subject: JAX-RS (JSR 311) Sub Resource NullPointerException
All,
I have implemented a set of basic classes in order to test the use of JAX-RS
sub resources and found a NullPointerException (see
end of message for stack trace).
I am getting the CXF 2.1 version from the maven repository.
In my example, I have 2 methods:
hello
hello2
hello2 is a resource method marked with a @GET and a @PATH
hello is a sub resource method without a @GET but with a @PATH
Both methods return an Helloe object. A call to hello2 via a browser
(http://localhost:9095/mzt-services/services/HelloRest/helloservice/hello2/toto)
works fine and returns something like:
<helloe>
<age>10</age>
<name>toto</name>
</helloe>
The call to hello via a browser
(http://localhost:9095/mzt-services/services/HelloRest/helloservice/hello/toto/age)
returns the
following: (exception is pasted at the end)
<ns1:XMLFault>
<ns1:faultstring>java.lang.NullPointerException</ns1:faultstring>
</ns1:XMLFault>
The code for the Root Resource (the REST service is):
@Path("helloservice")
public class HelloServiceImpl implements HelloService
{
@Path("hello/{name}")
public Helloe hello(@PathParam("name")
String name)
{
Helloe helloe = new HelloeImpl();
// Hardcode values
helloe.setName(name);
helloe.setAge(10);
return helloe;
}
@GET
@Path("hello2/{name}")
public Helloe hello2(@PathParam("name")
String name)
{
Helloe helloe = new HelloeImpl();
// Hardcode values
helloe.setName(name);
helloe.setAge(10);
return helloe;
//return "<name>" + name + "</name>";
}
}
The code for the HelloeImpl class is:
@XmlRootElement(name = "helloe")
public class HelloeImpl implements Helloe
{
private String name;
private int age;
public HelloeImpl() {
// TODO Auto-generated constructor stub
}
@GET
@Path("/name")
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
@GET
@Path("/age")
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
}
Exception:
=======
May 18, 2008 10:23:23 PM org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor han
dleMessage
INFO: Found operation: hello
May 18, 2008 10:23:23 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
INFO: Interceptor has thrown exception, unwinding now
java.lang.NullPointerException
at org.apache.cxf.jaxrs.JAXRSUtils.findTargetMethod(JAXRSUtils.java:237)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:139)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:53)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInv
okerInterceptor.java:56)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecu
tor.java:37)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(Se
rviceInvokerInterceptor.java:92)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercept
orChain.java:221)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainIniti
ationObserver.java:78)
at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDes
tination.java:92)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(
ServletController.java:214)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletCont
roller.java:113)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCX
FServlet.java:170)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXF
Servlet.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:442
)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:3
57)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:2
26)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:6
15)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHand
lerCollection.java:150)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.
java:123)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:1
41)
at org.mortbay.jetty.Server.handle(Server.java:272)
at org.mortbay.jetty.HttpConnection.handlerRequest(HttpConnection.java:3
96)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpCo
nnection.java:652)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:488)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:198)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:311)
at org.mortbay.jetty.nio.HttpChannelEndPoint.run(HttpChannelEndPoint.jav
a:270)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool
.java:475
----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland