Search in sources :

Example 1 with RemoteConnectFailureException

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);
    }
}
Also used : Context(javax.naming.Context) RemoteConnectFailureException(org.springframework.remoting.RemoteConnectFailureException) NamingException(javax.naming.NamingException) RemoteLookupFailureException(org.springframework.remoting.RemoteLookupFailureException) RemoteException(java.rmi.RemoteException)

Example 2 with RemoteConnectFailureException

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;
}
Also used : RemoteConnectFailureException(org.springframework.remoting.RemoteConnectFailureException) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) VehicleLastKnownRecord(org.onebusaway.admin.model.json.VehicleLastKnownRecord)

Example 3 with RemoteConnectFailureException

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;
}
Also used : RemoteConnectFailureException(org.springframework.remoting.RemoteConnectFailureException) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) VehicleLastKnownRecord(org.onebusaway.admin.model.json.VehicleLastKnownRecord)

Example 4 with RemoteConnectFailureException

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());
    }
}
Also used : RemoteConnectFailureException(org.springframework.remoting.RemoteConnectFailureException) Properties(java.util.Properties) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSJavaMailTransport(com.amazonaws.services.simpleemail.AWSJavaMailTransport) RemoteConnectFailureException(org.springframework.remoting.RemoteConnectFailureException) AmazonSimpleEmailServiceAsyncClient(com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceAsyncClient) Session(javax.mail.Session) PostConstruct(javax.annotation.PostConstruct)

Aggregations

RemoteConnectFailureException (org.springframework.remoting.RemoteConnectFailureException)4 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 VehicleLastKnownRecord (org.onebusaway.admin.model.json.VehicleLastKnownRecord)2 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AWSJavaMailTransport (com.amazonaws.services.simpleemail.AWSJavaMailTransport)1 AmazonSimpleEmailServiceAsyncClient (com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceAsyncClient)1 RemoteException (java.rmi.RemoteException)1 Properties (java.util.Properties)1 PostConstruct (javax.annotation.PostConstruct)1 Session (javax.mail.Session)1 Context (javax.naming.Context)1 NamingException (javax.naming.NamingException)1 RemoteLookupFailureException (org.springframework.remoting.RemoteLookupFailureException)1