Search in sources :

Example 6 with WebServiceSecurityException

use of org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException in project open-smart-grid-platform by OSGP.

the class AdminNotificationService method doSendNotification.

private void doSendNotification(final NotificationType notificationType, final String organisationIdentification, final String deviceIdentification, final String correlationUid, final String result, final String message) {
    final Notification notification = new Notification();
    // Required fields.
    notification.setNotificationType(notificationType);
    notification.setDeviceIdentification(deviceIdentification);
    // Optional fields.
    if (StringUtils.hasText(correlationUid)) {
        notification.setCorrelationUid(correlationUid);
    }
    if (StringUtils.hasText(result)) {
        notification.setResult(OsgpResultType.valueOf(result));
    }
    if (StringUtils.hasText(message)) {
        notification.setMessage(message);
    }
    // Try to send notification and catch security exceptions.
    try {
        this.sendNotificationServiceClient.sendNotification(organisationIdentification, notification);
    } catch (final WebServiceSecurityException e) {
        LOGGER.error("Unable to send notification", e);
    }
}
Also used : Notification(org.opensmartgridplatform.adapter.ws.schema.core.notification.Notification) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException)

Example 7 with WebServiceSecurityException

use of org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException in project open-smart-grid-platform by OSGP.

the class CreateDeviceSteps method receivingAnUpdateDeviceRequest.

@When("^receiving an update device request")
public void receivingAnUpdateDeviceRequest(final Map<String, String> settings) {
    final UpdateDeviceRequest request = new UpdateDeviceRequest();
    String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformCommonDefaults.DEFAULT_DEVICE_IDENTIFICATION);
    // DeviceIdentification with only spaces
    if (deviceIdentification.matches("(?!\")\\s*(?=\")")) {
        deviceIdentification = deviceIdentification.replaceAll("\"", " ");
    }
    request.setDeviceIdentification(deviceIdentification);
    final Device device = this.createDevice(settings);
    request.setUpdatedDevice(device);
    try {
        ScenarioContext.current().put(PlatformKeys.RESPONSE, this.client.updateDevice(request));
    } catch (final WebServiceSecurityException | SoapFaultClientException ex) {
        ScenarioContext.current().put(PlatformKeys.RESPONSE, ex);
    }
}
Also used : UpdateDeviceRequest(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.UpdateDeviceRequest) Device(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.Device) SoapFaultClientException(org.springframework.ws.soap.client.SoapFaultClientException) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException) When(io.cucumber.java.en.When)

Example 8 with WebServiceSecurityException

use of org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException in project open-smart-grid-platform by OSGP.

the class NotificationWebServiceTemplateFactory method createKeyStore.

private KeyStore createKeyStore(final String type, final String location, final String password) throws WebServiceSecurityException {
    final KeyStoreFactoryBean keyStoreFactory = new KeyStoreFactoryBean();
    keyStoreFactory.setType(type);
    keyStoreFactory.setLocation(new FileSystemResource(location));
    keyStoreFactory.setPassword(password);
    try {
        keyStoreFactory.afterPropertiesSet();
        final KeyStore keyStore = keyStoreFactory.getObject();
        if ((keyStore == null) || (keyStore.size() == 0)) {
            throw new KeyStoreException("Key store is empty");
        }
        return keyStore;
    } catch (final GeneralSecurityException | IOException e) {
        LOGGER.error("Exception creating {} key store for file {}", type, location, e);
        throw new WebServiceSecurityException("Unable to create KeyStore", e);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) FileSystemResource(org.springframework.core.io.FileSystemResource) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) KeyStoreFactoryBean(org.springframework.ws.soap.security.support.KeyStoreFactoryBean) KeyStore(java.security.KeyStore) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException)

Example 9 with WebServiceSecurityException

use of org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException in project open-smart-grid-platform by OSGP.

the class AbstractNotificationServiceWs method doSendNotification.

protected void doSendNotification(final WebserviceTemplateFactory wsTemplateFactory, final String organisationIdentification, final String userName, final String notificationURL, final Object notification) {
    try {
        /*
       * Get a template for the organisation representing the OSGP
       * platform, on behalf of which the notification is sent to the
       * organisation identified by the organisationIdentification.
       */
        final WebServiceTemplate wsTemplate = wsTemplateFactory.getTemplate(this.notificationOrganisation, userName, notificationURL);
        wsTemplate.marshalSendAndReceive(notification);
    } catch (WebServiceSecurityException | WebServiceIOException | SoapFaultClientException e) {
        final String msg = String.format("error sending notification message org=%s, user=%s, to org=%s, notifyUrl=%s, errmsg=%s", this.notificationOrganisation, userName, organisationIdentification, notificationURL, e.getMessage());
        LOGGER.error(msg, e);
    }
}
Also used : SoapFaultClientException(org.springframework.ws.soap.client.SoapFaultClientException) WebServiceIOException(org.springframework.ws.client.WebServiceIOException) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException)

Example 10 with WebServiceSecurityException

use of org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException in project open-smart-grid-platform by OSGP.

the class UpdateDeviceSettingsSteps method receivingAnUpdateDeviceRequest.

@When("^receiving a device management update device request")
public void receivingAnUpdateDeviceRequest(final Map<String, String> settings) {
    final UpdateDeviceRequest request = new UpdateDeviceRequest();
    String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformCommonDefaults.DEFAULT_DEVICE_IDENTIFICATION);
    // DeviceIdentification with only spaces
    if (deviceIdentification.matches("(?!\")\\s*(?=\")")) {
        deviceIdentification = deviceIdentification.replaceAll("\"", " ");
    }
    final UpdatedDevice device = this.createUpdatedDevice(settings);
    request.setDeviceIdentification(deviceIdentification);
    request.setUpdatedDevice(device);
    try {
        ScenarioContext.current().put(PlatformKeys.RESPONSE, this.client.updateDevice(request));
    } catch (final WebServiceSecurityException | SoapFaultClientException ex) {
        ScenarioContext.current().put(PlatformKeys.RESPONSE, ex);
    }
}
Also used : UpdateDeviceRequest(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceRequest) UpdatedDevice(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdatedDevice) SoapFaultClientException(org.springframework.ws.soap.client.SoapFaultClientException) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException) When(io.cucumber.java.en.When)

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