์๋ ํ์ธ์ ํ,
QAF๋ฅผ ์ฌ์ฉํ์ฌ API ์๋ํ๋ฅผ ๊ตฌํํ๋ ค๊ณ ํฉ๋๋ค.
๋๊ตฌ๋ ์ง ์๋ ์ฟผ๋ฆฌ์ ๋ํด ์ ์ํ ์ ์์ต๋๊น?
--> new RestTestBase().getWebResource(getBundle().getString("ws.endurl", url), "/application.json")์์ ๋ฐ์ํ์ต๋๋ค. * * --> ์ด๋ค GET ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ๊ฒ์ธ๊ฐ?
๋ฏธ๋ฆฌ ๊ฐ์ฌ๋๋ฆฝ๋๋ค!!
๋ฌธ์ ์ธ์ฌ,
ํ๋
POJO๊ฐ ์์๋๋ ๊ฒฝ์ฐ ํด๋น ํด๋์ค ๋๋ String.class
๋๋ ์ผ๋ฐ ์๋ต ClientResponse.class
์ฌ์ฉ ์ค๋น ๋จ๊ณ์ ws-support ๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์๋ตํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!
์ฝ๋์ ์๋ ๋ถ๋ถ์ด ๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
What's ----> ๋ฌธ์์ด ๋ฆฌ์์ค
๋ฌด์ ---->์ง๋
private static void requestFor(๋ฌธ์์ด ๋ฆฌ์์ค, ๋งต
์ฐ๋ฆฌ๋ ์ฝ๋์ ์๋ ๋ถ๋ถ์ผ๋ก ์๋ํ๊ณ ์๋์ ๊ฐ์ ์์ธ๊ฐ ๋ฐ์ํ์ต๋๋ค.
์๋ํ ์คํฌ๋ฆฝํธ:
WebResource webResource = new RestTestBase().getWebResource(getBundle().getString("ws.endurl", url));
webResource.get(ClientResponse.class);
์ค๋ฅ:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX ๊ฒฝ๋ก ๊ตฌ์ถ ์คํจ:
sun.security.provider.certpath.SunCertPathBuilderException: ์์ฒญ๋ ๋์์ ๋ํ ์ ํจํ ์ธ์ฆ ๊ฒฝ๋ก๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.
์๋ ํ์ธ์ @APrem
HTTP ํด๋ผ์ด์ธํธ๊ฐ ์ธ์ฆ์๋ฅผ ์ ๋ขฐํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ด๋ฅผ ์ํด - ์ฌ๊ธฐ์์ ์ฝ๋ ์ค๋ํซ์ ์ฌ์ฉํ์ฌ RestClientFactory๋ฅผ ํ์ฅํด์ผ ํฉ๋๋ค.
https://gist.github.com/outbounder/1069465
๋ฐ๋ผ์ ํ์ฅ ํด๋์ค๋ ์๋์ ๊ฐ์ ๊ฒ์ด๊ณ ์ด๊ฒ์ ์๋ฐ ํจํค์ง ์์ ๋ฃ์ ์ ์์ต๋๋ค:
`ํจํค์ง
com.qmetry.qaf.automation.ws.rest.RestClientFactory ๊ฐ์ ธ์ค๊ธฐ;
com.sun.jersey.api.client.Client ๊ฐ์ ธ์ค๊ธฐ;
com.sun.jersey.api.client.config.ClientConfig ๊ฐ์ ธ์ค๊ธฐ;
com.sun.jersey.api.client.config.DefaultClientConfig ๊ฐ์ ธ์ค๊ธฐ;
com.sun.jersey.client.urlconnection.HTTPSProperties ๊ฐ์ ธ์ค๊ธฐ;
๊ฐ์ ธ์ค๊ธฐ javax.net.ssl.*;
๊ฐ์ ธ์ค๊ธฐ java.security.SecureRandom;
import java.security.cert.CertificateException;
๊ฐ์ ธ์ค๊ธฐ java.security.cert.X509Certificate;
๊ณต๊ฐ ํด๋์ค ClientHelper๋ RestClientFactory {๋ฅผ ํ์ฅํฉ๋๋ค.
public static ClientConfig configureClient() {
TrustManager[ ] certs = new TrustManager[ ] {
new X509TrustManager() {
<strong i="24">@Override</strong>
public X509Certificate[] getAcceptedIssuers() {
return null;
}
<strong i="25">@Override</strong>
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
<strong i="26">@Override</strong>
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
}
};
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("TLS");
ctx.init(null, certs, new SecureRandom());
} catch (java.security.GeneralSecurityException ex) {
}
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
ClientConfig config = new DefaultClientConfig();
try {
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(
new HostnameVerifier() {
<strong i="27">@Override</strong>
public boolean verify(String hostname, SSLSession session) {
return true;
}
},
ctx
));
} catch(Exception e) {
}
return config;
}
<strong i="28">@Override</strong>
protected Client createClient() {
return Client.create(ClientHelper.configureClient());
}
}`
์ด๋ ๊ฒ ํ๋ฉด ์ ํ๋ฆฌ์ผ์ด์
์์ฑ ๋ด์ ์ด ํด๋์ค๋ฅผ ๋ฑ๋กํด์ผ ํฉ๋๋ค.
rest.client.impl=<Your Package Name>.ClientHelper
์๋
ํ์ธ์ ํ๋ ์
๋๋ค.
์์ ์๊ฒฌ์ด ๋ฌธ์ ํด๊ฒฐ์ ๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
QAF ํ๊ทธ๊ฐ ์๋ stackoverflow ๋๋ ๊ทธ๋ฃน์ผ๋ก ์ฐ๊ฒฐ๋ ๊ฒ๊ณผ ๊ฐ์ ์ปค๋ฎค๋ํฐ ์ง์ ํฌ๋ผ์ผ๋ก ์ง๋ฌธ์ ์ด๋ํด ๋ฌ๋ผ๊ณ ์์ฒญํ๊ณ ์ถ์ต๋๋ค. stackoverflow์ ์์ฒญํ ๋ qaf
ํ๊ทธ๋ฅผ ์ถ๊ฐํ์ฌ ๋น ๋ฅธ ์๋ต์ ์ป์ผ์ญ์์ค.
๊ฐ์ฌ ํด์,
์น๋ผ๊ทธ
์๋ตํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
ClientHelper ํด๋์ค๋ฅผ ์ถ๊ฐํ์ผ๋ฉฐ ์ด์ ์๋ต์ ๋ณผ ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ ๋ด๋ถ์ ์ ๊ณต๋ URL์ .getWebResource(getBundle().getString("ws.endurl", url)); api ํค๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค. ๋ฐ๋ผ์ ๋ฌผ์ํ ๊ธฐํธ "?" URL์ ์์ต๋๋ค. ์ด ์ฝ๋ ์กฐ๊ฐ์ "?" "%3F"๋ก ์ง์ ํ๊ณ ์๋์ ๊ฐ์ด ์ฝ์์ ์ถ๋ ฅํฉ๋๋ค.
์์: https://sample.url.com/xxxxxxxxxxxxx?apikey=l7xxfc8df89f313944a89e280481e09bb411
์ค์ : https://sample.url.com/xxxxxxxxxxxxxx%3Fapikey=l7xxfc8df89f313944a89e280481e09bb411
์ด ๋ณํ์ผ๋ก ์ธํด ์ถ๋ ฅ์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
์ฝ์ ์ถ๋ ฅ:
1 * ํด๋ผ์ด์ธํธ ์์๋ฐ์ด๋ ์์ฒญ
1 >> https://sample.url.com/xxxxxxxxxxxxx%3Fapikey=l7xxfc8df89f313944a89e280481e09bb411 ๊ฐ์ ธ ์ค๊ธฐ
1 * ์์ ์์: 87
1 * ์์ : ๋ธํ: 87๋ฐ์ดํธ: 87
์๋ฃ1 * ์๋ฃ
1 * ํด๋ผ์ด์ธํธ ์ธ๋ฐ์ด๋ ์๋ต
1 << 401
1 << ์๋ฒ: Apache-Coyote/1.1
1 << ์ฝํ
์ธ ๊ธธ์ด: 87
1 << ๋ ์ง: 2017๋
3์ 31์ผ ๊ธ์์ผ 14:39:19 GMT
1 << ์ฝํ
์ธ ์ ํ: text/plain;charset=UTF-8
1 <<
{
"์ค๋ฅ": [
{
"message": "์๋ชป๋ apikey",
"์ฝ๋": 4010
}
]
}
์๋์ ๊ฐ์ด Header ๊ฐ์ฒด๊ฐ ์๋ apikey๋ฅผ ์ ๋ฌํ๊ณ ์๋ต์ ๋ฐ์ ์ ์์์ต๋๋ค.
๋น๋ ๋น๋ = webResource.getRequestBuilder();
builder.header(apikey, apiValue);
builder.get(ClientResponse.class);
๊ฐ์ฌ ํด์!
@cjayswal @thetechnocrat ์ง์ ๊ฐ์ฌํฉ๋๋ค!!
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์๋ ํ์ธ์ @APrem
HTTP ํด๋ผ์ด์ธํธ๊ฐ ์ธ์ฆ์๋ฅผ ์ ๋ขฐํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ด๋ฅผ ์ํด - ์ฌ๊ธฐ์์ ์ฝ๋ ์ค๋ํซ์ ์ฌ์ฉํ์ฌ RestClientFactory๋ฅผ ํ์ฅํด์ผ ํฉ๋๋ค.
https://gist.github.com/outbounder/1069465
๋ฐ๋ผ์ ํ์ฅ ํด๋์ค๋ ์๋์ ๊ฐ์ ๊ฒ์ด๊ณ ์ด๊ฒ์ ์๋ฐ ํจํค์ง ์์ ๋ฃ์ ์ ์์ต๋๋ค:;
`ํจํค์ง
com.qmetry.qaf.automation.ws.rest.RestClientFactory ๊ฐ์ ธ์ค๊ธฐ;
com.sun.jersey.api.client.Client ๊ฐ์ ธ์ค๊ธฐ;
com.sun.jersey.api.client.config.ClientConfig ๊ฐ์ ธ์ค๊ธฐ;
com.sun.jersey.api.client.config.DefaultClientConfig ๊ฐ์ ธ์ค๊ธฐ;
com.sun.jersey.client.urlconnection.HTTPSProperties ๊ฐ์ ธ์ค๊ธฐ;
๊ฐ์ ธ์ค๊ธฐ javax.net.ssl.*;
๊ฐ์ ธ์ค๊ธฐ java.security.SecureRandom;
import java.security.cert.CertificateException;
๊ฐ์ ธ์ค๊ธฐ java.security.cert.X509Certificate;
๊ณต๊ฐ ํด๋์ค ClientHelper๋ RestClientFactory {๋ฅผ ํ์ฅํฉ๋๋ค.
}`
์ด๋ ๊ฒ ํ๋ฉด ์ ํ๋ฆฌ์ผ์ด์ ์์ฑ ๋ด์ ์ด ํด๋์ค๋ฅผ ๋ฑ๋กํด์ผ ํฉ๋๋ค.
rest.client.impl=<Your Package Name>.ClientHelper