gerekli malzemeler
- 1 adet tomcat ya da herhangi bir webserver örn. http://tomcat.apache.org/
- 1 adet webservice işlemlerini yapacak kütüphane örn. http://cxf.apache.org/
- 1 adet ide örn. http://www.eclipse.org/
yapılışı
Eclipse ile dinamik web projesi oluştur.
Daha sonra indirdiğin webservice kütüphanelerini web-inf/lib altına kopyala.
Bu işleri yaptıktan sonra web.xml dosyamıza şu cxf servlet i için gerekli parametreleri ve service.xml dosyamızı ekliyoruz.
service.xml dosyasını daha sonra oluşturacağız.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>kpsws</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:tr/edu/iu/kps/service.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<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>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>auth only</realm-name>
</login-config>
</web-app>
Şimdi bir adet webservice interface i oluşturuyoruz.
package tr.edu.iu.kps;
import javax.jws.WebService;
@WebService
public interface KPSService {
public String hello(@WebParam(name = "name")String name,@WebParam(name = "surname")String surname);
}
@WebParam o parametrenin oluşan xml dosyasında verilen isimle görünmesini sağlıyor.
Bu işlemi yaptıktan sonra bu interface i implement eden servisi yazıyoruz.
package tr.edu.iu.kps;
import javax.jws.WebService;
@WebService(endpointInterface = "tr.edu.iu.kps.KPSService", serviceName = "kps-service")
public class KPSServiceImpl implements KPSService {
String username;
String password;
public KPSServiceImpl() {
}
public String hello(String name, String surname) {
return "Hello " +name+" "+surname;
}
}
Bunları da yaptıktan sonra service.xml dosyamızı oluşturuyoruz.
<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.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" />
<bean id="kpsServiceBean" class="tr.edu.iu.kps.KPSServiceImpl" />
<jaxws:endpoint id="kpsService" implementor="#kpsServiceBean"
address="/kps-service">
</jaxws:endpoint>
</beans>
Uygulamanı tomcat e publish edip http://localhost:port/proje/services/ adresine girersen web servisini orada görebilirsin.
N/A
|