<< 2008년 9월 2일 (화) | | 2008년 9월 4일 (목) >>

Axis를 통해 SOAP Client만들기

1. 프로젝트 생성

 - File>New>Web>Dynamic Web Project 선택 후 Next
 - Project Name 작성 후 Finish



2. SOAP Client 소스 생성

 - 해당 프로젝트 오픈 > 오른쪽 마우스 클릭 > New > Web Service Client 클릭
 - Service definition : 해당 URL 입력
 - Finish 클릭
 - 그러면 해당 Stub등의 SOAP 클라이언트 소스가 생성됩니다.



 - 그런 다음 클라이언트 소스를 호출하는 Client.java를 만듭니다. 소스는 아래와 같습니다.
package client;

import java.net.URLEncoder;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.mimul.ucgate.KTUCService_jws.KTUCServiceService;
import com.mimul.ucgate.KTUCService_jws.KTUCServiceServiceLocator;

public class UCClient
{
private Log log = LogFactory.getLog(this.getClass());
private static UCClient instance_ = null;
private static KTUCServiceService serviceLocator = null;

public UCClient() throws Exception
{
try {
if (serviceLocator == null)
serviceLocator = new KTUCServiceServiceLocator();
} catch (Exception e) {
e.printStackTrace();
log.error(e);
throw e;
}
}

public static UCClient getInstance() throws Exception
{
try {
if (instance_ == null) {
synchronized (UCClient.class)
{
if (instance_ == null)
instance_ = new UCClient();
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return instance_;
}

public String setUserProfile(String profile) throws Exception
{
String result = null;
try {
if (profile == null)
return "-1";
result = serviceLocator.getKTUCService().
setUserProfile(profile);
} catch (Exception e) {
e.printStackTrace();
log.error(e);
result = "-2";
}
return result;
}

/**
* @param args
*/
public static void main(String[] args)
{
StringBuffer profile = null;
try {
profile = new StringBuffer(100);
profile.append("username=").append("test@mimul.com");
profile.append("&nickname=").append(URLEncoder.
encode("미물", "UTF-8"));
profile.append("&email=").append("pepsi@mimul.com");
String result = UCClient.getInstance().
setUserProfile(profile.toString());
System.out.println("result : " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
3. Web Service Client를 생성하게 되면 자동으로 아래와 같은 jar파일이 카피됨

 - axis.jar
 - commons-discovery-0.2.jar
 - commons-logging.jar
 - jaxrpc.jar
 - saaj.jar
 - wsdl4j-1.5.1.jar

4. SOAP Client 배포하기 위한 Eclipse에서 Jar파일 생성하기

 - File>Export
 - Java>JAR file -> Next



 - 해당 프로젝트 선택(소스와 build 클래스 디렉토리)
 - JAR file명 지정
 - Next -> Next
 - main 함수를 통해 실행하는 클래스가 있을 경우 Main class에 기술함
 - 없으면 그냥 Finish

태그 :