public class Protocol extends Object
The Protocol object is multithread safe.
Modifier and Type | Field and Description |
---|---|
protected String |
host |
protected MailLogger |
logger |
protected String |
prefix |
protected Properties |
props |
protected boolean |
quote |
protected MailLogger |
traceLogger |
Constructor and Description |
---|
Protocol(InputStream in,
PrintStream out,
Properties props,
boolean debug)
Constructor for debugging.
|
Protocol(String host,
int port,
Properties props,
String prefix,
boolean isSSL,
MailLogger logger)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addResponseHandler(ResponseHandler h)
Adds a response handler.
|
Response[] |
command(String command,
Argument args)
Send a command to the server.
|
protected void |
disconnect()
Disconnect.
|
protected void |
finalize()
Finalizer.
|
SocketChannel |
getChannel()
Return the SocketChannel associated with this connection, if any.
|
InetAddress |
getInetAddress()
Return the address the socket connected to.
|
protected ResponseInputStream |
getInputStream()
Return the Protocol's InputStream.
|
protected String |
getLocalHost()
Get the name of the local host.
|
protected OutputStream |
getOutputStream()
Return the Protocol's OutputStream
|
protected ByteArray |
getResponseBuffer()
Return a buffer to be used to read a response.
|
long |
getTimestamp()
Returns the timestamp.
|
void |
handleResult(Response response)
Convenience routine to handle OK, NO, BAD and BYE responses.
|
boolean |
hasResponse()
Is another response available in our buffer?
|
boolean |
isSSL()
Is this connection using an SSL socket?
|
protected boolean |
isTracing()
Is protocol tracing enabled?
|
void |
notifyResponseHandlers(Response[] responses)
Notify response handlers
|
protected void |
processGreeting(Response r) |
Response |
readResponse() |
void |
removeResponseHandler(ResponseHandler h)
Removed the specified response handler.
|
protected void |
resumeTracing()
Resume protocol tracing, if it was enabled to begin with.
|
void |
simpleCommand(String cmd,
Argument args)
Convenience routine to handle simple IAP commands
that do not have responses specific to that command.
|
void |
startCompression(String cmd)
Start compression on the current connection.
|
void |
startTLS(String cmd)
Start TLS on the current connection.
|
protected boolean |
supportsNonSyncLiterals()
Returns whether this Protocol supports non-synchronizing literals
Default is false.
|
boolean |
supportsUtf8()
Does the server support UTF-8?
This implementation returns false.
|
protected void |
suspendTracing()
Temporarily turn off protocol tracing, e.g., to prevent
tracing the authentication sequence, including the password.
|
String |
writeCommand(String command,
Argument args) |
protected String host
protected boolean quote
protected MailLogger logger
protected MailLogger traceLogger
protected Properties props
protected String prefix
public Protocol(String host, int port, Properties props, String prefix, boolean isSSL, MailLogger logger) throws IOException, ProtocolException
Opens a connection to the given host at given port.
host
- host to connect toport
- portnumber to connect toprops
- Properties object used by this protocolprefix
- Prefix to prepend to property keysisSSL
- use SSL?logger
- log messages hereIOException
- for I/O errorsProtocolException
- for protocol failurespublic Protocol(InputStream in, PrintStream out, Properties props, boolean debug) throws IOException
in
- the InputStream to read fromout
- the PrintStream to write toprops
- Properties object used by this protocoldebug
- true to enable debugging outputIOException
- for I/O errorspublic long getTimestamp()
public void addResponseHandler(ResponseHandler h)
h
- the response handlerpublic void removeResponseHandler(ResponseHandler h)
h
- the response handlerpublic void notifyResponseHandlers(Response[] responses)
responses
- the responsesprotected void processGreeting(Response r) throws ProtocolException
ProtocolException
protected ResponseInputStream getInputStream()
protected OutputStream getOutputStream()
protected boolean supportsNonSyncLiterals()
public Response readResponse() throws IOException, ProtocolException
IOException
ProtocolException
public boolean hasResponse()
protected ByteArray getResponseBuffer()
public String writeCommand(String command, Argument args) throws IOException, ProtocolException
IOException
ProtocolException
public Response[] command(String command, Argument args)
command
- the commandargs
- the argumentspublic void handleResult(Response response) throws ProtocolException
response
- the responseProtocolException
- for protocol failurespublic void simpleCommand(String cmd, Argument args) throws ProtocolException
cmd
- the commandargs
- the argumentsProtocolException
- for protocol failurespublic void startTLS(String cmd) throws IOException, ProtocolException
cmd
is the command to issue to start TLS negotiation.
If the command succeeds, we begin TLS negotiation.
If the socket is already an SSLSocket this is a nop and the command
is not issued.cmd
- the command to issueIOException
- for I/O errorsProtocolException
- for protocol failurespublic void startCompression(String cmd) throws IOException, ProtocolException
cmd
is the command to issue to start compression.
If the command succeeds, we begin compression.cmd
- the command to issueIOException
- for I/O errorsProtocolException
- for protocol failurespublic boolean isSSL()
public InetAddress getInetAddress()
public SocketChannel getChannel()
public boolean supportsUtf8()
protected void disconnect()
protected String getLocalHost()
protected boolean isTracing()
protected void suspendTracing()
protected void resumeTracing()
Copyright © 2018 JBoss by Red Hat. All rights reserved.