Free/Open Source Talend ESB Standard Edition has several CXF JAX-RS samples under its examples/tsf folder: http://www.jroller.com/gmazza/entry/tsf_jaxrs_intro_sample. JAXRS-intro and -advanced would be good places to start, and they both provide WAR deployment (on Tomcat) options.

HTH,
Glen

On 01/04/2012 03:19 PM, hdave wrote:
Total newbie here trying to get my first REST based web service up and
running using CXF.  The problem I am having is that when I go to a URL in
Firefox to see the result of the web service, I am getting an HTTP error 400
- Bad Request.  I get the same problem when running in either Tomcat or
Jetty.

I probably have something misconfigured as I am seeing a number of potential
issues in the log when I start up my webapp.  The URL I am browsing to is:

http://localhost:9999/rest/security/serverDateTime

Any help is appreciated, I've been banging my head on this for 2 days and
can't figure out what is wrong.

Here is the CXF portion of the log (DEBUG).  Notice CXF complains about not
finding a definition for my service bean.  Weird that Spring does not
complain.  I know the bean is there and works because I have used it from
other code.

I should also add that when I browse to my welcome file, I also see nothing
and get a 400.

--------------------
[20120104 14:07:51] [main] DEBUG
[org.apache.cxf.configuration.spring.ConfigurerImpl] LogUtils.doLog(372) |
Could not determine bean name for instance of class
org.apache.cxf.binding.xml.XMLBindingFactory.
[20120104 14:07:51] [main] DEBUG
[org.apache.cxf.configuration.spring.ConfigurerImpl] LogUtils.doLog(372) |
Could not determine bean name for instance of class
org.apache.cxf.service.factory.FactoryBeanListenerManager.
[20120104 14:07:51] [main] DEBUG
[org.apache.cxf.configuration.spring.ConfigurerImpl] LogUtils.doLog(372) |
Could not determine bean name for instance of class
org.apache.cxf.transport.http.HTTPTransportFactory.
[20120104 14:07:52] [main] DEBUG
[org.apache.cxf.configuration.spring.ConfigurerImpl]
ConfigurerImpl.configureBean(160) | Could not find a definition for bean
with id
{http://impl.security.service.core.myapp.com/}SecurityServiceImpl.http-destination
- no injection will be performed.
[20120104 14:07:52] [main] INFO [org.apache.cxf.endpoint.ServerImpl]
ServerImpl.initDestination(94) | Setting the server's publish address to be
/rest
[20120104 14:07:52] [main] DEBUG
[org.apache.cxf.configuration.spring.ConfigurerImpl] LogUtils.doLog(372) |
Could not determine bean name for instance of class
org.apache.cxf.buslifecycle.CXFBusLifeCycleManager.
[20120104 14:07:52] [main] DEBUG
[org.apache.cxf.configuration.spring.ConfigurerImpl] LogUtils.doLog(372) |
Could not determine bean name for instance of class
org.apache.cxf.endpoint.ServerRegistryImpl.
[20120104 14:07:52] [main] DEBUG
[org.apache.cxf.configuration.spring.ConfigurerImpl] LogUtils.doLog(372) |
Could not determine bean name for instance of class
org.apache.cxf.endpoint.ServerLifeCycleManagerImpl.
[20120104 14:07:52] [main] DEBUG [org.apache.cxf.endpoint.ServerImpl]
ServerImpl.start(126) | Server is starting.
[20120104 14:07:52] [main] DEBUG
[org.apache.cxf.transport.servlet.ServletDestination]
AbstractObservable.setMessageObserver(45) | registering incoming observer:
org.apache.cxf.transport.ChainInitiationObserver@808512
[20120104 14:07:52] [main] DEBUG [org.apache.cxf.endpoint.ServerImpl]
ServerImpl.start(136) | register the server to serverRegistry
--------------------

web.xml (partial):

--------------------
        <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/applicationContext.xml</param-value>
        </context-param>

        <listener>
        
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>

        <welcome-file-list>
                <welcome-file>MyAppCore.html</welcome-file>
        </welcome-file-list>

        <servlet>
                <display-name>MyApp Core REST Services</display-name>
                <servlet-name>MyAppCoreWebServices</servlet-name>
                
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
                <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
                <servlet-name>MyAppCoreWebServices</servlet-name>
                <url-pattern>/*</url-pattern>
        </servlet-mapping>
--------------------


applicationContext.xml (partial):

--------------------

        <bean id="securityService"
class="com.myapp.core.service.security.impl.SecurityServiceImpl">
                <constructor-arg index="0" ref="userDAO" />
                <constructor-arg index="1" ref="serverInfo" />
        </bean>


        <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

        <jaxrs:server id="myAppCoreSvcRest" address="/rest">
                <jaxrs:serviceBeans>
                        <ref bean="securityService" />
                </jaxrs:serviceBeans>
        </jaxrs:server>
--------------------


SecurityServiceImpl.java (partial):

--------------------
@Transactional
@Path("/security")
public class SecurityServiceImpl
                implements SecurityService {

         ... constructor and other details omitted for brevity.....

        @GET
        @Path("/serverDateTime")
        @Produces("text/plain")
        @Override
        public String getServerDateTime() {
                DateFormatter formatter = new DateFormatter("dd/MM/yyyy 
hh:mm:ss");
                return formatter.print(Calendar.getInstance().getTime(),
Locale.getDefault());
        }

}
--------------------



--
View this message in context: 
http://cxf.547215.n5.nabble.com/Newbie-struggling-with-first-CXF-web-service-tp5120716p5120716.html
Sent from the cxf-user mailing list archive at Nabble.com.


--
Glen Mazza
Talend Community Coders
http://coders.talend.com
blog: http://www.jroller.com/gmazza

Reply via email to