2

I'm trying to understand how to send https post request with post data using spring web or and other spring tools.

so far I've been using httpclient but i'm trying to convert to spring :)

the https post request should ignore self signed certificate.

please provide an example on how it can be done.

thank you

ufk
  • 30,912
  • 70
  • 235
  • 386

1 Answers1

3

I use Spring Integration to send http POST and GET http://static.springsource.org/spring-integration/reference/html/http.html The request-factory bean need to be configured to allow self-signed certificates. I use the following wiring to declare apacheHttpsRequestFactory to be used by http Spring Integration endpoints.

The httpClient bean can be injected to other Spring Beans and used to send http requests:

@Autowired
private HttpClient httpClient;

Here is the fragment of spring-intefration-context.xml:

<!-- HTTPS connection to trust self signed certificates -->
<bean id="sslSocketFactory" class="org.apache.http.conn.ssl.SSLSocketFactory">
    <constructor-arg name="trustStrategy">
        <bean class="org.apache.http.conn.ssl.TrustSelfSignedStrategy" />
    </constructor-arg>
    <constructor-arg name="hostnameVerifier">
        <bean class="org.apache.http.conn.ssl.AllowAllHostnameVerifier" />
    </constructor-arg>
</bean>
<bean id="httpsSchemaRegistry" class="org.apache.http.conn.scheme.SchemeRegistry">
    <property name="items">
        <map>
            <entry key="https">
                <bean class="org.apache.http.conn.scheme.Scheme">

                    <constructor-arg value="https" />
                    <constructor-arg value="443" />
                    <constructor-arg ref="sslSocketFactory" />
                </bean>
            </entry>
        </map>
    </property>
</bean>
<bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient">
    <constructor-arg>
        <bean class="org.apache.http.impl.conn.PoolingClientConnectionManager">
            <constructor-arg ref="httpsSchemaRegistry" />
        </bean>
    </constructor-arg>
</bean>
<bean id="apacheHttpsRequestFactory"
    class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
    <constructor-arg ref="httpClient" />