List of usage examples for java.net UnknownHostException getMessage
public String getMessage()
From source file:info.magnolia.cms.servlets.PropertyInitializer.java
/** * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) *//*from w w w .j av a 2 s . c o m*/ public void contextInitialized(ServletContextEvent sce) { final ServletContext context = sce.getServletContext(); String propertiesLocationString = context.getInitParameter(MAGNOLIA_INITIALIZATION_FILE); if (log.isDebugEnabled()) { log.debug("{} value in web.xml is :[{}]", MAGNOLIA_INITIALIZATION_FILE, propertiesLocationString); //$NON-NLS-1$ } if (StringUtils.isEmpty(propertiesLocationString)) { propertiesLocationString = DEFAULT_INITIALIZATION_PARAMETER; } String[] propertiesLocation = StringUtils.split(propertiesLocationString, ','); String servername = null; try { servername = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { log.error(e.getMessage()); } String rootPath = StringUtils.replace(context.getRealPath(StringUtils.EMPTY), "\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ String webapp = StringUtils.substringAfterLast(rootPath, "/"); //$NON-NLS-1$ File logs = new File(webapp + File.separator + "logs"); File tmp = new File(webapp + File.separator + "tmp"); if (!logs.exists()) { logs.mkdir(); log.debug("Creating " + logs.getAbsoluteFile() + " folder"); } if (!tmp.exists()) { tmp.mkdir(); log.debug("Creating " + tmp.getAbsoluteFile() + " folder"); } if (log.isDebugEnabled()) { log.debug("rootPath is {}, webapp is {}", rootPath, webapp); //$NON-NLS-1$ } for (int j = 0; j < propertiesLocation.length; j++) { String location = StringUtils.trim(propertiesLocation[j]); location = StringUtils.replace(location, "${servername}", servername); //$NON-NLS-1$ location = StringUtils.replace(location, "${webapp}", webapp); //$NON-NLS-1$ File initFile = new File(rootPath, location); if (!initFile.exists() || initFile.isDirectory()) { if (log.isDebugEnabled()) { log.debug("Configuration file not found with path [{}]", //$NON-NLS-1$ initFile.getAbsolutePath()); } continue; } InputStream fileStream; try { fileStream = new FileInputStream(initFile); } catch (FileNotFoundException e1) { log.debug("Configuration file not found with path [{}]", //$NON-NLS-1$ initFile.getAbsolutePath()); return; } try { envProperties.load(fileStream); log.info("Loading configuration at {}", initFile.getAbsolutePath());//$NON-NLS-1$ Log4jConfigurer.initLogging(context, envProperties); new ConfigLoader(context, envProperties); } catch (Exception e) { log.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(fileStream); } return; } log.error(MessageFormat.format( "No configuration found using location list {0}. [servername] is [{1}], [webapp] is [{2}] and base path is [{3}]", //$NON-NLS-1$ new Object[] { ArrayUtils.toString(propertiesLocation), servername, webapp, rootPath })); }
From source file:calculus.backend.JpaConfig.java
/** * //from w ww.ja va 2s . co m */ private void loadEnviromentConfig() { LOG.info("Cargando configuracion de la BDs en funcion del ambiente .."); String env = "RD00155DFBD797"; //DEFAULT_ENV try { env = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException ex) { LOG.error(ex.getMessage(), ex); } LOG.info("env=" + env); if (env.equals("localhost")) { //postgres local this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://localhost:5432/pis2016"; this.user = "postgres"; this.pass = "user"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("RD00155DFBD985")) { //AZURE_PROD this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://nutty-custard-apple.db.elephantsql.com:5432/gxedfpdw"; this.user = "gxedfpdw"; this.pass = "Ci05wYOZACatHbnzav_VmHiSIF6J-fNB"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("abentan-PC")) { this.driver = "com.mysql.jdbc.Driver"; this.url = "jdbc:mysql://localhost:3306/pis2016"; this.user = "pis2016"; this.pass = "pis2016"; this.dataBase = Database.MYSQL; this.poolSize = 5; } else if (env.equals("RD00155DFBD797")) { //AZURE_BETA this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://nutty-custard-apple.db.elephantsql.com:5432/fbonhmwr"; this.user = "fbonhmwr"; this.pass = "4axmS5tbJRUh_f5j8K2LBQZ8wrEO4jBR"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("MacBook-Pro.local")) { this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://localhost:5432/pis2016"; this.user = "tavidian"; this.pass = ""; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("NetPC")) { //postgres local this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://localhost:5432/postgres"; this.user = "postgres"; this.pass = "4512161-7"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("MARTINV-DELL")) { //postgres local this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://localhost:5432/postgres"; this.user = "postgres"; this.pass = "user"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("PC3")) { this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://localhost:5432/pis2016"; this.user = "postgres"; this.pass = "admin"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } }
From source file:org.zaproxy.zap.extension.ascanrules.BufferOverflow.java
@Override public void scan(HttpMessage msg, String param, String value) { if (this.isStop()) { // Check if the user stopped things if (log.isDebugEnabled()) { log.debug("Scanner " + this.getName() + " Stopping."); }/*from ww w . j a v a 2s. c om*/ return; // Stop! } if (getBaseMsg().getResponseHeader().getStatusCode() == HttpStatusCode.INTERNAL_SERVER_ERROR) // Check to see if the page closed initially { return; // Stop } try { // This is where you change the 'good' request to attack the application // You can make multiple requests if needed String checkStringHeader1 = "Connection: close"; // Un natural close // Always use getNewMsg() for each new request msg = getNewMsg(); String returnAttack = randomCharacterString(2100); setParameter(msg, param, returnAttack); try { sendAndReceive(msg); } catch (UnknownHostException ex) { if (log.isDebugEnabled()) log.debug("Caught " + ex.getClass().getName() + " " + ex.getMessage() + " when accessing: " + msg.getRequestHeader().getURI().toString() + "\n The target may have replied with a poorly formed redirect due to our input."); return; // Something went wrong no point continuing } HttpResponseHeader requestReturn = msg.getResponseHeader(); // This is where BASE baseResponseBody was you detect potential vulnerabilities in the // response String chkerrorheader = requestReturn.getHeadersAsString(); log.debug("Header: " + chkerrorheader); if (msg.getResponseHeader().getStatusCode() == HttpStatusCode.INTERNAL_SERVER_ERROR && chkerrorheader.contains(checkStringHeader1)) { log.debug("Found Header"); bingo(getRisk(), Alert.CONFIDENCE_MEDIUM, this.getBaseMsg().getRequestHeader().getURI().toString(), param, msg.getRequestHeader().toString(), this.getOther(), msg); return; } return; } catch (URIException e) { if (log.isDebugEnabled()) { log.debug("Failed to send HTTP message, cause: " + e.getMessage()); } } catch (IOException e) { log.error(e.getMessage(), e); } }
From source file:org.apache.geode.internal.net.SocketCreator.java
/** * Converts the string host to an instance of InetAddress. Returns null if the string is empty. * Fails Assertion if the conversion would result in <code>java.lang.UnknownHostException</code>. * <p>//from w w w.jav a2 s .co m * Any leading slashes on host will be ignored. * * @param host string version the InetAddress * * @return the host converted to InetAddress instance */ public static InetAddress toInetAddress(String host) { if (host == null || host.length() == 0) { return null; } try { if (host.indexOf("/") > -1) { return InetAddress.getByName(host.substring(host.indexOf("/") + 1)); } else { return InetAddress.getByName(host); } } catch (java.net.UnknownHostException e) { throw new IllegalArgumentException(e.getMessage()); } }
From source file:com.cws.esolutions.agent.AgentDaemon.java
public void init(final DaemonContext dContext) throws DaemonInitException { final String methodName = AgentDaemon.CNAME + "#init(final DaemonContext dContext) throws DaemonInitException"; if (DEBUG) {/*from www . j a va 2 s. c om*/ DEBUGGER.debug(methodName); DEBUGGER.debug("DaemonContext: {}", dContext); } JAXBContext context = null; Unmarshaller marshaller = null; final File xmlFile = new File( AgentConstants.CURRENT_DIRECTORY + System.getProperty(AgentDaemon.APP_CONFIG)); if (DEBUG) { DEBUGGER.debug("xmlFile: {}", xmlFile); } try { if (!(xmlFile.canRead())) { throw new DaemonInitException("No configuration file was located. Shutting down !"); } // set the app configuration context = JAXBContext.newInstance(ConfigurationData.class); marshaller = context.createUnmarshaller(); ConfigurationData configData = (ConfigurationData) marshaller.unmarshal(xmlFile); if (DEBUG) { DEBUGGER.debug("ConfigurationData: {}", configData); } String osName = System.getProperty("os.name").toLowerCase(); if (DEBUG) { DEBUGGER.debug("osName: {}", osName); } if (osName.indexOf("win") >= 0) { AgentDaemon.agentBean.setOsType(OSType.WINDOWS); } else if (osName.indexOf("mac") >= 0) { AgentDaemon.agentBean.setOsType(OSType.MAC); } else if ((osName.indexOf("nix") >= 0) || (osName.indexOf("sunos") >= 0) || (osName.indexOf("aix") >= 0)) { AgentDaemon.agentBean.setOsType(OSType.UNIX); } AgentDaemon.agentBean.setHostName(InetAddress.getLocalHost().getHostName()); AgentDaemon.agentBean.setConfigData(configData); } catch (JAXBException jx) { ERROR_RECORDER.error(jx.getMessage(), jx); this.exitCode = 1; stop(); } catch (UnknownHostException uhx) { ERROR_RECORDER.error(uhx.getMessage(), uhx); this.exitCode = 1; stop(); } }
From source file:org.ejbca.ui.web.pub.ClearCacheServlet.java
private boolean acceptedHost(String remotehost) { if (log.isTraceEnabled()) { log.trace(">acceptedHost: " + remotehost); }/*from w w w .j a va 2s.c o m*/ boolean ret = false; GlobalConfiguration gc = (GlobalConfiguration) globalconfigurationsession .getCachedConfiguration(GlobalConfiguration.GLOBAL_CONFIGURATION_ID); Set<String> nodes = gc.getNodesInCluster(); Iterator<String> itr = nodes.iterator(); String nodename = null; while (itr.hasNext()) { nodename = itr.next(); try { String nodeip = InetAddress.getByName(nodename).getHostAddress(); if (log.isDebugEnabled()) { log.debug("Checking remote host against host in list: " + nodename + ", " + nodeip); } if (StringUtils.equals(remotehost, nodeip)) { ret = true; } else if (StringUtils.equals(remotehost, "127.0.0.1")) { // Always allow requests from localhost, 127.0.0.1 may not be added in the list if (log.isDebugEnabled()) { log.debug("Always allowing request from 127.0.0.1"); } ret = true; } } catch (UnknownHostException e) { if (log.isDebugEnabled()) { log.debug("Unknown host '" + nodename + "': " + e.getMessage()); } } } if (log.isTraceEnabled()) { log.trace("<acceptedHost: " + ret); } return ret; }
From source file:org.openhab.binding.oceanic.handler.NetworkOceanicThingHandler.java
@Override public void initialize() { super.initialize(); NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class); try {//from w ww . j av a 2s .co m socket = new Socket(config.ipAddress, config.portNumber); socket.setSoTimeout(REQUEST_TIMEOUT); outputStream = socket.getOutputStream(); inputStream = socket.getInputStream(); updateStatus(ThingStatus.ONLINE); } catch (UnknownHostException e) { logger.error("An exception occurred while resolving host {}:{} : '{}'", config.ipAddress, config.portNumber, e.getMessage()); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Could not resolve host " + config.ipAddress + ": " + e.getMessage()); } catch (IOException e) { logger.debug("An exception occurred while connecting to host {}:{} : '{}'", config.ipAddress, config.portNumber, e.getMessage()); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Could not connect to host " + config.ipAddress + ": " + e.getMessage()); reconnectJob = scheduler.schedule(reconnectRunnable, RECONNECT_INTERVAL, TimeUnit.SECONDS); } }
From source file:com.eucalyptus.cloudformation.CloudFormationService.java
private static String extractTemplateTextFromURL(String templateUrl, User user) throws ValidationErrorException { final URL url; try {//w w w . j a v a 2s . c om url = new URL(templateUrl); } catch (MalformedURLException e) { throw new ValidationErrorException("Invalid template url " + templateUrl); } // First try straight HTTP GET if url is in whitelist boolean inWhitelist = WhiteListURLMatcher.urlIsAllowed(url, URL_DOMAIN_WHITELIST); if (inWhitelist) { InputStream templateIn = null; try { final URLConnection connection = SslSetup.configureHttpsUrlConnection(url.openConnection()); templateIn = connection.getInputStream(); long contentLength = connection.getContentLengthLong(); if (contentLength > Limits.REQUEST_TEMPLATE_URL_MAX_CONTENT_LENGTH_BYTES) { throw new ValidationErrorException("Template URL exceeds maximum byte count, " + Limits.REQUEST_TEMPLATE_URL_MAX_CONTENT_LENGTH_BYTES); } final byte[] templateData = ByteStreams.toByteArray(new BoundedInputStream(templateIn, Limits.REQUEST_TEMPLATE_URL_MAX_CONTENT_LENGTH_BYTES + 1)); if (templateData.length > Limits.REQUEST_TEMPLATE_URL_MAX_CONTENT_LENGTH_BYTES) { throw new ValidationErrorException("Template URL exceeds maximum byte count, " + Limits.REQUEST_TEMPLATE_URL_MAX_CONTENT_LENGTH_BYTES); } return new String(templateData, StandardCharsets.UTF_8); } catch (UnknownHostException ex) { throw new ValidationErrorException("Invalid template url " + templateUrl); } catch (SSLHandshakeException ex) { throw new ValidationErrorException("HTTPS connection error for " + templateUrl); } catch (IOException ex) { if (Strings.nullToEmpty(ex.getMessage()).startsWith("HTTPS hostname wrong")) { throw new ValidationErrorException( "HTTPS connection failed hostname verification for " + templateUrl); } LOG.info("Unable to connect to whitelisted URL, trying S3 instead"); LOG.debug(ex, ex); } finally { IO.close(templateIn); } } // Otherwise, assume the URL is a eucalyptus S3 url... String[] validHostBucketSuffixes = new String[] { "walrus", "objectstorage", "s3" }; String[] validServicePaths = new String[] { ObjectStorageProperties.LEGACY_WALRUS_SERVICE_PATH, ComponentIds.lookup(ObjectStorage.class).getServicePath() }; String[] validDomains = new String[] { DomainNames.externalSubdomain().relativize(Name.root).toString() }; S3Helper.BucketAndKey bucketAndKey = S3Helper.getBucketAndKeyFromUrl(url, validServicePaths, validHostBucketSuffixes, validDomains); try (final EucaS3Client eucaS3Client = EucaS3ClientFactory .getEucaS3Client(new SecurityTokenAWSCredentialsProvider(user))) { if (eucaS3Client.getObjectMetadata(bucketAndKey.getBucket(), bucketAndKey.getKey()) .getContentLength() > Limits.REQUEST_TEMPLATE_URL_MAX_CONTENT_LENGTH_BYTES) { throw new ValidationErrorException("Template URL exceeds maximum byte count, " + Limits.REQUEST_TEMPLATE_URL_MAX_CONTENT_LENGTH_BYTES); } return eucaS3Client.getObjectContent(bucketAndKey.getBucket(), bucketAndKey.getKey(), (int) Limits.REQUEST_TEMPLATE_URL_MAX_CONTENT_LENGTH_BYTES); } catch (Exception ex) { LOG.debug("Error getting s3 object content: " + bucketAndKey.getBucket() + "/" + bucketAndKey.getKey()); LOG.debug(ex, ex); throw new ValidationErrorException( "Template url is an S3 URL to a non-existent or unauthorized bucket/key. (bucket=" + bucketAndKey.getBucket() + ", key=" + bucketAndKey.getKey()); } }
From source file:org.jajuk.ui.views.ArtistView.java
@Override public Object longCall() { // Call last.fm wiki bio = LastFmService.getInstance().getWikiText(artist); artistInfo = LastFmService.getInstance().getArtist(artist); // Prefetch artist thumbs try {/* ww w . j a v a2 s . c om*/ preFetchOthersAlbum(); preFetchSimilarArtists(); } catch (UnknownHostException e) { Log.warn("Could not contact host for loading album information: {{" + e.getMessage() + "}}"); } catch (IOException e) { if (e.getMessage().contains(" 403 ")) { // server responded with code "forbidden" Log.warn("Server returned an error while fetching images: " + e.getMessage()); } else { // other exception Log.error(e); } } catch (Exception e) { Log.error(e); } return null; }
From source file:org.signserver.server.ListBasedAddressAuthorizer.java
@Override public void isAuthorized(ProcessRequest request, RequestContext requestContext) throws IllegalRequestException, AccessDeniedException, SignServerException { final String remote = (String) requestContext.get(RequestContext.REMOTE_IP); final String[] forwardedAddresses = XForwardedForUtils.getXForwardedForIPs(requestContext, maxForwardedAddresses);//from w w w. j ava 2s . com InetAddress remoteAddress; try { remoteAddress = InetAddress.getByName(remote); } catch (UnknownHostException e) { throw new IllegalRequestException("Illegal remote address in request: " + e.getMessage()); } if (!fatalErrors.isEmpty()) { throw new SignServerException("Misconfigured"); } // check direct address if ((isDirectWhitelisting && !addressesDirect.contains(remoteAddress)) || (!isDirectWhitelisting && addressesDirect.contains(remoteAddress))) { LOG.error("Worker " + workerId + ": " + "Not authorized remote address: " + remote); throw new AccessDeniedException("Remote address not authorized"); } if (isForwardedWhitelisting) { // if there is no forwarded header, of if header is empty if (forwardedAddresses == null || forwardedAddresses.length == 0) { throw new AccessDeniedException("No forwarded address in request"); } for (final String forwarded : forwardedAddresses) { InetAddress forwardedAddress; try { forwardedAddress = InetAddress.getByName(forwarded); } catch (UnknownHostException e) { throw new IllegalRequestException("Illegal forwarded address in request: " + e.getMessage()); } if (!addressesForwarded.contains(forwardedAddress)) { LOG.error("Worker " + workerId + ": " + "No authorized forwarded address among inspected addesses"); throw new AccessDeniedException("Forwarded address not athorized"); } } } else { if (forwardedAddresses != null && forwardedAddresses.length > 0) { for (final String forwarded : forwardedAddresses) { InetAddress forwardedAddress; try { forwardedAddress = InetAddress.getByName(forwarded); } catch (UnknownHostException e) { throw new IllegalRequestException( "Illegal forwarded address in request: " + e.getMessage()); } if (addressesForwarded.contains(forwardedAddress)) { LOG.error("Worker " + workerId + ": " + "Found blacklisted address among inspected addresses: " + forwarded); throw new AccessDeniedException("Forwarded address not athorized"); } } } } logRemoteAddress(remote, forwardedAddresses, requestContext); }