本文整理匯總了Java中org.eclipse.jetty.util.ssl.SslContextFactory.setTrustAll方法的典型用法代碼示例。如果您正苦於以下問題:Java SslContextFactory.setTrustAll方法的具體用法?Java SslContextFactory.setTrustAll怎麽用?Java SslContextFactory.setTrustAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jetty.util.ssl.SslContextFactory
的用法示例。
在下文中一共展示了SslContextFactory.setTrustAll方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newHttpClient
import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
/**
* Async http client used to connect to <b>proxyTo</b> server.
* TLS config is usually done here.
*
* @return {@link HttpClient}
*/
@Override
protected HttpClient newHttpClient() {
SslContextFactory sslFactory = new SslContextFactory();
sslFactory.setTrustAll(trustAllCerts);
return new HttpClient(sslFactory);
}
示例2: provideHttpClient
import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
@Provides
@Singleton
public HttpClient provideHttpClient(ExecutorService executorService,
@Named("httpClient.maxConnectionsQueued") Integer maxConnectionsQueued,
@Named("httpClient.maxConnectionPerRoute") Integer maxConnectionPerRoute,
@Named("httpClient.requestBufferSize") Integer requestBufferSize,
@Named("httpClient.responseBufferSize") Integer responseBufferSize,
@Named("httpClient.maxRedirects") Integer maxRedirects,
@Named("httpClient.trustAllCertificates") Boolean trustAllCertificates) {
try {
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setTrustAll(trustAllCertificates);
HttpClient httpClient = new HttpClient(sslContextFactory);
httpClient.setExecutor(executorService);
httpClient.setMaxConnectionsPerDestination(maxConnectionsQueued);
httpClient.setMaxRequestsQueuedPerDestination(maxConnectionPerRoute);
httpClient.setRequestBufferSize(requestBufferSize);
httpClient.setResponseBufferSize(responseBufferSize);
httpClient.setMaxRedirects(maxRedirects);
httpClient.start();
registerHttpClientShutdownHook(httpClient);
return httpClient;
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
throw new RuntimeException(e.getLocalizedMessage(), e);
}
}
示例3: initServerForTrustedAuths
import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
/**
* Initialize HTTPS server to which trusted Auths connect
* @param properties Auth server's properties to get paths for key stores and certificates
* @param authKeyStorePassword Password for Auth's key store that is used for communication with trusted Auths
* @return HTTPS server object
* @throws CertificateException When there is a problem with certificate.
* @throws NoSuchAlgorithmException If the specified algorithm cannot be found.
* @throws KeyStoreException When there is a problem with accessing key store.
* @throws IOException If there is a problem in IO.
*/
private Server initServerForTrustedAuths(AuthServerProperties properties, String authKeyStorePassword)
throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException
{
TrustedAuthConnectionHandler trustedAuthConnectionHandler = new TrustedAuthConnectionHandler(this);
Server serverForTrustedAuths = new Server();
serverForTrustedAuths.setHandler(trustedAuthConnectionHandler);
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setTrustAll(false);
sslContextFactory.setKeyStore(AuthCrypto.loadKeyStore(properties.getInternetKeyStorePath(), authKeyStorePassword));
sslContextFactory.setKeyStorePassword(authKeyStorePassword);
KeyStore serverTrustStore = KeyStore.getInstance(KeyStore.getDefaultType());
serverTrustStore.load(null, authKeyStorePassword.toCharArray());
String[] trustedCACertPaths = properties.getTrustedCACertPaths();
for (int i = 0; i < trustedCACertPaths.length; i++) {
serverTrustStore.setCertificateEntry("" + i, AuthCrypto.loadCertificateFromFile(trustedCACertPaths[i]));
}
sslContextFactory.setTrustStore(serverTrustStore);
sslContextFactory.setNeedClientAuth(true);
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setPersistentConnectionsEnabled(true);
httpConfig.setSecureScheme("https");
// time out with out keep alive messages?
//httpConfig.setBlockingTimeout();
httpConfig.addCustomizer(new SecureRequestCustomizer());
//new SSL
ServerConnector connector = new ServerConnector(serverForTrustedAuths,
new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpConfig));
connector.setPort(properties.getTrustedAuthPort());
// Idle time out for keep alive connections
// time out with out requests?
connector.setIdleTimeout(properties.getTrustedAuthPortIdleTimeout());
serverForTrustedAuths.setConnectors(new org.eclipse.jetty.server.Connector[]{connector});
return serverForTrustedAuths;
}
示例4: getConnectionWS
import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
public WebSocketConnection getConnectionWS (String connectionId) throws Exception{
URI uri = getUri();;
String closeConnectionPattern = getCloseConnectionPattern();
int connectionTimeout;
try {
connectionTimeout = Integer.parseInt(getConnectionTimeout());
} catch (NumberFormatException ex) {
log.warn("Request timeout is not a number; using the default connection timeout of " + DEFAULT_CONNECTION_TIMEOUT + "ms");
connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
}
SslContextFactory sslContexFactory = new SslContextFactory();
sslContexFactory.setTrustAll(true);
WebSocketClient webSocketClient = new WebSocketClient(sslContexFactory);
WebSocketConnection webSocketConnection = new WebSocketConnection(webSocketClient, closeConnectionPattern, getContentEncoding());
webSocketClient.start();
ClientUpgradeRequest request = new ClientUpgradeRequest();
setConnectionHeaders(request, getHeaderManager(), null);
setConnectionCookie(request, uri, getCookieManager());
webSocketClient.connect(webSocketConnection, uri, request);
webSocketConnection.awaitOpen(connectionTimeout, TimeUnit.MILLISECONDS);
if (!webSocketConnection.isConnected()){
return null;
}
connectionList.put(connectionId, webSocketConnection);
return webSocketConnection;
}
示例5: connectWebsocket
import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
public void connectWebsocket(String url, int sampleEveryN, boolean showMessages) {
try {
int timeout = 9000; // 9 seconds
System.out.println("NOTE: For GeoEvent Stream Service append /subscribe to the Web Socket URL");
System.out.println("Starting: If you see rapid connection lost messages. Ctrl-C and check you're URL");
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setTrustAll(true);
sslContextFactory.start();
final WebSocketClientFactory factory = new WebSocketClientFactory();
factory.start();
WebSocketClient client = factory.newWebSocketClient();
URI uri = new URI(url);
//WebSocketMessage msg = new WebSocketMessage();
//WebSocket.Connection websocketConnection = client.open(uri, new WebSocketMessage(sampleEveryN, showMessages)).get(5, TimeUnit.SECONDS);
WebSocket.Connection websocketConnection = client.open(uri, new WebSocketMessage(sampleEveryN, showMessages),timeout, TimeUnit.SECONDS);
//System.out.println(System.currentTimeMillis());
websocketConnection.setMaxTextMessageSize(MAX_MESSAGE_SIZE);
//System.out.println(timeout);
websocketConnection.setMaxIdleTime(timeout);
//websocketConnection.setMaxIdleTime(-1);
while (true) {
if (websocketConnection.isOpen()) {
// Wait a second
Thread.sleep(1000);
} else {
// Reopen
websocketConnection = client.open(uri, new WebSocketMessage(sampleEveryN, showMessages)).get(5, TimeUnit.SECONDS);
websocketConnection.setMaxTextMessageSize(MAX_MESSAGE_SIZE);
websocketConnection.setMaxIdleTime(timeout);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}