by
2
8
469k
7
Top 1% !
Popular
Famous
Pearl of Wisdom
Tagged
Easy-to-find
Specified
OpenSource
Popularity: 1538th place
JVMjre6
LanguageJava
LicenseMIT_X11

Load a SOAP endpoint with Apache CXF using JMS transport provided by Apache ActiveMQ

This is an example on how to load a SOAP web service in order to be able to invoke its methods via JMS transport
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/334/Load-a-SOAP-endpoint-with-Apache-CXF-usi?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
private JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); public MyInterface loadEndPoint() { //try to load from local, if available: boolean loadOK = false; MyInterface result = null; try { Class<?> c = Class.forName("MyImplClass"); Method fact = c.getMethod("get"); result = (MyInterface) fact.invoke(null); loadOK = true; } catch (ClassNotFoundException e) { log.info("Cannot find MyImplClass, redirecting to remote access...", e); } catch (Exception e) { log.warn("Error searching MyImplClass, , redirecting to remote access. Exception is " + e, e); } //load remote endpoint: if (!loadOK) { //detect transport protocol for web services: String brokerAddr = "127.0.0.1"; //the right broker address String queueName = "MyQueueName"; String address = "jms:jndi:dynamicQueues/" + queueName + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&jndiConnectionFactoryName=ConnectionFactory&jndiURL=" + brokerAddr; log.info("Connecting to " + address); String connString = "tcp://" + brokerAddr + ":61616"; ActiveMQConnectionFactory connFactory = new ActiveMQConnectionFactory("Myusername", "Mypassword", connString); SoapBindingConfiguration conf = new SoapBindingConfiguration(); //MTOM not supported! .net does not interoperate with cxf mtom impl. // conf.setMtomEnabled(true); conf.setVersion(Soap12.getInstance()); factory.setBindingConfig(conf); factory.setServiceClass(MyInterface.class); factory.setAddress(address); factory.getFeatures().add(new WSAddressingFeature()); factory.getFeatures().add(getJMSConfigFeature(queueName, connFactory, 10000))); Object resObj = factory.create(); if ((resObj != null) && (resObj instanceof MyInterface)) result = (MyInterface) resObj; } return result; } } public static JMSConfigFeature getJMSConfigFeature(String queueName, ActiveMQConnectionFactory connectionFactory, Long receiveTimeout) { JMSConfigFeature jmsConfigFeature = new JMSConfigFeature(); JMSConfiguration jmsConfig = new JMSConfiguration(); jmsConfig.setUseJms11(true); jmsConfig.setTargetDestination(queueName); jmsConfig.setConnectionFactory(connectionFactory); if (receiveTimeout != null) jmsConfig.setReceiveTimeout(receiveTimeout); jmsConfigFeature.setJmsConfig(jmsConfig); return jmsConfigFeature; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus