Search in sources :

Example 1 with CommandResult

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");
}
Also used : IPartner(com.helger.as2lib.partner.xml.IPartner) CommandResult(com.helger.as2.cmd.CommandResult)

Example 2 with CommandResult

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");
}
Also used : Partnership(com.helger.as2lib.partner.Partnership) CommandResult(com.helger.as2.cmd.CommandResult)

Example 3 with CommandResult

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) SSLSocket(javax.net.ssl.SSLSocket) NonBlockingBufferedWriter(com.helger.commons.io.stream.NonBlockingBufferedWriter) IOException(java.io.IOException) OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) WrappedOpenAS2Exception(com.helger.as2lib.exception.WrappedOpenAS2Exception) CommandResult(com.helger.as2.cmd.CommandResult) OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) WrappedOpenAS2Exception(com.helger.as2lib.exception.WrappedOpenAS2Exception) CommandTokenizer(com.helger.as2.util.CommandTokenizer) ICommand(com.helger.as2.cmd.ICommand) OutputStreamWriter(java.io.OutputStreamWriter) NonBlockingBufferedReader(com.helger.commons.io.stream.NonBlockingBufferedReader) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Example 4 with CommandResult

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);
    }
}
Also used : CommandTokenizer(com.helger.as2.util.CommandTokenizer) ICommand(com.helger.as2.cmd.ICommand) IOException(java.io.IOException) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) CommandResult(com.helger.as2.cmd.CommandResult)

Example 5 with CommandResult

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");
}
Also used : NonBlockingByteArrayInputStream(com.helger.commons.io.stream.NonBlockingByteArrayInputStream) IAliasedCertificateFactory(com.helger.as2lib.cert.IAliasedCertificateFactory) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) CommandResult(com.helger.as2.cmd.CommandResult)

Aggregations

CommandResult (com.helger.as2.cmd.CommandResult)13 Partnership (com.helger.as2lib.partner.Partnership)4 Certificate (java.security.cert.Certificate)4 X509Certificate (java.security.cert.X509Certificate)4 ICommand (com.helger.as2.cmd.ICommand)2 CommandTokenizer (com.helger.as2.util.CommandTokenizer)2 IAliasedCertificateFactory (com.helger.as2lib.cert.IAliasedCertificateFactory)2 XMLPartnershipFactory (com.helger.as2lib.partner.xml.XMLPartnershipFactory)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 NonBlockingBufferedInputStream (com.helger.commons.io.stream.NonBlockingBufferedInputStream)2 IMicroDocument (com.helger.xml.microdom.IMicroDocument)2 IMicroElement (com.helger.xml.microdom.IMicroElement)2 MicroDocument (com.helger.xml.microdom.MicroDocument)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 CertificateFactory (java.security.cert.CertificateFactory)2 OpenAS2Exception (com.helger.as2lib.exception.OpenAS2Exception)1 WrappedOpenAS2Exception (com.helger.as2lib.exception.WrappedOpenAS2Exception)1 IPartner (com.helger.as2lib.partner.xml.IPartner)1 Partner (com.helger.as2lib.partner.xml.Partner)1