tutorial hello world web services with apache cxf

19
Tutorial Hello World Web Services With Apache CXF 2014 Muhammad Arif Nasution [email protected] http://marifnst.net

Upload: muhammad-arif-nasution

Post on 18-Dec-2014

2.908 views

Category:

Software


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Tutorial Hello World Web Services with Apache CXF

Tutorial Hello World Web Services With Apache CXF

2014

Muhammad Arif Nasution [email protected]

http://marifnst.net

Page 2: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 1

Inisialisasi Project 1. Buat project baru di eclipse, pilih “File” – “New” – “Project”.

2. Pilih folder “Web” – “Dynamic Web Project”.

Page 3: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 2

3. Isi Project Name (disini menggunakan “HelloWorldCXF”).

4. Klik “Next”.

Page 4: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 3

5. Pastikan check box “Generate Web.xml deployment descriptor” dalam kondisi Checked dan pilih “Next”.

6. Apabila muncul Pop Up Eclipse masalah “Perspective”, silahkan pilih “Yes”.

Page 5: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 4

Konfigurasi Library / JAR

JAR in folder Modules 7. Masuk ke folder hasil ekstrak Apache CXF (file hasil ekstrak kurang lebih seperti gambar di bawah ini).

8. Masuk ke folder “modules”, dan ambil file JAR berikut :

cxf-api-2.7.8.jar

cxf-rt-bindings-soap-2.7.8.jar

cxf-rt-core-2.7.8.jar

cxf-rt-databinding-jaxb-2.7.8.jar

cxf-rt-frontend-jaxws-2.7.8.jar

cxf-rt-frontend-simple-2.7.8.jar

cxf-rt-transports-http-2.7.8.jar

cxf-rt-transports-http-jetty-2.7.8.jar

Page 6: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 5

9. Copy JAR tersebut ke folder “WEB-INF” – “lib” pada project.

Page 7: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 6

Jar in folder LIB 10. Masuk ke folder “lib”, dan copy JAR berikut :

asm-3.3.1.jar

commons-logging-1.1.1.jar

spring-aop-3.0.7.RELEASE.jar

spring-asm-3.0.7.RELEASE.jar

spring-beans-3.0.7.RELEASE.jar

spring-context-3.0.7.RELEASE.jar

spring-core-3.0.7.RELEASE.jar

spring-expression-3.0.7.RELEASE.jar

spring-jms-3.0.7.RELEASE.jar

spring-tx-3.0.7.RELEASE.jar

spring-web-3.0.7.RELEASE.jar

stax2-api-3.1.1.jar

woodstox-core-asl-4.2.0.jar

wsdl4j-1.6.3.jar

xmlschema-core-2.0.3.jar

Page 8: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 7

11. Copy JAR dari folder lib ke “WEB-INF” – “lib” pada project.

Include JAR in Project 12. Klik kanan project – “Build Path” – “Configure Build Path”.

Page 9: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 8

13. Pilih tab “Java Build Path”, tab “Libraries”, kemudian klik Button “Add JAR’s”. Pilih semua JAR yang sudah di copy

di folder “WEB-INF” – “lib” tadi.

14. Apabila benar, maka JAR-JAR tersebut akan ditampilkan seperti gambar di bawah ini & kemudian klik “OK”.

Page 10: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 9

Konfigurasi Source Code 15. Masuk ke folder “samples” dari hasil ekstrak Apache CXF. Isi dari folder tersebut seperti pada gambar di bawah

ini. Pilih folder “java_first_jaxws”.

16. Masuk ke folder “src” – “main” – “java”, kemudian copy folder “demo”.

Page 11: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 10

17. Paste folder tersebut ke folder “src” project.

18. Apabila benar, maka semua file JAVA akan muncul seperti gambar di bawah ini.

Page 12: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 11

19. Masuk ke folder “java_first_jaxws” – “src” – “main” – “webapp” – “WEB-INF”, kemudian copy file “cxf-

servlet.xml”.

20. Paste file tersebut ke folder “WebContent “– “WEB-INF” pada project.

Page 13: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 12

21. Ubah file “Web.xml” pada project seperti gambar di bawah ini (hint : bisa dilihat pada source code yang di

include pada project ini).

Page 14: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 13

Running Web Services 22. Klik kanan project – “Run As” – “Run On Server”.

23. Pilih server Tomcat anda, kemudian pilih “Next”.

Page 15: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 14

24. Pastikan project anda didalam tab “Configured” kemudian pilih “Finish”.

25. Hasil running pertama akan seperti pada gambar atau sesuai konfigurasi masing-masing.

Page 16: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 15

26. Ubah URL menjadi http://localhost:8080/<NAMA PROJECT ANDA>/services/hello_world?wsdl. Apabila

berhasil maka akan muncul WSDL anda seperti gambar di bawah ini.

Page 17: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 16

Running Web Services Client 27. Buka file Client.java.

28. Gunakan nilai http://localhost:8080/<NAMA PROJECT ANDA>/services/hello_world untuk variabel

“endpointAddress”.

Page 18: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 17

29. Jangan lupa ubah “java_first_jaxws” menjadi “NAMA PROJECT ANDA” pada variabel “endpointAddress”.

30. Klik kanan pada file, “Run As” – “Java Application”.

Page 19: Tutorial Hello World Web Services with Apache CXF

http://marifnst.net Page 18

31. Apabila benar, maka akan mendapat output seperti gambar di bawah ini. Output tersebut merupakan respon

dari Web Server yang sudah kita buat .

=== sekian ===