當前位置: 首頁>>代碼示例>>Java>>正文


Java SocketFactory類代碼示例

本文整理匯總了Java中javax.net.SocketFactory的典型用法代碼示例。如果您正苦於以下問題:Java SocketFactory類的具體用法?Java SocketFactory怎麽用?Java SocketFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SocketFactory類屬於javax.net包,在下文中一共展示了SocketFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createSocketFactory

import javax.net.SocketFactory; //導入依賴的package包/類
public SocketFactory createSocketFactory() {
    try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, new TrustManager[] { this }, null);
        return sslContext.getSocketFactory();
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        throw new RuntimeException("Failed to create a SSL socket factory");
    }
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:10,代碼來源:UserOverrideTrustManager.java

示例2: Address

import javax.net.SocketFactory; //導入依賴的package包/類
public Address(String uriHost, int uriPort, Dns dns, SocketFactory socketFactory,
    SSLSocketFactory sslSocketFactory, HostnameVerifier hostnameVerifier,
    CertificatePinner certificatePinner, Authenticator proxyAuthenticator, Proxy proxy,
    List<Protocol> protocols, List<ConnectionSpec> connectionSpecs, ProxySelector proxySelector) {
  this.url = new HttpUrl.Builder()
      .scheme(sslSocketFactory != null ? "https" : "http")
      .host(uriHost)
      .port(uriPort)
      .build();

  if (dns == null) throw new NullPointerException("dns == null");
  this.dns = dns;

  if (socketFactory == null) throw new NullPointerException("socketFactory == null");
  this.socketFactory = socketFactory;

  if (proxyAuthenticator == null) {
    throw new NullPointerException("proxyAuthenticator == null");
  }
  this.proxyAuthenticator = proxyAuthenticator;

  if (protocols == null) throw new NullPointerException("protocols == null");
  this.protocols = Util.immutableList(protocols);

  if (connectionSpecs == null) throw new NullPointerException("connectionSpecs == null");
  this.connectionSpecs = Util.immutableList(connectionSpecs);

  if (proxySelector == null) throw new NullPointerException("proxySelector == null");
  this.proxySelector = proxySelector;

  this.proxy = proxy;
  this.sslSocketFactory = sslSocketFactory;
  this.hostnameVerifier = hostnameVerifier;
  this.certificatePinner = certificatePinner;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:36,代碼來源:Address.java

示例3: openChannel

import javax.net.SocketFactory; //導入依賴的package包/類
public static Channel openChannel ( InetSocketAddress isa ) throws IOException, SocketException {
    System.err.println("* Opening socket " + isa);
    Socket s = SocketFactory.getDefault().createSocket(isa.getAddress(), isa.getPort());
    s.setKeepAlive(true);
    s.setTcpNoDelay(true);

    System.err.println("* Opening channel");
    OutputStream outputStream = s.getOutputStream();
    DataOutputStream dos = new DataOutputStream(outputStream);
    dos.writeUTF("Protocol:CLI-connect");
    ExecutorService cp = Executors.newCachedThreadPool(new ThreadFactory() {

        public Thread newThread ( Runnable r ) {
            Thread t = new Thread(r, "Channel");
            t.setDaemon(true);
            return t;
        }
    });
    Channel c = new ChannelBuilder("EXPLOIT", cp).withMode(Mode.BINARY).build(s.getInputStream(), outputStream);
    System.err.println("* Channel open");
    return c;
}
 
開發者ID:hucheat,項目名稱:APacheSynapseSimplePOC,代碼行數:23,代碼來源:JenkinsCLI.java

示例4: getSocketFactory

import javax.net.SocketFactory; //導入依賴的package包/類
/**
 * Get the socket factory for the given class according to its
 * configuration parameter
 * <tt>hadoop.rpc.socket.factory.class.&lt;ClassName&gt;</tt>. When no
 * such parameter exists then fall back on the default socket factory as
 * configured by <tt>hadoop.rpc.socket.factory.class.default</tt>. If
 * this default socket factory is not configured, then fall back on the JVM
 * default socket factory.
 * 
 * @param conf the configuration
 * @param clazz the class (usually a {@link VersionedProtocol})
 * @return a socket factory
 */
public static SocketFactory getSocketFactory(Configuration conf,
    Class<?> clazz) {

  SocketFactory factory = null;

  String propValue =
      conf.get("hadoop.rpc.socket.factory.class." + clazz.getSimpleName());
  if ((propValue != null) && (propValue.length() > 0))
    factory = getSocketFactoryFromProperty(conf, propValue);

  if (factory == null)
    factory = getDefaultSocketFactory(conf);

  return factory;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:29,代碼來源:NetUtils.java

示例5: getProxyForAddress

import javax.net.SocketFactory; //導入依賴的package包/類
private HAServiceProtocol getProxyForAddress(Configuration conf,
    int timeoutMs, InetSocketAddress addr) throws IOException {
  Configuration confCopy = new Configuration(conf);
  // Lower the timeout so we quickly fail to connect
  confCopy.setInt(
      CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1);
  SocketFactory factory = NetUtils.getDefaultSocketFactory(confCopy);
  return new HAServiceProtocolClientSideTranslatorPB(
      addr,
      confCopy, factory, timeoutMs);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:12,代碼來源:HAServiceTarget.java

示例6: HAServiceProtocolClientSideTranslatorPB

import javax.net.SocketFactory; //導入依賴的package包/類
public HAServiceProtocolClientSideTranslatorPB(
    InetSocketAddress addr, Configuration conf,
    SocketFactory socketFactory, int timeout) throws IOException {
  RPC.setProtocolEngine(conf, HAServiceProtocolPB.class,
      ProtobufRpcEngine.class);
  rpcProxy = RPC.getProxy(HAServiceProtocolPB.class,
      RPC.getProtocolVersion(HAServiceProtocolPB.class), addr,
      UserGroupInformation.getCurrentUser(), conf, socketFactory, timeout);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:10,代碼來源:HAServiceProtocolClientSideTranslatorPB.java

示例7: getDefaultSocketFactory

import javax.net.SocketFactory; //導入依賴的package包/類
/**
 * Get the default socket factory as specified by the configuration
 * parameter <tt>hadoop.rpc.socket.factory.default</tt>
 * 
 * @param conf the configuration
 * @return the default socket factory as specified in the configuration or
 *         the JVM default socket factory if the configuration does not
 *         contain a default socket factory property.
 */
public static SocketFactory getDefaultSocketFactory(Configuration conf) {

  String propValue = conf.get(
      CommonConfigurationKeysPublic.HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_KEY,
      CommonConfigurationKeysPublic.HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_DEFAULT);
  if ((propValue == null) || (propValue.length() == 0))
    return SocketFactory.getDefault();

  return getSocketFactoryFromProperty(conf, propValue);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:20,代碼來源:NetUtils.java

示例8: createSocket

import javax.net.SocketFactory; //導入依賴的package包/類
/**
 * Attempts to get a new socket connection to the given host within the given time limit.
 * <p>
 * This method employs several techniques to circumvent the limitations of older JREs that 
 * do not support connect timeout. When running in JRE 1.4 or above reflection is used to 
 * call Socket#connect(SocketAddress endpoint, int timeout) method. When executing in older 
 * JREs a controller thread is executed. The controller thread attempts to create a new socket
 * within the given limit of time. If socket constructor does not return until the timeout 
 * expires, the controller terminates and throws an {@link ConnectTimeoutException}
 * </p>
 *  
 * @param host the host name/IP
 * @param port the port on the host
 * @param clientHost the local host name/IP to bind the socket to
 * @param clientPort the port on the local machine
 * @param params {@link HttpConnectionParams Http connection parameters}
 * 
 * @return Socket a new socket
 * 
 * @throws IOException if an I/O error occurs while creating the socket
 * @throws UnknownHostException if the IP address of the host cannot be
 * determined
 */
public Socket createSocket(
    final String host,
    final int port,
    final InetAddress localAddress,
    final int localPort,
    final HttpConnectionParams params
) throws IOException, UnknownHostException, ConnectTimeoutException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }
    int timeout = params.getConnectionTimeout();
    Socket socket = null;
    
    SocketFactory socketfactory = SSLSocketFactory.getDefault();
    if (timeout == 0) {
        socket = socketfactory.createSocket(host, port, localAddress, localPort);
    } else {
        socket = socketfactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
    }
    verifyHostname((SSLSocket)socket);
    return socket;
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:50,代碼來源:StrictSSLProtocolSocketFactory.java

示例9: testSocketFactoryException

import javax.net.SocketFactory; //導入依賴的package包/類
/**
 * Test that, if the socket factory throws an IOE, it properly propagates
 * to the client.
 */
@Test(timeout=60000)
public void testSocketFactoryException() throws IOException {
  SocketFactory mockFactory = mock(SocketFactory.class);
  doThrow(new IOException("Injected fault")).when(mockFactory).createSocket();
  Client client = new Client(LongWritable.class, conf, mockFactory);
  
  InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10);
  try {
    call(client, RANDOM.nextLong(), address, conf);
    fail("Expected an exception to have been thrown");
  } catch (IOException e) {
    assertTrue(e.getMessage().contains("Injected fault"));
  } finally {
    client.stop();
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:21,代碼來源:TestIPC.java

示例10: ZKFCProtocolClientSideTranslatorPB

import javax.net.SocketFactory; //導入依賴的package包/類
public ZKFCProtocolClientSideTranslatorPB(
    InetSocketAddress addr, Configuration conf,
    SocketFactory socketFactory, int timeout) throws IOException {
  RPC.setProtocolEngine(conf, ZKFCProtocolPB.class,
      ProtobufRpcEngine.class);
  rpcProxy = RPC.getProxy(ZKFCProtocolPB.class,
      RPC.getProtocolVersion(ZKFCProtocolPB.class), addr,
      UserGroupInformation.getCurrentUser(), conf, socketFactory, timeout);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:10,代碼來源:ZKFCProtocolClientSideTranslatorPB.java

示例11: RealConnection

import javax.net.SocketFactory; //導入依賴的package包/類
RealConnection(SocketFactory socketFactory,
               SSLSocketFactory sslSocketFactory,
               HostnameVerifier hostnameVerifier,
               Endpoint endpoint, int connectTimeout, TimeUnit timeUnit) throws IOException {
    this.socketFactory = socketFactory;
    this.sslSocketFactory = sslSocketFactory;
    this.hostnameVerifier = hostnameVerifier;
    this.endpoint = endpoint;
    try {
        this.rawSocket = createSocket(endpoint, (int) timeUnit.toMillis(connectTimeout));
        this.socket = upgradeSocket(rawSocket, endpoint);
        this.inputStream = socket.getInputStream();
        this.outputStream = socket.getOutputStream();
        this.source = Okio.buffer(Okio.source(inputStream));
        this.sink = Okio.buffer(Okio.sink(outputStream));
        socket.setSoTimeout(0);
        source.timeout().timeout(readTimeout(), TimeUnit.MILLISECONDS);
        sink.timeout().timeout(writeTimeout(), TimeUnit.MILLISECONDS);
        connected = true;
    } finally {
        if (!connected) {
            close();
        }
    }
}
 
開發者ID:pCloud,項目名稱:pcloud-networking-java,代碼行數:26,代碼來源:RealConnection.java

示例12: setUp

import javax.net.SocketFactory; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    DummySocket dummySocket = new DummySocket();
    socket = spy(dummySocket);
    socketFactory = mock(SocketFactory.class);
    when(socketFactory.createSocket()).thenReturn(socket);

    sslSocket = mock(SSLSocket.class);
    when(sslSocket.getInputStream()).thenReturn(dummySocket.getInputStream());
    when(sslSocket.getOutputStream()).thenReturn(dummySocket.getOutputStream());

    sslSocketFactory = mock(SSLSocketFactory.class);
    when(sslSocketFactory.createSocket(any(Socket.class), anyString(), anyInt(), anyBoolean()))
            .thenReturn(sslSocket);

    hostnameVerifier = mock(HostnameVerifier.class);
    when(hostnameVerifier.verify(anyString(), any(SSLSession.class))).thenReturn(true);
}
 
開發者ID:pCloud,項目名稱:pcloud-networking-java,代碼行數:19,代碼來源:RealConnectionTest.java

示例13: getSocketFactory

import javax.net.SocketFactory; //導入依賴的package包/類
/**
 * Get the socket factory for the given class according to its
 * configuration parameter
 * <tt>hadoop.rpc.socket.factory.class.&lt;ClassName&gt;</tt>. When no
 * such parameter exists then fall back on the default socket factory as
 * configured by <tt>hadoop.rpc.socket.factory.class.default</tt>. If
 * this default socket factory is not configured, then fall back on the JVM
 * default socket factory.
 * 
 * @param conf the configuration
 * @param clazz the class (usually a {@link ProtocolInterface})
 * @return a socket factory
 */
public static SocketFactory getSocketFactory(Configuration conf,
    Class<?> clazz) {

  SocketFactory factory = null;

  String propValue =
      conf.get("hadoop.rpc.socket.factory.class." + clazz.getSimpleName());
  if ((propValue != null) && (propValue.length() > 0))
    factory = getSocketFactoryFromProperty(conf, propValue);

  if (factory == null)
    factory = getDefaultSocketFactory(conf);

  return factory;
}
 
開發者ID:spafka,項目名稱:spark_deep,代碼行數:29,代碼來源:NetUtils.java

示例14: main

import javax.net.SocketFactory; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    try (Server server = new Server()) {
        new Thread(server).start();

        SocketFactory factory = SSLSocketFactory.getDefault();
        try (SSLSocket socket = (SSLSocket) factory.createSocket("localhost",
                server.getPort())) {
            socket.setSoTimeout(2000);
            System.out.println("Client established TCP connection");
            boolean failed = false;
            for (TestCase testCase : testCases) {
                try {
                    testCase.test(socket);
                    System.out.println("ERROR: no exception");
                    failed = true;
                } catch (IOException e) {
                    System.out.println("Failed as expected: " + e);
                }
            }
            if (failed) {
                throw new Exception("One or more tests failed");
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:CloseSocket.java

示例15: getProxy

import javax.net.SocketFactory; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public <T> ProtocolProxy<T> getProxy(Class<T> protocol, long clientVersion,
    InetSocketAddress addr, UserGroupInformation ticket, Configuration conf,
    SocketFactory factory, int rpcTimeout, RetryPolicy connectionRetryPolicy,
    AtomicBoolean fallbackToSimpleAuth) throws IOException {

  final Invoker invoker = new Invoker(protocol, addr, ticket, conf, factory,
      rpcTimeout, connectionRetryPolicy, fallbackToSimpleAuth);
  return new ProtocolProxy<T>(protocol, (T) Proxy.newProxyInstance(
      protocol.getClassLoader(), new Class[]{protocol}, invoker), false);
}
 
開發者ID:apache,項目名稱:incubator-ratis,代碼行數:13,代碼來源:ProtobufRpcEngineShaded.java


注:本文中的javax.net.SocketFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。