List of usage examples for javax.net.ssl SSLServerSocketFactory createServerSocket
@Override public ServerSocket createServerSocket(int port) throws IOException
From source file:MainClass.java
public static void main(String args[]) throws Exception { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(443); while (true) { Socket s = ss.accept();/*from w ww. j av a 2s . c om*/ PrintStream out = new PrintStream(s.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String info = null; String request = null; String refer = null; while ((info = in.readLine()) != null) { if (info.startsWith("GET")) { request = info; } if (info.startsWith("Referer:")) { refer = info; } if (info.equals("")) break; } if (request != null) { out.println("HTTP/1.0 200 OK\nMIME_version:1.0\nContent_Type:text/html"); int sp1 = request.indexOf(' '); int sp2 = request.indexOf(' ', sp1 + 1); String filename = request.substring(sp1 + 2, sp2); if (refer != null) { sp1 = refer.indexOf(' '); refer = refer.substring(sp1 + 1, refer.length()); if (!refer.endsWith("/")) { refer = refer + "/"; } filename = refer + filename; } URL con = new URL(filename); InputStream gotoin = con.openStream(); int n = gotoin.available(); byte buf[] = new byte[1024]; out.println("HTTP/1.0 200 OK\nMIME_version:1.0\nContent_Type:text/html"); out.println("Content_Length:" + n + "\n"); while ((n = gotoin.read(buf)) >= 0) { out.write(buf, 0, n); } out.close(); s.close(); in.close(); } } }
From source file:MainClass.java
public static void main(String[] args) { int port = Integer.parseInt(args[0]); try {//from www. ja v a2 s .c om System.out.println("Locating server socket factory for SSL..."); SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); System.out.println("Creating a server socket on port " + port); SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port); String[] suites = serverSocket.getSupportedCipherSuites(); System.out.println("Support cipher suites are:"); for (int i = 0; i < suites.length; i++) { System.out.println(suites[i]); } serverSocket.setEnabledCipherSuites(suites); System.out.println("Support protocols are:"); String[] protocols = serverSocket.getSupportedProtocols(); for (int i = 0; i < protocols.length; i++) { System.out.println(protocols[i]); } System.out.println("Waiting for client..."); SSLSocket socket = (SSLSocket) serverSocket.accept(); System.out.println("Starting handshake..."); socket.startHandshake(); System.out.println("Just connected to " + socket.getRemoteSocketAddress()); } catch (IOException e) { e.printStackTrace(); } }
From source file:Test.java
public static void main(String[] arstring) throws Exception { SSLServerSocketFactory sslServerSocketFactory = (SSLServerSocketFactory) SSLServerSocketFactory .getDefault();/* ww w . j a v a 2s . c o m*/ SSLServerSocket sslServerSocket = (SSLServerSocket) sslServerSocketFactory.createServerSocket(9999); System.out.println("Waiting for a client ..."); SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept(); SSLParameters parameters = sslSocket.getSSLParameters(); parameters.setAlgorithmConstraints(new SimpleConstraints()); AlgorithmConstraints constraints = parameters.getAlgorithmConstraints(); System.out.println("Constraint: " + constraints); String endPoint = parameters.getEndpointIdentificationAlgorithm(); System.out.println("End Point: " + endPoint); System.out.println("Local Supported Signature Algorithms"); if (sslSocket.getSession() instanceof ExtendedSSLSession) { ExtendedSSLSession extendedSSLSession = (ExtendedSSLSession) sslSocket.getSession(); String alogrithms[] = extendedSSLSession.getLocalSupportedSignatureAlgorithms(); for (String algorithm : alogrithms) { System.out.println("Algortihm: " + algorithm); } } System.out.println("Peer Supported Signature Algorithms"); if (sslSocket.getSession() instanceof ExtendedSSLSession) { String alogrithms[] = ((ExtendedSSLSession) sslSocket.getSession()) .getPeerSupportedSignatureAlgorithms(); for (String algorithm : alogrithms) { System.out.println("Algortihm: " + algorithm); } } InputStream inputstream = sslSocket.getInputStream(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); SSLSession session = sslSocket.getHandshakeSession(); if (session != null) { System.out.println("Last accessed: " + new Date(session.getLastAccessedTime())); } String string = null; while ((string = bufferedreader.readLine()) != null) { System.out.println(string); System.out.flush(); } }
From source file:LoginClient.java
public LoginServer() throws Exception { SSLServerSocketFactory socketFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); serverSocket = (SSLServerSocket) socketFactory.createServerSocket(7070); }
From source file:com.apporiented.hermesftp.server.impl.SecureFtpServer.java
/** * {@inheritDoc}/*from w w w . ja v a 2 s. c o m*/ */ protected ServerSocket createServerSocket() throws IOException { SSLContext sslContext = getOptions().getSslContext(); int sslPort = getOptions().getImplicitSslPort(); SSLServerSocketFactory factory = sslContext.getServerSocketFactory(); SSLServerSocket sslServerSocket = (SSLServerSocket) factory.createServerSocket(sslPort); enableCipherSuites(sslServerSocket); log.info("Enabled cipher suites (implicit SSL): " + StringUtils.arrayToCommaDelimitedString(sslServerSocket.getEnabledCipherSuites())); return sslServerSocket; }
From source file:httpscheduler.GenericRequestListenerThread.java
public GenericRequestListenerThread(final int port, final HttpService httpService, final SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port); this.httpService = httpService; // only 4 connections can run concurrently connectionHandlerExecutor = Executors.newFixedThreadPool(1000); //System.out.println("Request Listener Thread created"); }
From source file:httpscheduler.LateBindingRequestListenerThread.java
public LateBindingRequestListenerThread(final int port, final HttpService httpService, final SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port); this.httpService = httpService; // only 4 connections can run concurrently connectionHandlerExecutor = Executors.newFixedThreadPool(22); System.out.println("Request Listener Thread created"); }
From source file:org.pepstock.jem.node.https.RequestListener.java
/** * Builds the object creating the socket server to stay in listening mode. * //from w ww. j av a 2 s .c o m * @param port HTTPS port to stay in istening * @param httpService HTTP service * @param socketFactory SSL socket factory * @throws IOException if any errors occurs * */ public RequestListener(final int port, final HttpService httpService, final SSLServerSocketFactory socketFactory) throws IOException { super(THREAD_NAME); this.connectionFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serverSocket = socketFactory.createServerSocket(port); this.httpService = httpService; }
From source file:edu.gmu.isa681.server.Server.java
/** * Establishes the SSL server socket and listens for incoming connections. A stand-alone <code>SessionHandler</code> * is spawned for each connection./*from www .jav a 2 s. co m*/ */ public void run() { try { SSLServerSocketFactory ssf = (SSLServerSocketFactory) getSSLServerSocketFactory(); try { sslServerSocket = (SSLServerSocket) ssf.createServerSocket(port); log.info("Server started."); while (true) { synchronized (shutdownLock) { if (shuttingDown) break; } try { SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept(); handleRequest(sslSocket); } catch (IOException ex) { log.error("Exception while handling request.", ex); } } } catch (IOException ex) { log.error(ex.getMessage(), ex); } } catch (GeneralSecurityException | IOException ex) { log.fatal(ex.getMessage(), ex); } shutdown(); }
From source file:org.globus.gsi.jsse.SSLConfiguratorTest.java
private SSLServerSocket startServer(SSLConfigurator config) throws GlobusSSLConfigurationException, IOException { SSLServerSocketFactory sslserversocketfactory = config.createServerFactory(); final SSLServerSocket sslserversocket = (SSLServerSocket) sslserversocketfactory.createServerSocket(9991); ExecutorService executor = Executors.newFixedThreadPool(1); executor.execute(new Runnable() { /**//from w w w.j a v a 2 s . c o m * When an object implementing interface <code>Runnable</code> is * used to create a thread, starting the thread causes the object's * <code>run</code> method to be called in that separately executing * thread. * <p/> * The general contract of the method <code>run</code> is that it * may take any action whatsoever. * * @see Thread#run() */ public void run() { latch.countDown(); try { SSLSocket sslsocket = (SSLSocket) sslserversocket.accept(); InputStream inputstream = sslsocket.getInputStream(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); String line; while ((line = bufferedreader.readLine()) != null) { builder.append(line); } assertEquals(builder.toString().trim(), "hello"); } catch (IOException e) { e.printStackTrace(); } } }); return sslserversocket; }