Created
February 12, 2016 13:33
-
-
Save jforge/f0f6d473a37371d2498b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // First write a custom class of org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor : | |
| package com.myorg.proid.sample; | |
| import static org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; | |
| import java.security.KeyManagementException; | |
| import java.security.KeyStoreException; | |
| import java.security.NoSuchAlgorithmException; | |
| import java.security.UnrecoverableKeyException; | |
| import java.security.cert.X509Certificate; | |
| import org.apache.http.client.HttpClient; | |
| import org.apache.http.conn.scheme.Scheme; | |
| import org.apache.http.conn.ssl.SSLSocketFactory; | |
| import org.apache.http.conn.ssl.TrustStrategy; | |
| import org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor; | |
| public class CustomHttpComponentsHttpInvokerRequestExecutor extends | |
| HttpComponentsHttpInvokerRequestExecutor { | |
| public CustomHttpComponentsHttpInvokerRequestExecutor() { | |
| skipSecurityChecking(); | |
| } | |
| @SuppressWarnings("deprecation") | |
| private void skipSecurityChecking() { | |
| // HttpClient from super class. | |
| HttpClient httpClient = getHttpClient(); | |
| TrustStrategy trustStrategy = new TrustStrategy() { | |
| @Override | |
| public boolean isTrusted(X509Certificate[] certificate, | |
| String authType) { | |
| return true; | |
| } | |
| }; | |
| try { | |
| httpClient | |
| .getConnectionManager() | |
| .getSchemeRegistry() | |
| .register( | |
| new Scheme("https", 80, new SSLSocketFactory( | |
| trustStrategy, | |
| ALLOW_ALL_HOSTNAME_VERIFIER))); | |
| } catch (KeyManagementException e) { | |
| e.printStackTrace(); | |
| } catch (UnrecoverableKeyException e) { | |
| e.printStackTrace(); | |
| } catch (NoSuchAlgorithmException e) { | |
| e.printStackTrace(); | |
| } catch (KeyStoreException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| // and refer this class in your xml file instead of org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor as | |
| <bean id="userService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> | |
| <property name="serviceUrl" value="https://${backend.host}/backend-ws/remoting/UserService"/> | |
| <property name="serviceInterface" value="com...service.UserService"/> | |
| <property name="httpInvokerRequestExecutor"> | |
| <bean class="com.myorg.proid.sample.CustomHttpComponentsHttpInvokerRequestExecutor" /> | |
| </property> | |
| </bean> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment