Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exists any <jaxws:endpoint /> annotation?

I'm using CXF with Spring to publish and to consume my WebServices in JBoss 5.1. All works fine.

However, there's a thing that's I think very tedious: to put a jaxws:endpoint tag for every WebService in applicationContext.xml.

There's realy no way to do that with annotations? Thanks for all.

like image 586
bruno.zambiazi Avatar asked Apr 08 '11 18:04

bruno.zambiazi


2 Answers

As time pass, there arise some new possibilities.

Working with CXF/SpringBoot (SpringBoot: 1.2.3, CXF: 3.10, Spring: 4.1.6) there is a nice alternative in order to get rid of the jaxws:endpoint configuration in cxf-servlet.xml, as jonashackt pointed out in nabble.com. However, this solution is only possible if there is only one endpoint in the application (at least I did not succeed to configure more than one).

public static void main(String[] args) { 
    SpringApplication.run(Application.class, args); 
} 

@Bean 
public ServletRegistrationBean dispatcherServlet() { 
    CXFServlet cxfServlet = new CXFServlet(); 
    return new ServletRegistrationBean(cxfServlet, "/api/*"); 
} 

@Bean(name="cxf") 
public SpringBus springBus() { 
    return new SpringBus(); 
} 

@Bean 
public MyServicePortType myService() { 
    return new MyServiceImpl(); 
} 

@Bean 
public Endpoint endpoint() { 
    EndpointImpl endpoint = new EndpointImpl(springBus(), myService()); 
    endpoint.publish("/MyService"); 
    return endpoint; 
} 

Where MyServicePortType is a class having the @WebService annotation. This Endpoint is then called for URL's like "localhost:8080/api/MyService"

Of course these @Bean declarations may be placed in any other spring config class.

In contrary to the copied original solution I suggest to instantiate the Bus (cxf-Bean) by using the factory method instead of the direct "new SpringBus()":

BusFactory.newInstance().createBus()
like image 62
Heri Avatar answered Nov 04 '22 02:11

Heri


There are some annotations to configure things that you can also put in <jaxws:endpoint>. An annotation to declare a CXF endpoint would be nice.

You can configure an endpoint using code instead of Spring XML. This can be handy if you have a lot of repetitive configuration that you can factor out. Or if you have certain endpoints configured differently in different environments.

For example:

@Autowired var authImpl: Auth = _
@Autowired var faultListener: FaultListener = _

def initWebServices() {
  var sf: JaxWsServerFactoryBean = _

  val propMap = mutable.HashMap[String, AnyRef]("org.apache.cxf.logging.FaultListener"->faultListener.asInstanceOf[AnyRef])

  sf = new JaxWsServerFactoryBean
  sf.setServiceBean(authImpl)
  sf.setAddress("/auth")
  sf.setServiceName(new QName("http://auth.ws.foo.com/", "auth", "AuthService"))
  sf.setProperties(propMap)
  sf.create   

  // more services...
like image 29
sourcedelica Avatar answered Nov 04 '22 00:11

sourcedelica