How to use NullHostnameVerifier class of com.qaprosoft.carina.core.foundation.api.ssl package

Best Carina code snippet using com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier

Source:AbstractApiMethod.java Github

copy

Full Screen

...36import com.jayway.restassured.http.ContentType;37import com.jayway.restassured.response.Response;38import com.jayway.restassured.specification.RequestSpecification;39import com.qaprosoft.carina.core.foundation.api.log.LoggingOutputStream;40import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;41import com.qaprosoft.carina.core.foundation.api.ssl.NullX509TrustManager;42import com.qaprosoft.carina.core.foundation.api.ssl.SSLContextBuilder;43import com.qaprosoft.carina.core.foundation.http.HttpClient;44import com.qaprosoft.carina.core.foundation.http.HttpMethodType;45import com.qaprosoft.carina.core.foundation.http.HttpResponseStatusType;46import com.qaprosoft.carina.core.foundation.utils.Configuration;47import com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter;48import com.qaprosoft.carina.core.foundation.utils.R;49@SuppressWarnings("deprecation")50public abstract class AbstractApiMethod extends HttpClient51{52 protected static final Logger LOGGER = Logger.getLogger(AbstractApiMethod.class);53 private StringBuilder bodyContent = null;54 protected String methodPath = null;55 protected HttpMethodType methodType = null;56 protected Object response;57 public RequestSpecification request;58 private boolean logRequest = Configuration.getBoolean(Parameter.LOG_ALL_JSON);59 private boolean logResponse = Configuration.getBoolean(Parameter.LOG_ALL_JSON);60 public AbstractApiMethod()61 {62 init(getClass());63 bodyContent = new StringBuilder();64 request = given();65 request.contentType(ContentType.TEXT);66 }67 68 public AbstractApiMethod(String contentType)69 {70 init(getClass());71 bodyContent = new StringBuilder();72 request = given();73 request.contentType(contentType);74 }75 @SuppressWarnings("rawtypes")76 private void init(Class clazz)77 {78 String typePath = R.API.get(clazz.getSimpleName());79 if (typePath == null)80 {81 throw new RuntimeException("Method type and path are not specified for: " + clazz.getSimpleName());82 }83 if(typePath.contains(":"))84 {85 methodType = HttpMethodType.valueOf(typePath.split(":")[0]);86 methodPath = typePath.split(":")[1];87 }88 else89 {90 methodType = HttpMethodType.valueOf(typePath);91 }92 93 }94 public void setHeaders(String... headerKeyValues)95 {96 for (String headerKeyValue : headerKeyValues)97 {98 String key = headerKeyValue.split("=")[0];99 String value = headerKeyValue.split("=")[1];100 request.header(key, value);101 }102 }103 public void addUrlParameter(String key, String value)104 {105 if (value != null)106 {107 request.queryParam(key, value);108 }109 }110 public void addParameter(String key, String value)111 {112 request.param(key, value.replace(" ", "%20"));113 }114 public void addParameterIfNotNull(String key, String value)115 {116 if (value != null)117 {118 this.addParameter(key, value);119 }120 }121 122 public void addBodyParameter(String key, Object value)123 {124 if (bodyContent.length() != 0)125 {126 bodyContent.append("&");127 }128 bodyContent.append(key + "=" + value);129 }130 protected void addBodyParameterIfNotNull(String key, Object value)131 {132 if (value != null)133 {134 addBodyParameter(key, value);135 }136 }137 138 public void addCookie(String key, String value)139 {140 request.given().cookie(key, value);141 }142 143 public void addCookies(Map<String, String> cookies)144 {145 request.given().cookies(cookies);146 }147 public void replaceUrlPlaceholder(String placeholder, String value)148 {149 if (value != null)150 {151 methodPath = methodPath.replace("${" + placeholder + "}", value);152 }153 else154 {155 methodPath = methodPath.replace("${" + placeholder + "}", "");156 methodPath = StringUtils.removeEnd(methodPath, "/");157 }158 }159 public void expectResponseStatus(HttpResponseStatusType status)160 {161 request.expect().statusCode(status.getCode());162 request.expect().statusLine(Matchers.containsString(status.getMessage()));163 }164 public <T> void expectResponseContains(Matcher<T> key, Matcher<T> value)165 {166 request.expect().body(key, value);167 }168 public void expectValueByXpath(String xPath, String value)169 {170 request.expect().body(Matchers.hasXPath(xPath), Matchers.containsString(value));171 }172 public void expectValueByXpath(String xPath, String value1, String value2)173 {174 request.expect().body(Matchers.hasXPath(xPath), Matchers.anyOf(Matchers.containsString(value1), Matchers.containsString(value2)));175 }176 public <T> void expectResponseContains(Matcher<T> value)177 {178 request.expect().body(value);179 }180 public <T> void expectResponseContains(String key, Matcher<T> value)181 {182 request.expect().body(key, value);183 }184 public <T> void expectResponseContainsXpath(String xPath)185 {186 request.expect().body(HasXPath.hasXPath(xPath));187 }188 189 public Response callAPI()190 {191 if (bodyContent.length() != 0)192 request.body(bodyContent.toString());193 Response rs = null;194 PrintStream ps = null;195 if (logRequest || logResponse)196 {197 ps = new PrintStream(new LoggingOutputStream(LOGGER, Level.INFO));198 }199 if (logRequest)200 request.filter(new RequestLoggingFilter(ps));201 if (logResponse)202 request.filter(new ResponseLoggingFilter(ps));203 try204 {205 rs = HttpClient.send(request, methodPath, methodType);206 } finally207 {208 if (ps != null)209 ps.close();210 }211 return rs;212 }213 214 /**215 * @deprecated use {@link #callAPI()} instead. 216 * 217 * @return String218 */219 @Deprecated220 public String call()221 {222 Response response = callAPI();223 return response != null ? response.asString() : null;224 }225 226 public void expectInResponse(Matcher<?> matcher)227 {228 request.expect().body(matcher);229 }230 231 public void expectInResponse(String locator, Matcher<?> value)232 {233 request.expect().body(locator, value);234 }235 public String getMethodPath()236 {237 return methodPath;238 }239 public void setMethodPath(String methodPath)240 {241 RestAssured.reset();242 this.methodPath = methodPath;243 }244 public void setBodyContent(String content)245 {246 this.bodyContent = new StringBuilder(content);247 }248 249 public RequestSpecification getRequest()250 {251 return request;252 }253 public void setLogRequest(boolean logRequest)254 {255 this.logRequest = logRequest;256 }257 public void setLogResponse(boolean logResponse)258 {259 this.logResponse = logResponse;260 }261 public void ignoreSSLCerts()262 {263 SSLContext sslContext = null;264 try265 {266 sslContext = SSLContext.getInstance("TLS");267 } catch (NoSuchAlgorithmException e)268 {269 throw new RuntimeException(e);270 }271 TrustManager[] trustManagerArray = { new NullX509TrustManager() };272 try273 {274 sslContext.init(null, trustManagerArray, null);275 } catch (KeyManagementException e)276 {277 throw new RuntimeException(e);278 }279 SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, new NullHostnameVerifier());280 SSLConfig sslConfig = new SSLConfig();281 sslConfig = sslConfig.sslSocketFactory(socketFactory);282 sslConfig = sslConfig.x509HostnameVerifier(new NullHostnameVerifier());283 RestAssuredConfig cfg = new RestAssuredConfig();284 cfg = cfg.sslConfig(sslConfig);285 request = request.config(cfg);286 }287 public void setSSLContext(SSLContext sslContext)288 {289 SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext);290 SSLConfig sslConfig = new SSLConfig();291 sslConfig = sslConfig.sslSocketFactory(socketFactory);292 RestAssuredConfig cfg = new RestAssuredConfig();293 cfg = cfg.sslConfig(sslConfig);294 request = request.config(cfg);295 }296 public void setDefaultTLSSupport()...

Full Screen

Full Screen

NullHostnameVerifier

Using AI Code Generation

copy

Full Screen

1 SSLContext sslContext = SSLContexts.custom()2 .loadTrustMaterial(null, new TrustSelfSignedStrategy())3 .build();4 SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);5 CloseableHttpClient httpClient = HttpClients.custom()6 .setSSLSocketFactory(sslsf)7 .build();8 HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();9 requestFactory.setHttpClient(httpClient);10 RestTemplate restTemplate = new RestTemplate(requestFactory);11 HttpHeaders headers = new HttpHeaders();12 headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));13 HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);14 ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);15RestTemplate restTemplate = new RestTemplate();16 restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory() {17 protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {18 SSLContext sslContext;19 try {20 sslContext = SSLContextBuilder.create().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();21 SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, new NullHostnameVerifier());22 HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory).build();23 HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);24 return requestFactory.getHttpContext();25 } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {26 e.printStackTrace();27 }28 return null;29 }30 });31RestTemplate restTemplate = new RestTemplate();32 restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory() {33 protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {34 SSLContext sslContext;35 try {36 sslContext = SSLContextBuilder.create().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();37 SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(ssl

Full Screen

Full Screen

NullHostnameVerifier

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;2import org.apache.http.conn.ssl.SSLSocketFactory;3import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;4import org.apache.http.conn.ssl.SSLSocketFactory;5import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;6import org.apache.http.conn.ssl.SSLSocketFactory;7import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;8import org.apache.http.conn.ssl.SSLSocketFactory;9import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;10import org.apache.http.conn.ssl.SSLSocketFactory;11import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;12import org.apache.http.conn.ssl.SSLSocketFactory;13import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;14import org.apache.http.conn.ssl.SSLSocketFactory;15import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;16import org.apache.http.conn.ssl.SSLSocketFactory;17import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;18import org.apache.http.conn.ssl.SSLSocketFactory;19import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;20import org.apache.http.conn.ssl.SSLSocketFactory;21import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;22import org.apache

Full Screen

Full Screen

NullHostnameVerifier

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo.api.ssl;2import com.qaprosoft.carina.core.foundation.api.ssl.NullHostnameVerifier;3import org.apache.http.conn.ssl.SSLConnectionSocketFactory;4public class MyNullHostnameVerifier extends NullHostnameVerifier {5 public SSLConnectionSocketFactory getSSLConnectionSocketFactory() {6 return super.getSSLConnectionSocketFactory();7 }8}9import com.qaprosoft.carina.core.foundation.api.ssl.SSLContextBuilder;10import com.qaprosoft.carina.demo.api.ssl.MyNullHostnameVerifier;11import org.apache.http.conn.ssl.SSLConnectionSocketFactory;12import org.apache.http.impl.client.CloseableHttpClient;13import org.apache.http.impl.client.HttpClients;14import org.testng.annotations.Test;15import javax.net.ssl.SSLContext;16import java.security.KeyManagementException;17import java.security

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Carina automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in NullHostnameVerifier

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful