use of org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException in project open-smart-grid-platform by OSGP.
the class GetAdministrativeStatus method theAdministrativeStatusShouldBeReturnedForDevices.
@Then("^the administrative status should be returned for devices$")
public void theAdministrativeStatusShouldBeReturnedForDevices(final List<String> deviceIdentifications) throws Throwable {
@SuppressWarnings("unchecked") final Map<String, String> correlationUidMap = (Map<String, String>) ScenarioContext.current().get(CORRELATION_UID_BY_DEVICE_IDENTIFICATION);
final CountDownLatch responseCountDownLatch = new CountDownLatch(deviceIdentifications.size());
final List<String> responseNotifications = Collections.synchronizedList(new ArrayList<>());
for (final String deviceIdentification : deviceIdentifications) {
new Thread(() -> {
final GetAdministrativeStatusAsyncRequest getAdministrativeStatusAsyncRequest;
synchronized (correlationUidMap) {
ScenarioContext.current().put(PlatformKeys.KEY_DEVICE_IDENTIFICATION, deviceIdentification);
ScenarioContext.current().put(PlatformKeys.KEY_CORRELATION_UID, Objects.requireNonNull(correlationUidMap.get(deviceIdentification), "Correlation UID for request with device identification " + deviceIdentification + " must be available"));
getAdministrativeStatusAsyncRequest = GetAdministrativeStatusRequestFactory.fromScenarioContext();
}
try {
final GetAdministrativeStatusResponse getAdministrativeStatusResponse = GetAdministrativeStatus.this.smartMeteringConfigurationClient.retrieveGetAdministrativeStatusResponse(getAdministrativeStatusAsyncRequest);
final Instant receivedAt = Instant.now();
responseNotifications.add(String.format("%s - administrative status %s for device %s", receivedAt, getAdministrativeStatusResponse.getEnabled(), deviceIdentification));
} catch (final WebServiceSecurityException e) {
e.printStackTrace();
} finally {
responseCountDownLatch.countDown();
}
}).start();
}
responseCountDownLatch.await();
LOGGER.info("Received administrative status responses:{}", responseNotifications.stream().sorted().collect(Collectors.joining(System.lineSeparator() + " - ", System.lineSeparator() + " - ", System.lineSeparator())));
}
use of org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException in project open-smart-grid-platform by OSGP.
the class FindScheduledTasksSteps method whenReceivingAFindScheduledTasksRequests.
@When("receiving a find scheduled tasks request")
public void whenReceivingAFindScheduledTasksRequests() {
final FindScheduledTasksRequest request = new FindScheduledTasksRequest();
try {
final FindScheduledTasksResponse response = this.client.findScheduledTasks(request);
ScenarioContext.current().put(RESPONSE, response);
} catch (final WebServiceSecurityException e) {
ScenarioContext.current().put(RESPONSE, e);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException in project open-smart-grid-platform by OSGP.
the class UpdateDeviceCdmaSettingsSteps method thePlatformShouldBufferAnUpdateDeviceCdmaSettingsResponseMessage.
@Then("^the platform should buffer an update device CDMA settings response message$")
public void thePlatformShouldBufferAnUpdateDeviceCdmaSettingsResponseMessage(final Map<String, String> responseParameters) {
final String deviceIdentification = (String) ScenarioContext.current().get(PlatformKeys.KEY_DEVICE_IDENTIFICATION);
final String correlationUid = (String) ScenarioContext.current().get(PlatformKeys.KEY_CORRELATION_UID);
final OsgpResultType expectedResult = Enum.valueOf(OsgpResultType.class, responseParameters.get(PlatformKeys.KEY_RESULT));
LOGGER.info("THEN: Buffer UpdateCdmaSettingsResponse [correlationUid={}, deviceIdentification={}, result={}]", correlationUid, deviceIdentification, expectedResult);
final UpdateDeviceCdmaSettingsAsyncRequest request = new UpdateDeviceCdmaSettingsAsyncRequest();
request.setDeviceId(deviceIdentification);
request.setCorrelationUid(correlationUid);
Wait.until(() -> {
UpdateDeviceCdmaSettingsResponse response = null;
try {
response = this.client.getUpdateDeviceCdmaSettingsResponse(request);
} catch (final WebServiceSecurityException e) {
// do nothing
}
assertThat(response).isNotNull();
assertThat(response.getResult()).isEqualTo(expectedResult);
});
}
use of org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException in project open-smart-grid-platform by OSGP.
the class NotificationWebServiceTemplateFactory method createSslConnectionSocketFactory.
private LayeredConnectionSocketFactory createSslConnectionSocketFactory(final NotificationWebServiceConfiguration config) throws WebServiceSecurityException {
final SSLContextBuilder sslContextBuilder = SSLContexts.custom();
this.loadKeyMaterial(sslContextBuilder, config);
this.loadTrustMaterial(sslContextBuilder, config);
try {
return new SSLConnectionSocketFactory(sslContextBuilder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
} catch (final GeneralSecurityException e) {
LOGGER.error("Exception creating SSL connection socket factory", e);
throw new WebServiceSecurityException("Unable to build SSL context", e);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException in project open-smart-grid-platform by OSGP.
the class DefaultWebServiceTemplateFactory method webServiceMessageSender.
private HttpComponentsMessageSender webServiceMessageSender(final String keystore) throws WebServiceSecurityException {
final HttpClientBuilder clientbuilder = HttpClientBuilder.create();
if (this.isSecurityEnabled) {
try {
clientbuilder.setSSLSocketFactory(this.getSSLConnectionSocketFactory(keystore));
} catch (GeneralSecurityException | IOException e) {
LOGGER.error("Webservice exception occurred: Certificate not available", e);
throw new WebServiceSecurityException("Certificate not available", e);
}
}
clientbuilder.setMaxConnPerRoute(this.maxConnectionsPerRoute);
clientbuilder.setMaxConnTotal(this.maxConnectionsTotal);
// Add intercepter to prevent issue with duplicate headers.
// See also:
// http://forum.spring.io/forum/spring-projects/web-services/118857-spring-ws-2-1-4-0-httpclient-proxy-content-length-header-already-present
clientbuilder.addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor());
final RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(this.connectionTimeout).build();
clientbuilder.setDefaultRequestConfig(requestConfig);
return new HttpComponentsMessageSender(clientbuilder.build());
}
Aggregations