List of usage examples for java.net UnknownHostException getLocalizedMessage
public String getLocalizedMessage()
From source file:org.apache.kylin.engine.mr.CubingJob.java
/** * build fail because the metadata store has problem. * @param exception/*from w ww. ja va 2s . c o m*/ */ @Override protected void handleMetaDataPersistException(Exception exception) { String title = "[ERROR] - [" + getDeployEnvName() + "] - [" + getProjectName() + "] - " + CubingExecutableUtil.getCubeName(this.getParams()); String content = ExecutableConstants.NOTIFY_EMAIL_TEMPLATE; final String UNKNOWN = "UNKNOWN"; String errMsg = null; if (exception != null) { final StringWriter out = new StringWriter(); exception.printStackTrace(new PrintWriter(out)); errMsg = out.toString(); } content = content.replaceAll("\\$\\{job_name\\}", getName()); content = content.replaceAll("\\$\\{result\\}", ExecutableState.ERROR.toString()); content = content.replaceAll("\\$\\{env_name\\}", getDeployEnvName()); content = content.replaceAll("\\$\\{project_name\\}", getProjectName()); content = content.replaceAll("\\$\\{cube_name\\}", CubingExecutableUtil.getCubeName(this.getParams())); content = content.replaceAll("\\$\\{source_records_count\\}", UNKNOWN); content = content.replaceAll("\\$\\{start_time\\}", UNKNOWN); content = content.replaceAll("\\$\\{duration\\}", UNKNOWN); content = content.replaceAll("\\$\\{mr_waiting\\}", UNKNOWN); content = content.replaceAll("\\$\\{last_update_time\\}", UNKNOWN); content = content.replaceAll("\\$\\{submitter\\}", StringUtil.noBlank(getSubmitter(), "missing submitter")); content = content.replaceAll("\\$\\{error_log\\}", Matcher.quoteReplacement(StringUtil.noBlank(errMsg, "no error message"))); try { InetAddress inetAddress = InetAddress.getLocalHost(); content = content.replaceAll("\\$\\{job_engine\\}", inetAddress.getCanonicalHostName()); } catch (UnknownHostException e) { logger.warn(e.getLocalizedMessage(), e); } sendMail(Pair.of(title, content)); }
From source file:org.apache.kylin.engine.mr.CubingJob.java
@Override protected Pair<String, String> formatNotifications(ExecutableContext context, ExecutableState state) { CubeInstance cubeInstance = CubeManager.getInstance(context.getConfig()) .getCube(CubingExecutableUtil.getCubeName(this.getParams())); final Output output = getManager().getOutput(getId()); String logMsg;//ww w. j a v a 2 s . c o m state = output.getState(); if (state != ExecutableState.ERROR && !cubeInstance.getDescriptor().getStatusNeedNotify().contains(state.toString())) { logger.info("state:" + state + " no need to notify users"); return null; } switch (state) { case ERROR: logMsg = output.getVerboseMsg(); break; case DISCARDED: logMsg = "job has been discarded"; break; case SUCCEED: logMsg = "job has succeeded"; break; default: return null; } String content = ExecutableConstants.NOTIFY_EMAIL_TEMPLATE; content = content.replaceAll("\\$\\{job_name\\}", getName()); content = content.replaceAll("\\$\\{result\\}", state.toString()); content = content.replaceAll("\\$\\{env_name\\}", getDeployEnvName()); content = content.replaceAll("\\$\\{project_name\\}", getProjectName()); content = content.replaceAll("\\$\\{cube_name\\}", CubingExecutableUtil.getCubeName(this.getParams())); content = content.replaceAll("\\$\\{source_records_count\\}", String.valueOf(findSourceRecordCount())); content = content.replaceAll("\\$\\{start_time\\}", new Date(getStartTime()).toString()); content = content.replaceAll("\\$\\{duration\\}", getDuration() / 60000 + "mins"); content = content.replaceAll("\\$\\{mr_waiting\\}", getMapReduceWaitTime() / 60000 + "mins"); content = content.replaceAll("\\$\\{last_update_time\\}", new Date(getLastModified()).toString()); content = content.replaceAll("\\$\\{submitter\\}", StringUtil.noBlank(getSubmitter(), "missing submitter")); content = content.replaceAll("\\$\\{error_log\\}", Matcher.quoteReplacement(StringUtil.noBlank(logMsg, "no error message"))); try { InetAddress inetAddress = InetAddress.getLocalHost(); content = content.replaceAll("\\$\\{job_engine\\}", inetAddress.getCanonicalHostName()); } catch (UnknownHostException e) { logger.warn(e.getLocalizedMessage(), e); } String title = "[" + state.toString() + "] - [" + getDeployEnvName() + "] - [" + getProjectName() + "] - " + CubingExecutableUtil.getCubeName(this.getParams()); return Pair.of(title, content); }
From source file:org.openhab.io.net.http.SecureHttpContext.java
/** * Checks whether the <code>request</code>s remote address is external or * internal.//w w w .j av a 2s . c o m * * @param request * @return <code>true</code> if the <code>request</code>s remote address * is out of range of the given netmask (see <code>security:netmask</code> * configuration in openhab.cfg) or if any error occured and <code>false</code> * in all other cases. */ private boolean isExternalRequest(HttpServletRequest request) { long startTime = System.currentTimeMillis(); String remoteAddr = request.getRemoteAddr(); try { return isExternalIp(remoteAddr); } catch (UnknownHostException uhe) { logger.error(uhe.getLocalizedMessage()); } catch (IllegalArgumentException iae) { logger.warn("couldn't parse '{}' to a valid ip address", remoteAddr); } finally { logger.debug("checking ip is in range took {}ms", System.currentTimeMillis() - startTime); } // if there are any doubts we assume this request to be external! return true; }
From source file:de.forsthaus.gui.service.impl.GuiLoginLoggingServiceImpl.java
@Override public void fillIp2CountryOnceForAppUpdate() { final List<SecLoginlog> originList = getAllLogs(); int count = 0; int localCount = 0; int checkCount = 0; int updateCount = 0; int unknownCount = 0; int unknownsysCCCount = 0; for (final SecLoginlog secLoginlog : originList) { count++;//from www .j a v a 2 s . c om // check if no entry exists for this login if (secLoginlog.getIp2Country() == null) { IpToCountry ipToCountry = null; try { // try to get a ipToCountry for the IP from the table final InetAddress inetAddress = InetAddress.getByName(secLoginlog.getLglIp()); // Skip a local ip. Therefore is no country to identify. if (inetAddress.isLoopbackAddress() || inetAddress.isSiteLocalAddress()) { localCount++; continue; } checkCount++; ipToCountry = getIpToCountryService().getIpToCountry(inetAddress); // if found than get the CountryCode object for it and save // all if (ipToCountry != null) { final String code2 = ipToCountry.getIpcCountryCode2(); final CountryCode sysCC = getCountryCodeService().getCountryCodeByCode2(code2); if (sysCC != null) { final Ip2Country ip2 = getIp2CountryService().getNewIp2Country(); ip2.setCountryCode(sysCC); // save all getIp2CountryService().saveOrUpdate(ip2); secLoginlog.setIp2Country(ip2); getLoginLoggingService().update(secLoginlog); updateCount++; } else { unknownsysCCCount++; } continue; } } catch (final UnknownHostException e) { try { Messagebox.show(e.getLocalizedMessage()); } catch (final InterruptedException e1) { throw new RuntimeException(e1); } } unknownCount++; } } if (logger.isInfoEnabled()) { logger.info("Ueberpruefte SecLoginlog " + count); logger.info("davon localhost: " + localCount); logger.info("hostcheck: " + checkCount); logger.info("SecLoginlog updates: " + updateCount); logger.info("Hosts, denen kein SysCountryCode zugeordnet werden konnte: : " + unknownsysCCCount); logger.info("unbekannte Hosts: " + unknownCount); } }
From source file:com.netxforge.oss2.config.SnmpEventInfo.java
/** * <p>Constructor for SnmpEventInfo.</p> * * @param event a {@link org.opennms.netmgt.xml.event.Event} object. */// www .ja v a2s . com public SnmpEventInfo(Event event) { String parmName = null; Value parmValue = null; String parmContent = null; if (!event.getUei().equals(EventConstants.CONFIGURE_SNMP_EVENT_UEI)) { throw new IllegalArgumentException("Event is not an a \"configure SNMP\" event: " + event.toString()); } for (Parm parm : event.getParmCollection()) { parmName = parm.getParmName(); parmValue = parm.getValue(); if (parmValue == null) continue; parmContent = parmValue.getContent(); try { if (parmName.equals(EventConstants.PARM_FIRST_IP_ADDRESS)) { setFirstIPAddress(parmContent); } else if (parmName.equals(EventConstants.PARM_LAST_IP_ADDRESS)) { setLastIPAddress(parmContent); } else if (parmName.equals(EventConstants.PARM_COMMUNITY_STRING)) { setCommunityString(parmContent); } else if (parmName.equals(EventConstants.PARM_RETRY_COUNT)) { setRetryCount(computeIntValue(parmContent)); } else if (parmName.equals(EventConstants.PARM_TIMEOUT)) { setTimeout(computeIntValue(parmContent)); } else if (parmName.equals(EventConstants.PARM_VERSION)) { setVersion(parmContent); } else if (parmName.equals(EventConstants.PARM_PORT)) { setPort(computeIntValue(parmContent)); } } catch (UnknownHostException e) { log().error("SnmpEventInfo constructor: ", e); throw new IllegalArgumentException("SnmpEventInfo constructor. " + e.getLocalizedMessage()); } catch (IllegalArgumentException e) { log().error("SnmpEventInfo constructor: ", e); throw e; } } }
From source file:org.opennms.netmgt.config.SnmpEventInfo.java
/** * <p>Constructor for SnmpEventInfo.</p> * * @param event a {@link org.opennms.netmgt.xml.event.Event} object. *//* w w w .jav a2 s . c om*/ @SuppressWarnings("deprecation") public SnmpEventInfo(Event event) { String parmName = null; Value parmValue = null; String parmContent = null; if (!event.getUei().equals(EventConstants.CONFIGURE_SNMP_EVENT_UEI)) { throw new IllegalArgumentException("Event is not an a \"configure SNMP\" event: " + event.toString()); } for (Parm parm : event.getParmCollection()) { parmName = parm.getParmName(); parmValue = parm.getValue(); if (parmValue == null) continue; parmContent = parmValue.getContent(); try { if (parmName.equals(EventConstants.PARM_FIRST_IP_ADDRESS)) { setFirstIPAddress(parmContent); } else if (parmName.equals(EventConstants.PARM_LAST_IP_ADDRESS)) { setLastIPAddress(parmContent); } else if (parmName.equals(EventConstants.PARM_COMMUNITY_STRING) || parmName.equals(EventConstants.PARM_SNMP_READ_COMMUNITY_STRING)) { setReadCommunityString(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_WRITE_COMMUNITY_STRING)) { setWriteCommunityString(parmContent); } else if (parmName.equals(EventConstants.PARM_RETRY_COUNT)) { setRetryCount(computeIntValue(parmContent)); } else if (parmName.equals(EventConstants.PARM_TIMEOUT)) { setTimeout(computeIntValue(parmContent)); } else if (parmName.equals(EventConstants.PARM_VERSION)) { setVersion(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_MAX_REPETITIONS)) { setMaxRepetitions(computeIntValue(parmContent)); } else if (parmName.equals(EventConstants.PARM_SNMP_MAX_REQUEST_SIZE)) { setMaxRequestSize(computeIntValue(parmContent)); } else if (parmName.equals(EventConstants.PARM_SNMP_MAX_VARS_PER_PDU)) { setMaxVarsPerPdu(computeIntValue(parmContent)); } else if (parmName.equals(EventConstants.PARM_PORT)) { setPort(computeIntValue(parmContent)); } else if (parmName.equals(EventConstants.PARM_SNMP_AUTH_PASSPHRASE)) { setAuthPassPhrase(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_AUTH_PROTOCOL)) { setAuthProtocol(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_SECURITY_LEVEL)) { setSecurityLevel(computeIntValue(parmContent)); } else if (parmName.equals(EventConstants.PARM_SNMP_SECURITY_NAME)) { setSecurityName(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_ENGINE_ID)) { setEngineId(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_ENTERPRISE_ID)) { setEnterpriseId(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_CONTEXT_ENGINE_ID)) { setContextEngineId(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_CONTEXT_NAME)) { setContextName(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_PRIVACY_PASSPHRASE)) { setPrivPassPhrase(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_PRIVACY_PROTOCOL)) { setPrivProtocol(parmContent); } else if (parmName.equals(EventConstants.PARM_SNMP_PROXY_HOST)) { setProxyHost(parmContent); } } catch (UnknownHostException e) { LOG.error("SnmpEventInfo constructor", e); throw new IllegalArgumentException("SnmpEventInfo constructor. " + e.getLocalizedMessage()); } catch (IllegalArgumentException e) { LOG.error("SnmpEventInfo constructor", e); throw e; } } }
From source file:com.photon.phresco.service.impl.DbService.java
private GridFS getGridFs() throws PhrescoException { if (isDebugEnabled) { LOGGER.debug("DbService.getGridFs:Entry"); }//from www . j a va2 s . c o m try { Mongo mongo = new Mongo(serverConfig.getDbHost(), serverConfig.getDbPort()); DB db = mongo.getDB(serverConfig.getDbName()); GridFS gfsPhoto = new GridFS(db, "icons"); if (isDebugEnabled) { LOGGER.debug("DbService.getGridFs:Exit"); } return gfsPhoto; } catch (UnknownHostException e) { if (isDebugEnabled) { LOGGER.error("DbService.getGridFs", STATUS_FAILURE, MESSAGE_EQUALS + "\"" + e.getLocalizedMessage() + "\""); } throw new PhrescoException(e); } catch (MongoException e) { if (isDebugEnabled) { LOGGER.error("DbService.getGridFs", STATUS_FAILURE, MESSAGE_EQUALS + "\"" + e.getLocalizedMessage() + "\""); } throw new PhrescoException(e); } }
From source file:org.eclipse.jubula.client.core.ClientTest.java
/** * {@inheritDoc}/* ww w. ja v a 2s . co m*/ */ public void startAut(IAUTMainPO aut, IAUTConfigPO conf, Locale locale) throws ToolkitPluginException { final String autToolkit = aut.getToolkit(); if (!ComponentBuilder.getInstance().getLevelToolkitIds().contains(autToolkit) && ToolkitConstants.LEVEL_TOOLKIT.equals(ToolkitSupportBP.getToolkitLevel(autToolkit))) { throw new ToolkitPluginException(Messages.ErrorMessageAUT_TOOLKIT_NOT_AVAILABLE); } try { // start the AUTServer Map<String, String> autConfigMap = createAutConfigMap(conf); StartAUTServerMessage startAUTServerMessage = new StartAUTServerMessage( InetAddress.getLocalHost().getCanonicalHostName(), AUTConnection.getInstance().getCommunicator().getLocalPort(), autConfigMap, autToolkit, aut.isGenerateNames()); startAUTServerMessage.setLocale(locale); AutAgentConnection.getInstance().send(startAUTServerMessage); if (log.isDebugEnabled()) { log.debug(Messages.StartAUTServerMessageSend); } } catch (NotConnectedException nce) { // The AutAgentConnection was closed. This Exception occurs after // initialising the server, so there must be a shutdown(). The // listeners are already notified from the ConnectionListener of // the AutAgentConnection, -> just log. log.info(nce.getLocalizedMessage(), nce); } catch (ConnectionException ce) { // This exception is thrown from AutAgentConnection.getInstance(). See comment above. log.info(ce.getLocalizedMessage(), ce); } catch (CommunicationException cce) { log.error(cce.getLocalizedMessage(), cce); // message could not send for any reason, close the connections try { closeConnections(); } catch (ConnectionException ce) { log.error(Messages.ClosingTheConnectionsFailed, ce); } } catch (UnknownHostException uhe) { log.error(uhe.getLocalizedMessage(), uhe); try { // from InetAdress.getLocalHost().getName(), should not occur // -> no communication possible -> close the connections as a // precaution AUTConnection.getInstance().close(); AutAgentConnection.getInstance().close(); } catch (ConnectionException ce) { log.error(Messages.ClosingTheConnectionsFailed, ce); } } }
From source file:com.mindquarry.desktop.client.MindClient.java
/** * Displays an error message and prompts the user to check their server * settings in the preferences dialog, or to cancel. * /*from w w w . j ava 2 s.c o m*/ * @param exception * Contains the unknown host. * @return True if and only if preferences dialog was shown to user which * means that the server details were potentially updated. */ public boolean handleUnknownHostException(UnknownHostException exception) { // create custom error message with the option to open the preferences // dialog MessageDialog messageDialog = new MessageDialog(getShell(), I18N.getString("Error"), //$NON-NLS-1$ null, (I18N.get("Unknown server: \"{0}\"", exception.getLocalizedMessage()) //$NON-NLS-1$ + "\n\n" //$NON-NLS-1$ + I18N.getString("Please check your Mindquarry server URL in the preferences dialog.")), //$NON-NLS-1$ MessageDialog.ERROR, new String[] { I18N.getString("Go to preferences"), //$NON-NLS-1$ I18N.getString("Cancel") //$NON-NLS-1$ }, 0); int buttonClicked = messageDialog.open(); switch (buttonClicked) { case 0: // go to preferences showPreferenceDialog(true); return true; case 1: // cancel displayNotConnected(); return false; } return false; }
From source file:org.globus.replica.rls.impl.rpc.SimpleRLSConnection.java
/** * Establishes a connection to RLS server without security. *///from w ww . j av a2s . c o m private void _establishUnsecuredConnection(GlobusURL url) throws RLSException { // Establish RLS connection try { // Parse port int port = url.getPort(); if (port < 0) port = DEFAULT_PORT; // Parse host String host = url.getHost(); if (LOCALHOST.equalsIgnoreCase(host)) host = InetAddress.getLocalHost().getCanonicalHostName(); // Connect to server sock = new Socket(host, port); // Get socket input/output streams OutputStream rawOut = sock.getOutputStream(); InputStream rawIn = sock.getInputStream(); rawOut.flush(); // Not required to flush // Wrap I/O streams with RPC streams out = new RPCOutputStream(rawOut); in = new RPCInputStream(rawIn); // Verify RLS server response int rc = in.readInt(); if (rc != RLSStatusCode.RLS_SUCCESS) { logger.debug("Failed to establish RLS connection, RLS server" + " returned rc=" + rc); _release(); throw new RLSException(rc, RLSStatusCode.toMessage(rc)); } // Instantiate RLS interfaces catalog = new LRCImpl(); index = new RLIImpl(); admin = new AdminImpl(); } catch (UnknownHostException e) { _release(); throw new RLSException(RLSStatusCode.RLS_GLOBUSERR, "Unable to " + "resolve localhost (cause: " + e.getLocalizedMessage() + ")", e); } catch (IOException e) { _release(); throw new RLSException(RLSStatusCode.RLS_GLOBUSERR, "I/O failure" + " when establishing connection (cause: " + e.getLocalizedMessage() + ")", e); } }