cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Liu, Jervis" <j...@iona.com>
Subject RE: restful_jaxrs sample
Date Fri, 30 Nov 2007 06:26:00 GMT
Fixed. To return a String using text/plain content type, you need a @ProduceMime annotation
as below:

    @HttpMethod("GET")
    @UriTemplate("/booknames/{bookId}/")
    @ProduceMime("text/plain")
    public String getBookName(@UriParam("bookId") int id) throws BookNotFoundFault {
        ...
    }

> -----Original Message-----
> From: Liu, Jervis [mailto:jliu@iona.com]
> Sent: 2007年11月29日 11:48
> To: cxf-user@incubator.apache.org
> Subject: RE: restful_jaxrs sample
> 
> 
> 
> > -----Original Message-----
> > From: Eric Le Goff [mailto:elegoff@gmail.com]
> > Sent: 2007年11月28日 20:31
> > To: cxf-user@incubator.apache.org
> > Subject: Re: restful_jaxrs sample
> >
> > On Nov 28, 2007 10:53 AM, Liu, Jervis <jliu@iona.com> wrote:
> > >
> > > 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;
> > >     }
> >
> > DONE
> >
> > >
> > > 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.
> > >
> >
> > Cool I will check it when it is done
> >
> > > String type can be handled by JAX-RS runtime by default.
> >
> > Now my demo class looks like
> >
> > =====
> > @javax.ws.rs.UriTemplate("/helloworld/")
> > public class HelloWorldRessource {
> >
> >    @javax.ws.rs.HttpMethod("GET")
> >    @javax.ws.rs.UriTemplate("{section}/{id}")
> >    public String findBySectionAndId(@javax.ws.rs.UriParam("section")
> >    String section, @javax.ws.rs.UriParam("id")
> >    String id) {
> >        return "Hello World - section is " + section + ", id is " + id + "\n";
> >    }
> >
> >
> >    //FIXME: wont work if remove this method, has to set hasSubResource
> > to true
> >    @UriTemplate("/foo")
> >    public String foobar() {
> >        return null;
> >    }
> > }
> > ======
> >
> > FWIW I had to change type of the "Id" parameter from an int to a
> > String not to throw a IllegalArgumentException
> >
> 
> This is a bug. I've filed JIRA https://issues.apache.org/jira/browse/CXF-1240
> for this.
> 
> > Still my response is a NPE
> > but the stack trace on console is a bit different :
> >
> > <====
> > java] java.lang.NullPointerException
> >     [java]     at
> >
> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRS
> > OutInterceptor.java:94)
> >     [java]     at
> >
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
> > hain.java:207)
> >     [java]     at
> >
> org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outgo
> > ingChainInterceptor.java:74)
> >     [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)
> > [...]
> >
> >
> > ====>
> >
> > By looking at the code, it shows that in
> > org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage()
> > method, the provider variable is set to null
> >
> > <====
> > [...]
> >  EntityProvider provider =
> > ((ProviderFactoryImpl)ProviderFactory.getInstance())
> >                .createEntityProvider(targetType, methodMimeTypes,
> > false);   ///          <---- getting a null provider here !!!
> >
> >            try {
> >                if (!"*/*".equals(methodMimeTypes[0])) {
> >                    message.put(Message.CONTENT_TYPE,
> > methodMimeTypes[0]);
> >                }
> >
> >                provider.writeTo(responseObj, null, null, out);
> > [...]
> > ====>
> >
> >
> > the
> >
> org.apache.cxf.jaxrs.provider.ProviderFactoryImpl.createEntityProvider(Clas
> > s<T>
> > type, String[] requestedMineTypes, boolean isConsumeMime)  returns
> > null because the test
> >
> > <===
> > [...]
> > if (matchMineTypes(supportedMimeTypes, requestedMineTypes) &&
> > ep.supports(type)) {
> >                return ep;
> >            }
> > [...]
> > ===>
> >
> > always fails.
> >
> > Actually the "ep.supports(type) " is trying to check if my method
> > return type (java.lang.String) has been annotated with @XmlRootElement
> > which is of course never true...
> >
> > What could I be missing here ?
> >
> 
> Bug. JIRA https://issues.apache.org/jira/browse/CXF-1240.
> 
> > --
> > Eric Le Goff
> 
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

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