|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface ProtocolIfc
defines genral interface for reaching
network resources. Now it can be incomplete for some protocols ideas but
desiging is in progress.
All protocols implementations should implement every of methods including
in this interface. Note that there is also AbstractProtocol
class which has many simple implementation of methods in this interface.
You can use them if they are enough for your protocol use or reimplement.
Each metod returning particular resource info (header or data) can be called
at any time, even before calling to connect() method. If call to some method
occured before call to connect(), protocol implementation should perform
connect() automaticaly.
Field Summary | |
static int |
CODE_BAD_REQUEST
|
static int |
CODE_CONNECTION_ERROR
Constant CODE_CONNECTION_ERROR means that
unknown error occured. |
static int |
CODE_CONNECTION_OK
Constant CODE_CONNECTION_OK means that everuthing
was correct and successful and application can continue downloading
data or can close connection. |
static int |
CODE_FORBIDDEN
|
static int |
CODE_HOST_NOT_FOUND
Constant CODE_HOST_NOT_FOUND means that
it was impossible to resolve host name into IP number. |
static int |
CODE_INTERNAL_SERVER_ERROR
|
static int |
CODE_LENGTH_REQUIRED
|
static int |
CODE_NETWORK_NOT_REACHABLE
|
static int |
CODE_NO_CONTENT
Constant CODE_NO_CONTENT means that
request to resource was correct but resource contains no data. |
static int |
CODE_NOT_FOUND
|
static int |
CODE_NOT_INITIALIZED
Constant CODE_NOT_INITIALIZED means that no
connection tries were performed. |
static int |
CODE_PARTIAL_CONTENT
|
static int |
CODE_REDIRECT
|
static int |
CODE_REQUEST_TIMEOUT
|
static int |
CODE_SERVER_NOT_REACHABLE
Constant CODE_SERVER_NOT_REACHABLE means that there
was no route to host or remote host is reachable but there was
no response from web server application (on given remote port). |
static int |
CODE_UNAUTHORIZED
|
static int |
CODE_VERSION_NOT_SUPPORTED
|
static int |
METHOD_GET
constant METHOD_GET contains value of |
static int |
METHOD_HEAD
constant METHOD_HEAD contains value of |
Method Summary | |
void |
connect()
connect method performs all necessary actions
required to connect to remote resource. |
void |
disconnect()
disconnect method closes network connection. |
java.util.HashMap |
getAllHeaders()
Methods getAllHeaders returns all received header from
the web server. |
java.lang.String |
getClientId()
getClientId method returns client identification
string which it sends to web sever during connection. |
java.lang.Object |
getConnectionInfo()
getConnectionInfo method should return some connection
parameters. |
int |
getConnectionResult()
getConnectionResult method returns standarized for
all protocols connection with server result. |
java.util.List |
getConnectionStatuses()
getConnectionStatuses method calculates and returns connection
statuses in List . |
byte[] |
getContentData()
|
long |
getContentLength()
getContentLength method returns expected content length. |
java.lang.String |
getContentType()
getContentType method returns type of data stored in resource. |
URI |
getEffectiveURI()
getEffectiveURI returns effective uri of requested
resource. |
long |
getHeaderIntValue(java.lang.String headerKey)
Method getHeaderStrValue returns header value
as long integer for given header name. |
java.lang.String |
getHeaderStrValue(java.lang.String headerKey)
Method getHeaderStrValue returns header value
as String for given header name. |
int |
getInputBufferSize()
getInputBufferSize method returns input buffer size
which is set for this protocol. |
java.io.InputStream |
getInputStream()
getInputStream method returns InputStream
where from user can read resource data. |
java.lang.String |
getProtocolType()
getProtocolType method returns protocols type
it implementing. |
long |
getRealContentSize()
getRealContentSize method returns received size of data. |
java.lang.String |
getRequestData()
|
java.lang.String |
getServerId()
getServerId method returns web server identification string
detected during making connection. |
int |
getStreamReadTimeout()
getStreamReadTimeout method returns value of stream
read timeout. |
float |
getTransferSpeed()
getTransferSpeed method calculates and returns transfer speed
in bytes/sec. |
URI |
getURI()
getURI method returns URI for
which performing connection. |
java.lang.String |
getUserName()
getUserName method returns user name used during authorization process. |
java.lang.String |
getUserPassword()
getUserPassword method returns user password used during authorization process. |
boolean |
isAllowAllCookies()
|
boolean |
isAllowRedirect()
|
boolean |
isAllowUserInteraction()
|
boolean |
isDebug()
|
boolean |
isErrorRecoverable(int code)
This method isErrorRecoverable should be able to return
info if given error code is permanent or not. |
boolean |
isKeepAlive()
getKeepAlive method returns value of keepAlive
field. |
void |
saveContent(java.io.OutputStream out_stream)
saveContent method performs saving resource data
to given OutputStream . |
void |
saveContent(java.lang.String file_name)
saveContent method performs saving resource data
to given disk file. |
void |
setAllowAllCookies(boolean allow)
|
void |
setAllowRedirect(boolean redirect)
|
void |
setAllowUserInteraction(boolean allow)
|
void |
setClientId(java.lang.String id)
setClientId method sets client identification
string. |
void |
setDebug(boolean debug)
Method setDebug sets debug mode. |
void |
setInputBufferSize(int buff_size)
setInputBufferSize method InputStream
returns data in packets. |
void |
setKeepAlive(boolean keepAlive)
setKeepAlive method sets keepAlive
variable. |
void |
setRequestData(java.lang.String data)
|
void |
setStreamReadTimeout(int tm_out)
setStreamReadTimeout method sets timeout for reading
from input stream taken from socket. |
void |
setURI(URI uri)
setURI method sets new URI for
protocol instance. |
void |
setUserName(java.lang.String name)
setUserName method sets user name for authorization. |
void |
setUserPassword(java.lang.String password)
setUserPassword method sets user password dor authorization. |
Field Detail |
public static final int METHOD_HEAD
METHOD_HEAD
contains value ofpublic static final int METHOD_GET
METHOD_GET
contains value ofpublic static final int CODE_HOST_NOT_FOUND
CODE_HOST_NOT_FOUND
means that
it was impossible to resolve host name into IP number.public static final int CODE_SERVER_NOT_REACHABLE
CODE_SERVER_NOT_REACHABLE
means that there
was no route to host or remote host is reachable but there was
no response from web server application (on given remote port).public static final int CODE_NETWORK_NOT_REACHABLE
public static final int CODE_CONNECTION_ERROR
CODE_CONNECTION_ERROR
means that
unknown error occured.public static final int CODE_NOT_INITIALIZED
CODE_NOT_INITIALIZED
means that no
connection tries were performed. Instance of protocol
implementation object was just created.public static final int CODE_CONNECTION_OK
CODE_CONNECTION_OK
means that everuthing
was correct and successful and application can continue downloading
data or can close connection. Note that in some cases data still
can be broken. From the protocol implementation sight everything
could look correct but for example if protocol doesn't
know how many bytes should download and server closed connection
during transfer protocol implementation may not know that not
all necessary data was downloaded.public static final int CODE_NO_CONTENT
CODE_NO_CONTENT
means that
request to resource was correct but resource contains no data.public static final int CODE_PARTIAL_CONTENT
public static final int CODE_REDIRECT
public static final int CODE_BAD_REQUEST
public static final int CODE_UNAUTHORIZED
public static final int CODE_FORBIDDEN
public static final int CODE_NOT_FOUND
public static final int CODE_REQUEST_TIMEOUT
public static final int CODE_LENGTH_REQUIRED
public static final int CODE_INTERNAL_SERVER_ERROR
public static final int CODE_VERSION_NOT_SUPPORTED
Method Detail |
public int getConnectionResult() throws java.io.IOException
getConnectionResult
method returns standarized for
all protocols connection with server result. For some protocols
such HTTP
it could translated server response code
for other particular protocol implementation should decide
what code return in given situation.int
value standarized connection code.java.io.IOException
- if an error occurspublic java.lang.String getProtocolType()
getProtocolType
method returns protocols type
it implementing. It should allways be a string taken from
package name. For example for HTTP implementation
we have class wttools.protocols.http.ProtocolImpl
.
And we know what protocol it implement from class name, becouse
it is stored in last package name level
wttools.protocols.http
.String
valuepublic void setURI(URI uri) throws java.io.IOException
setURI
method sets new URI
for
protocol instance. Note that there can be problem that if
we have for example FTP
instance implementation
for URI="ftp://ftp.wttools.sf.net/protocols.jar"
We must define proper action if somebody sets new url with
different protocol for example URI="http://wttools.sf.net/"
.uri
- an URI
value of new resource URI
java.io.IOException
- if an error occurspublic URI getURI()
getURI
method returns URI
for
which performing connection.URI
value of internal field
URI uri
public URI getEffectiveURI() throws java.io.IOException
getEffectiveURI
returns effective uri of requested
resource. If during connecting to web server redirection response
occurs it means that effective URI is different then original.URI
value of effective resource URI.public void setClientId(java.lang.String id)
setClientId
method sets client identification
string. I don't know if it make sense but there is
"User-Aget" header in HTTP
protocol
there which client sends to HTTP
server.id
- a String
value of client idenification string.public java.lang.String getClientId()
getClientId
method returns client identification
string which it sends to web sever during connection. In
HTTP
protocol it is value of "User-Agent"
header.String
value of userId
field.public void setStreamReadTimeout(int tm_out)
setStreamReadTimeout
method sets timeout for reading
from input stream taken from socket. When some communication
problem occures during perfmorming data transmision application
may infinitely wait for data which will never arrive. To prevent
such situation you can set stream read timeout to ensure waiting
for data no longer than you expect. If set to 0 it means turn off
timeout and allow infinite reading.tm_out
- an int
value of reading from stream
timeout.public int getStreamReadTimeout()
getStreamReadTimeout
method returns value of stream
read timeout.int
value of stream read timeout.public void setInputBufferSize(int buff_size)
setInputBufferSize
method InputStream
returns data in packets. With this method you can sets size of
this packet. The smaller size of packet should be used if there
are some transmision problems and bigger size should be used if
we use network with very good bandwich to improve transmision
efficiency.buff_size
- an int
value of input buffer size.public int getInputBufferSize()
getInputBufferSize
method returns input buffer size
which is set for this protocol.int
value of input buffer size.public void setKeepAlive(boolean keepAlive)
setKeepAlive
method sets keepAlive
variable. This variable determines keeping connection to web
server after completing user request. If we know that we want
reach only one resource from thet web server we can set
keepAlive
to false
and protocol
implementation should disconnect after finishing transmision.
But very often we want to download many files from web server
for example from FTP
or HTTP
server.
It is not effective to reconnection every time. It is better
to keep alive connection between downloading every file.HTTP
server. Each file is about 10kB size.
So downloading each of them with good internet connection takes about
1 sec. But establishing connection takes from 1 sec to 30 sec.
Lets suppose that it takes about 10 sec. So we can see how much time
we can save with using keep alive connections.keepAlive
- a boolean
valuepublic boolean isKeepAlive()
getKeepAlive
method returns value of keepAlive
field. keepAlive
field switches between permaneent connection
mode and single transfer connection mode. Permanent connection mode
should allow to transfer many files with one persistent connection
to server.boolean
value of keepAlive
field.setKeepAlive(boolean keepAlive)
public void setAllowUserInteraction(boolean allow)
public boolean isAllowUserInteraction()
public void setAllowAllCookies(boolean allow)
public boolean isAllowAllCookies()
public void setRequestData(java.lang.String data)
public java.lang.String getRequestData()
public void setAllowRedirect(boolean redirect)
public boolean isAllowRedirect()
public boolean isErrorRecoverable(int code)
isErrorRecoverable
should be able to return
info if given error code is permanent or not. I mean for example if
error code means "Page not found" it mean that there is no page
under requested URL. It is most probably permanent error. However
if error code means "Network not reachable" or
"Request timeout" it mean that in future during next try download
may be successful.code
- an int
value of requested error code.boolean
calculated value of recoverability of error.public void connect() throws java.io.IOException
connect
method performs all necessary actions
required to connect to remote resource. After successfuly
completing this method connection should be established and
remote data should be ready to download.java.io.IOException
- if an error occurspublic void disconnect() throws java.io.IOException
disconnect
method closes network connection.
All received resource info should be still available but not
additional data resource data.java.io.IOException
- if an error occurspublic void saveContent(java.lang.String file_name) throws java.io.IOException
saveContent
method performs saving resource data
to given disk file. I have doubt what mean resource data.
In general we can divide resource info on resource headers
and resource data. It is very usefull if we think about
HTTP
resources. But if we think about mail message
headers are almost as important as message data. So in particular
protocol implementation headers should be joined with data.file_name
- a String
valuejava.io.IOException
- if an error occurspublic void saveContent(java.io.OutputStream out_stream) throws java.io.IOException
saveContent
method performs saving resource data
to given OutputStream
. This method does not open
nor close given stream. Closing stream should be performed by
user.out_stream
- an OutputStream
valuejava.io.IOException
- if an error occurssaveContent(String file_name)
public java.io.InputStream getInputStream() throws java.io.IOException
getInputStream
method returns InputStream
where from user can read resource data. For some protocols implementation
InputStream
should return not only resource data but also
resource headers - it is important in mail protocols for example (POP3,
IMAP4, SMTP).InputStream
valuejava.io.IOException
- if an error occurspublic byte[] getContentData() throws java.io.IOException
public java.lang.String getHeaderStrValue(java.lang.String headerKey) throws java.io.IOException
getHeaderStrValue
returns header value
as String
for given header name.headerKey
- a String
name of header.String
value of header.public long getHeaderIntValue(java.lang.String headerKey) throws java.io.IOException
getHeaderStrValue
returns header value
as long
integer for given header name.headerKey
- a String
name of header.long
value of given header.public java.util.HashMap getAllHeaders() throws java.io.IOException
getAllHeaders
returns all received header from
the web server.HashMap
value table of pairs header keys and values.public java.lang.String getContentType() throws java.io.IOException
getContentType
method returns type of data stored in resource.
for some protocols implementation it is easy to return info received
from web server (HTTP
server returns Content-Type
header with such info) for others it is necessary to create engine to determine
content type. This engine may base on file extension or based on mime-magic
file.String
value returns standard internet mime-type of resource
data.public long getContentLength() throws java.io.IOException
getContentLength
method returns expected content length. In many
situations web server sends size of resource data, but sometimes we don't know
how much data we receive till end of transmision. If expected content length
is not known protocol should return -1.long
value size of resource data or -1.public long getRealContentSize()
getRealContentSize
method returns received size of data. First of all
if undetected network error occurs we can recieve less data that we expect. So during
verification we can check if expected data size is equal to received. Second
if web server don't send expected data size then with this method we can know
how many bytes were received.long
valuepublic float getTransferSpeed()
getTransferSpeed
method calculates and returns transfer speed
in bytes/sec. This info should be available during downloading data to
allow breaking transfer if ransfer speed is too low.float
valuepublic java.lang.String getServerId() throws java.io.IOException
getServerId
method returns web server identification string
detected during making connection. in HTTP
protocol server
identification string can be found in header named Server
.String
value containing server identification string.public java.lang.Object getConnectionInfo()
getConnectionInfo
method should return some connection
parameters. for example remote host IP number, socket buffers size,
socket timeout, remote server info and so on.Object
value containing connection info in any form.public java.util.List getConnectionStatuses()
getConnectionStatuses
method calculates and returns connection
statuses in List
. All objects stored in returned
List
should have implemented String toString()
method to allow displaing info.List
value contain list of objects representing
connection statuses.public void setUserName(java.lang.String name)
setUserName
method sets user name for authorization.
in general user name and pasword should be encoded in url with the form:
http://user:passwd@www.sf.net:8000/path/file.html
but sometimes it isn't possible to put user name and password in url and then
you can set them with these methods.name
- a String
value cotains user name.public java.lang.String getUserName()
getUserName
method returns user name used during authorization process.
User name can be taken from URI or from data received in setUserName(Strin name)
method.String
value cotains user name.public void setUserPassword(java.lang.String password)
setUserPassword
method sets user password dor authorization.
in general user name and pasword should be encoded in url with the form:
http://user:passwd@www.sf.net:8000/path/file.html
but sometimes it isn't possible to put user name and password in url and then
you can set them with these methods.password
- a String
value cotains user password.public java.lang.String getUserPassword()
getUserPassword
method returns user password used during authorization process.
User name can be taken from URI or from data received in setUserName(Strin name)
method.String
value cotains user password.public void setDebug(boolean debug)
setDebug
sets debug mode.debug
- a boolean
value of debug mode.public boolean isDebug()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |