Search in sources :

Example 1 with ServerResponseException

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);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ServerResponseException(com.yahoo.vespa.http.client.core.ServerResponseException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 2 with ServerResponseException

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();
}
Also used : ServerResponseException(com.yahoo.vespa.http.client.core.ServerResponseException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ServerResponseException(com.yahoo.vespa.http.client.core.ServerResponseException) IOException(java.io.IOException)

Example 3 with ServerResponseException

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;
}
Also used : ServerResponseException(com.yahoo.vespa.http.client.core.ServerResponseException) Endpoint(com.yahoo.vespa.http.client.config.Endpoint)

Aggregations

ServerResponseException (com.yahoo.vespa.http.client.core.ServerResponseException)3 Endpoint (com.yahoo.vespa.http.client.config.Endpoint)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpResponse (org.apache.http.HttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1