当前位置: 首页>>代码示例>>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;未经允许,请勿转载。