use of org.springframework.remoting.RemoteConnectFailureException in project spring-framework by spring-projects.
the class JndiRmiClientInterceptor method invoke.
/**
* Fetches an RMI stub and delegates to {@link #doInvoke}.
* If configured to refresh on connect failure, it will call
* {@link #refreshAndRetry} on corresponding RMI exceptions.
* @see #getStub
* @see #doInvoke
* @see #refreshAndRetry
* @see java.rmi.ConnectException
* @see java.rmi.ConnectIOException
* @see java.rmi.NoSuchObjectException
*/
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
Object stub;
try {
stub = getStub();
} catch (NamingException ex) {
throw new RemoteLookupFailureException("JNDI lookup for RMI service [" + getJndiName() + "] failed", ex);
}
Context ctx = (this.exposeAccessContext ? getJndiTemplate().getContext() : null);
try {
return doInvoke(invocation, stub);
} catch (RemoteConnectFailureException ex) {
return handleRemoteConnectFailure(invocation, ex);
} catch (RemoteException ex) {
if (isConnectFailure(ex)) {
return handleRemoteConnectFailure(invocation, ex);
} else {
throw ex;
}
} finally {
getJndiTemplate().releaseContext(ctx);
}
}
use of org.springframework.remoting.RemoteConnectFailureException in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method getLastKnownRecordData.
private VehicleLastKnownRecord getLastKnownRecordData(String vehicleId) {
List<VehicleLastKnownRecord> lastKnownRecords = new ArrayList<VehicleLastKnownRecord>();
String operationalAPIHost = null;
try {
operationalAPIHost = configurationService.getConfigurationValueAsString("operational-api.host", DEFAULT_OPERATIONAL_API_HOST);
} catch (RemoteConnectFailureException e) {
log.error("Failed retrieving operational API host from TDM. Setting to default value");
operationalAPIHost = DEFAULT_OPERATIONAL_API_HOST;
}
String url = buildURL(operationalAPIHost, "/record/last-known/vehicle/" + vehicleId);
log.info("making request for : " + url);
String lastknownContent = remoteConnectionService.getContent(url);
lastknownContent = lastknownContent.replace(System.getProperty("line.separator"), "");
String json = extractJsonArrayString(lastknownContent);
try {
JSONArray lastKnownContentArray = new JSONArray("[" + json + "]");
for (int i = 0; i < lastKnownContentArray.length(); i++) {
VehicleLastKnownRecord lastKnownRecord = convertToObject(lastKnownContentArray.getString(i), VehicleLastKnownRecord.class);
// lastknownrecord can be null if no data is returned by web service call
if (lastKnownRecord != null) {
lastKnownRecords.add(lastKnownRecord);
}
}
} catch (JSONException e) {
log.error("Error parsing json content : " + e);
e.printStackTrace();
}
if (!lastKnownRecords.isEmpty())
return lastKnownRecords.get(0);
return null;
}
use of org.springframework.remoting.RemoteConnectFailureException in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method getLastKnownRecordData.
private List<VehicleLastKnownRecord> getLastKnownRecordData() {
List<VehicleLastKnownRecord> lastKnownRecords = new ArrayList<VehicleLastKnownRecord>();
String operationalAPIHost = null;
try {
operationalAPIHost = configurationService.getConfigurationValueAsString("operational-api.host", DEFAULT_OPERATIONAL_API_HOST);
} catch (RemoteConnectFailureException e) {
log.error("Failed retrieving operational API host from TDM. Setting to default value");
operationalAPIHost = DEFAULT_OPERATIONAL_API_HOST;
}
String url = buildURL(operationalAPIHost, "/record/last-known/list");
log.debug("making request for : " + url);
String lastknownContent = remoteConnectionService.getContent(url);
lastknownContent = lastknownContent.replace(System.getProperty("line.separator"), "");
String json = extractJsonArrayString(lastknownContent);
try {
JSONArray lastKnownContentArray = new JSONArray("[" + json + "]");
for (int i = 0; i < lastKnownContentArray.length(); i++) {
VehicleLastKnownRecord lastKnownRecord = convertToObject(lastKnownContentArray.getString(i), VehicleLastKnownRecord.class);
// lastknownrecord can be null if no data is returned by web service call
if (lastKnownRecord != null) {
lastKnownRecords.add(lastKnownRecord);
}
}
} catch (JSONException e) {
log.error("Error parsing json content : " + e);
e.printStackTrace();
}
return lastKnownRecords;
}
use of org.springframework.remoting.RemoteConnectFailureException in project onebusaway-application-modules by camsys.
the class EmailServiceImpl method setup.
@PostConstruct
@Override
public void setup() {
try {
String mailSMTPServer = "";
String mailSMTPServerPort = "";
// Try getting smtp host and port values from configurationService.
try {
mailSMTPServer = configurationService.getConfigurationValueAsString("admin.smtpHost", SMTP_HOST_NOT_FOUND);
mailSMTPServerPort = configurationService.getConfigurationValueAsString("admin.smtpPort", "25");
} catch (RemoteConnectFailureException e) {
_log.error("Setting smtp host to value : '" + SMTP_HOST_NOT_FOUND + "' due to failure to connect to TDM");
mailSMTPServer = SMTP_HOST_NOT_FOUND;
e.printStackTrace();
}
// If smtp host name was not found, assume this should use AWS
_properties = new Properties();
boolean useSMTP = mailSMTPServer.equals(SMTP_HOST_NOT_FOUND) ? false : true;
if (useSMTP) {
// Configure for SMTP
_properties.setProperty("mail.transport.protocol", "smtp");
_properties.setProperty("mail.smtp.starttls.enable", "false");
_properties.setProperty("mail.smtp.host", mailSMTPServer);
_properties.setProperty("mail.smtp.auth", "false");
_properties.setProperty("mail.debug", "false");
_properties.setProperty("mail.smtp.port", mailSMTPServerPort);
} else {
// Configure for AWS
// AWS specifics
_credentials = new BasicAWSCredentials(_username, _password);
_eClient = new AmazonSimpleEmailServiceAsyncClient(_credentials);
// Java specifics
_properties.setProperty("mail.transport.protocol", "aws");
_properties.setProperty("mail.aws.user", _credentials.getAWSAccessKeyId());
_properties.setProperty("mail.aws.password", _credentials.getAWSSecretKey());
}
_session = Session.getInstance(_properties);
Session session = Session.getDefaultInstance(_properties);
session.setDebug(false);
_transport = useSMTP ? _session.getTransport("smtp") : new AWSJavaMailTransport(_session, null);
} catch (Exception ioe) {
// log this heavily, but don't let it prevent context startup
_log.error("EmailServiceImpl setup failed, likely due to missing or invalid credentials.");
_log.error(ioe.toString());
}
}
Aggregations