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);
}
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;
}
Aggregations