Consume a web service using Apache CXF client library

Apache CXF may also be used to consume a web service. Obviously, the match of client and server both with CXF make the development very simple, as the same IMyAPI interface may be used as a contract between server and client.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
import; import; public class CxfClientImpl { private static final QName SERVICE_NAME = new QName("http://com.snip2code.api", "MyAPIService"); private static final QName PORT_NAME_DB = new QName("http://com.snip2code.api", "apiName"); private IMyAPI portAPI; public CxfClientImpl() { //initialize web service utilities: URL wsdlURL = null; String location = ""; try { wsdlURL = new URL(location); } catch (MalformedURLException e) { log.error("Malformed Url:" + location + ", due to:" + e.getMessage()); return; } Service service = Service.create(SERVICE_NAME); service.addPort(SERVICE_NAME, SOAPBinding.SOAP11HTTP_BINDING, wsdlURL.toString()); portAPI = service.getPort(PORT_NAME, IMyAPI.class); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus