use of java.net.UnknownServiceException in project okhttp by square.
the class RealConnection method connect.
public void connect(int connectTimeout, int readTimeout, int writeTimeout, boolean connectionRetryEnabled) {
if (protocol != null)
throw new IllegalStateException("already connected");
RouteException routeException = null;
List<ConnectionSpec> connectionSpecs = route.address().connectionSpecs();
ConnectionSpecSelector connectionSpecSelector = new ConnectionSpecSelector(connectionSpecs);
if (route.address().sslSocketFactory() == null) {
if (!connectionSpecs.contains(ConnectionSpec.CLEARTEXT)) {
throw new RouteException(new UnknownServiceException("CLEARTEXT communication not enabled for client"));
}
String host = route.address().url().host();
if (!Platform.get().isCleartextTrafficPermitted(host)) {
throw new RouteException(new UnknownServiceException("CLEARTEXT communication to " + host + " not permitted by network security policy"));
}
}
while (true) {
try {
if (route.requiresTunnel()) {
connectTunnel(connectTimeout, readTimeout, writeTimeout);
} else {
connectSocket(connectTimeout, readTimeout);
}
establishProtocol(connectionSpecSelector);
break;
} catch (IOException e) {
closeQuietly(socket);
closeQuietly(rawSocket);
socket = null;
rawSocket = null;
source = null;
sink = null;
handshake = null;
protocol = null;
http2Connection = null;
if (routeException == null) {
routeException = new RouteException(e);
} else {
routeException.addConnectException(e);
}
if (!connectionRetryEnabled || !connectionSpecSelector.connectionFailed(e)) {
throw routeException;
}
}
}
if (http2Connection != null) {
synchronized (connectionPool) {
allocationLimit = http2Connection.maxConcurrentStreams();
}
}
}
use of java.net.UnknownServiceException in project okhttp by square.
the class CallTest method cleartextCallsFailWhenCleartextIsDisabled.
@Test
public void cleartextCallsFailWhenCleartextIsDisabled() throws Exception {
// Configure the client with only TLS configurations. No cleartext!
client = client.newBuilder().connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS)).build();
server.enqueue(new MockResponse());
Request request = new Request.Builder().url(server.url("/")).build();
try {
client.newCall(request).execute();
fail();
} catch (UnknownServiceException expected) {
assertEquals("CLEARTEXT communication not enabled for client", expected.getMessage());
}
}
use of java.net.UnknownServiceException in project okhttp by square.
the class ConnectionSpecSelector method configureSecureSocket.
/**
* Configures the supplied {@link SSLSocket} to connect to the specified host using an appropriate
* {@link ConnectionSpec}. Returns the chosen {@link ConnectionSpec}, never {@code null}.
*
* @throws IOException if the socket does not support any of the TLS modes available
*/
public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException {
ConnectionSpec tlsConfiguration = null;
for (int i = nextModeIndex, size = connectionSpecs.size(); i < size; i++) {
ConnectionSpec connectionSpec = connectionSpecs.get(i);
if (connectionSpec.isCompatible(sslSocket)) {
tlsConfiguration = connectionSpec;
nextModeIndex = i + 1;
break;
}
}
if (tlsConfiguration == null) {
// protocols than was suggested by a prior socket).
throw new UnknownServiceException("Unable to find acceptable protocols. isFallback=" + isFallback + ", modes=" + connectionSpecs + ", supported protocols=" + Arrays.toString(sslSocket.getEnabledProtocols()));
}
isFallbackPossible = isFallbackPossible(sslSocket);
Internal.instance.apply(tlsConfiguration, sslSocket, isFallback);
return tlsConfiguration;
}
use of java.net.UnknownServiceException in project azure-tools-for-java by Microsoft.
the class SparkBatchRemoteDebugJob method getSparkDriverHost.
/**
* Get Spark batch job driver host by ID
*
* @return Spark driver node host
* @throws IOException exceptions for the driver host not found
*/
@Override
public String getSparkDriverHost() throws IOException {
String applicationId = this.getSparkJobApplicationId(this.getConnectUri(), this.getBatchId());
App yarnApp = this.getSparkJobYarnApplication(this.getConnectUri(), applicationId);
if (yarnApp.isFinished()) {
throw new UnknownServiceException("The Livy job " + this.getBatchId() + " on yarn is not running.");
}
String driverHttpAddress = yarnApp.getAmHostHttpAddress();
/*
* The sample here is:
* host.domain.com:8900
* or
* 10.0.0.15:30060
*/
String driverHost = this.parseAmHostHttpAddressHost(driverHttpAddress);
if (driverHost == null) {
throw new UnknownServiceException("Bad amHostHttpAddress got from /yarnui/ws/v1/cluster/apps/" + applicationId);
}
return driverHost;
}
use of java.net.UnknownServiceException in project azure-tools-for-java by Microsoft.
the class SparkBatchRemoteDebugJob method createBatchSparkJobWithDriverDebugging.
/**
* Create a batch Spark job with driver debugging enabled
*
* @return the current instance for chain calling
* @throws IOException the exceptions for networking connection issues related
* @throws DebugParameterDefinedException the exception for debug option already defined in Spark submission parameter
*/
@Override
public SparkBatchRemoteDebugJob createBatchSparkJobWithDriverDebugging() throws IOException, DebugParameterDefinedException {
// Submit the batch job
HttpResponse httpResponse = this.getSubmission().createBatchSparkJob(this.getConnectUri().toString(), this.getSubmissionParameter());
// Get the batch ID from response and save it
if (httpResponse.getCode() >= 200 && httpResponse.getCode() < 300) {
SparkSubmitResponse jobResp = ObjectConvertUtils.convertJsonToObject(httpResponse.getMessage(), SparkSubmitResponse.class).orElseThrow(() -> new UnknownServiceException("Bad spark job response: " + httpResponse.getMessage()));
this.setBatchId(jobResp.getId());
}
return this;
}
Aggregations