'[Simple Web Services]'에 해당되는 글 1

  1. 2011.01.01 [IBM dWs] Java SE 6, Ecipse, Ant 를 이용한 간단한 웹 서비스

[IBM dWs] Java SE 6, Ecipse, Ant 를 이용한 간단한 웹 서비스

- Eclipse와 Java SE 6을 사용하여 독립형 웹 서비스 개발하기, Part 1: 웹 서비스 서버 애플리케이션
Create stand-alone Web services applications with Eclipse and Java SE 6, Part 1: The Web service server application
- Eclipse와 Java SE 6을 사용하여 독립형 웹 서비스 개발하기: Part 2: 웹 서비스 클라이언트 응용프로그램
Create stand-alone Web services applications with Eclipse and Java SE 6: Part 2: The Web service client application

- Java SE 6, Ecipse, Ant 를 이용해서 간단한 웹서비스를 구현하고 모니터링한다.

Java SE 6 JDK 설치
Eclipse JRE 설정

서버
package com.myfirst.wsServer;

@WebService
public class SayHello {
    private static final String SALUTATION = "Hello";
   
    public String getGreeting(String name){
        return SALUTATION + " " + name;
    }
}
<project default="wsgen">
    <target name="wsgen">
        <exec executable="wsgen">
            <arg line="-cp ./bin -keep -s ./src -d ./bin com.myfirst.wsServer.SayHello" />
        </exec>
    </target>
</project>
Ant 를 실행시키면 com.myfirst.wsServer.jaxws 가 생김
package com.myfirst.wsServer;

public class RunService {
    public static void main(String[] args) {
        System.out.println("SayHello Web Service started.");
        Endpoint.publish("http://localhost:8080/wsServerExample", new SayHello());
    }
}
서버를 실행시키고, Internal Web Browser 로 http://localhost:8080/wsServerExample?wsdl 을 입력하면 WSDL 을 볼 수 있다.

Eclipse 의 Web Services Explorer 를 이용해서 웹서비스를 테스트해 볼 수 있다.
Java EE Perspective 에서 Run - Launch the Web Services Explorer 을 선택하고
http://localhost:8080/wsServerExample?wsdl 를 호출해서 getGreeting 을 직접 호출해 본다.

클라이언트
<project default="wsimport">
    <target name="wsimport">
        <exec executable="${java.home}/../bin/wsimport">
            <arg line="-keep -s ./src -p com.myfirst.wsClient
                -d ./bin http://localhost:8080/wsServerExample?wsdl" />
        </exec>
    </target>
</project>
wsimport 태스크를 실행하면 WSDL 를 참조해서 JAX-WS 관련 스텁?이 생성된다.
  • wsgen은 서비스 엔드 포인트 클래스를 읽고서 웹 서비스 전개 및 호출에 필요한 모든 아티팩트를 생성한다.
  • wsimport는 WSDL을 읽고서 웹 서비스 개발, 전개 및 호출에 필요한 모든 아티팩트를 생성한다.
package com.myfirst.wsClient;

public class SayHelloClient {
	public static void main(String[] args) {
		SayHelloService service = new SayHelloService();
		SayHello proxy = (SayHello)service.getSayHelloPort();
		((BindingProvider)proxy).getRequestContext().put(
			BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8081/wsServerExample");
		
		System.out.println(((BindingProvider)proxy).toString());
		System.out.println(proxy.getGreeting("miso"));
	}
}

- Eclipse TCP/IP Monitor 를 이용해서 모니터링을 할 수 있다.