use of com.helger.as2.cmd.CommandResult in project as2-server by phax.
the class ViewPartnerCommand method execute.
@Override
protected CommandResult execute(final IPartnershipFactoryWithPartners partFx, final Object[] params) throws OpenAS2Exception {
if (params.length < 1)
return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
final String name = params[0].toString();
final IPartner aPartner = partFx.getPartnerOfName(name);
if (aPartner != null) {
final String out = name + "\n" + aPartner.toString();
return new CommandResult(ECommandResultType.TYPE_OK, out);
}
return new CommandResult(ECommandResultType.TYPE_ERROR, "Unknown partner name");
}
use of com.helger.as2.cmd.CommandResult in project as2-server by phax.
the class ViewPartnershipCommand method execute.
@Override
protected CommandResult execute(final IPartnershipFactoryWithPartners partFx, final Object[] params) throws OpenAS2Exception {
if (params.length < 1) {
return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
}
final String name = params[0].toString();
final Partnership part = partFx.getPartnershipByName(name);
if (part != null)
return new CommandResult(ECommandResultType.TYPE_OK, part.toString());
return new CommandResult(ECommandResultType.TYPE_ERROR, "Unknown partnership name");
}
use of com.helger.as2.cmd.CommandResult 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.CommandResult 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.CommandResult in project as2-server by phax.
the class ImportCertInEncodedStreamCommand method _importCert.
private CommandResult _importCert(final IAliasedCertificateFactory certFx, final String alias, final String encodedCert) throws CertificateException, OpenAS2Exception {
final NonBlockingByteArrayInputStream bais = new NonBlockingByteArrayInputStream(ByteCoder.decode(encodedCert).getBytes());
final CertificateFactory cf = CertificateFactory.getInstance("X.509");
while (bais.available() > 0) {
final Certificate cert = cf.generateCertificate(bais);
if (cert instanceof X509Certificate) {
certFx.addCertificate(alias, (X509Certificate) cert, true);
final CommandResult cmdRes = new CommandResult(ECommandResultType.TYPE_OK, "Certificate(s) imported successfully");
cmdRes.addResult("Imported certificate: " + cert.toString());
return cmdRes;
}
}
return new CommandResult(ECommandResultType.TYPE_ERROR, "No valid X509 certificates found");
}
Aggregations