use of org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException in project open-smart-grid-platform by OSGP.
the class DetailSoapFaultMappingExceptionResolver method customizeFault.
@Override
protected void customizeFault(final Object endpoint, final Exception ex, final SoapFault fault) {
final SoapFaultDetail detail = fault.addFaultDetail();
final Result result = detail.getResult();
FunctionalException fex = null;
TechnicalException tex = null;
ConnectionFailureException cex = null;
if (ex instanceof FunctionalException) {
fex = (FunctionalException) ex;
} else if (ex instanceof TechnicalException) {
tex = (TechnicalException) ex;
} else if (ex instanceof ConnectionFailureException) {
cex = (ConnectionFailureException) ex;
}
if (fex != null) {
try {
this.marshalFunctionalException(fex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Functional Exception", e);
}
}
if (tex != null) {
try {
this.marshalTechnicalException(tex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Technical Exception", e);
}
}
if (cex != null) {
try {
this.marshalConnectionFailureException(cex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Connection Failure Exception", e);
}
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException in project open-smart-grid-platform by OSGP.
the class DetailSoapFaultMappingExceptionResolver method customizeFault.
@Override
protected void customizeFault(final Object endpoint, final Exception ex, final SoapFault fault) {
final SoapFaultDetail detail = fault.addFaultDetail();
final Result result = detail.getResult();
FunctionalException fex = null;
TechnicalException tex = null;
ConnectionFailureException cex = null;
if (ex instanceof FunctionalException) {
fex = (FunctionalException) ex;
} else if (ex instanceof TechnicalException) {
tex = (TechnicalException) ex;
} else if (ex instanceof ConnectionFailureException) {
cex = (ConnectionFailureException) ex;
}
if (fex != null) {
try {
this.marshalFunctionalException(fex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Functional Exception", e);
}
}
if (tex != null) {
try {
this.marshalTechnicalException(tex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Technical Exception", e);
}
}
if (cex != null) {
try {
this.marshalConnectionFailureException(cex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Connection Failure Exception", e);
}
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException in project open-smart-grid-platform by OSGP.
the class DetailSoapFaultMappingExceptionResolver method customizeFault.
@Override
protected void customizeFault(final Object endpoint, final Exception ex, final SoapFault fault) {
final SoapFaultDetail detail = fault.addFaultDetail();
final Result result = detail.getResult();
FunctionalException fex = null;
TechnicalException tex = null;
ConnectionFailureException cex = null;
if (ex instanceof FunctionalException) {
fex = (FunctionalException) ex;
} else if (ex instanceof TechnicalException) {
tex = (TechnicalException) ex;
} else if (ex instanceof ConnectionFailureException) {
cex = (ConnectionFailureException) ex;
}
if (fex != null) {
try {
this.marshalFunctionalException(fex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Functional Exception", e);
}
}
if (tex != null) {
try {
this.marshalTechnicalException(tex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Technical Exception", e);
}
}
if (cex != null) {
try {
this.marshalConnectionFailureException(cex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Connection Failure Exception", e);
}
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException in project open-smart-grid-platform by OSGP.
the class Iec60870Client method connect.
@Override
public ClientConnection connect(final ConnectionParameters connectionParameters, final ConnectionEventListener asduListener) throws ConnectionFailureException {
final InetAddress address = this.convertIpAddress(connectionParameters.getIpAddress());
final String deviceIdentification = connectionParameters.getDeviceIdentification();
final int port = connectionParameters.getPort() == null ? IEC60870_DEFAULT_PORT : connectionParameters.getPort();
final ClientConnectionBuilder clientConnectionBuilder = new ClientConnectionBuilder(address).setPort(port).setConnectionTimeout(this.connectionTimeout);
try {
LOGGER.info("Connecting to device: {}...", deviceIdentification);
final Connection connection = clientConnectionBuilder.build();
connection.startDataTransfer(asduListener);
LOGGER.info("Connected to device: {}", deviceIdentification);
return new DeviceConnection(connection, connectionParameters);
} catch (final IOException e) {
final String errorMessage = "Unable to connect to remote host: " + connectionParameters.getIpAddress();
LOGGER.error(errorMessage, e);
throw new ConnectionFailureException(ComponentType.PROTOCOL_IEC60870, errorMessage);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException in project open-smart-grid-platform by OSGP.
the class OslpDeviceService method handleException.
protected void handleException(final Throwable t, final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) {
Metrics.counter(this.failedMessagesMetric).increment();
final DeviceResponse deviceResponse = new DeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), deviceRequest.getMessagePriority());
if (t instanceof IOException) {
// Replace t by an OSGP Exception
final ConnectionFailureException ex = new ConnectionFailureException(ComponentType.PROTOCOL_OSLP, "Connection failure");
deviceResponseHandler.handleException(ex, deviceResponse);
} else {
deviceResponseHandler.handleException(t, deviceResponse);
}
}
Aggregations