use of com.orientechnologies.orient.server.network.protocol.http.command.OServerCommand in project orientdb by orientechnologies.
the class OHttpNetworkCommandManager method getCommand.
public Object getCommand(final String iName) {
OServerCommand cmd = exactCommands.get(iName);
if (cmd == null) {
for (Entry<String, OServerCommand> entry : restCommands.entrySet()) {
if (matches(entry.getKey(), iName)) {
return entry.getValue();
}
}
}
if (cmd == null) {
// TRY WITH WILDCARD COMMANDS
// TODO: OPTIMIZE SEARCH!
String partLeft, partRight;
for (Entry<String, OServerCommand> entry : wildcardCommands.entrySet()) {
final int wildcardPos = entry.getKey().indexOf('*');
partLeft = entry.getKey().substring(0, wildcardPos);
partRight = entry.getKey().substring(wildcardPos + 1);
if (iName.startsWith(partLeft) && iName.endsWith(partRight)) {
cmd = entry.getValue();
break;
}
}
}
if (cmd == null && parent != null)
cmd = (OServerCommand) parent.getCommand(iName);
return cmd;
}
use of com.orientechnologies.orient.server.network.protocol.http.command.OServerCommand in project orientdb by orientechnologies.
the class OServerNetworkListener method createCommand.
@SuppressWarnings("unchecked")
public static OServerCommand createCommand(final OServer server, final OServerCommandConfiguration iCommand) {
try {
final Constructor<OServerCommand> c = (Constructor<OServerCommand>) Class.forName(iCommand.implementation).getConstructor(OServerCommandConfiguration.class);
final OServerCommand cmd = c.newInstance(new Object[] { iCommand });
cmd.configure(server);
return cmd;
} catch (Exception e) {
throw new IllegalArgumentException("Cannot create custom command invoking the constructor: " + iCommand.implementation + "(" + iCommand + ")", e);
}
}
use of com.orientechnologies.orient.server.network.protocol.http.command.OServerCommand 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;
}
use of com.orientechnologies.orient.server.network.protocol.http.command.OServerCommand in project orientdb by orientechnologies.
the class ONetworkProtocolHttpAbstract method registerStatelessCommands.
protected void registerStatelessCommands(final OServerNetworkListener iListener) {
cmdManager = new OHttpNetworkCommandManager(server, null);
cmdManager.registerCommand(new OServerCommandGetConnect());
cmdManager.registerCommand(new OServerCommandGetDisconnect());
cmdManager.registerCommand(new OServerCommandGetClass());
cmdManager.registerCommand(new OServerCommandGetCluster());
cmdManager.registerCommand(new OServerCommandGetDatabase());
cmdManager.registerCommand(new OServerCommandGetDictionary());
cmdManager.registerCommand(new OServerCommandGetDocument());
cmdManager.registerCommand(new OServerCommandGetDocumentByClass());
cmdManager.registerCommand(new OServerCommandGetQuery());
cmdManager.registerCommand(new OServerCommandGetServer());
cmdManager.registerCommand(new OServerCommandGetConnections());
cmdManager.registerCommand(new OServerCommandGetStorageAllocation());
cmdManager.registerCommand(new OServerCommandGetFileDownload());
cmdManager.registerCommand(new OServerCommandGetIndex());
cmdManager.registerCommand(new OServerCommandGetListDatabases());
cmdManager.registerCommand(new OServerCommandIsEnterprise());
cmdManager.registerCommand(new OServerCommandGetExportDatabase());
cmdManager.registerCommand(new OServerCommandPatchDocument());
cmdManager.registerCommand(new OServerCommandPostBatch());
cmdManager.registerCommand(new OServerCommandPostClass());
cmdManager.registerCommand(new OServerCommandPostCommand());
cmdManager.registerCommand(new OServerCommandPostDatabase());
cmdManager.registerCommand(new OServerCommandPostInstallDatabase());
cmdManager.registerCommand(new OServerCommandPostDocument());
cmdManager.registerCommand(new OServerCommandPostImportRecords());
cmdManager.registerCommand(new OServerCommandPostProperty());
cmdManager.registerCommand(new OServerCommandPostConnection());
cmdManager.registerCommand(new OServerCommandPostServer());
cmdManager.registerCommand(new OServerCommandPostStudio());
cmdManager.registerCommand(new OServerCommandPutDocument());
cmdManager.registerCommand(new OServerCommandPutIndex());
cmdManager.registerCommand(new OServerCommandDeleteClass());
cmdManager.registerCommand(new OServerCommandDeleteDatabase());
cmdManager.registerCommand(new OServerCommandDeleteDocument());
cmdManager.registerCommand(new OServerCommandDeleteProperty());
cmdManager.registerCommand(new OServerCommandDeleteIndex());
cmdManager.registerCommand(new OServerCommandOptions());
cmdManager.registerCommand(new OServerCommandFunction());
cmdManager.registerCommand(new OServerCommandPostKillDbConnection());
cmdManager.registerCommand(new OServerCommandGetSupportedLanguages());
cmdManager.registerCommand(new OServerCommandPostAuthToken());
cmdManager.registerCommand(new OServerCommandGetSSO());
cmdManager.registerCommand(new OServerCommandGetPing());
for (OServerCommandConfiguration c : iListener.getStatefulCommands()) try {
cmdManager.registerCommand(OServerNetworkListener.createCommand(server, c));
} catch (Exception e) {
OLogManager.instance().error(this, "Error on creating stateful command '%s'", e, c.implementation);
}
for (OServerCommand c : iListener.getStatelessCommands()) cmdManager.registerCommand(c);
}
Aggregations