티스토리 뷰
1. WADL2Apex를 사용하여 Apex 코드 생성
- Rest 콜아웃 외에도 Apex는 XML을 사용하여 SOAP 웹 서비스에 콜아웃을 만들 수 있다.
- WSDL2APEX는 WSDL 문서에서 Apex 클래스를 자동으로 생성한다.
- 웹 서비스의 WSDL 파일을 다운로드한 다음 WSDL을 업로드하면 WSDL2Apex가 Apex 클래스를 생성해 준다.
- Apex 클래스는 SOAP XML을 구성하고 데이터를 전송하며 응답 XML을 Apex 개체로 구문 분석한다.
2. WSDL에서 Apex 클래스 생성하는 방법
- 1) Setup -> Apex Classes -> Generate Apex code from WSDL
- 2) 파일 선택에서 다운받은 WSDL 파일을 선택한다.
- 3) Parse WSDL을 클릭한다.
- 4) Apex Class Name을 확인한 후, Generate Apex Code를 클릭한다.
- 이렇게 생성된 Apex 클래스에는 WSDL 문서로 표시되는 타사 웹 서비스 호출을 하기 위한 stub 및 유형 클래스가 포함된다.
- 이러한 클래스를 사용하면 Apex에서 외부 웹 서비스를 호출할 수 있다.
3. Set up에서 End Point Setting하기
- Setup -> Remote Site Settings -> new
4. 실습 과제
5. 실습 코드
public class ParkLocator {
public static List<String> country (String str) {
ParkService.ParksImplPort pp = new ParkService.ParksImplPort();
return pp.byCountry(str);
} // country
} // end class
@isTest
global class ParkServiceMock implements WebServiceMock {
global void doInvoke(
Object stub,
Object request,
Map<String, Object> response,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {
ParkService.byCountryResponse byCoRe = new ParkService.byCountryResponse ();
byCoRe.return_x = new List<String> {'Yellowstone', 'Mackinac National Park', 'Yosemite'};
response.put('response_x', byCoRe);
// ParkService에서 변수 값을 String이 response_x인것으로 인식하기에
// response.put('response_x', 변수);로 해야 한다.
} // doInvoke
} // end class
@isTest
public class ParkLocatorTest {
@isTest
static void testCallout() {
Test.setMock(WebServiceMock.class, new ParkServiceMock());
String county = 'United States';
List<String> li = ParkLocator.country(county);
} // testCallout
} // end class
'[세일즈포스 개발자]' 카테고리의 다른 글
Force.com Objects (0) | 2023.03.03 |
---|---|
Debug Log ( 디버그 로그 ) (0) | 2023.03.02 |
HTTP과 REST Callouts (0) | 2023.02.24 |
Org Development Model (0) | 2023.02.23 |
Apex Testing (0) | 2023.02.23 |