How to use RestTemplate method of com.qaprosoft.appcenter.http.resttemplate.RestTemplateBuilder class

Best Carina code snippet using com.qaprosoft.appcenter.http.resttemplate.RestTemplateBuilder.RestTemplate

copy

Full Screen

...36import org.springframework.http.HttpMethod;37import org.springframework.http.RequestEntity;38import org.springframework.util.LinkedMultiValueMap;39import org.springframework.util.MultiValueMap;40import org.springframework.web.client.RestTemplate;41import org.springframework.web.util.UriComponents;42import org.springframework.web.util.UriComponentsBuilder;43import com.fasterxml.jackson.databind.JsonNode;44import com.qaprosoft.appcenter.http.resttemplate.RestTemplateBuilder;45import com.qaprosoft.carina.core.foundation.utils.Configuration;46import com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter;47/​**48 * Created by boyle on 8/​16/​17.49 */​50public class AppCenterManager {51 private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());52 53 protected RestTemplate restTemplate = RestTemplateBuilder.newInstance().withDisabledSslChecking().withSpecificJsonMessageConverter().build();54 private String ownerName;55 private String versionLong;56 private String versionShort;57 private static final String HOST_URL = "api.appcenter.ms";58 private static final String API_APPS = "/​v0.1/​apps";59 private static AppCenterManager instance = null;60 private AppCenterManager() {61 }62 public synchronized static AppCenterManager getInstance() {63 if (instance == null) {64 instance = new AppCenterManager();65 }66 return instance;67 }...

Full Screen

Full Screen
copy

Full Screen

...29import org.springframework.http.converter.HttpMessageConverter;30import org.springframework.http.converter.StringHttpMessageConverter;31import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;32import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;33import org.springframework.web.client.RestTemplate;34import com.fasterxml.jackson.databind.DeserializationFeature;35import com.google.common.base.Predicate;36import com.google.common.collect.Iterables;37import com.google.common.collect.Lists;38import com.qaprosoft.appcenter.http.resttemplate.ssl.DisabledSslClientHttpRequestFactory;39/​**40 * Created by mk on 6/​30/​15.41 */​42public class RestTemplateBuilder {43 protected RestTemplate restTemplate = new RestTemplate();44 protected List<HttpMessageConverter<?>> httpMessageConverters = new ArrayList<HttpMessageConverter<?>>();45 protected boolean isDisableSslChecking = false;46 protected boolean isUseDefaultJsonMessageConverter = true;47 protected boolean isUseBasicAuth = false;48 protected String basicAuthUsername;49 protected String basicAuthPassword;50 protected RestTemplateBuilder() {51 }52 public static RestTemplateBuilder newInstance() {53 return new RestTemplateBuilder();54 }55 public RestTemplateBuilder withMessageConverter(56 HttpMessageConverter<?> messageConverter) {57 this.httpMessageConverters.add(messageConverter);58 return this;59 }60 public RestTemplateBuilder withDisabledSslChecking() {61 this.isDisableSslChecking = true;62 return this;63 }64 public RestTemplateBuilder withSpecificJsonMessageConverter() {65 isUseDefaultJsonMessageConverter = false;66 AbstractHttpMessageConverter<?> jsonMessageConverter = new MappingJackson2HttpMessageConverter(67 Jackson2ObjectMapperBuilder68 .json()69 .featuresToEnable(70 DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,71 DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)72 .build());73 jsonMessageConverter.setSupportedMediaTypes(Lists.newArrayList(74 MediaType.TEXT_HTML, MediaType.TEXT_PLAIN,75 MediaType.APPLICATION_JSON));76 withMessageConverter(jsonMessageConverter);77 return this;78 }79 /​**80 * http:/​/​stackoverflow.com/​questions/​27603782/​java-spring-resttemplate-character-encoding81 * 82 * @return RestTemplateBuilder83 */​84 public RestTemplateBuilder withUtf8EncodingMessageConverter() {85 withMessageConverter(new StringHttpMessageConverter(Charset.forName("UTF-8")));86 return this;87 }88 public RestTemplateBuilder withBasicAuthentication(String username, String password) {89 isUseBasicAuth = true;90 basicAuthUsername = username;91 basicAuthPassword = password;92 return this;93 }94 public RestTemplate build() {95 if (!isUseDefaultJsonMessageConverter) {96 HttpMessageConverter<?> httpMessageConverter = Iterables.tryFind(97 restTemplate.getMessageConverters(),98 new Predicate<HttpMessageConverter<?>>() {99 @Override100 public boolean apply(HttpMessageConverter<?> input) {101 return input instanceof MappingJackson2HttpMessageConverter;102 }103 }).orNull();104 restTemplate.getMessageConverters().remove(httpMessageConverter);105 }106 restTemplate.getMessageConverters().addAll(httpMessageConverters);107 if (isDisableSslChecking) {108 restTemplate...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Handle Multiple Windows In Selenium Python

Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.

Top 22 Selenium Automation Testing Blogs To Look Out In 2020

If you are a web tester then somewhere down the road you will have to come across Selenium, an open-source test automation framework that has been on boom ever since its launch in 2004.

11 Best Automated UI Testing Tools In 2022

The web development industry is growing, and many Best Automated UI Testing Tools are available to test your web-based project to ensure it is bug-free and easily accessible for every user. These tools help you test your web project and make it fully compatible with user-end requirements and needs.

Automated App Testing Using Appium With TestNG [Tutorial]

In recent times, many web applications have been ported to mobile platforms, and mobile applications are also created to support businesses. However, Android and iOS are the major platforms because many people use smartphones compared to desktops for accessing web applications.

How To Choose The Best JavaScript Unit Testing Frameworks

JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful