-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
145 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
22 changes: 22 additions & 0 deletions
22
lib/src/main/java/uk/gov/di/ipv/cri/kbv/api/security/CXFConfigurator.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package uk.gov.di.ipv.cri.kbv.api.security; | ||
|
||
import org.apache.cxf.Bus; | ||
import org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduitFactory; | ||
|
||
import java.net.http.HttpClient; | ||
|
||
public class CXFConfigurator { | ||
private final TelemetryHttpClientFactory telemetryHttpClientFactory; | ||
|
||
public CXFConfigurator(TelemetryHttpClientFactory telemetryHttpClientFactory) { | ||
this.telemetryHttpClientFactory = telemetryHttpClientFactory; | ||
} | ||
|
||
public void configure(Bus bus) { | ||
HttpClient instrumentedHttpClient = telemetryHttpClientFactory.createHttpClient(); | ||
|
||
bus.setExtension( | ||
new CustomAsyncHttpConduitFactory(instrumentedHttpClient, bus), | ||
AsyncHTTPConduitFactory.class); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
lib/src/main/java/uk/gov/di/ipv/cri/kbv/api/security/CustomAsyncHttpConduitFactory.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package uk.gov.di.ipv.cri.kbv.api.security; | ||
|
||
import org.apache.cxf.Bus; | ||
import org.apache.cxf.service.model.EndpointInfo; | ||
import org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit; | ||
import org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduitFactory; | ||
import org.apache.cxf.ws.addressing.EndpointReferenceType; | ||
|
||
import java.io.IOException; | ||
import java.net.http.HttpClient; | ||
|
||
public class CustomAsyncHttpConduitFactory extends AsyncHTTPConduitFactory { | ||
private final HttpClient httpClient; | ||
|
||
public CustomAsyncHttpConduitFactory(HttpClient httpClient, Bus bus) { | ||
super(bus); | ||
this.httpClient = httpClient; | ||
} | ||
|
||
@Override | ||
public AsyncHTTPConduit createConduit( | ||
Bus bus, EndpointInfo endpointInfo, EndpointReferenceType target) throws IOException { | ||
return new AsyncHTTPConduit(bus, endpointInfo, target, this) { | ||
protected HttpClient getHttpClient() { | ||
return httpClient; | ||
} | ||
}; | ||
} | ||
} |
This file contains 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
This file contains 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
15 changes: 15 additions & 0 deletions
15
lib/src/main/java/uk/gov/di/ipv/cri/kbv/api/security/TelemetryHttpClientFactory.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package uk.gov.di.ipv.cri.kbv.api.security; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.instrumentation.httpclient.JavaHttpClientTelemetry; | ||
|
||
import java.net.http.HttpClient; | ||
|
||
public class TelemetryHttpClientFactory { | ||
public HttpClient createHttpClient() { | ||
return JavaHttpClientTelemetry.builder(GlobalOpenTelemetry.get()) | ||
.build() | ||
.newHttpClient( | ||
HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build()); | ||
} | ||
} |
This file contains 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
33 changes: 33 additions & 0 deletions
33
lib/src/test/java/uk/gov/di/ipv/cri/kbv/api/security/CustomAsyncHttpConduitFactoryTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package uk.gov.di.ipv.cri.kbv.api.security; | ||
|
||
import org.apache.cxf.Bus; | ||
import org.apache.cxf.service.model.EndpointInfo; | ||
import org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit; | ||
import org.apache.cxf.ws.addressing.EndpointReferenceType; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.io.IOException; | ||
import java.net.http.HttpClient; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class CustomAsyncHttpConduitFactoryTest { | ||
@Test | ||
void shouldReturnAsyncHTTPConduitWithCustomHttpClient() throws IOException { | ||
HttpClient mockHttpClient = mock(HttpClient.class); | ||
Bus mockBus = mock(Bus.class); | ||
EndpointInfo mockEndpointInfo = mock(EndpointInfo.class); | ||
EndpointReferenceType mockTarget = mock(EndpointReferenceType.class); | ||
|
||
CustomAsyncHttpConduitFactory factory = | ||
new CustomAsyncHttpConduitFactory(mockHttpClient, mockBus); | ||
|
||
AsyncHTTPConduit conduit = factory.createConduit(mockBus, mockEndpointInfo, mockTarget); | ||
|
||
assertNotNull(conduit, "The AsyncHTTPConduit should not be null"); | ||
} | ||
} |
This file contains 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
This file contains 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