wttools.protocols.extend.http
Class ProtocolImpl

java.lang.Object
  |
  +--wttools.protocols.AbstractProtocol
        |
        +--wttools.protocols.extend.http.ProtocolImpl
All Implemented Interfaces:
ProtocolIfc

public class ProtocolImpl
extends AbstractProtocol

ProtocolImpl.java Created: Thu Nov 1 15:10:01 2001

Version:
$Revision: 1.13 $
Author:
Artur Hefczyc

Field Summary
protected  HTTPConnection con
           
protected  HTTPResponse res
           
 
Fields inherited from class wttools.protocols.AbstractProtocol
allowAllCookies, allowRedirect, allowUserInteraction, bytesDownloaded, clientId, debug, inputBufferSize, keepAlive, requestData, streamReadTimeout, uri, userName, userPassword
 
Fields inherited from interface wttools.protocols.ifc.ProtocolIfc
CODE_BAD_REQUEST, CODE_CONNECTION_ERROR, CODE_CONNECTION_OK, CODE_FORBIDDEN, CODE_HOST_NOT_FOUND, CODE_INTERNAL_SERVER_ERROR, CODE_LENGTH_REQUIRED, CODE_NETWORK_NOT_REACHABLE, CODE_NO_CONTENT, CODE_NOT_FOUND, CODE_NOT_INITIALIZED, CODE_PARTIAL_CONTENT, CODE_REDIRECT, CODE_REQUEST_TIMEOUT, CODE_SERVER_NOT_REACHABLE, CODE_UNAUTHORIZED, CODE_VERSION_NOT_SUPPORTED, METHOD_GET, METHOD_HEAD
 
Constructor Summary
ProtocolImpl()
           
 
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.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.
 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.
 java.lang.String getHeaderStrValue(java.lang.String param1)
          Method getHeaderStrValue returns header value as String for given header name.
 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.
 java.lang.String getServerId()
          getServerId method returns web server identification string detected during making connection.
 float getTransferSpeed()
          getTransferSpeed method calculates and returns transfer speed in bytes/sec.
protected  void initialize(int method)
           
 void setURI(URI v)
          Set the value of uri.
protected  int translateResponseCode(int code)
           
 
Methods inherited from class wttools.protocols.AbstractProtocol
deb, getClientId, getContentData, getHeaderIntValue, getInputBufferSize, getRealContentSize, getRequestData, getStreamReadTimeout, getURI, getUserName, getUserPassword, isAllowAllCookies, isAllowRedirect, isAllowUserInteraction, isDebug, isErrorRecoverable, isKeepAlive, saveContent, saveContent, setAllowAllCookies, setAllowRedirect, setAllowUserInteraction, setClientId, setDebug, setInputBufferSize, setKeepAlive, setRequestData, setStreamReadTimeout, setUserName, setUserPassword
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

con

protected HTTPConnection con

res

protected HTTPResponse res
Constructor Detail

ProtocolImpl

public ProtocolImpl()
Method Detail

setURI

public void setURI(URI v)
            throws java.io.IOException
Description copied from class: AbstractProtocol
Set the value of uri.
Overrides:
setURI in class AbstractProtocol
Following copied from class: wttools.protocols.AbstractProtocol
Parameters:
v - Value to assign to uri.
Throws:
java.io.IOException - if an error occurs

initialize

protected void initialize(int method)
                   throws java.io.IOException

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Description copied from interface: ProtocolIfc
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).
Returns:
Throws:
java.io.IOException -

connect

public void connect()
             throws java.io.IOException
Description copied from interface: ProtocolIfc
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.
User is able both to retrieve special resource info (data headers only) or resource data. For example user should be allowed to return only mail headers instead of full message.
Throws:
java.io.IOException -

getConnectionStatuses

public java.util.List getConnectionStatuses()
Description copied from interface: ProtocolIfc
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.
As statuses should be put info about transmision: average transfer speed, bytes received, transfer time and so on.
Returns:

getConnectionInfo

public java.lang.Object getConnectionInfo()
Description copied from interface: ProtocolIfc
getConnectionInfo method should return some connection parameters. for example remote host IP number, socket buffers size, socket timeout, remote server info and so on.
Returns:

getTransferSpeed

public float getTransferSpeed()
Description copied from interface: ProtocolIfc
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.
Returns:

getAllHeaders

public java.util.HashMap getAllHeaders()
                                throws java.io.IOException
Description copied from interface: ProtocolIfc
Methods getAllHeaders returns all received header from the web server.
Returns:

getHeaderStrValue

public java.lang.String getHeaderStrValue(java.lang.String param1)
                                   throws java.io.IOException
Description copied from interface: ProtocolIfc
Method getHeaderStrValue returns header value as String for given header name.
Parameters:
param1 -
Returns:

disconnect

public void disconnect()
                throws java.io.IOException
Description copied from interface: ProtocolIfc
disconnect method closes network connection. All received resource info should be still available but not additional data resource data.
Throws:
java.io.IOException -

getProtocolType

public java.lang.String getProtocolType()
Description copied from interface: ProtocolIfc
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.
Returns:

getConnectionResult

public int getConnectionResult()
                        throws java.io.IOException
Description copied from interface: ProtocolIfc
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.
Returns:
Throws:
java.io.IOException -

getEffectiveURI

public URI getEffectiveURI()
                    throws java.io.IOException
Description copied from interface: ProtocolIfc
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.
Following copied from interface: wttools.protocols.ifc.ProtocolIfc
Returns:
an URI value of effective resource URI.

getContentLength

public long getContentLength()
                      throws java.io.IOException
Description copied from interface: ProtocolIfc
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.
Returns:

getContentType

public java.lang.String getContentType()
                                throws java.io.IOException
Description copied from interface: ProtocolIfc
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.
Returns:

getServerId

public java.lang.String getServerId()
                             throws java.io.IOException
Description copied from interface: ProtocolIfc
getServerId method returns web server identification string detected during making connection. in HTTP protocol server identification string can be found in header named Server.
Returns:

translateResponseCode

protected int translateResponseCode(int code)


Copyright GNU, wttools developers Team.