Search in sources :

Example 1 with ONetworkProtocolException

use of com.orientechnologies.orient.enterprise.channel.binary.ONetworkProtocolException in project orientdb by orientechnologies.

the class OServerShutdownMain method connect.

public void connect(final int iTimeout) throws IOException {
    // TRY TO CONNECT TO THE RIGHT PORT
    for (int port : networkPort) try {
        channel = new OChannelBinaryAsynchClientSynch(networkAddress, port, null, contextConfig);
        break;
    } catch (Exception e) {
        OLogManager.instance().error(this, "Error on connecting to %s:%d", e, networkAddress, port);
    }
    if (channel == null)
        throw new ONetworkProtocolException("Cannot connect to server host '" + networkAddress + "', ports: " + Arrays.toString(networkPort));
    channel.writeByte(OChannelBinaryProtocol.REQUEST_SHUTDOWN);
    channel.writeInt(0);
    channel.writeString(rootUser);
    channel.writeString(rootPassword);
    channel.flush();
    channel.beginResponse(0, false);
}
Also used : ONetworkProtocolException(com.orientechnologies.orient.enterprise.channel.binary.ONetworkProtocolException) OChannelBinaryAsynchClientSynch(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClientSynch) ONetworkProtocolException(com.orientechnologies.orient.enterprise.channel.binary.ONetworkProtocolException) IOException(java.io.IOException)

Example 2 with ONetworkProtocolException

use of com.orientechnologies.orient.enterprise.channel.binary.ONetworkProtocolException in project orientdb by orientechnologies.

the class ONetworkProtocolHttpAbstract method service.

public void service() throws ONetworkProtocolException, IOException {
    ++connection.getStats().totalRequests;
    connection.getData().commandInfo = null;
    connection.getData().commandDetail = null;
    final String callbackF;
    if (OGlobalConfiguration.NETWORK_HTTP_JSONP_ENABLED.getValueAsBoolean() && request.parameters != null && request.parameters.containsKey(OHttpUtils.CALLBACK_PARAMETER_NAME))
        callbackF = request.parameters.get(OHttpUtils.CALLBACK_PARAMETER_NAME);
    else
        callbackF = null;
    response = new OHttpResponse(channel.outStream, request.httpVersion, additionalResponseHeaders, responseCharSet, connection.getData().serverInfo, request.sessionId, callbackF, request.keepAlive, connection);
    response.setJsonErrorResponse(jsonResponseError);
    if (request.contentEncoding != null && request.contentEncoding.equals(OHttpUtils.CONTENT_ACCEPT_GZIP_ENCODED)) {
        response.setContentEncoding(OHttpUtils.CONTENT_ACCEPT_GZIP_ENCODED);
    }
    final long begin = System.currentTimeMillis();
    boolean isChain;
    do {
        isChain = false;
        final String command;
        if (request.url.length() < 2) {
            command = "";
        } else {
            command = request.url.substring(1);
        }
        final String commandString = getCommandString(command);
        final OServerCommand cmd = (OServerCommand) cmdManager.getCommand(commandString);
        Map<String, String> requestParams = cmdManager.extractUrlTokens(commandString);
        if (requestParams != null) {
            if (request.parameters == null) {
                request.parameters = new HashMap<String, String>();
            }
            for (Map.Entry<String, String> entry : requestParams.entrySet()) {
                request.parameters.put(entry.getKey(), URLDecoder.decode(entry.getValue(), "UTF-8"));
            }
        }
        if (cmd != null)
            try {
                if (cmd.beforeExecute(request, response))
                    try {
                        // EXECUTE THE COMMAND
                        isChain = cmd.execute(request, response);
                    } finally {
                        cmd.afterExecute(request, response);
                    }
            } catch (Exception e) {
                handleError(e);
            }
        else {
            try {
                OLogManager.instance().warn(this, "->" + channel.socket.getInetAddress().getHostAddress() + ": Command not found: " + request.httpMethod + "." + URLDecoder.decode(command, "UTF-8"));
                sendError(OHttpUtils.STATUS_INVALIDMETHOD_CODE, OHttpUtils.STATUS_INVALIDMETHOD_DESCRIPTION, null, OHttpUtils.CONTENT_TEXT_PLAIN, "Command not found: " + command, request.keepAlive);
            } catch (IOException e1) {
                sendShutdown();
            }
        }
    } while (isChain);
    connection.getStats().lastCommandInfo = connection.getData().commandInfo;
    connection.getStats().lastCommandDetail = connection.getData().commandDetail;
    connection.getStats().lastCommandExecutionTime = System.currentTimeMillis() - begin;
    connection.getStats().totalCommandExecutionTime += connection.getStats().lastCommandExecutionTime;
}
Also used : OServerCommand(com.orientechnologies.orient.server.network.protocol.http.command.OServerCommand) IOException(java.io.IOException) OLockException(com.orientechnologies.common.concur.lock.OLockException) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) SocketException(java.net.SocketException) ONetworkProtocolException(com.orientechnologies.orient.enterprise.channel.binary.ONetworkProtocolException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Aggregations

ONetworkProtocolException (com.orientechnologies.orient.enterprise.channel.binary.ONetworkProtocolException)2 IOException (java.io.IOException)2 OLockException (com.orientechnologies.common.concur.lock.OLockException)1 OChannelBinaryAsynchClientSynch (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClientSynch)1 OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)1 OServerCommand (com.orientechnologies.orient.server.network.protocol.http.command.OServerCommand)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1