/** * Creates a new Socket connected to the given IP address. The method uses connection settings * supplied in the constructor for connecting the socket. * * @param address the IP address to connect to * @return connected socket * @throws java.net.UnknownHostException if the hostname of the address or the proxy cannot be * resolved * @throws java.io.IOException if an I/O error occured while connecting to the remote end or to * the proxy */ private Socket createSocket(InetSocketAddress address, int timeout) throws IOException { String socksProxyHost = System.getProperty("socksProxyHost"); System.getProperties().remove("socksProxyHost"); try { ConnectivitySettings cs = lastKnownSettings.get(address); if (cs != null) { try { return createSocket(cs, address, timeout); } catch (IOException e) { // not good anymore, try all proxies lastKnownSettings.remove(address); } } URI uri = addressToURI(address, "socket"); try { return createSocket(uri, address, timeout); } catch (IOException e) { // we will also try https } uri = addressToURI(address, "https"); return createSocket(uri, address, timeout); } finally { if (socksProxyHost != null) { System.setProperty("socksProxyHost", socksProxyHost); } } }
public void setUp() throws Exception { super.setUp(); theDaemon = getMockLockssDaemon(); tempDir = getTempDir(); String tempDirPath = tempDir.getAbsolutePath(); System.setProperty("java.io.tmpdir", tempDirPath); Properties p = new Properties(); p.setProperty(IdentityManager.PARAM_IDDB_DIR, tempDirPath + "iddb"); p.setProperty(ConfigManager.PARAM_PLATFORM_DISK_SPACE_LIST, tempDirPath); p.setProperty(IdentityManager.PARAM_LOCAL_IP, "127.0.0.1"); p.setProperty(V3LcapMessage.PARAM_REPAIR_DATA_THRESHOLD, "4096"); ConfigurationUtil.setCurrentConfigFromProps(p); IdentityManager idmgr = theDaemon.getIdentityManager(); idmgr.startService(); mPollMgr = new MockPollManager(); theDaemon.setPollManager(mPollMgr); try { m_testID = idmgr.stringToPeerIdentity("127.0.0.1"); } catch (IOException ex) { fail("can't open test host 127.0.0.1: " + ex); } m_repairProps = new CIProperties(); m_repairProps.setProperty("key1", "val1"); m_repairProps.setProperty("key2", "val2"); m_repairProps.setProperty("key3", "val3"); m_testVoteBlocks = V3TestUtils.makeVoteBlockList(10); m_testMsg = this.makeTestVoteMessage(m_testVoteBlocks); }
/** * 发起同步请求,获取后台信息,直接显示在页面上 * * @param req * @param res */ public static void sync(HttpServletRequest req, HttpServletResponse res) { System.setProperty("0", "aaaaaaaa"); // h.put(i+"","aaaaaaaaaaaaaaaaaaaaaaaa"); // i++; // System.out.println("*************************system prop is " + // System.getProperties()); IAsyncMgntInt iAsyncMgntInt = new IAsyncMgntInt(); SSysOperatorsListHolder holder = new SSysOperatorsListHolder(); CBSErrorMsg errMsg = new CBSErrorMsg(); try { res.getWriter().println("<a href=\"./index.html\">返回首页</a></script>"); int result = iAsyncMgntInt.select_sysOperators(holder, errMsg); System.out.println("*****result is " + result); if (result != 0) { res.getWriter().println(errMsg.get_errorMsg() + ":" + errMsg.get_errorCode()); } SSysOperatorsList list = holder.value; int size = list.size(); res.getWriter().println("<pre>"); for (int i = 0; i < size; i++) { SSysOperators opers = (SSysOperators) list.get(i); res.getWriter().println(i + ":" + opers.get_loginName()); } res.getWriter().println("<a href=\"./index.html\">返回首页</a></script>"); } catch (Exception e) { e.printStackTrace(); } }
/** * @param args arg[0] - URL of the Virtual Center Server / ESX host https://<Server host name / * ip>/sdk arg[1] - User name arg[2] - Password arg[3] - One of vminfo, hostvminfo, or vmmor * arg[4] - If vmmor is arg[3], then vmname argument is mandatory */ public static void main(String[] args) { // This is to accept all SSL certifcates by default. System.setProperty( "org.apache.axis.components.net.SecureSocketFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory"); if (args.length < 3) { printUsage(); } else { try { /** * ****************************** ******************************* ** *** ** Your code goes * here *** ** (fill-in 1 of 1) *** ** *** ******************************* * ******************************* */ VIM_HOST = args[0]; USER_NAME = args[1]; PASSWORD = args[2]; initAll(); System.out.println("***************************************************************"); long st = System.currentTimeMillis(); getVMInfo(); long et = System.currentTimeMillis(); System.out.println( "\nTotal time (msec) to retrieve the properties of all VMs in one call: " + (et - st)); System.out.println("\n***************************************************************"); System.out.println("\n***************************************************************"); st = System.currentTimeMillis(); initVMMorList(); Iterator<ManagedObjectReference> iter = VM_MOR_LIST.iterator(); StringBuilder sb = new StringBuilder(); String name = "name"; String powerState = "runtime.powerState"; while (iter.hasNext()) { ManagedObjectReference vmMor = iter.next(); String vmName = (String) getVMProperty(vmMor, name); sb.append(vmName); VirtualMachinePowerState vmPs = (VirtualMachinePowerState) getVMProperty(vmMor, powerState); sb.append(" : "); sb.append(vmPs); sb.append("\n"); } et = System.currentTimeMillis(); System.out.println(sb.toString()); System.out.println( "\nTotal time (msec) to retrieve the properties of all VMs individually: " + (et - st)); System.out.println("\n***************************************************************"); } catch (Exception e) { e.printStackTrace(); } finally { try { disconnect(); } catch (Exception e) { e.printStackTrace(); } } } }
public static void main(String[] args) throws Exception { if (debug) System.setProperty("javax.net.debug", "all"); /* * Start the tests. */ new CheckMyTrustedKeystore(); }
public static void main(String[] args) throws Exception { String keyFilename = System.getProperty("test.src", "./") + "/" + pathToStores + "/" + keyStoreFile; String trustFilename = System.getProperty("test.src", "./") + "/" + pathToStores + "/" + trustStoreFile; System.setProperty("javax.net.ssl.keyStore", keyFilename); System.setProperty("javax.net.ssl.keyStorePassword", passwd); System.setProperty("javax.net.ssl.trustStore", trustFilename); System.setProperty("javax.net.ssl.trustStorePassword", passwd); if (debug) System.setProperty("javax.net.debug", "all"); /* * Start the tests. */ new JavaxHTTPSConnection(); }
private void createConnection() throws IOException { String completeUrl = getCompleteUrl(); if (connection == null) { System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false"); connection = (HttpURLConnection) new URL(completeUrl).openConnection(); connection.setInstanceFollowRedirects(followRedirects); } }
public static void main(String[] args) throws Exception { System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); /** * This test does not establish any connection to the specified URL, hence a dummy URL is used. */ URL foobar = new URL("https://example.com/"); HttpsURLConnection urlc = (HttpsURLConnection) foobar.openConnection(); try { urlc.getCipherSuite(); } catch (IllegalStateException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); } try { urlc.getServerCertificateChain(); } catch (IllegalStateException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); } try { urlc.setDefaultHostnameVerifier(null); } catch (IllegalArgumentException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); } try { urlc.setHostnameVerifier(null); } catch (IllegalArgumentException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); } try { urlc.setDefaultSSLSocketFactory(null); } catch (IllegalArgumentException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); } try { urlc.setSSLSocketFactory(null); } catch (IllegalArgumentException e) { System.out.print("Caught proper exception"); System.out.println(e.getMessage()); } System.out.println("TESTS PASSED"); }
/** * Creates a new instance loading any providers found in the provided skin. * * @param site The skin to generate a sitemap for * @param dest The directory to write files to. * @param url The URI at which this directory is accessible using HTTP. * @throws IOException If the files can't be written. */ public SitemapGenerator(final URI site, final File dest, final URI url) throws IOException { this(new ArrayList<PageProvider>(), dest, url); // HACK add site into system properties, a la the global context System.setProperty("no.sesat.sitemap.SitemapGenerator.site", site.toString()); for (PageProvider provider : ServiceLoader.load(PageProvider.class, getClassLoader(site))) { LOG.info("Found " + provider.getName()); providers.add(provider); } }
/** 利用属性文件中的信息连接数据库 * */ public static Connection getConnection() throws SQLException, IOException { Properties props = new Properties(); String fileName = "QueryDB.properties"; FileInputStream in = new FileInputStream(fileName); props.load(in); String drivers = props.getProperty("jdbc.drivers"); if (drivers != null) System.setProperty("jdbc.drivers", drivers); String url = props.getProperty("jdbc.url"); String username = props.getProperty("jdbc.username"); String password = props.getProperty("jdbc.password"); return DriverManager.getConnection(url, username, password); }
public PrivateReader(String file, String head, String foot) throws MalformedURLException, IOException { header = head; footer = foot; if (file.indexOf("://") < 0) { internal = new BufferedReader(new FileReader(file)); } else if (file.startsWith("https:")) { log.debug("trying ssl connection..."); System.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory"); HttpsURLConnection conn = (HttpsURLConnection) (new URL(file)).openConnection(); internal = new BufferedReader(new InputStreamReader(conn.getInputStream()), 200000); } else if (file.endsWith(".z") || file.endsWith(".gz")) { internal = new InputStreamReader( new GZIPInputStream((new URL(file)).openConnection().getInputStream())); } else internal = new InputStreamReader((new URL(file)).openConnection().getInputStream()); }
private void createConnection() throws IOException { String effectiveUrl = URLUtils.appendParametersToQueryString(url, querystringParams); if (connection == null) { System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false"); // connection = (HttpURLConnection) new URL(effectiveUrl).openConnection(); URL url = new URL(effectiveUrl); if (url.getProtocol().toLowerCase().equals("https")) { trustAllHosts(); HttpsURLConnection https = (HttpsURLConnection) url.openConnection(); https.setHostnameVerifier(DO_NOT_VERIFY); connection = https; } else { connection = (HttpURLConnection) url.openConnection(); } } }
void configureProxy() { if (Prefs.useSystemProxies) { try { System.setProperty("java.net.useSystemProxies", "true"); } catch (Exception e) { } } else { String server = Prefs.get("proxy.server", null); if (server == null || server.equals("")) return; int port = (int) Prefs.get("proxy.port", 0); if (port == 0) return; Properties props = System.getProperties(); props.put("proxySet", "true"); props.put("http.proxyHost", server); props.put("http.proxyPort", "" + port); } // new ProxySettings().logProperties(); }
private void initHttps() { // if(!setHttps) { String pkgs = SAAJUtil.getSystemProperty("java.protocol.handler.pkgs"); log.log(Level.FINE, "SAAJ0053.p2p.providers", new String[] {pkgs}); if (pkgs == null || pkgs.indexOf(SSL_PKG) < 0) { if (pkgs == null) pkgs = SSL_PKG; else pkgs = pkgs + "|" + SSL_PKG; System.setProperty("java.protocol.handler.pkgs", pkgs); log.log(Level.FINE, "SAAJ0054.p2p.set.providers", new String[] {pkgs}); try { Class c = Class.forName(SSL_PROVIDER); Provider p = (Provider) c.newInstance(); Security.addProvider(p); log.log(Level.FINE, "SAAJ0055.p2p.added.ssl.provider", new String[] {SSL_PROVIDER}); // System.out.println("Added SSL_PROVIDER " + SSL_PROVIDER); // setHttps = true; } catch (Exception ex) { } } // } }
/* * Define the client side of the test. * * If the server prematurely exits, serverReady will be set to true * to avoid infinite hangs. */ void doClientSide() throws Exception { /* * Wait for server to get started. */ while (!serverReady) { Thread.sleep(50); } System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier()); URL url = new URL("https://" + "localhost:" + serverPort + "/etc/hosts"); URLConnection urlc = url.openConnection(); if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) { throw new Exception("URLConnection ! instanceof " + "com.sun.net.ssl.HttpsURLConnection"); } BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(urlc.getInputStream())); String inputLine; System.out.print("Client reading... "); while ((inputLine = in.readLine()) != null) System.out.println(inputLine); System.out.println("Cipher Suite: " + ((HttpsURLConnection) urlc).getCipherSuite()); X509Certificate[] certs = ((HttpsURLConnection) urlc).getServerCertificateChain(); for (int i = 0; i < certs.length; i++) { System.out.println(certs[0]); } in.close(); } catch (SSLException e) { if (in != null) in.close(); throw e; } System.out.println("Client reports: SUCCESS"); }
private DarkBotMCSpambot( DarkBot darkBot, String server, String username, String password, String sessionId, String loginProxy, String proxy, String owner) { synchronized (bots) { bots.add(this); // slotsTaken.incrementAndGet(); synchronized (slotsTaken) { slotsTaken.notifyAll(); } } MinecraftBotData.Builder builder = MinecraftBotData.builder(); // botData.nickname = ""; // for(int i = 0; i < 10; i++) // botData.nickname += alphas[random.nextInt(alphas.length)]; if (proxy != null && !proxy.isEmpty()) { int port = 80; ProxyType type = ProxyType.SOCKS; if (proxy.contains(":")) { String[] parts = proxy.split(":"); proxy = parts[0]; port = Integer.parseInt(parts[1]); if (parts.length > 2) type = ProxyType.values()[Integer.parseInt(parts[2]) - 1]; } builder.withSocksProxy(new ProxyData(proxy, port, type)); this.proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxy, port)); } if (loginProxy != null && !loginProxy.isEmpty()) { int port = 80; if (loginProxy.contains(":")) { String[] parts = loginProxy.split(":"); loginProxy = parts[0]; port = Integer.parseInt(parts[1]); } builder.withHttpProxy(new ProxyData(loginProxy, port, ProxyType.HTTP)); this.loginProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(loginProxy, port)); } builder.withUsername(username); if (sessionId != null) builder.withSessionId(sessionId); else builder.withPassword(password); if (server != null && !server.isEmpty()) { int port = 25565; if (server.contains(":")) { String[] parts = server.split(":"); server = parts[0]; port = Integer.parseInt(parts[1]); } builder.withServer(server).withPort(port); } else throw new IllegalArgumentException("Unknown server!"); this.owner = owner; MinecraftBotData botData = builder.build(); System.setProperty("socksProxyHost", ""); System.setProperty("socksProxyPort", ""); System.out.println("[" + username + "] Connecting..."); bot = new MinecraftBot(darkBot, botData); bot.setMovementDisabled(true); connectionHandler = bot.getConnectionHandler(); Session session = bot.getSession(); // System.gc(); System.out.println("[" + username + "] Done! (" + amountJoined.incrementAndGet() + ")"); bot.getEventManager().registerListener(this); bot.getGameHandler().registerListener(this); long lastShoutTime = System.currentTimeMillis(); while (bot.isConnected()) { if (die) { connectionHandler.sendPacket(new Packet255KickDisconnect("Goodbye")); return; } try { Thread.sleep(3000 + random.nextInt(1000)); } catch (InterruptedException exception) { exception.printStackTrace(); } if (!bot.hasSpawned()) continue; connectionHandler.sendPacket(new Packet0KeepAlive(random.nextInt())); if (spamMessage == null || !canSpam) continue; String message = spamMessage; if (message.contains("%skill")) message = message.replace("%skill", skills[nextSkill++]); if (nextSkill >= skills.length) nextSkill = 0; if (message.contains("%bot")) { synchronized (bots) { message = message.replace( "%bot", bots.get(nextBot > bots.size() ? (nextBot = 0) * 0 : nextBot++) .bot .getSession() .getUsername()); } } if (message.contains("%spamlist")) message = message.replace("%spamlist", spamList[nextSpamList++]); if (nextSpamList >= spamList.length) nextSpamList = 0; if (message.contains("%rnd")) { int length = 1; int index = message.indexOf("%rnd") + "%rnd".length(); int lastIndex; for (lastIndex = index; lastIndex < message.length(); lastIndex++) if (Character.isDigit(message.charAt(lastIndex))) lastIndex++; else break; if (lastIndex > message.length()) lastIndex--; try { System.out.println(index + "," + lastIndex + "," + message.length()); length = Integer.parseInt(message.substring(index, lastIndex)); } catch (Exception exception) { } String randomChars = ""; for (int i = 0; i < length; i++) randomChars += alphas[random.nextInt(alphas.length)]; message = message.replace("%rnd", randomChars); } if (message.contains("%msg")) message = "/msg " + msgChars[nextMsgChar++] + " " + message.replace("%msg", ""); if (message.contains("%ernd")) { message = message.replace("%ernd", ""); int extraMessageLength = 15 + random.nextInt(6); message = message.substring(0, Math.min(100 - extraMessageLength, message.length())) + " ["; extraMessageLength -= 3; for (int i = 0; i < extraMessageLength; i++) message += alphas[random.nextInt(alphas.length)]; message += "]"; } else message = message.substring(0, Math.min(100, message.length())); connectionHandler.sendPacket(new Packet3Chat(message)); } synchronized (bots) { bots.remove(this); } amountJoined.decrementAndGet(); slotsTaken.decrementAndGet(); synchronized (slotsTaken) { slotsTaken.notifyAll(); } }
public void init() throws MQClientException { nameServer = PropertyFileUtil.get("rocketmq.namesrv.domain"); if (StringUtils.isBlank(nameServer)) { logger.warn("【MQ init】property rocketmq.namesrv.domain not found"); return; } if ("localTest".equals(nameServer)) { logger.warn("【MQ init】localTest"); return; } if (StringUtils.isBlank(System.getProperty("rocketmq.namesrv.domain"))) { System.setProperty("rocketmq.namesrv.domain", nameServer); } topicType = getTopic(); topic = RocketMqUtils.getTopic(topicType); if (StringUtils.isBlank(group)) { group = "S_" + topic.getTopic() + "_" + topic.getTags(); } consumer = new DefaultMQPushConsumer(group); consumer.setNamesrvAddr(nameServer); consumer.setMessageModel(getMessageModel()); consumer.setConsumeThreadMin(minConsumeThread); consumer.setConsumeThreadMax(maxConsumeThread); // 可以不设置 设置后可以起多个 消费端 try { consumer.setInstanceName("DEFAULT_CONSUMER-" + InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { logger.error("getHostName error", e); } // 设置订阅的topic 设置订阅过滤表达式 if (StringUtils.isBlank(subExpression)) { subExpression = topic.getTags(); consumer.subscribe(topic.getTopic(), subExpression); } else { consumer.subscribe(topic.getTopic(), subExpression); } try { consumer.registerMessageListener(this); consumer.start(); } catch (MQClientException e) { logger.error( "consumer start error!topic={},subExpression={},group={}", topic.getTopic(), subExpression, group, e); } logger.info( "consumer start! topic={},subExpression={},group={}", topic.getTopic(), subExpression, group); }
private void runOnDtlsTransport(StreamConnector connector) throws IOException { DtlsControlImpl dtlsControl = (DtlsControlImpl) getTransportManager().getDtlsControl(this); DtlsTransformEngine engine = dtlsControl.getTransformEngine(); final DtlsPacketTransformer transformer = (DtlsPacketTransformer) engine.getRTPTransformer(); byte[] receiveBuffer = new byte[SCTP_BUFFER_SIZE]; if (LOG_SCTP_PACKETS) { System.setProperty( ConfigurationService.PNAME_SC_HOME_DIR_LOCATION, System.getProperty("java.io.tmpdir")); System.setProperty( ConfigurationService.PNAME_SC_HOME_DIR_NAME, SctpConnection.class.getName()); } synchronized (this) { // FIXME local SCTP port is hardcoded in bridge offer SDP (Jitsi // Meet) sctpSocket = Sctp.createSocket(5000); assocIsUp = false; acceptedIncomingConnection = false; } // Implement output network link for SCTP stack on DTLS transport sctpSocket.setLink( new NetworkLink() { @Override public void onConnOut(SctpSocket s, byte[] packet) throws IOException { if (LOG_SCTP_PACKETS) { LibJitsi.getPacketLoggingService() .logPacket( PacketLoggingService.ProtocolName.ICE4J, new byte[] {0, 0, 0, (byte) debugId}, 5000, new byte[] {0, 0, 0, (byte) (debugId + 1)}, remoteSctpPort, PacketLoggingService.TransportName.UDP, true, packet); } // Send through DTLS transport transformer.sendApplicationData(packet, 0, packet.length); } }); if (logger.isDebugEnabled()) { logger.debug("Connecting SCTP to port: " + remoteSctpPort + " to " + getEndpoint().getID()); } sctpSocket.setNotificationListener(this); sctpSocket.listen(); // FIXME manage threads threadPool.execute( new Runnable() { @Override public void run() { SctpSocket sctpSocket = null; try { // sctpSocket is set to null on close sctpSocket = SctpConnection.this.sctpSocket; while (sctpSocket != null) { if (sctpSocket.accept()) { acceptedIncomingConnection = true; break; } Thread.sleep(100); sctpSocket = SctpConnection.this.sctpSocket; } if (isReady()) { notifySctpConnectionReady(); } } catch (Exception e) { logger.error("Error accepting SCTP connection", e); } if (sctpSocket == null && logger.isInfoEnabled()) { logger.info( "SctpConnection " + getID() + " closed" + " before SctpSocket accept()-ed."); } } }); // Notify that from now on SCTP connection is considered functional sctpSocket.setDataCallback(this); // Setup iceSocket DatagramSocket datagramSocket = connector.getDataSocket(); if (datagramSocket != null) { this.iceSocket = new IceUdpSocketWrapper(datagramSocket); } else { this.iceSocket = new IceTcpSocketWrapper(connector.getDataTCPSocket()); } DatagramPacket rcvPacket = new DatagramPacket(receiveBuffer, 0, receiveBuffer.length); // Receive loop, breaks when SCTP socket is closed try { do { iceSocket.receive(rcvPacket); RawPacket raw = new RawPacket(rcvPacket.getData(), rcvPacket.getOffset(), rcvPacket.getLength()); raw = transformer.reverseTransform(raw); // Check for app data if (raw == null) continue; if (LOG_SCTP_PACKETS) { LibJitsi.getPacketLoggingService() .logPacket( PacketLoggingService.ProtocolName.ICE4J, new byte[] {0, 0, 0, (byte) (debugId + 1)}, remoteSctpPort, new byte[] {0, 0, 0, (byte) debugId}, 5000, PacketLoggingService.TransportName.UDP, false, raw.getBuffer(), raw.getOffset(), raw.getLength()); } // Pass network packet to SCTP stack sctpSocket.onConnIn(raw.getBuffer(), raw.getOffset(), raw.getLength()); } while (true); } finally { // Eventually, close the socket although it should happen from // expire(). synchronized (this) { assocIsUp = false; acceptedIncomingConnection = false; if (sctpSocket != null) { sctpSocket.close(); sctpSocket = null; } } } }
/** {@inheritDoc} */ @SuppressWarnings("BusyWait") @Override public void start(GridRestProtocolHandler hnd) throws GridException { InetAddress locHost; try { locHost = U.resolveLocalHost(ctx.config().getLocalHost()); } catch (IOException e) { throw new GridException( "Failed to resolve local host to bind address: " + ctx.config().getLocalHost(), e); } System.setProperty(GG_JETTY_HOST, locHost.getHostAddress()); jettyHnd = new GridJettyRestHandler( hnd, new C1<String, Boolean>() { @Override public Boolean apply(String tok) { return F.isEmpty(secretKey) || authenticate(tok); } }, log); String jettyPath = ctx.config().getRestJettyPath(); final URL cfgUrl; if (jettyPath == null) { cfgUrl = null; if (log.isDebugEnabled()) log.debug("Jetty configuration file is not provided, using defaults."); } else { cfgUrl = U.resolveGridGainUrl(jettyPath); if (cfgUrl == null) throw new GridSpiException("Invalid Jetty configuration file: " + jettyPath); else if (log.isDebugEnabled()) log.debug("Jetty configuration file: " + cfgUrl); } loadJettyConfiguration(cfgUrl); AbstractNetworkConnector connector = getJettyConnector(); try { host = InetAddress.getByName(connector.getHost()); } catch (UnknownHostException e) { throw new GridException("Failed to resolve Jetty host address: " + connector.getHost(), e); } int initPort = connector.getPort(); int lastPort = initPort + ctx.config().getRestPortRange() - 1; for (port = initPort; port <= lastPort; port++) { connector.setPort(port); if (startJetty()) { if (log.isInfoEnabled()) log.info(startInfo()); return; } } U.warn( log, "Failed to start Jetty REST server (possibly all ports in range are in use) " + "[firstPort=" + initPort + ", lastPort=" + lastPort + ']'); }
public static void main(String args[]) throws Exception { if (debug) System.setProperty("javax.net.debug", "all"); new LargePacket(); }
/** * Try to determine whether this application is running under Windows or some other platform by * examining the "os.name" property. */ static { String os = System.getProperty("os.name"); // String version = System.getProperty("os.version"); // for Win7, reports "6.0" on JDK7, should // be "6.1"; for Win8, reports "6.2" as of JDK7u17 if (SystemUtils.startsWithIgnoreCase(os, "windows 7")) isWin7 = true; // reports "Windows Vista" on JDK7 else if (SystemUtils.startsWithIgnoreCase(os, "windows 8")) isWin7 = true; // reports "Windows 8" as of JDK7u17 else if (SystemUtils.startsWithIgnoreCase(os, "windows vista")) isVista = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows xp")) isWinXP = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows 2000")) isWin2k = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows nt")) isWinNT = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows")) isWin9X = true; // win95 or win98 (what about WinME?) else if (SystemUtils.startsWithIgnoreCase(os, "mac")) isMac = true; else if (SystemUtils.startsWithIgnoreCase(os, "so")) isSolaris = true; // sunos or solaris else if (os.equalsIgnoreCase("linux")) isLinux = true; else isUnix = true; // assume UNIX, e.g. AIX, HP-UX, IRIX String osarch = System.getProperty("os.arch"); String arch = (osarch != null && osarch.contains("64")) ? "_x64" /* eg. 'amd64' */ : "_x32"; String syslib = SYSLIB + arch; try { // loading a native lib in a static initializer ensures that it is available before any // method in this class is called: System.loadLibrary(syslib); System.out.println( "Done loading '" + System.mapLibraryName(syslib) + "', PID=" + getProcessID()); } catch (Error e) { System.err.println( "Native library '" + System.mapLibraryName(syslib) + "' not found in 'java.library.path': " + System.getProperty("java.library.path")); throw e; // re-throw } if (isWinPlatform()) { System.setProperty( "line.separator", "\n"); // so we won't have to mess with DOS line endings ever again comSpec = getEnv( "comSpec"); // use native method here since getEnvironmentVariable() needs to know // comSpec comSpec = (comSpec != null) ? comSpec + " /c " : ""; try (BufferedReader br = new BufferedReader( new InputStreamReader( RUNTIME.exec(comSpec + "ver").getInputStream()))) { // fix for Win7,8 for (String line = null; (line = br.readLine()) != null; ) { if (isVista && (line.contains("6.1" /*Win7*/) || line.contains("6.2" /*Win8*/))) { isVista = false; isWin7 = true; } } } catch (IOException e) { e.printStackTrace(); } String cygdir = getEnv("cygdir"); // this is set during CygWin install to "?:/cygwin/bin" isCygWin = (cygdir != null && !cygdir.equals("%cygdir%")); cygstartPath = cygdir + "/cygstart.exe"; // path to CygWin's cygutils' "cygstart" binary if (getDebug() && Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); for (Desktop.Action action : Desktop.Action.values()) System.out.println( "Desktop action " + action + " supported? " + desktop.isSupported(action)); } } }
/** * Set the environment variable to indicate where the CA cert is found on the filesystem. * LibMyProxy relies on this. */ public static void setCoGProperties() { System.setProperty("X509_CERT_DIR", getCurrentDir()); }