Search in sources :

Example 1 with WebServiceSecurityException

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())));
}
Also used : Instant(org.joda.time.Instant) CountDownLatch(java.util.concurrent.CountDownLatch) HashMap(java.util.HashMap) Map(java.util.Map) GetAdministrativeStatusAsyncRequest(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetAdministrativeStatusAsyncRequest) GetAdministrativeStatusResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetAdministrativeStatusResponse) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException) Then(io.cucumber.java.en.Then)

Example 2 with WebServiceSecurityException

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);
    }
}
Also used : FindScheduledTasksResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindScheduledTasksResponse) FindScheduledTasksRequest(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.FindScheduledTasksRequest) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException) When(io.cucumber.java.en.When)

Example 3 with WebServiceSecurityException

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);
    });
}
Also used : UpdateDeviceCdmaSettingsAsyncRequest(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceCdmaSettingsAsyncRequest) UpdateDeviceCdmaSettingsResponse(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceCdmaSettingsResponse) OsgpResultType(org.opensmartgridplatform.adapter.ws.schema.core.common.OsgpResultType) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException) Then(io.cucumber.java.en.Then)

Example 4 with WebServiceSecurityException

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);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) SSLContextBuilder(org.apache.http.conn.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException)

Example 5 with WebServiceSecurityException

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());
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) GeneralSecurityException(java.security.GeneralSecurityException) HttpComponentsMessageSender(org.springframework.ws.transport.http.HttpComponentsMessageSender) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) IOException(java.io.IOException) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException)

Aggregations

WebServiceSecurityException (org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException)11 When (io.cucumber.java.en.When)3 GeneralSecurityException (java.security.GeneralSecurityException)3 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)3 SoapFaultClientException (org.springframework.ws.soap.client.SoapFaultClientException)3 Then (io.cucumber.java.en.Then)2 IOException (java.io.IOException)2 Notification (org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification)2 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)1 SSLContextBuilder (org.apache.http.conn.ssl.SSLContextBuilder)1 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)1 Instant (org.joda.time.Instant)1 OsgpResultType (org.opensmartgridplatform.adapter.ws.schema.core.common.OsgpResultType)1 Device (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.Device)1