Skip to main content

Publishing a service with the JAVA API

Developers who don't wish to modify the WSDL file can also publish the endpoint information using Java code. For CXF's SOAP over JMS implementation you can write the following:

// You just need to set the address with JMS URI
String address = "jms:jndi:dynamicQueues/test.cxf.jmstransport.queue3"
   + "?jndiInitialContextFactory"
   + "=org.apache.activemq.jndi.ActiveMQInitialContextFactory"
   + "&jndiConnectionFactoryName=ConnectionFactory&jndiURL" 
   + "=tcp://localhost:61500";
Hello implementor = new HelloImpl();
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setServiceClass(Hello.class);
svrFactory.setAddress(address);
// And specify the transport ID with SOAP over JMS specification
svrFactory.setTransportId(
   JMSSpecConstants.SOAP_JMS_SPECIFICIATION_TRANSPORTID);
svrFactory.setServiceBean(implementor);
svrFactory.create();

NOTE: For tests it can be useful to create an embedded broker like this:

public final void run() {
    try {            
         broker = new BrokerService();
         broker.setPersistent(false);
         broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
         broker.setTmpDataDirectory(new File("./target"));
         broker.setUseJmx(false);
         if (brokerName != null) {
             broker.setBrokerName(brokerName);
         }        broker.addConnector(brokerUrl1);
         broker.start();
    } catch (Exception e) {
         e.printStackTrace();
    }
}

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!