You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by asarkar <so...@outlook.com> on 2014/01/19 08:19:04 UTC

CXF + Tomcat + Spring Java config

Hi,
Trying to deploy a JAX-WS endpoint using Tomcat 7 Maven plugin and CXF
2.7.8. As a matter of preference, I don't want to have any XML config for
Spring or CXF. I see several blogs, articles, posts using cxf-servlet.xml
and CXFServlet but none whatsoever completely using Java config. Heck, I'm
not sure if I even need CXFServlet. I did set it up though in my application
initializer class, mapped to "/calculator/*", along with a
"classpath:META-INF/cxf/cxf.xml" context param been set for the Spring
context listener. Lastly, I've a @Configuration class where I declare an
endpoint as follows:

@Configuration
@ImportResource({ "classpath:META-INF/cxf/cxf.xml" })
public class CXFConfig {
    @Autowired
    Bus cxfBus;

// More code

@Bean
public Endpoint calculator() {
    EndpointImpl endpoint = new EndpointImpl(cxfBus, new Calculator());
    endpoint.setAddress("/CalculatorService");
    return endpoint;
}

With all this, when I try to view the WSDL, I get:
WARNING: Can't find the the request for
http://localhost:8080/<context-root>/calculator/CalculatorService's Observer

Any ideas on what I'm doing wrong?



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-Tomcat-Spring-Java-config-tp5738793.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF + Tomcat + Spring Java config

Posted by asarkar <so...@outlook.com>.
I found that setting a bus on the CXFServlet is not necessary (and difficult)
during application startup. CXFServlet.loadBus() is called only on receiving
the first request at which time it'll get the bus from Spring application
context. It's the same bus that the endpoint is configured with so the appl.
should (and does) work just fine.
I appreciate the help so far. Thank you all.



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-Tomcat-Spring-Java-config-tp5738793p5738938.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF + Tomcat + Spring Java config

Posted by Daniel Kulp <dk...@apache.org>.
On Jan 21, 2014, at 12:39 PM, asarkar <so...@outlook.com> wrote:

> Seems like just invoking publish() on the endpoint does the job. Should I
> really be calling publish() though - isn't that for standalone applications
> only (or for unit tests), and not for a servlet/application container?

No, if you want a “listener” connected to the Endpoint, you would need to call publish.   It’s at that point that the Endpoint is finally wired together with the listeners and such and is made available to clients.


> @Bean
>    public Endpoint calculator() {
>    EndpointImpl endpoint = new EndpointImpl(cxfBus, new Calculator());
>    endpoint.setAddress("/CalculatorService");
> 		
>    // I was deliberately missing this    
>    endpoint.publish();
> 
>    return endpoint;
> }
> 
> Also, the test Andrei referred to sets the bus on the CXFServlet which seems
> to have no effect in my case. What does it do - is it necessary?
> cxfServlet.setBus(cxfBus);

Well, you need to make sure the Bus that the Servlet see’s and the bus that you use for the EndpointImpl are the same.   The “servlet http transport” that the servlet is dispatching into is registered on the bus that it sees.   If a different bus object sees a different HTTP transport, then the servlet wouldn’t be able to dispatch requests to that endpoint.


-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


RE: CXF + Tomcat + Spring Java config

Posted by asarkar <so...@outlook.com>.
Seems like just invoking publish() on the endpoint does the job. Should I
really be calling publish() though - isn't that for standalone applications
only (or for unit tests), and not for a servlet/application container?

@Bean
    public Endpoint calculator() {
    EndpointImpl endpoint = new EndpointImpl(cxfBus, new Calculator());
    endpoint.setAddress("/CalculatorService");
		
    // I was deliberately missing this    
    endpoint.publish();

    return endpoint;
}

Also, the test Andrei referred to sets the bus on the CXFServlet which seems
to have no effect in my case. What does it do - is it necessary?
cxfServlet.setBus(cxfBus);



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-Tomcat-Spring-Java-config-tp5738793p5738922.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: CXF + Tomcat + Spring Java config

Posted by Andrei Shakirin <as...@talend.com>.
You could try to do something similar as NoSpringServletServer code: http://svn.apache.org/repos/asf/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java

Regards,
Andrei.

> -----Original Message-----
> From: asarkar [mailto:socialguy@outlook.com]
> Sent: Sonntag, 19. Januar 2014 23:43
> To: users@cxf.apache.org
> Subject: Re: CXF + Tomcat + Spring Java config
> 
> I see that CXFServlet is looking for the cxf-servlet.xml or anything in the
> servlet context under the key 'config-location'; thus programmatically
> registering the endpoint is not working. Does someone know if it's possible
> to deploy a JAX-WS endpoint to a servlet container without the cxf-
> servlet.xml?
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-Tomcat-
> Spring-Java-config-tp5738793p5738800.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF + Tomcat + Spring Java config

Posted by asarkar <so...@outlook.com>.
I see that CXFServlet is looking for the cxf-servlet.xml or anything in the
servlet context under the key 'config-location'; thus programmatically
registering the endpoint is not working. Does someone know if it's possible
to deploy a JAX-WS endpoint to a servlet container without the
cxf-servlet.xml?



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-Tomcat-Spring-Java-config-tp5738793p5738800.html
Sent from the cxf-user mailing list archive at Nabble.com.