@@ -45,11 +45,10 @@ import org.springframework.ws.client.support.interceptor.ClientInterceptor;
|
||||
public class HttpComponents5ClientFactory implements FactoryBean<CloseableHttpClient> {
|
||||
|
||||
/**
|
||||
* AuthScope to match any Host.
|
||||
* {@link AuthScope} to match any Host.
|
||||
* <p>
|
||||
* <b>HEADS-UP</b>: ANY has been removed from {@link AuthScope} since httpcomponents version 5.x. It has been
|
||||
* redefined here to ease migration from httpcomponents 4. The associated functionality might be removed in a future
|
||||
* version of apache httpcomponents. Consider using a {@link ClientInterceptor} to implement http client agnostic
|
||||
* <b>NOTE</b>: {@code ANY} was removed from {@link AuthScope} in HttpComponents 5.0. This value object will easy
|
||||
* migration from HttpComponents 4. Consider using a {@link ClientInterceptor} to implement http client agnostic
|
||||
* preemptive basic auth.
|
||||
*
|
||||
* @see AuthScope#AuthScope(String, String, int, String, String)
|
||||
@@ -91,7 +90,7 @@ public class HttpComponents5ClientFactory implements FactoryBean<CloseableHttpCl
|
||||
/**
|
||||
* Sets the authentication scope to be used. Only used when the {@code credentials} property has been set.
|
||||
* <p>
|
||||
* By default, the {@link #ANY} is used.
|
||||
* By default, {@link #ANY} is used.
|
||||
*
|
||||
* @see #setCredentials(Credentials)
|
||||
*/
|
||||
|
||||
@@ -1,33 +1,54 @@
|
||||
/*
|
||||
* Copyright 2005-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.transport.http;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class HttpComponents5MessageSenderTest {
|
||||
|
||||
@Test
|
||||
void afterPropertiesSet_createHttpClient() throws Exception {
|
||||
void afterPropertiesSetShouldProperlyInitializeHttpClient() throws Exception {
|
||||
|
||||
HttpComponents5MessageSender messageSender = new HttpComponents5MessageSender();
|
||||
assertThat(messageSender.getHttpClient()).isNull();
|
||||
|
||||
Duration timeout = Duration.ofSeconds(1);
|
||||
assertThatCode(() -> messageSender.setConnectionTimeout(timeout)).doesNotThrowAnyException();
|
||||
|
||||
messageSender.afterPropertiesSet();
|
||||
assertThat(messageSender.getHttpClient()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void afterPropertiesSet_httpClientAlreadySet() throws Exception {
|
||||
void afterPropertiesSetShouldUseAlreadyProvidedHttpClientIfAvailable() throws Exception {
|
||||
|
||||
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
||||
HttpComponents5MessageSender messageSender = new HttpComponents5MessageSender(httpClient);
|
||||
|
||||
Duration timeout = Duration.ofSeconds(1);
|
||||
assertThatCode(() -> messageSender.setConnectionTimeout(timeout)).isInstanceOf(IllegalStateException.class);
|
||||
|
||||
messageSender.afterPropertiesSet();
|
||||
assertThat(messageSender.getHttpClient()).isSameAs(httpClient);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user