use of com.helger.as2.cmd.ICommand in project as2-server by phax.
the class SocketCommandProcessor method processCommand.
@Override
public void processCommand() throws OpenAS2Exception {
try (final SSLSocket socket = (SSLSocket) m_aSSLServerSocket.accept()) {
socket.setSoTimeout(2000);
m_aReader = new NonBlockingBufferedReader(new InputStreamReader(socket.getInputStream()));
m_aWriter = new NonBlockingBufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
final String line = m_aReader.readLine();
m_aParser.parse(line);
if (!m_aParser.getUserid().equals(m_sUserID)) {
m_aWriter.write("Bad userid/password");
throw new OpenAS2Exception("Bad userid");
}
if (!m_aParser.getPassword().equals(m_sPassword)) {
m_aWriter.write("Bad userid/password");
throw new OpenAS2Exception("Bad password");
}
final String str = m_aParser.getCommandText();
if (str != null && str.length() > 0) {
final CommandTokenizer cmdTkn = new CommandTokenizer(str);
if (cmdTkn.hasMoreTokens()) {
final String sCommandName = cmdTkn.nextToken().toLowerCase();
if (sCommandName.equals(StreamCommandProcessor.EXIT_COMMAND)) {
terminate();
} else {
final ICommonsList<String> params = new CommonsArrayList<>();
while (cmdTkn.hasMoreTokens()) {
params.add(cmdTkn.nextToken());
}
final ICommand aCommand = getCommand(sCommandName);
if (aCommand != null) {
final CommandResult aResult = aCommand.execute(params.toArray());
if (aResult.getType().isSuccess()) {
m_aWriter.write(aResult.getAsXMLString());
} else {
m_aWriter.write("\r\n" + StreamCommandProcessor.COMMAND_ERROR + "\r\n");
m_aWriter.write(aResult.getResultAsString());
}
} else {
m_aWriter.write(StreamCommandProcessor.COMMAND_NOT_FOUND + "> " + sCommandName + "\r\n");
m_aWriter.write("List of commands:" + "\r\n");
for (final String sCurCmd : getAllCommands().keySet()) m_aWriter.write(sCurCmd + "\r\n");
}
}
}
}
m_aWriter.flush();
} catch (final Exception ex) {
throw WrappedOpenAS2Exception.wrap(ex);
}
}
use of com.helger.as2.cmd.ICommand in project as2-server by phax.
the class StreamCommandProcessor method processCommand.
@Override
public void processCommand() throws OpenAS2Exception {
try {
final String sLine = readLine();
if (sLine != null) {
final CommandTokenizer aTokenizer = new CommandTokenizer(sLine);
if (aTokenizer.hasMoreTokens()) {
final String sCommandName = aTokenizer.nextToken().toLowerCase(Locale.US);
if (sCommandName.equals(EXIT_COMMAND)) {
terminate();
} else {
final ICommonsList<String> aParams = new CommonsArrayList<>();
while (aTokenizer.hasMoreTokens()) {
aParams.add(aTokenizer.nextToken());
}
final ICommand aCommand = getCommand(sCommandName);
if (aCommand != null) {
final CommandResult aResult = aCommand.execute(aParams.toArray());
if (aResult.getType().isSuccess()) {
writeLine(aResult.toString());
} else {
writeLine(COMMAND_ERROR);
writeLine(aResult.getResultAsString());
}
} else {
writeLine(COMMAND_NOT_FOUND + "> " + sCommandName);
writeLine("List of commands:");
writeLine(EXIT_COMMAND);
for (final String sCurCmd : getAllCommands().keySet()) writeLine(sCurCmd);
}
}
}
write(PROMPT);
} else {
ThreadHelper.sleep(100);
}
} catch (final IOException ex) {
throw WrappedOpenAS2Exception.wrap(ex);
}
}
use of com.helger.as2.cmd.ICommand in project as2-server by phax.
the class XMLCommandRegistry method loadCommand.
protected void loadCommand(final IMicroElement eCommand, @Nullable final MultiCommand aParent) throws OpenAS2Exception {
final IAS2Session aSession = getSession();
final String sBaseDirectory = aSession instanceof AS2ServerXMLSession ? ((AS2ServerXMLSession) aSession).getBaseDirectory() : null;
final ICommand aCommand = AS2XMLHelper.createComponent(eCommand, ICommand.class, aSession, sBaseDirectory);
if (aParent != null)
aParent.getCommands().add(aCommand);
else
addCommand(aCommand);
}
Aggregations