use of com.yahoo.vespa.http.client.core.ServerResponseException in project vespa by vespa-engine.
the class ApacheGatewayConnection method handshake.
@Override
public void handshake() throws ServerResponseException, IOException {
final boolean useCompression = false;
final boolean drain = false;
final boolean handshake = true;
HttpPost httpPost = createPost(drain, useCompression, handshake);
final String oldSessionID = sessionId;
sessionId = null;
try (InputStream stream = executePost(httpPost)) {
if (oldSessionID != null && !oldSessionID.equals(sessionId)) {
throw new ServerResponseException("Session ID changed after new handshake, some documents might not be acked to correct thread. " + getEndpoint() + " old " + oldSessionID + " new " + sessionId);
}
if (stream == null) {
log.fine("Stream is null.");
}
log.fine("Got session ID " + sessionId);
}
}
use of com.yahoo.vespa.http.client.core.ServerResponseException in project vespa by vespa-engine.
the class ApacheGatewayConnection method executePost.
private InputStream executePost(HttpPost httpPost) throws ServerResponseException, IOException {
HttpResponse response;
try {
if (httpClient == null) {
throw new IOException("Trying to executePost while not having a connection/http client");
}
response = httpClient.execute(httpPost);
} catch (IOException e) {
httpPost.abort();
throw e;
} catch (Exception e) {
httpPost.abort();
throw e;
}
try {
verifyServerResponseCode(response.getStatusLine());
verifyServerVersion(response.getFirstHeader(Headers.VERSION));
verifySessionHeader(response.getFirstHeader(Headers.SESSION_ID));
} catch (ServerResponseException e) {
httpPost.abort();
throw e;
}
return response.getEntity().getContent();
}
use of com.yahoo.vespa.http.client.core.ServerResponseException in project vespa by vespa-engine.
the class ApacheGatewayConnection method verifyServerVersion.
private void verifyServerVersion(Header serverHeader) throws ServerResponseException {
if (serverHeader == null) {
throw new ServerResponseException("Got bad protocol version from server.");
}
int serverVersion;
try {
serverVersion = Integer.parseInt(serverHeader.getValue());
} catch (NumberFormatException nfe) {
throw new ServerResponseException("Got bad protocol version from server: " + nfe.getMessage());
}
if (!SUPPORTED_VERSIONS.contains(serverVersion)) {
throw new ServerResponseException("Unsupported version: " + serverVersion + ". Supported versions: " + SUPPORTED_VERSIONS);
}
if (negotiatedVersion == -1) {
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "Server decided upon protocol version " + serverVersion + ".");
}
}
if (this.connectionParams.isEnableV3Protocol() && serverVersion != 3) {
throw new ServerResponseException("Client was set up to use v3 of protocol, however, gateway wants to " + "use version " + serverVersion + ". Already set up structures for v3 so can not do v2 now.");
}
this.negotiatedVersion = serverVersion;
}
Aggregations