You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by David Castro <ap...@entwash.org> on 2008/06/25 21:48:26 UTC

CXF REST - output in both XML & JSON

Is there a way to use the same service class and methods to generate
both XML and JSON output depending on say the client "Accept" format?
Or if not possible, what about mapping the same service methods to
different URLs with different output types.

Cheers,
David


RE: Missing @WebService annotation?

Posted by "Sica, David (David)" <ds...@avaya.com>.
It looks like I resolved this due to a Eclipse/MyEclipse configuration
error.

David

-----Original Message-----
From: Sica, David (David) [mailto:dsica@avaya.com] 
Sent: Friday, June 27, 2008 5:08 PM
To: users@cxf.apache.org
Subject: Missing @WebService annotation?

I'm trying to deploy my web service with CXF 2.1 on Tomcat 6.0.16 and am
getting the following error which makes no sense because I clearly have
both my Interface and implementation annotated with @WebService.  I'm
stumped, any ideas would be greatly appreciated.

Thanks,
David

SEVERE: Exception sending context initialized event to listener instance
of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'ProductCommandService': Invocation of init method
failed; nested exception is javax.xml.ws.WebServiceException: Service
endpoint interface does not have a @WebService annotation.
Caused by: javax.xml.ws.WebServiceException: Service endpoint interface
does not have a @WebService annotation.
	at
org.apache.cxf.jaxws.support.JaxWsImplementorInfo.initialize(JaxWsImplem
entorInfo.java:284)
	at
org.apache.cxf.jaxws.support.JaxWsImplementorInfo.<init>(JaxWsImplemento
rInfo.java:57)
	at
org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:271)
	at
org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:244)
	at
org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:194)
	at
org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:380)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1242
)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1208)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.createBean(AbstractAutowireCapableBeanFactory.java:427)
	at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObjec
t(AbstractBeanFactory.java:249)
	at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.g
etSingleton(DefaultSingletonBeanRegistry.java:155)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ab
stractBeanFactory.java:246)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ab
stractBeanFactory.java:160)
	at
org.springframework.beans.factory.support.DefaultListableBeanFactory.pre
InstantiateSingletons(DefaultListableBeanFactory.java:291)
	at
org.springframework.context.support.AbstractApplicationContext.refresh(A
bstractApplicationContext.java:352)
	at
org.springframework.web.context.ContextLoader.createWebApplicationContex
t(ContextLoader.java:246)
	at
org.springframework.web.context.ContextLoader.initWebApplicationContext(
ContextLoader.java:189)
	at
org.springframework.web.context.ContextLoaderListener.contextInitialized
(ContextLoaderListener.java:49)
	at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.j
ava:3843)
	at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4350
)
	at
org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:11
14)
	at
org.apache.catalina.startup.HostConfig.check(HostConfig.java:1212)
	at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:29
3)
	at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSu
pport.java:117)
	at
org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.j
ava:1337)
	at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.proc
essChildren(ContainerBase.java:1601)
	at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.proc
essChildren(ContainerBase.java:1610)
	at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(
ContainerBase.java:1590)
	at java.lang.Thread.run(Thread.java:595)



Missing @WebService annotation?

Posted by "Sica, David (David)" <ds...@avaya.com>.
I'm trying to deploy my web service with CXF 2.1 on Tomcat 6.0.16 and am
getting the following error which makes no sense because I clearly have
both my Interface and implementation annotated with @WebService.  I'm
stumped, any ideas would be greatly appreciated.

Thanks,
David

SEVERE: Exception sending context initialized event to listener instance
of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'ProductCommandService': Invocation of init method
failed; nested exception is javax.xml.ws.WebServiceException: Service
endpoint interface does not have a @WebService annotation.
Caused by: javax.xml.ws.WebServiceException: Service endpoint interface
does not have a @WebService annotation.
	at
org.apache.cxf.jaxws.support.JaxWsImplementorInfo.initialize(JaxWsImplem
entorInfo.java:284)
	at
org.apache.cxf.jaxws.support.JaxWsImplementorInfo.<init>(JaxWsImplemento
rInfo.java:57)
	at
org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:271)
	at
org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:244)
	at
org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:194)
	at
org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:380)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1242
)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1208)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.createBean(AbstractAutowireCapableBeanFactory.java:427)
	at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObjec
t(AbstractBeanFactory.java:249)
	at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.g
etSingleton(DefaultSingletonBeanRegistry.java:155)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ab
stractBeanFactory.java:246)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ab
stractBeanFactory.java:160)
	at
org.springframework.beans.factory.support.DefaultListableBeanFactory.pre
InstantiateSingletons(DefaultListableBeanFactory.java:291)
	at
org.springframework.context.support.AbstractApplicationContext.refresh(A
bstractApplicationContext.java:352)
	at
org.springframework.web.context.ContextLoader.createWebApplicationContex
t(ContextLoader.java:246)
	at
org.springframework.web.context.ContextLoader.initWebApplicationContext(
ContextLoader.java:189)
	at
org.springframework.web.context.ContextLoaderListener.contextInitialized
(ContextLoaderListener.java:49)
	at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.j
ava:3843)
	at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4350
)
	at
org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:11
14)
	at
org.apache.catalina.startup.HostConfig.check(HostConfig.java:1212)
	at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:29
3)
	at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSu
pport.java:117)
	at
org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.j
ava:1337)
	at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.proc
essChildren(ContainerBase.java:1601)
	at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.proc
essChildren(ContainerBase.java:1610)
	at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(
ContainerBase.java:1590)
	at java.lang.Thread.run(Thread.java:595)



Re: CXF REST - output in both XML & JSON

Posted by David Castro <dc...@youmail.com>.
Thanks.  I'll give that a try.

Britt Crawford wrote:
> You just need to add the annotation
>
> @ProduceMime({"application/xml", "application/json"})
>
> to your service methods.  You can add 
>
> @ConsumeMime({"application/xml", "application/json"})
>
> to allow the to receive input in both formats as well.  I am assuming that
> you are using the JAXRS front-end.  You'll also need to add Jettison
> (org.codehaus.jettison) as a dependency.
>
> Cheers,
> Britt Crawford
>
>
> arimus wrote:
>   
>> Is there a way to use the same service class and methods to generate
>> both XML and JSON output depending on say the client "Accept" format?
>> Or if not possible, what about mapping the same service methods to
>> different URLs with different output types.
>>
>> Cheers,
>> David
>>
>>
>>
>>     
>
>   


Re: CXF REST - output in both XML & JSON

Posted by Britt Crawford <bc...@cafepress.com>.
You just need to add the annotation

@ProduceMime({"application/xml", "application/json"})

to your service methods.  You can add 

@ConsumeMime({"application/xml", "application/json"})

to allow the to receive input in both formats as well.  I am assuming that
you are using the JAXRS front-end.  You'll also need to add Jettison
(org.codehaus.jettison) as a dependency.

Cheers,
Britt Crawford


arimus wrote:
> 
> Is there a way to use the same service class and methods to generate
> both XML and JSON output depending on say the client "Accept" format?
> Or if not possible, what about mapping the same service methods to
> different URLs with different output types.
> 
> Cheers,
> David
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/CXF-REST---output-in-both-XML---JSON-tp18124045p18163838.html
Sent from the cxf-user mailing list archive at Nabble.com.