Introduction: Recently, I was struggling to invoke SOAP WebService inside an OSGI Service in AEM. I tried to search however there was not a single article or tutorial I could find to refer to. I thought it would be good to provide some steps around this. I could not make this an extensive article with a lot of information and code samples however, this could be a good starting point for others. Step -1: Setup AEM Project Structure: Create an AEM Project which has an OSGI Service implemented. Here is the Sample code // Service Interface public interface SoapClient { public String greetMe(String name); } // Service Interface Implementation Class @Component(service = SoapClient.class, immediate = true, configurationPid = "com.api.connector.service.impl.SoapClient", property = { Constants.SERVICE_DESCRIPTION + "=SOAP Client Service Interface", "label" + "=SOAP Client Service Interface", "service.ranking:Integer=10", }) @Designate(ocd=SoapClientConfig.class) public class SoapClientImpl implements SoapClient { private static final Logger log = LoggerFactory.getLogger(SoapClientImpl.class); @WebServiceRef(wsdlLocation = "http://www.examples.com/wsdl/HelloService.wsdl") private HelloService serviceObj; public BMSAPIWrapperImpl() { if (SoapClientImpl == null) { log.info("Service not found hence being created."); try { URL myWSDLURL = new URL("http://www.examples.com/wsdl/HelloService.wsdl"); this.serviceObj = new HelloService(myWSDLURL); log.info("Service created successfully."); } catch (Exception e) { log.info("Service not created Error : "+e.getMessage()); } } } // public String greetMe(String name) { IHelloService endPoint = serviceObj.getServiceEndPoint(); // get the endPoint of the service - generated by WSDL2JAVA Utility endPoint.greetMe(name); // Invoke GreetMe Method } } Step -2: Generate Java Classes from WSDL Generate Java Classes from your WSDL using the WSDL2JAVA Utility. You may use the following command wsdl2java -verbose -d folderNameWhereJavaFilesGenerated http://www.examples.com/wsdl/HelloService.wsdl Step -3: Copy all the Generated JAVA files Copy all the Generated JAVA files inside your AEM OSGI Project Step -4: Install Apache-CFX Runtime dependency Download Apache-CFX from this URL and install it to your AEM Instance using package explorer.
Please use this thread to ask the related questions.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes