List of usage examples for java.net InetSocketAddress getAddress
public final InetAddress getAddress()
From source file:org.apache.james.protocols.lmtp.AbstractLMTPServerTest.java
@Test public void testEhloNotSupported() throws Exception { TestMessageHook hook = new TestMessageHook(); InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort()); ProtocolServer server = null;// w w w .j a v a2s. c o m try { server = createServer(createProtocol(hook), address); server.bind(); SMTPClient client = createClient(); client.connect(address.getAddress().getHostAddress(), address.getPort()); assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode())); client.sendCommand("HELO localhost"); assertTrue(SMTPReply.isNegativePermanent(client.getReplyCode())); client.quit(); assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode())); client.disconnect(); Iterator<MailEnvelope> queued = hook.getQueued().iterator(); assertFalse(queued.hasNext()); } finally { if (server != null) { server.unbind(); } } }
From source file:org.apache.james.protocols.lmtp.AbstractLMTPServerTest.java
@Override public void testMailWithoutBrackets() throws Exception { TestMessageHook hook = new TestMessageHook(); InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort()); ProtocolServer server = null;//from w w w . j av a 2s. co m try { server = createServer(createProtocol(hook), address); server.bind(); SMTPClient client = createClient(); client.connect(address.getAddress().getHostAddress(), address.getPort()); assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode())); client.helo("localhost"); assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode())); client.mail(SENDER); assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode())); client.quit(); assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode())); client.disconnect(); Iterator<MailEnvelope> queued = hook.getQueued().iterator(); assertFalse(queued.hasNext()); } finally { if (server != null) { server.unbind(); } } }
From source file:org.apache.james.protocols.lmtp.AbstractLMTPServerTest.java
@Override public void testRcptWithoutBrackets() throws Exception { TestMessageHook hook = new TestMessageHook(); InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort()); ProtocolServer server = null;/*ww w .j ava 2 s . co m*/ try { server = createServer(createProtocol(hook), address); server.bind(); SMTPClient client = createClient(); client.connect(address.getAddress().getHostAddress(), address.getPort()); assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode())); client.helo("localhost"); assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode())); client.setSender(SENDER); assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode())); client.rcpt(RCPT1); assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode())); client.quit(); assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode())); client.disconnect(); Iterator<MailEnvelope> queued = hook.getQueued().iterator(); assertFalse(queued.hasNext()); } finally { if (server != null) { server.unbind(); } } }
From source file:org.apache.james.protocols.pop3.AbstractStartTlsPOP3ServerTest.java
@Test public void testStartTls() throws Exception { InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort()); ProtocolServer server = null;/*from www.ja v a 2s .co m*/ try { String identifier = "id"; TestPassCmdHandler handler = new TestPassCmdHandler(); handler.add("valid", new MockMailbox(identifier)); server = createServer(createProtocol(handler), address, Encryption.createStartTls(BogusSslContextFactory.getServerContext())); server.bind(); POP3SClient client = createClient(); client.connect(address.getAddress().getHostAddress(), address.getPort()); // TODO: Make use of client.capa() once possible // See NET-438 assertEquals(POP3Reply.OK, client.sendCommand("CAPA")); client.getAdditionalReply(); boolean startTlsCapa = false; for (String cap : client.getReplyStrings()) { if (cap.equalsIgnoreCase("STLS")) { startTlsCapa = true; break; } } assertTrue(startTlsCapa); assertTrue(client.execTLS()); // TODO: Reenable when commons-net 3.1.0 was released // See NET-430 // //assertTrue(client.logout()); client.disconnect(); } finally { if (server != null) { server.unbind(); } } }
From source file:org.apache.james.protocols.lmtp.AbstractLMTPServerTest.java
@Test public void testDeliveryHook() throws Exception { TestDeliverHook deliverHook = new TestDeliverHook(); InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort()); ProtocolServer server = null;/*from w w w. ja v a 2 s. c o m*/ try { server = createServer(createProtocol(deliverHook), address); server.bind(); SMTPClient client = createClient(); client.connect(address.getAddress().getHostAddress(), address.getPort()); assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode())); client.helo("localhost"); assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode())); client.setSender(SENDER); assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode())); client.addRecipient(RCPT1); assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode())); client.addRecipient(RCPT2); assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode())); assertTrue(client.sendShortMessageData(MSG1)); int[] replies = ((LMTPClient) client).getReplies(); assertEquals("Expected two replies", 2, replies.length); assertTrue(SMTPReply.isNegativePermanent(replies[0])); assertTrue(SMTPReply.isPositiveCompletion(replies[1])); client.quit(); assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode())); client.disconnect(); Iterator<MailEnvelope> queued = deliverHook.getDelivered().iterator(); assertTrue(queued.hasNext()); MailEnvelope env = queued.next(); checkEnvelope(env, SENDER, Arrays.asList(RCPT1, RCPT2), MSG1); assertFalse(queued.hasNext()); } finally { if (server != null) { server.unbind(); } } }
From source file:com.cloud.bridge.io.S3CAStorBucketAdapter.java
private String castorURL(String mountedRoot, String bucket, String fileName) { // TODO: Replace this method with access to ScspClient's Locator, // or add read method that returns the body as an unread // InputStream for use by loadObject() and loadObjectRange(). myClient(mountedRoot); // make sure castorNodes and castorPort initialized InetSocketAddress nodeAddr = _locator.locate(); if (nodeAddr == null) { throw new ConfigurationException("Unable to locate CAStor node with locator " + _locator); }//from w w w .j a v a 2 s. co m InetAddress nodeInetAddr = nodeAddr.getAddress(); if (nodeInetAddr == null) { _locator.foundDead(nodeAddr); throw new ConfigurationException( "Unable to resolve CAStor node name '" + nodeAddr.getHostName() + "' to IP address"); } return "http://" + nodeInetAddr.getHostAddress() + ":" + nodeAddr.getPort() + "/" + bucket + "/" + fileName + (_domain == null ? "" : "?domain=" + _domain); }
From source file:com.nebkat.junglist.bot.http.EasySSLSocketFactory.java
public Socket connectSocket(Socket sock, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpParams params) throws IOException { int connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params); int localPort = localAddress != null ? localAddress.getPort() : -1; SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket()); if (localAddress != null) { // we need to bind explicitly if (localPort < 0) { localPort = 0; // indicates "any" }/* ww w . java 2 s.c o m*/ InetSocketAddress isa = new InetSocketAddress(localAddress.getAddress(), localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress, connTimeout); sslsock.setSoTimeout(soTimeout); return sslsock; }
From source file:org.apache.bookkeeper.client.TestRegionAwareEnsemblePlacementPolicy.java
private int getNumCoveredRegionsInWriteQuorum(ArrayList<InetSocketAddress> ensemble, int writeQuorumSize) throws Exception { int ensembleSize = ensemble.size(); int numCoveredWriteQuorums = 0; for (int i = 0; i < ensembleSize; i++) { Set<String> regions = new HashSet<String>(); for (int j = 0; j < writeQuorumSize; j++) { int bookieIdx = (i + j) % ensembleSize; InetSocketAddress addr = ensemble.get(bookieIdx); regions.add(StaticDNSResolver.getRegion(addr.getAddress().getHostAddress())); }// ww w .j a v a 2 s. com numCoveredWriteQuorums += (regions.size() > 1 ? 1 : 0); } return numCoveredWriteQuorums; }
From source file:org.apache.tajo.ha.HdfsServiceTracker.java
public HdfsServiceTracker(TajoConf conf) throws IOException { this.conf = conf; initSystemDirectory();//from ww w . j av a 2 s. c om InetSocketAddress socketAddress = conf.getSocketAddrVar(ConfVars.TAJO_MASTER_UMBILICAL_RPC_ADDRESS); this.masterName = socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort(); this.monitorInterval = conf.getIntVar(ConfVars.TAJO_MASTER_HA_MONITOR_INTERVAL); }
From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java
@Test public void testResolveLocalAddress() throws Exception { final InternalAddressResolver addressResolver = new InternalAddressResolver(schemePortResolver, dnsResolver);//from w ww. j a v a 2 s . c om final HttpHost target = new HttpHost("localhost"); final byte[] ip = new byte[] { 10, 0, 0, 10 }; final HttpRoute route = new HttpRoute(target, InetAddress.getByAddress(ip), false); final InetSocketAddress address = (InetSocketAddress) addressResolver.resolveLocalAddress(route); Assert.assertNotNull(address); Assert.assertEquals(InetAddress.getByAddress(ip), address.getAddress()); Assert.assertEquals(0, address.getPort()); }