Ron Szcz
Ron Szcz

Reputation: 21

Publishing a NonSpring webservice with CXF

We are upgrading the webservice engine in our application suite from AXIS1.1 to CXF3.0.2. I am having a few challenges with publishing web services in our applications.

From what I understand there’s a SPRING approach to publishing services in CXF and there’s a non-spring approach. My preference is to go with non-spring approach since our application is built on STRUTS framework and I do not want to bring in SPRING as part of this upgrade effort. I am open to choosing SPRING approach to publishing a CXF webservice, if I do not have other options.

Here’s my non-spring approach to publishing a webservice:

I have a servlet that extends org.apache.cxf.transport.servlet.CXFNonSpringServlet and overrides the loadBus(ServletConfig) method (The code snippet of the loadBus method is below). This servlet is configured in the web.xml to receive all requests originating with the URL pattern /services/*

@Override
public void loadBus(ServletConfig servletConfig)
{
   super.loadBus(servletConfig);
   Bus bus = getBus();
   BusFactory.setDefaultBus(bus);
   Endpoint ep = Endpoint.create(new myWebService());
   ep.publish("/myService");
}

The Endpoint class in the above code snippet is the javax.xml.ws.Endpoint. My expectation is that I should see the published services with the URL http://www.myhost.com/contextRoot/services/. But I all I see with the URL is “No services have been found” – Clearly says publishing failed.. The exception stack trace on server console is as follows:

java.lang.IllegalArgumentException: Cannot create URL for this address /myService at com.sun.xml.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:237) at com.chase.ccs.servlet.CCSCXFNonSpringServlet.loadBus(CCSCXFNonSpringServlet.java:37) at org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:76) at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:329) at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.init(ServletWrapperImpl.java:168) at com.ibm.ws.webcontainer.servlet.ServletWrapper.load(ServletWrapper.java:1283) at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:973) at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3703) at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304) at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:953) at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1655) at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276) at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214) at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113) at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)

What am I missing or where did I go wrong?

Upvotes: 2

Views: 2112

Answers (2)

Gilberto Matos
Gilberto Matos

Reputation: 101

I know this answer may come a bit late, but I recently faced a similar problem (cxf 3.1.4). On my case, cxf-rt-frontend-jaxws jar was not on my application's classpath. Adding it solved my problem.

Upvotes: 1

Chathuranga Tennakoon
Chathuranga Tennakoon

Reputation: 2189

i also faced the same situation. can you change your loadBus method as follows. it worked for me.

@Override 
public void loadBus(ServletConfig servletConfig){
super.loadBus(servletConfig);
ServerFactoryBean factory = new ServerFactoryBean();
factory.setBus(bus);
factory.setServiceClass(myWebService.class);
factory.setAddress("/myService");
factory.create();
}

Upvotes: 1

Related Questions