2. create interface ICalculator
public interface ICalculator {
public int add(int a, int b);
public int multiply(int a, int b);
public int divide(int a, int b);
public int subtract(int a, int b);
}
3. create class of implementation of soap service
public class CalculatorSoapImpl implements ICalculator{
public int add(int a, int b) {
return (a+b);
}
public int multiply(int a, int b) {
return (a*b);
}
public int divide(int a, int b) {
return (a/b);
}
public int subtract(int a, int b) {
return (a-b);
}
}
4. right click on CalculatorSoapImpl Web service/Create web service, configure with Apach CXF
5. web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>SOAPCalculator</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>Apache CXF Endpoint</description>
<display-name>cxf</display-name>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/cxf-beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
6. cxf-bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint xmlns:tns="http://webService.com/" id="soapcalc"
implementor="com.webService.SoapCalcImpl" wsdlLocation="wsdl/soapcalcimpl.wsdl"
endpointName="tns:SoapCalcImplPort" serviceName="tns:SoapCalcImplService"
address="/soap">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:endpoint>
</beans>
7. in wsdl file edit
<soap:address location="http://localhost:8080/SOAPCalculator/soap"/>
8. right click on the project Run on the server
9. click on link
http://localhost:8080/SOAPCalculator/soap?wsdl
should be opened

Немає коментарів:
Дописати коментар