Demo entry 6624166

test

   

Submitted by anonymous on Jun 13, 2017 at 22:08
Language: Java. Code size: 2.8 kB.

package guiche.whitelabel;

import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;

import guiche.whitelabel.configuration.rest.ssl.SSLIgnoreRequestFactory;
import guiche.whitelabel.configuration.rest.handler.error.RestTemplateErrorHandler;
import guiche.whitelabel.configuration.rest.handler.interceptor.RestTemplateLogInterceptor;
import guiche.whitelabel.configuration.rest.handler.interceptor.XDeviceInterceptor;
import guiche.whitelabel.configuration.rest.ssl.NullHostnameVerifier;

@SpringBootApplication
@EnableAutoConfiguration
@ComponentScans( { @ComponentScan( "guiche.api.commons" ), @ComponentScan( "guiche.whitelabel" ) } )
public class WhitelabelApplication extends SpringBootServletInitializer
{
    @Value( "${guiche.virtual.api.url}" )
    private String restDomain;

    @Autowired
    private RestTemplateLogInterceptor restTemplateLogInterceptor;

    @Autowired
    private XDeviceInterceptor xDeviceInterceptor;

    @Override
    protected SpringApplicationBuilder configure( SpringApplicationBuilder application ) {
        return application.sources( WhitelabelApplication.class );
    }

    public static void main( String[] args ) {
        SpringApplication.run( WhitelabelApplication.class, args );
    }

    @Bean
    public RestTemplate guicheRestTemplate( RestTemplateBuilder builder ) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
        RestTemplate template = builder.rootUri( restDomain )
                .requestFactory( new SSLIgnoreRequestFactory( new NullHostnameVerifier()) )
                .errorHandler( new RestTemplateErrorHandler() ).build();

        List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
        interceptors.add( restTemplateLogInterceptor );
        interceptors.add( xDeviceInterceptor );
        template.setInterceptors( interceptors );
        return template;
    }
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).