You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by daveor <do...@westglobal.com> on 2008/03/05 12:41:52 UTC

CXF REST problems

Hi there,

I've been looking through the user group and I haven't been able to find an
answer to my problem so I thought I'd send a post and see if anyone can help
me. 

I downloaded the 20080228 and the 20080303 snapshots. What I describe below
are problems that I have found in both. 

First problem that I've noticed is that I can't find the @UriTemplate
annotation. It's not in the jsr311-api-0.5.jar file where all of the other
JSR annotations can be found. So, I had a look at the JSR spec, and the
@Path annotation seemed appropriate so I used that instead. Is that correct?

Second problem is that I implemented a service using the @Path annotation
and I'm getting a null pointer exception as described below. I am using
spring configuration, so here's my spring config file:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:jaxrs="http://cxf.apache.org/jaxrs"
	xmlns:cxf="http://cxf.apache.org/core"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
	http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
	http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
	http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
	
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"
/>
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

  	<jaxrs:server id="registryEndpoint" address="/">
    	<jaxrs:serviceBeans>
    		<ref bean="emitterResource"/>
    	</jaxrs:serviceBeans>
  	</jaxrs:server>
</beans>

Here's the resource file:

@Path("/emitterResource")
public class EmitterResource {

    @Path("/getEmitters")
    public Collection<Emitter> getEmitters() {
        return emitterDAO.getAllEmitters();
    }
    
    @Path("/emitters/{emitterId}")
    public Emitter getEmitter(@QueryParam("emitterId") int id) {
    //public Emitter getEmitter(@WebParam(name = "emitterId") int id) {
       LOG.debug("looking for emitter id " + id);
       return emitterDAO.get(id);
    }
    
    @Path("/emitters")
    public void addEmitter(@QueryParam("emitter")Emitter emitter) {
        LOG.warn("Adding an emitter");
        LOG.warn("ID is " + emitter.getId());
        LOG.warn("Name is " + emitter.getName());
        emitterDAO.save(emitter);
    }

When I try to add @HttpMethod annotations above the @Path annotations I get
the error "The annotation @HttpMethod is disallowed for this location" 

The Emitter class is just a POJO with an Id and a Name.

Here's a snippet of my client code (I'm using apache commons HttpClient) :

           Emitter e = new Emitter();
           e.setId(12345);
           e.setName("Test Name");
           PostMethod post = new
PostMethod("http://localhost:8080/emitterResource/emitters");
          
            StringWriter stringWriter = new StringWriter();
            jaxbMarshaller.marshal(registryObject, stringWriter);
            
            StringRequestEntity requestEntity = new
StringRequestEntity(stringWriter.toString(), "text/xml", "ISO-8859-1");
            post.setRequestEntity(requestEntity);

            HttpClient httpClient = new HttpClient();
            int result = httpClient.executeMethod(post);
            System.out.println("Response code " + result);
            System.out.println(post.getResponseBodyAsString());
            post.releaseConnection();

I'm deploying the server in tomcat 5.5 successfully (no errors), but when I
run the client, I'm getting the following exception:

05-Mar-2008 11:08:39 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
FINE: Invoking handleMessage on interceptor
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor@2da8c22b
05-Mar-2008 11:08:39 org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
handleMessage
FINE: Request path is: /emitterResource/emitters/
05-Mar-2008 11:08:39 org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
handleMessage
FINE: Request HTTP method is: POST
05-Mar-2008 11:08:39 org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
handleMessage
FINE: Request contentType is: text/xml; charset=ISO-8859-1
05-Mar-2008 11:08:39 org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
handleMessage
FINE: Accept contentType is: */*
05-Mar-2008 11:08:39 org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
handleMessage
INFO: Found operation: getEmitter
05-Mar-2008 11:08:39 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
INFO: Interceptor has thrown exception, unwinding now
java.lang.NumberFormatException: null
	at java.lang.Integer.parseInt(Integer.java:415)
	at java.lang.Integer.valueOf(Integer.java:553)
	at org.apache.cxf.common.util.PrimitiveUtils.read(PrimitiveUtils.java:60)
	at org.apache.cxf.jaxrs.JAXRSUtils.readQueryString(JAXRSUtils.java:295)
	at org.apache.cxf.jaxrs.JAXRSUtils.processParameter(JAXRSUtils.java:277)
	at org.apache.cxf.jaxrs.JAXRSUtils.processParameters(JAXRSUtils.java:241)
	at
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:112)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
	at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)
	at
org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92)
	at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
	at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:113)
	at
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:170)
	at
org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:148)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
	at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
	at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
	at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
	at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
	at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
	at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
	at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
	at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
	at java.lang.Thread.run(Thread.java:619)

Just for completeness, I've captured what's being sent on the wire, and here
it is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><emitter
xmlns="http://registry.mscape.westglobal.com"><id>12345</id><name>Test
Emitter</name></emitter>

Can anyone help me please, I'm completely stuck. 

thanks,
daveor


-- 
View this message in context: http://www.nabble.com/CXF-REST-problems-tp15848325p15848325.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF REST problems

Posted by daveor <do...@westglobal.com>.
Hey hey! 

Removing the @UriParam did the trick!

@POST
@Path("/emitters")
 public void addEmitter(Emitter emitter) {
 }

thanks for the help!
-- 
View this message in context: http://www.nabble.com/CXF-REST-problems-tp15848325p15850224.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF REST problems

Posted by Sergey Beryozkin <se...@iona.com>.
Hi,

In this case what happens is that no MessageBodyReader (provider capable of getting the input stream data and turning them into Emitter object) has been found, thus it's a null and it's an application level error. That said, I need to check what the spec says about it, perhaps an exception shouild be raised earlier...

What is an Emmiter class ? Is it annotated with JAXB annotatations such as @XmlRootElement ?
Does GET works for you, that is can you retrieve an individual Emitter from a browser ?

If Emitters are not JAXB-aware then you'd need to register a custom Emitter provider, which would know how to serialize/deserialize them. Alertantive you might want to use JAXP Source and deal with XML locally...

Actually, I've written it all and just realized that your annotations are not correct :

>    @POST
>    @Path("/emitters/")
>    public void addEmitter(@UriParam("emitter")Emitter emitter) {

One can annotate with @UriParam only those parameters which are supposed to be substituted as template variables found in your @Path, for ex :

 @PUT
 @Path("/emitters/{id}")
 public void addEmitter(@UriParam("id") String id, Emitter emitter) {
 }


So in your case doing just

@POST
@Path("/emitters")
 public void addEmitter(Emitter emitter) {
 }

should work fine, provided your Emitter is JAXB-aware :-)

Give it a try please,
Cheers, Sergey


----- Original Message ----- 
From: "daveor" <do...@westglobal.com>
To: <cx...@incubator.apache.org>
Sent: Wednesday, March 05, 2008 12:37 PM
Subject: Re: CXF REST problems


> 
> Hi, and thanks for your reply. I have tried your suggestion, I changed the
> @QueryParam to @UriParam and now I get a different error. Here's the updated
> method:
> 
>    @POST
>    @Path("/emitters")
>    public void addEmitter(@UriParam("emitter")Emitter emitter) {
>        LOG.warn("Adding an emitter");
>        LOG.warn("ID is " + emitter.getId()); <----- NullPointerException on
> this line
>        LOG.warn("Name is " + emitter.getName());
>        emitterDAO.save(emitter);
>    } 
> 
> 
> This is the NullPointerException exception:
> 
> FINE: Invoking handleMessage on interceptor
> org.apache.cxf.interceptor.ServiceInvokerInterceptor@22e38fca
> 05-Mar-2008 12:25:05 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
> FINE: Application has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault
> at
> org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:107)
> at
> org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:95)
> at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:62)
> at
> org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56)
> at
> org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
> at
> org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:92)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
> at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)
> at
> org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92)
> at
> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
> at
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:113)
> at
> org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:170)
> at
> org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:148)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
> at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
> at
> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
> at
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
> at
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
> at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
> at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
> at
> com.westglobal.mscape.registry.EmitterResource.addEmitter(EmitterResource.java:50)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:124)
> at
> org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:82)
> ... 27 more
> 
> All other code/content is as per my previous message.
> 
> Thanks again!
> 
> daveor
> -- 
> View this message in context: http://www.nabble.com/CXF-REST-problems-tp15848325p15849017.html
> Sent from the cxf-user mailing list archive at Nabble.com.

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

Re: CXF REST problems

Posted by daveor <do...@westglobal.com>.
Hi, and thanks for your reply. I have tried your suggestion, I changed the
@QueryParam to @UriParam and now I get a different error. Here's the updated
method:

    @POST
    @Path("/emitters")
    public void addEmitter(@UriParam("emitter")Emitter emitter) {
        LOG.warn("Adding an emitter");
        LOG.warn("ID is " + emitter.getId()); <----- NullPointerException on
this line
        LOG.warn("Name is " + emitter.getName());
        emitterDAO.save(emitter);
    } 


This is the NullPointerException exception:

FINE: Invoking handleMessage on interceptor
org.apache.cxf.interceptor.ServiceInvokerInterceptor@22e38fca
05-Mar-2008 12:25:05 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
FINE: Application has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault
	at
org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:107)
	at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:95)
	at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:62)
	at
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56)
	at
org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
	at
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:92)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
	at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)
	at
org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92)
	at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
	at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:113)
	at
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:170)
	at
org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:148)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
	at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
	at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
	at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
	at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
	at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
	at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
	at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
	at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
	at
com.westglobal.mscape.registry.EmitterResource.addEmitter(EmitterResource.java:50)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:124)
	at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:82)
	... 27 more

All other code/content is as per my previous message.

Thanks again!

daveor
-- 
View this message in context: http://www.nabble.com/CXF-REST-problems-tp15848325p15849017.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF REST problems

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

> First problem that I've noticed is that I can't find the @UriTemplate
> annotation. It's not in the jsr311-api-0.5.jar file where all of the other
> JSR annotations can be found. So, I had a look at the JSR spec, and the
> @Path annotation seemed appropriate so I used that instead. Is that correct?

Yes, 0.5 replaced @UriTemplate with @Path

> Second problem is that I implemented a service using the @Path annotation
> and I'm getting a null pointer exception as described below.

It's a NumberFormatException there, and it's caused by the fact there's no expected QueryParam in a request.
You need to use @UriParam instead (please note in 0.6 it will be replaced with @PathParam), see below...

> When I try to add @HttpMethod annotations above the @Path annotations I get
> the error "The annotation @HttpMethod is disallowed for this location" 

Yes, starrting from 0.5 one can use @HttpMethod to create designators, sucg as @GET/@POST@PUT/@DELETE,
so you may for example create @GetRequest if you think it's better than @GET or create designators for other http methods

Here's the class :

@Path("/emitterResource")
 public class EmitterResource {
 
    @GET
    @Path("/getEmitters")
    public Collection<Emitter> getEmitters() {
        return emitterDAO.getAllEmitters();
    }
    
    @GET
    @Path("/emitters/{emitterId}")
    public Emitter getEmitter(@UriParam("emitterId") int id) {
        LOG.debug("looking for emitter id " + id);
       return emitterDAO.get(id);
    }
}

You might want to chnage it like this to minimize a bit the numbner of annotations :

@Path("/emitters")
public class EmitterResource {
 
    @GET
    public Collection<Emitter> getEmitters() {
        return emitterDAO.getAllEmitters();
    }
    
    @GET
    @Path("{emitterId}")
    public Emitter getEmitter(@UriParam("emitterId") int id) {
        LOG.debug("looking for emitter id " + id);
       return emitterDAO.get(id);
    }
}


Hope it helps

Cheers, Sergey



> 
> Hi there,
> 
> I've been looking through the user group and I haven't been able to find an
> answer to my problem so I thought I'd send a post and see if anyone can help
> me. 
> 
> I downloaded the 20080228 and the 20080303 snapshots. What I describe below
> are problems that I have found in both. 
> 
> First problem that I've noticed is that I can't find the @UriTemplate
> annotation. It's not in the jsr311-api-0.5.jar file where all of the other
> JSR annotations can be found. So, I had a look at the JSR spec, and the
> @Path annotation seemed appropriate so I used that instead. Is that correct?
> 
> Second problem is that I implemented a service using the @Path annotation
> and I'm getting a null pointer exception as described below. I am using
> spring configuration, so here's my spring config file:
> 
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:jaxrs="http://cxf.apache.org/jaxrs"
> xmlns:cxf="http://cxf.apache.org/core"
> xsi:schemaLocation="
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
> http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
> http://cxf.apache.org/bindings/soap
> http://cxf.apache.org/schemas/configuration/soap.xsd
> http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
> 
> <import resource="classpath:META-INF/cxf/cxf.xml" />
> <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"
> />
> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
> 
>  <jaxrs:server id="registryEndpoint" address="/">
>    <jaxrs:serviceBeans>
>    <ref bean="emitterResource"/>
>    </jaxrs:serviceBeans>
>  </jaxrs:server>
> </beans>
> 
> Here's the resource file:
> 
> @Path("/emitterResource")
> public class EmitterResource {
> 
>    @Path("/getEmitters")
>    public Collection<Emitter> getEmitters() {
>        return emitterDAO.getAllEmitters();
>    }
>    
>    @Path("/emitters/{emitterId}")
>    public Emitter getEmitter(@QueryParam("emitterId") int id) {
>    //public Emitter getEmitter(@WebParam(name = "emitterId") int id) {
>       LOG.debug("looking for emitter id " + id);
>       return emitterDAO.get(id);
>    }
>    
>    @Path("/emitters")
>    public void addEmitter(@QueryParam("emitter")Emitter emitter) {
>        LOG.warn("Adding an emitter");
>        LOG.warn("ID is " + emitter.getId());
>        LOG.warn("Name is " + emitter.getName());
>        emitterDAO.save(emitter);
>    }
> 
> When I try to add @HttpMethod annotations above the @Path annotations I get
> the error "The annotation @HttpMethod is disallowed for this location" 
> 
> The Emitter class is just a POJO with an Id and a Name.
> 
> Here's a snippet of my client code (I'm using apache commons HttpClient) :
> 
>           Emitter e = new Emitter();
>           e.setId(12345);
>           e.setName("Test Name");
>           PostMethod post = new
> PostMethod("http://localhost:8080/emitterResource/emitters");
>          
>            StringWriter stringWriter = new StringWriter();
>            jaxbMarshaller.marshal(registryObject, stringWriter);
>            
>            StringRequestEntity requestEntity = new
> StringRequestEntity(stringWriter.toString(), "text/xml", "ISO-8859-1");
>            post.setRequestEntity(requestEntity);
> 
>            HttpClient httpClient = new HttpClient();
>            int result = httpClient.executeMethod(post);
>            System.out.println("Response code " + result);
>            System.out.println(post.getResponseBodyAsString());
>            post.releaseConnection();
> 
> I'm deploying the server in tomcat 5.5 successfully (no errors), but when I
> run the client, I'm getting the following exception:
> 
> 05-Mar-2008 11:08:39 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
> FINE: Invoking handleMessage on interceptor
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor@2da8c22b
> 05-Mar-2008 11:08:39 org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
> handleMessage
> FINE: Request path is: /emitterResource/emitters/
> 05-Mar-2008 11:08:39 org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
> handleMessage
> FINE: Request HTTP method is: POST
> 05-Mar-2008 11:08:39 org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
> handleMessage
> FINE: Request contentType is: text/xml; charset=ISO-8859-1
> 05-Mar-2008 11:08:39 org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
> handleMessage
> FINE: Accept contentType is: */*
> 05-Mar-2008 11:08:39 org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
> handleMessage
> INFO: Found operation: getEmitter
> 05-Mar-2008 11:08:39 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
> INFO: Interceptor has thrown exception, unwinding now
> java.lang.NumberFormatException: null
> at java.lang.Integer.parseInt(Integer.java:415)
> at java.lang.Integer.valueOf(Integer.java:553)
> at org.apache.cxf.common.util.PrimitiveUtils.read(PrimitiveUtils.java:60)
> at org.apache.cxf.jaxrs.JAXRSUtils.readQueryString(JAXRSUtils.java:295)
> at org.apache.cxf.jaxrs.JAXRSUtils.processParameter(JAXRSUtils.java:277)
> at org.apache.cxf.jaxrs.JAXRSUtils.processParameters(JAXRSUtils.java:241)
> at
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:112)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
> at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)
> at
> org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92)
> at
> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
> at
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:113)
> at
> org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:170)
> at
> org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:148)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
> at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
> at
> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
> at
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
> at
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
> at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
> at java.lang.Thread.run(Thread.java:619)
> 
> Just for completeness, I've captured what's being sent on the wire, and here
> it is:
> 
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><emitter
> xmlns="http://registry.mscape.westglobal.com"><id>12345</id><name>Test
> Emitter</name></emitter>
> 
> Can anyone help me please, I'm completely stuck. 
> 
> thanks,
> daveor
> 
> 
> -- 
> View this message in context: http://www.nabble.com/CXF-REST-problems-tp15848325p15848325.html
> Sent from the cxf-user mailing list archive at Nabble.com.

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