List of usage examples for java.net InetAddress getByName
public static InetAddress getByName(String host) throws UnknownHostException
From source file:com.dtstack.jlogstash.inputs.Tcp.java
@Override public void emit() { // TODO Auto-generated method stub try {/*from ww w . ja v a 2 s.c o m*/ // ssl ? if (sslEnable) { SslFilter sslFilter = new SslFilter(getSslContext()); acceptor.getFilterChain().addLast("sslFilter", sslFilter); logger.warn("ssl authenticate is open"); } LoggingFilter loggingFilter = new LoggingFilter(); acceptor.getFilterChain().addLast("logger", loggingFilter); TextLineCodecFactory textLineCodecFactory = new TextLineCodecFactory(Charset.forName(encodiing)); textLineCodecFactory.setDecoderMaxLineLength(maxLineLength); textLineCodecFactory.setEncoderMaxLineLength(maxLineLength); acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(textLineCodecFactory)); acceptor.setHandler(minaBizHandler); acceptor.getSessionConfig().setReadBufferSize(bufSize); acceptor.getSessionConfig().setWriteTimeout(10); // acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, // 10);//? acceptor.bind(new InetSocketAddress(InetAddress.getByName(host), port)); } catch (Exception e) { // TODO Auto-generated catch block logger.error(e.getMessage()); System.exit(1); } }
From source file:org.jboss.shrinkwrap.tomcat_6.test.TomcatDeploymentIntegrationUnitTestCase.java
/** * Configures and starts the Tomcat Embedded Server *///from ww w.ja va 2 s .co m @BeforeClass public static void createServerAndDeployWebapp() throws Exception { // Create the new server server = new Embedded(); server.setName("tomcat"); Engine engine = server.createEngine(); engine.setName("tomcat"); engine.setDefaultHost(HTTP_BIND_HOST); engine.setService(server); server.setContainer(engine); server.addEngine(engine); StandardHost host = (StandardHost) server.createHost(HTTP_BIND_HOST, System.getProperty("java.io.tmpdir")); host.setUnpackWARs(false); host.setWorkDir("target/work"); engine.addChild(host); Connector connector = server.createConnector(InetAddress.getByName(HTTP_BIND_HOST), HTTP_BIND_PORT, false); server.addConnector(connector); connector.setContainer(engine); // starts embedded tomcat server.init(); server.start(); final WebArchive archive = ShrinkWrap.create(WebArchive.class, NAME_WAR); archive.setWebXML(PATH_ACTUAL_WEB_XML).addClasses(servletClass, echoServletClass); log.info(archive.toString(true)); // Deploy final StandardContext context = archive.as(ShrinkWrapStandardContext.class); context.addLifecycleListener(new ContextConfig()); host.addChild(context); }
From source file:gov.hhs.fha.nhinc.lift.ServerApp.java
private InetSocketAddress createSocketAddr() { InetSocketAddress addr = null; String proxyAddr = ""; String proxyPort = ""; try {// w ww . jav a 2s. com proxyAddr = PropertyAccessor.getProperty(NhincConstants.GATEWAY_PROPERTY_FILE, NhincConstants.LIFT_PROXY_ADDRESS); proxyPort = PropertyAccessor.getProperty(NhincConstants.GATEWAY_PROPERTY_FILE, NhincConstants.LIFT_PROXY_PORT); int portNum = Integer.parseInt(proxyPort); InetAddress inetAddr = InetAddress.getByName(proxyAddr); addr = new InetSocketAddress(inetAddr, portNum); log.debug("LiFT Server Address defined as: " + addr.toString()); } catch (UnknownHostException ex) { log.error("Unknown LiFT Proxy Address and Port " + proxyAddr + ":" + proxyPort + " " + ex.getMessage()); } catch (PropertyAccessException ex) { log.error("Missing LiFT Proxy Address and Port Properties " + ex.getMessage()); } return addr; }
From source file:org.jboss.as.test.integration.security.CustomLoginModuleTestCase.java
@AfterClass public static void after() throws Exception { final ModelControllerClient client = ModelControllerClient.Factory .create(InetAddress.getByName("localhost"), 9999); // remove test security domains removeSecurityDomains(client);//from ww w. j a v a 2 s . c o m }
From source file:org.muckebox.android.net.DownloadServer.java
@Override public void run() { super.run();//from w w w. j a va 2 s . c o m try { d("Starting server on " + mPort); mServerSocket = new ServerSocket(mPort, 0, InetAddress.getByName("localhost")); mServerSocket.setReuseAddress(true); try { mReady = true; while (!mStopped) { Socket socket = null; DefaultHttpServerConnection connection = new DefaultHttpServerConnection(); try { d("Waiting for new connection"); socket = mServerSocket.accept(); d("Got connection"); connection.bind(socket, new BasicHttpParams()); mHttpService.handleRequest(connection, mHttpContext); d("Request handling finished"); } catch (HttpException e) { Log.e(LOG_TAG, "Got HTTP error: " + e); } finally { connection.shutdown(); if (socket != null) socket.close(); socket = null; } } } finally { if (mServerSocket != null) mServerSocket.close(); } d("Server stopped"); } catch (IOException e) { Log.i(LOG_TAG, "IOException, probably ok"); e.printStackTrace(); } }
From source file:com.odap.server.audit.AuditServer.java
public static void simple(AuditEvent.Processor processor, String iname) { try {// www . java 2 s. co m //TODO Ensure performance of SSL is good TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters(); params.setKeyStore("keystore.jks", keystore_password); TServerSocket serverTransport = TSSLTransportFactory.getServerSocket(7911, 10000, InetAddress.getByName(iname), params); TServer server = new TThreadPoolServer( new TThreadPoolServer.Args(serverTransport).processor(processor)); logger.info("Starting server on port 7911 ..."); server.serve(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.mirth.connect.connectors.mllp.MllpMessageDispatcher.java
protected StateAwareSocket initSocket(String endpoint) throws IOException, URISyntaxException { if (connectedSockets.get(endpoint) != null) { monitoringController.updateStatus(connector, connectorType, Event.DISCONNECTED, connectedSockets.get(endpoint)); }// w w w. ja v a2 s . c om URI uri = new URI(endpoint); int port = uri.getPort(); InetAddress inetAddress = InetAddress.getByName(uri.getHost()); InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, port); StateAwareSocket socket = new StateAwareSocket(); createSocket(socket, inetSocketAddress); socket.setReuseAddress(true); socket.setReceiveBufferSize(connector.getBufferSize()); socket.setSendBufferSize(connector.getBufferSize()); socket.setSoTimeout(connector.getSendTimeout()); socket.setKeepAlive(connector.isKeepAlive()); connectedSockets.put(endpoint, socket); monitoringController.updateStatus(connector, connectorType, Event.CONNECTED, socket); return socket; }
From source file:ch.sentric.URL.java
/** * Resolve the ip address from the authority. * /*from www. jav a 2 s. c o m*/ * @return ip address as string * @throws UnknownHostException * when ip can not be resolved */ public String resolveIp() throws UnknownHostException { final String ip = InetAddress.getByName(this.getAuthority().getAsString()).getHostAddress(); if (ip.equals("127.0.0.1")) { throw new UnknownHostException("IP" + ip + "not valid"); } return ip; }
From source file:net.dnsviz.lookingglass.DNSLookingGlass.java
public DNSQueryTransportHandler getDNSQueryTransportHandler(String req, String dst, int dport, String src, int sport, long timeout, boolean tcp) throws UnknownHostException { Base64Decoder d = new Base64Decoder(); byte[] byteReq = d.decode(req.getBytes()); InetAddress srcAddr = null;//from w ww . j a va 2 s .co m InetAddress dstAddr = null; if (dst != null) { dstAddr = InetAddress.getByName(dst); } if (src != null) { srcAddr = InetAddress.getByName(src); } if (tcp) { return new DNSQueryTransportHandlerTCP(byteReq, dstAddr, dport, srcAddr, sport, timeout); } else { return new DNSQueryTransportHandlerUDP(byteReq, dstAddr, dport, srcAddr, sport, timeout); } }
From source file:com.xsdn.main.util.IpNetwork.java
/** * Create an {@link InetAddress} instance which represents the IP address * specified by the given string./*from ww w . ja v a 2 s . c om*/ * * @param text A string representation of an IP address. * @return An {@link InetAddress} instance. * @throws NullPointerException * {@code text} is {@code null}. * @throws IllegalArgumentException * The given string does not represent an IP address. */ public static final InetAddress getInetAddress(String text) { if (text.isEmpty()) { throw new IllegalArgumentException("IP address cannot be empty."); } try { return InetAddress.getByName(text); } catch (Exception e) { throw new IllegalArgumentException("Invalid IP address: " + text, e); } }