Java Doc for HTTPConnection.java in  » Net » SkunkDAV » HTTPClient » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » SkunkDAV » HTTPClient 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   HTTPClient.HTTPConnection

HTTPConnection
public class HTTPConnection implements GlobalConstants,HTTPClientModuleConstants(Code)
This class implements http protocol requests; it contains most of HTTP/1.1 and ought to be unconditionally compliant. Redirections are automatically handled, and authorizations requests are recognized and dealt with via an authorization handler. Only full HTTP/1.0 and HTTP/1.1 requests are generated. HTTP/1.1, HTTP/1.0 and HTTP/0.9 responses are recognized.

Using the HTTPClient should be quite simple. First add the import statement 'import HTTPClient.*;' to your file(s). Request can then be sent using one of the methods Head(), Get(), Post(), etc in HTTPConnection. These methods all return an instance of HTTPResponse which has methods for accessing the response headers (getHeader(), getHeaderAsInt(), etc), various response info (getStatusCode(), getReasonLine(), etc) and the reponse data (getData() and getInputStream()). Following are some examples.

If this is in an applet you can retrieve files from your server as follows:

 try
 {
 HTTPConnection con = new HTTPConnection(this);
 HTTPResponse   rsp = con.Get("/my_file");
 if (rsp.getStatusCode() >= 300)
 {
 System.err.println("Received Error: "+rsp.getReasonLine());
 System.err.println(new String(rsp.getData()));
 }
 else
 data = rsp.getData();
 rsp = con.Get("/another_file");
 if (rsp.getStatusCode() >= 300)
 {
 System.err.println("Received Error: "+rsp.getReasonLine());
 System.err.println(new String(rsp.getData()));
 }
 else
 other_data = rsp.getData();
 }
 catch (IOException ioe)
 {
 System.err.println(ioe.toString());
 }
 catch (ModuleException me)
 {
 System.err.println("Error handling request: " + me.getMessage());
 }
 
This will get the files "/my_file" and "/another_file" and put their contents into byte[]s accessible via getData(). Note that you need to only create a new HTTPConnection when sending a request to a new server (different host or port); although you may create a new HTTPConnection for every request to the same server this not recommended, as various information about the server is cached after the first request (to optimize subsequent requests) and persistent connections are used whenever possible.

To POST form data you would use something like this (assuming you have two fields called name and e-mail, whose contents are stored in the variables name and email):

 try
 {
 NVPair form_data[] = new NVPair[2];
 form_data[0] = new NVPair("name", name);
 form_data[1] = new NVPair("e-mail", email);
 HTTPConnection con = new HTTPConnection(this);
 HTTPResponse   rsp = con.Post("/cgi-bin/my_script", form_data);
 if (rsp.getStatusCode() >= 300)
 {
 System.err.println("Received Error: "+rsp.getReasonLine());
 System.err.println(new String(rsp.getData()));
 }
 else
 stream = rsp.getInputStream();
 }
 catch (IOException ioe)
 {
 System.err.println(ioe.toString());
 }
 catch (ModuleException me)
 {
 System.err.println("Error handling request: " + me.getMessage());
 }
 
Here the response data is read at leasure via an InputStream instead of all at once into a byte[].

As another example, if you have a URL you're trying to send a request to you would do something like the following:

 try
 {
 URL url = new URL("http://www.mydomain.us/test/my_file");
 HTTPConnection con = new HTTPConnection(url);
 HTTPResponse   rsp = con.Put(url.getFile(), "Hello World");
 if (rsp.getStatusCode() >= 300)
 {
 System.err.println("Received Error: "+rsp.getReasonLine());
 System.err.println(new String(rsp.getData()));
 }
 else
 data = rsp.getData();
 }
 catch (IOException ioe)
 {
 System.err.println(ioe.toString());
 }
 catch (ModuleException me)
 {
 System.err.println("Error handling request: " + me.getMessage());
 }
 

There are a whole number of methods for each request type; however the general forms are ([...] means that the enclosed is optional):

  • Head ( file [, form-data [, headers ] ] )
  • Head ( file [, query [, headers ] ] )
  • Get ( file [, form-data [, headers ] ] )
  • Get ( file [, query [, headers ] ] )
  • Post ( file [, form-data [, headers ] ] )
  • Post ( file [, data [, headers ] ] )
  • Post ( file [, stream [, headers ] ] )
  • Put ( file , data [, headers ] )
  • Put ( file , stream [, headers ] )
  • Delete ( file [, headers ] )
  • Options ( file [, headers [, data] ] )
  • Options ( file [, headers [, stream] ] )
  • Trace ( file [, headers ] )

version:
   0.3-2 18/06/1999
author:
   Ronald Tschalär


Field Summary
 LinkedListDemuxList
    
 booleanServProtVersKnown
    
 intServerProtocolVersion
    
final public static  Stringversion
     The current version of this package.

Constructor Summary
public  HTTPConnection(Applet applet)
     Constructs a connection to the host from where the applet was loaded.
public  HTTPConnection(String host)
    
public  HTTPConnection(String host, int port)
    
public  HTTPConnection(String prot, String host, int port)
     Constructs a connection to the specified host on the specified port, using the specified protocol (currently only "http" is supported).
public  HTTPConnection(URL url)
     Constructs a connection to the host (port) as given in the url.

Method Summary
public  HTTPResponseDelete(String file)
     Requests that file be DELETEd from the server.
public  HTTPResponseDelete(String file, NVPair[] headers)
     Requests that file be DELETEd from the server.
public  HTTPResponseExtensionMethod(String method, String file, byte[] data, NVPair[] headers)
     This is here to allow an arbitrary, non-standard request to be sent.
public  HTTPResponseExtensionMethod(String method, String file, HttpOutputStream os, NVPair[] headers)
     This is here to allow an arbitrary, non-standard request to be sent.
public  HTTPResponseGet(String file)
     GETs the file.
public  HTTPResponseGet(String file, NVPair form_data)
     GETs the file with a query consisting of the specified form-data.
public  HTTPResponseGet(String file, NVPair[] form_data, NVPair[] headers)
     GETs the file with a query consisting of the specified form-data.
public  HTTPResponseGet(String file, String query)
     GETs the file using the specified query string.
public  HTTPResponseGet(String file, String query, NVPair[] headers)
     GETs the file using the specified query string.
public  HTTPResponseHead(String file)
     Sends the HEAD request.
public  HTTPResponseHead(String file, NVPair form_data)
     Sends the HEAD request.
public  HTTPResponseHead(String file, NVPair[] form_data, NVPair[] headers)
     Sends the HEAD request.
public  HTTPResponseHead(String file, String query)
     Sends the HEAD request.
public  HTTPResponseHead(String file, String query, NVPair[] headers)
     Sends the HEAD request.
public  HTTPResponseOptions(String file)
     Request OPTIONS from the server.
public  HTTPResponseOptions(String file, NVPair[] headers)
     Request OPTIONS from the server.
public  HTTPResponseOptions(String file, NVPair[] headers, byte[] data)
     Request OPTIONS from the server.
public  HTTPResponseOptions(String file, NVPair[] headers, HttpOutputStream stream)
     Request OPTIONS from the server.
public  HTTPResponsePost(String file)
     POSTs to the specified file.
public  HTTPResponsePost(String file, NVPair form_data)
     POSTs form-data to the specified file.
public  HTTPResponsePost(String file, NVPair form_data, NVPair headers)
     POST's form-data to the specified file using the specified headers. The data is first urlencoded and then turned into a string of the form "name1=value1&name2=value2".
public  HTTPResponsePost(String file, String data)
     POSTs the data to the specified file.
public  HTTPResponsePost(String file, String data, NVPair[] headers)
     POSTs the data to the specified file using the specified headers.
public  HTTPResponsePost(String file, byte data)
     POSTs the raw data to the specified file.
public  HTTPResponsePost(String file, byte data, NVPair[] headers)
     POSTs the raw data to the specified file using the specified headers.
public  HTTPResponsePost(String file, HttpOutputStream stream)
     POSTs the data written to the output stream to the specified file.
public  HTTPResponsePost(String file, HttpOutputStream stream, NVPair[] headers)
     POSTs the data written to the output stream to the specified file using the specified headers.
final static  StringProtVers2String(int prot_vers)
    
public  HTTPResponsePut(String file, String data)
     PUTs the data into the specified file.
public  HTTPResponsePut(String file, String data, NVPair[] headers)
     PUTs the data into the specified file using the additional headers for the request.
public  HTTPResponsePut(String file, byte data)
     PUTs the raw data into the specified file.
public  HTTPResponsePut(String file, byte data, NVPair[] headers)
     PUTs the raw data into the specified file using the additional headers.
public  HTTPResponsePut(String file, HttpOutputStream stream)
     PUTs the data written to the output stream into the specified file.
public  HTTPResponsePut(String file, HttpOutputStream stream, NVPair[] headers)
     PUTs the data written to the output stream into the specified file using the additional headers.
final static  intString2ProtVers(String prot_vers)
    
public  HTTPResponseTrace(String file, NVPair[] headers)
     Requests a TRACE.
public  HTTPResponseTrace(String file)
     Requests a TRACE.
public  voidaddBasicAuthorization(String realm, String user, String passwd)
     Adds an authorization entry for the "basic" authorization scheme to the list.
public static  booleanaddDefaultModule(Class module, int pos)
     Adds a module to the default list.
public  voidaddDigestAuthorization(String realm, String user, String passwd)
     Adds an authorization entry for the "digest" authorization scheme to the list.
public  booleanaddModule(Class module, int pos)
     Adds a module to the current list.
synchronized  voidcloseDemux(IOException ioe, boolean was_reset)
    
public static  booleandoProxyFor(String host)
     Remove host from the list of hosts for which the proxy should not be used.
public static  voiddontProxyFor(String host)
     Add host to the list of hosts which should be accessed directly, not via any proxy set by setProxyServer().

The host may be any of:

  • a complete host name (e.g.
public static  voiddontProxyFor(String[] hosts)
     Convenience method to add a number of hosts at once.
public  booleangetAllowUserInteraction()
     returns whether modules are allowed to prompt or popup dialogs if neccessary.
public  ObjectgetContext()
     Returns the current context.
public static  booleangetDefaultAllowUserInteraction()
     Gets the default allow-user-action.
static  ObjectgetDefaultContext()
     Returns the default context.
public  NVPair[]getDefaultHeaders()
     Gets the current list of default http headers.
public static  Class[]getDefaultModules()
     Returns the default list of modules.
public static  intgetDefaultTimeout()
     Gets the default timeout value to be used for each new HTTPConnection.
public  StringgetHost()
     Returns the host this connection is talking to.
public  Class[]getModules()
     Returns the list of modules used currently.
public  intgetPort()
     Returns the port this connection connects to.
public  StringgetProtocol()
     Returns the protocol this connection is talking.
public  StringgetProxyHost()
     Returns the host of the proxy this connection is using.
public  intgetProxyPort()
     Returns the port of the proxy this connection is using.
public  intgetTimeout()
     Gets the timeout used for reading response data.
 booleanhandleFirstRequest(Request req, Response resp)
     The very first request is special in that we use it to figure out the protocol version the server (or proxy) is compliant with.
 voidhandleRequest(Request req, HTTPResponse http_resp, Response resp, boolean usemodules)
     handles the Request.
public  booleanisCompatibleWith(URI uri)
     See if the given uri is compatible with this connection.
synchronized  voidoutputFinished()
    
public static  booleanremoveDefaultModule(Class module)
     Removes a module from the default list.
public  booleanremoveModule(Class module)
     Removes a module from the current list.
 ResponsesendRequest(Request req, int con_timeout)
     sends the request over the line.
Parameters:
  req - the request
Parameters:
  con_timeout - the timeout to use when establishing a socketconnection; an InterruptedIOException is thrownif the procedure times out.
public  voidsetAllowUserInteraction(boolean allow)
     Controls whether modules are allowed to prompt the user or pop up dialogs if neccessary.
public  voidsetContext(Object context)
     Sets the current context.
public synchronized  voidsetCurrentProxy(String host, int port)
     Sets the proxy used by this instance.
public static  voidsetDefaultAllowUserInteraction(boolean allow)
     Sets the default allow-user-action.
public  voidsetDefaultHeaders(NVPair[] headers)
     Sets the default http headers to be sent with each request.
public static  voidsetDefaultTimeout(int time)
     Sets the default timeout value to be used for each new HTTPConnection.
public static  voidsetProxyServer(String host, int port)
     Sets the default proxy server to use.
public  voidsetRawMode(boolean raw)
     Sets/Resets raw mode.
public static  voidsetSocksServer(String host)
     Sets the SOCKS server to use.
public static  voidsetSocksServer(String host, int port)
     Sets the SOCKS server to use.
public static  voidsetSocksServer(String host, int port, int version)
     Sets the SOCKS server to use.
public  voidsetTimeout(int time)
     Sets the timeout to be used for creating connections and reading responses.
public  voidstop()
     Aborts all the requests currently in progress on this connection and closes all associated sockets.

Note: there is a small window where a request method such as Get() may have been invoked but the request has not been built and added to the list.

public  StringtoString()
     Generates a string of the form protocol://host.domain:port .

Field Detail
DemuxList
LinkedList DemuxList(Code)
a list of active stream demultiplexors



ServProtVersKnown
boolean ServProtVersKnown(Code)
Have we gotten the server's protocol version yet?



ServerProtocolVersion
int ServerProtocolVersion(Code)
The server's protocol version; M.m stored as (M<<16 | m)



version
final public static String version(Code)
The current version of this package.




Constructor Detail
HTTPConnection
public HTTPConnection(Applet applet) throws ProtocolNotSuppException(Code)
Constructs a connection to the host from where the applet was loaded. Note that current security policies only let applets connect home.
Parameters:
  applet - the current applet



HTTPConnection
public HTTPConnection(String host)(Code)
Constructs a connection to the specified host on port 80
Parameters:
  host - the host



HTTPConnection
public HTTPConnection(String host, int port)(Code)
Constructs a connection to the specified host on the specified port
Parameters:
  host - the host
Parameters:
  port - the port



HTTPConnection
public HTTPConnection(String prot, String host, int port) throws ProtocolNotSuppException(Code)
Constructs a connection to the specified host on the specified port, using the specified protocol (currently only "http" is supported).
Parameters:
  prot - the protocol
Parameters:
  host - the host
Parameters:
  port - the port, or -1 for the default port
exception:
  ProtocolNotSuppException - if the protocol is not HTTP



HTTPConnection
public HTTPConnection(URL url) throws ProtocolNotSuppException(Code)
Constructs a connection to the host (port) as given in the url.
Parameters:
  url - the url
exception:
  ProtocolNotSuppException - if the protocol is not HTTP




Method Detail
Delete
public HTTPResponse Delete(String file) throws IOException, ModuleException(Code)
Requests that file be DELETEd from the server.
Parameters:
  file - the absolute path of the resource an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Delete
public HTTPResponse Delete(String file, NVPair[] headers) throws IOException, ModuleException(Code)
Requests that file be DELETEd from the server.
Parameters:
  file - the absolute path of the resource
Parameters:
  headers - additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



ExtensionMethod
public HTTPResponse ExtensionMethod(String method, String file, byte[] data, NVPair[] headers) throws IOException, ModuleException(Code)
This is here to allow an arbitrary, non-standard request to be sent. I'm assuming you know what you are doing...
Parameters:
  method - the extension method
Parameters:
  file - the absolute path of the resource, or null
Parameters:
  data - optional data, or null
Parameters:
  headers - optional headers, or null an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



ExtensionMethod
public HTTPResponse ExtensionMethod(String method, String file, HttpOutputStream os, NVPair[] headers) throws IOException, ModuleException(Code)
This is here to allow an arbitrary, non-standard request to be sent. I'm assuming you know what you are doing...
Parameters:
  method - the extension method
Parameters:
  file - the absolute path of the resource, or null
Parameters:
  stream - optional output stream, or null
Parameters:
  headers - optional headers, or null an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Get
public HTTPResponse Get(String file) throws IOException, ModuleException(Code)
GETs the file.
Parameters:
  file - the absolute path of the file an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Get
public HTTPResponse Get(String file, NVPair form_data) throws IOException, ModuleException(Code)
GETs the file with a query consisting of the specified form-data. The data is urlencoded, turned into a string of the form "name1=value1&name2=value2" and then sent as a query string.
Parameters:
  file - the absolute path of the file
Parameters:
  form_data - an array of Name/Value pairs an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Get
public HTTPResponse Get(String file, NVPair[] form_data, NVPair[] headers) throws IOException, ModuleException(Code)
GETs the file with a query consisting of the specified form-data. The data is urlencoded, turned into a string of the form "name1=value1&name2=value2" and then sent as a query string.
Parameters:
  file - the absolute path of the file
Parameters:
  form_data - an array of Name/Value pairs
Parameters:
  headers - additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Get
public HTTPResponse Get(String file, String query) throws IOException, ModuleException(Code)
GETs the file using the specified query string. The query string is first urlencoded.
Parameters:
  file - the absolute path of the file
Parameters:
  query - the query an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Get
public HTTPResponse Get(String file, String query, NVPair[] headers) throws IOException, ModuleException(Code)
GETs the file using the specified query string. The query string is first urlencoded.
Parameters:
  file - the absolute path of the file
Parameters:
  query - the query string
Parameters:
  headers - additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Head
public HTTPResponse Head(String file) throws IOException, ModuleException(Code)
Sends the HEAD request. This request is just like the corresponding GET except that it only returns the headers and no data.
See Also:   HTTPConnection.Get(java.lang.String)
Parameters:
  file - the absolute path of the file an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Head
public HTTPResponse Head(String file, NVPair form_data) throws IOException, ModuleException(Code)
Sends the HEAD request. This request is just like the corresponding GET except that it only returns the headers and no data.
See Also:   HTTPConnection.Get(java.lang.String,HTTPClient.NVPair[])
Parameters:
  file - the absolute path of the file
Parameters:
  form_data - an array of Name/Value pairs an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Head
public HTTPResponse Head(String file, NVPair[] form_data, NVPair[] headers) throws IOException, ModuleException(Code)
Sends the HEAD request. This request is just like the corresponding GET except that it only returns the headers and no data.
See Also:   HTTPConnection.Get(java.lang.String,HTTPClient.NVPair[],HTTPClient.NVPair[])
Parameters:
  file - the absolute path of the file
Parameters:
  form_data - an array of Name/Value pairs
Parameters:
  headers - additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Head
public HTTPResponse Head(String file, String query) throws IOException, ModuleException(Code)
Sends the HEAD request. This request is just like the corresponding GET except that it only returns the headers and no data.
See Also:   HTTPConnection.Get(java.lang.String,java.lang.String)
Parameters:
  file - the absolute path of the file
Parameters:
  query - the query string; it will be urlencoded an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Head
public HTTPResponse Head(String file, String query, NVPair[] headers) throws IOException, ModuleException(Code)
Sends the HEAD request. This request is just like the corresponding GET except that it only returns the headers and no data.
See Also:   HTTPConnection.Get(java.lang.String,java.lang.String,HTTPClient.NVPair[])
Parameters:
  file - the absolute path of the file
Parameters:
  query - the query string; it will be urlencoded
Parameters:
  headers - additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Options
public HTTPResponse Options(String file) throws IOException, ModuleException(Code)
Request OPTIONS from the server. If file is "*" then the request applies to the server as a whole; otherwise it applies only to that resource.
Parameters:
  file - the absolute path of the resource, or "*" an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Options
public HTTPResponse Options(String file, NVPair[] headers) throws IOException, ModuleException(Code)
Request OPTIONS from the server. If file is "*" then the request applies to the server as a whole; otherwise it applies only to that resource.
Parameters:
  file - the absolute path of the resource, or "*"
Parameters:
  headers - the headers containing optional info. an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Options
public HTTPResponse Options(String file, NVPair[] headers, byte[] data) throws IOException, ModuleException(Code)
Request OPTIONS from the server. If file is "*" then the request applies to the server as a whole; otherwise it applies only to that resource.
Parameters:
  file - the absolute path of the resource, or "*"
Parameters:
  headers - the headers containing optional info.
Parameters:
  data - any data to be sent in the optional body an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Options
public HTTPResponse Options(String file, NVPair[] headers, HttpOutputStream stream) throws IOException, ModuleException(Code)
Request OPTIONS from the server. If file is "*" then the request applies to the server as a whole; otherwise it applies only to that resource.
Parameters:
  file - the absolute path of the resource, or "*"
Parameters:
  headers - the headers containing optional info.
Parameters:
  stream - an output stream for sending the optional body an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Post
public HTTPResponse Post(String file) throws IOException, ModuleException(Code)
POSTs to the specified file. No data is sent.
Parameters:
  file - the absolute path of the file an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Post
public HTTPResponse Post(String file, NVPair form_data) throws IOException, ModuleException(Code)
POSTs form-data to the specified file. The data is first urlencoded and then turned into a string of the form "name1=value1&name2=value2". A Content-type header with the value application/x-www-form-urlencoded is added.
Parameters:
  file - the absolute path of the file
Parameters:
  form_data - an array of Name/Value pairs an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Post
public HTTPResponse Post(String file, NVPair form_data, NVPair headers) throws IOException, ModuleException(Code)
POST's form-data to the specified file using the specified headers. The data is first urlencoded and then turned into a string of the form "name1=value1&name2=value2". If no Content-type header is given then one is added with a value of application/x-www-form-urlencoded.
Parameters:
  file - the absolute path of the file
Parameters:
  form_data - an array of Name/Value pairs
Parameters:
  headers - additional headers a HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Post
public HTTPResponse Post(String file, String data) throws IOException, ModuleException(Code)
POSTs the data to the specified file. The data is converted to an array of bytes using the lower byte of each character. The request is sent using the content-type "application/octet-stream".
See Also:   java.lang.String.getBytes(intintbyte[]int)
Parameters:
  file - the absolute path of the file
Parameters:
  data - the data an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Post
public HTTPResponse Post(String file, String data, NVPair[] headers) throws IOException, ModuleException(Code)
POSTs the data to the specified file using the specified headers.
Parameters:
  file - the absolute path of the file
Parameters:
  data - the data
Parameters:
  headers - additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Post
public HTTPResponse Post(String file, byte data) throws IOException, ModuleException(Code)
POSTs the raw data to the specified file. The request is sent using the content-type "application/octet-stream"
Parameters:
  file - the absolute path of the file
Parameters:
  data - the data an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Post
public HTTPResponse Post(String file, byte data, NVPair[] headers) throws IOException, ModuleException(Code)
POSTs the raw data to the specified file using the specified headers.
Parameters:
  file - the absolute path of the file
Parameters:
  data - the data
Parameters:
  headers - additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Post
public HTTPResponse Post(String file, HttpOutputStream stream) throws IOException, ModuleException(Code)
POSTs the data written to the output stream to the specified file. The request is sent using the content-type "application/octet-stream"
Parameters:
  file - the absolute path of the file
Parameters:
  stream - the output stream on which the data is written an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Post
public HTTPResponse Post(String file, HttpOutputStream stream, NVPair[] headers) throws IOException, ModuleException(Code)
POSTs the data written to the output stream to the specified file using the specified headers.
Parameters:
  file - the absolute path of the file
Parameters:
  stream - the output stream on which the data is written
Parameters:
  headers - additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



ProtVers2String
final static String ProtVers2String(int prot_vers)(Code)



Put
public HTTPResponse Put(String file, String data) throws IOException, ModuleException(Code)
PUTs the data into the specified file. The data is converted to an array of bytes using the lower byte of each character. The request ist sent using the content-type "application/octet-stream".
See Also:   java.lang.String.getBytes(intintbyte[]int)
Parameters:
  file - the absolute path of the file
Parameters:
  data - the data an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Put
public HTTPResponse Put(String file, String data, NVPair[] headers) throws IOException, ModuleException(Code)
PUTs the data into the specified file using the additional headers for the request.
Parameters:
  file - the absolute path of the file
Parameters:
  data - the data
Parameters:
  headers - additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Put
public HTTPResponse Put(String file, byte data) throws IOException, ModuleException(Code)
PUTs the raw data into the specified file. The request is sent using the content-type "application/octet-stream".
Parameters:
  file - the absolute path of the file
Parameters:
  data - the data an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Put
public HTTPResponse Put(String file, byte data, NVPair[] headers) throws IOException, ModuleException(Code)
PUTs the raw data into the specified file using the additional headers.
Parameters:
  file - the absolute path of the file
Parameters:
  data - the data
Parameters:
  headers - any additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Put
public HTTPResponse Put(String file, HttpOutputStream stream) throws IOException, ModuleException(Code)
PUTs the data written to the output stream into the specified file. The request is sent using the content-type "application/octet-stream".
Parameters:
  file - the absolute path of the file
Parameters:
  stream - the output stream on which the data is written an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Put
public HTTPResponse Put(String file, HttpOutputStream stream, NVPair[] headers) throws IOException, ModuleException(Code)
PUTs the data written to the output stream into the specified file using the additional headers.
Parameters:
  file - the absolute path of the file
Parameters:
  stream - the output stream on which the data is written
Parameters:
  headers - any additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



String2ProtVers
final static int String2ProtVers(String prot_vers)(Code)



Trace
public HTTPResponse Trace(String file, NVPair[] headers) throws IOException, ModuleException(Code)
Requests a TRACE. Headers of particular interest here are "Via" and "Max-Forwards".
Parameters:
  file - the absolute path of the resource
Parameters:
  headers - additional headers an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



Trace
public HTTPResponse Trace(String file) throws IOException, ModuleException(Code)
Requests a TRACE.
Parameters:
  file - the absolute path of the resource an HTTPResponse structure containing the response
exception:
  java.io.IOException - when an exception is returned fromthe socket.
exception:
  ModuleException - if an exception is encountered in any module.



addBasicAuthorization
public void addBasicAuthorization(String realm, String user, String passwd)(Code)
Adds an authorization entry for the "basic" authorization scheme to the list. If an entry already exists for the "basic" scheme and the specified realm then it is overwritten.

This is a convenience method and just invokes the corresponding method in AuthorizationInfo.
Parameters:
  realm - the realm
Parameters:
  user - the username
Parameters:
  passw - the password
See Also:   AuthorizationInfo.addBasicAuthorization(java.lang.Stringintjava.lang.Stringjava.lang.Stringjava.lang.String)




addDefaultModule
public static boolean addDefaultModule(Class module, int pos)(Code)
Adds a module to the default list. It must implement the HTTPClientModule interface. If the module is already in the list then this method does nothing.

Example:

 HTTPConnection.addDefaultModule(Class.forName("HTTPClient.CookieModule"), 1);
 
adds the cookie module as the second module in the list.

The default list is created at class initialization time from the property HTTPClient.Modules. This must contain a "|" separated list of classes in the order they're to be invoked. If this property is not set it defaults to: "HTTPClient.RetryModule | HTTPClient.CookieModule | HTTPClient.RedirectionModule | HTTPClient.AuthorizationModule | HTTPClient.DefaultModule | HTTPClient.TransferEncodingModule | HTTPClient.ContentMD5Module | HTTPClient.ContentEncodingModule"
See Also:   HTTPClientModule
Parameters:
  module - the module's Class object
Parameters:
  pos - the position of this module in the list; if pos>= 0 then this is the absolute position in the list (0 isthe first position); if pos < 0 then this isthe position relative to the end of the list (-1 meansthe last element, -2 the second to last element, etc). true if module was successfully added; false if themodule is already in the list.
exception:
  ArrayIndexOutOfBoundsException - if pos >list-size or if pos < -(list-size).
exception:
  ClassCastException - if module does notimplement the HTTPClientModule interface.
exception:
  RuntimeException - if module cannot beinstantiated.




addDigestAuthorization
public void addDigestAuthorization(String realm, String user, String passwd)(Code)
Adds an authorization entry for the "digest" authorization scheme to the list. If an entry already exists for the "digest" scheme and the specified realm then it is overwritten.

This is a convenience method and just invokes the corresponding method in AuthorizationInfo.
Parameters:
  realm - the realm
Parameters:
  user - the username
Parameters:
  passw - the password
See Also:   AuthorizationInfo.addDigestAuthorization(java.lang.Stringintjava.lang.Stringjava.lang.Stringjava.lang.String)




addModule
public boolean addModule(Class module, int pos)(Code)
Adds a module to the current list. It must implement the HTTPClientModule interface. If the module is already in the list then this method does nothing.
See Also:   HTTPClientModule
Parameters:
  module - the module's Class object
Parameters:
  pos - the position of this module in the list; if pos>= 0 then this is the absolute position in the list (0 isthe first position); if pos < 0 then this isthe position relative to the end of the list (-1 meansthe last element, -2 the second to last element, etc). true if module was successfully added; false if themodule is already in the list.
exception:
  ArrayIndexOutOfBoundsException - if pos >list-size or if pos < -(list-size).
exception:
  ClassCastException - if module does notimplement the HTTPClientModule interface.
exception:
  RuntimeException - if module cannot beinstantiated.



closeDemux
synchronized void closeDemux(IOException ioe, boolean was_reset)(Code)



doProxyFor
public static boolean doProxyFor(String host) throws ParseException(Code)
Remove host from the list of hosts for which the proxy should not be used. The syntax for host is specified in dontProxyFor().
Parameters:
  host - a host name, domain name, IP-address or IP-subnet. true if the remove was sucessful, false otherwise
exception:
  ParseException - if the length of the netmask does not matchthe length of the IP-address
See Also:   HTTPConnection.dontProxyFor(java.lang.String)



dontProxyFor
public static void dontProxyFor(String host) throws ParseException(Code)
Add host to the list of hosts which should be accessed directly, not via any proxy set by setProxyServer().

The host may be any of:

  • a complete host name (e.g. "www.disney.com")
  • a domain name; domain names must begin with a dot (e.g. ".disney.com")
  • an IP-address (e.g. "12.34.56.78")
  • an IP-subnet, specified as an IP-address and a netmask separated by a "/" (e.g. "34.56.78/255.255.255.192"); a 0 bit in the netmask means that that bit won't be used in the comparison (i.e. the addresses are AND'ed with the netmask before comparison).

The two properties HTTPClient.nonProxyHosts and http.nonProxyHosts are used when this class is loaded to initialize the list of non-proxy hosts. The second property is only read if the first one is not set; the second property is also used the JDK's URLConnection. These properties must contain a "|" separated list of entries which conform to the above rules for the host parameter (e.g. "11.22.33.44|.disney.com").
Parameters:
  host - a host name, domain name, IP-address or IP-subnet.
exception:
  ParseException - if the length of the netmask does not matchthe length of the IP-address




dontProxyFor
public static void dontProxyFor(String[] hosts)(Code)
Convenience method to add a number of hosts at once. If any one host is null or cannot be parsed it is ignored.
Parameters:
  hosts - The list of hosts to set
See Also:   HTTPConnection.dontProxyFor(java.lang.String)
since:
   V0.3-2



getAllowUserInteraction
public boolean getAllowUserInteraction()(Code)
returns whether modules are allowed to prompt or popup dialogs if neccessary. true if modules are allowed to interact with user.



getContext
public Object getContext()(Code)
Returns the current context.
See Also:   HTTPConnection.setContext(java.lang.Object) the current context, or the default context ifsetContext() hasn't been invoked



getDefaultAllowUserInteraction
public static boolean getDefaultAllowUserInteraction()(Code)
Gets the default allow-user-action. true if modules are allowed to interact with user.



getDefaultContext
static Object getDefaultContext()(Code)
Returns the default context.
See Also:   HTTPConnection.setContext(java.lang.Object) the default context



getDefaultHeaders
public NVPair[] getDefaultHeaders()(Code)
Gets the current list of default http headers. an array of header/value pairs.



getDefaultModules
public static Class[] getDefaultModules()(Code)
Returns the default list of modules. an array of classes



getDefaultTimeout
public static int getDefaultTimeout()(Code)
Gets the default timeout value to be used for each new HTTPConnection. the timeout in milliseconds.
See Also:   HTTPConnection.setTimeout(int)



getHost
public String getHost()(Code)
Returns the host this connection is talking to. a string containing the (lowercased) host name.



getModules
public Class[] getModules()(Code)
Returns the list of modules used currently. an array of classes



getPort
public int getPort()(Code)
Returns the port this connection connects to. This is always the actual port number, never -1. the port number



getProtocol
public String getProtocol()(Code)
Returns the protocol this connection is talking. a string containing the (lowercased) protocol



getProxyHost
public String getProxyHost()(Code)
Returns the host of the proxy this connection is using. a string containing the (lowercased) host name.



getProxyPort
public int getProxyPort()(Code)
Returns the port of the proxy this connection is using. the port number



getTimeout
public int getTimeout()(Code)
Gets the timeout used for reading response data. the current timeout value
See Also:   HTTPConnection.setTimeout(int)



handleFirstRequest
boolean handleFirstRequest(Request req, Response resp) throws IOException(Code)
The very first request is special in that we use it to figure out the protocol version the server (or proxy) is compliant with. true if all went fine, false if the request needs to be resent
exception:
  IOException - if any exception is thrown by the response



handleRequest
void handleRequest(Request req, HTTPResponse http_resp, Response resp, boolean usemodules) throws IOException, ModuleException(Code)
handles the Request. First the request handler for each module is is invoked, and then if no response was generated the request is sent.
Parameters:
  req - the Request
Parameters:
  http_resp - the HTTPResponse
Parameters:
  resp - the Response
Parameters:
  usemodules - if false then skip module loop
exception:
  IOException - if any module or sendRequest throws it
exception:
  ModuleException - if any module throws it



isCompatibleWith
public boolean isCompatibleWith(URI uri)(Code)
See if the given uri is compatible with this connection. Compatible means that the given uri can be retrieved using this connection object.
Parameters:
  uri - the URI to check true if they're compatible, false otherwise
since:
   V0.3-2



outputFinished
synchronized void outputFinished()(Code)



removeDefaultModule
public static boolean removeDefaultModule(Class module)(Code)
Removes a module from the default list. If the module is not in the list it does nothing.
Parameters:
  module - the module's Class object true if module was successfully removed; false otherwise



removeModule
public boolean removeModule(Class module)(Code)
Removes a module from the current list. If the module is not in the list it does nothing.
Parameters:
  module - the module's Class object true if module was successfully removed; false otherwise



sendRequest
Response sendRequest(Request req, int con_timeout) throws IOException, ModuleException(Code)
sends the request over the line.
Parameters:
  req - the request
Parameters:
  con_timeout - the timeout to use when establishing a socketconnection; an InterruptedIOException is thrownif the procedure times out. the response.
exception:
  IOException - if thrown by the socket
exception:
  InterruptedIOException - if the connection is not establishedwithin the specified timeout
exception:
  ModuleException - if any module throws it during the SSL-tunneling handshake



setAllowUserInteraction
public void setAllowUserInteraction(boolean allow)(Code)
Controls whether modules are allowed to prompt the user or pop up dialogs if neccessary.
Parameters:
  allow - if true allows modules to interact with user.



setContext
public void setContext(Object context)(Code)
Sets the current context. The context is used by modules such as the AuthorizationModule and the CookieModule which keep lists of info that is normally shared between all instances of HTTPConnection. This is usually the desired behaviour. However, in some cases one would like to simulate multiple independent clients within the same application and hence the sharing of such info should be restricted. This is where the context comes in. Modules will only share their info between requests using the same context (i.e. they keep multiple lists, one for each context).

The context may be any object. Contexts are considered equal if equals() returns true. Examples of useful context objects are threads (e.g. if you are running multiple clients, one per thread) and sockets (e.g. if you are implementing a gateway).

When a new HTTPConnection is created it is initialized with a default context which is the same for all instances. This method must be invoked immediately after a new HTTPConnection is created and before any request method is invoked. Furthermore, this method may only be called once (i.e. the context is "sticky").
Parameters:
  context - the new context; must be non-null
exception:
  IllegalArgumentException - if context is null
exception:
  RuntimeException - if the context has already been set




setCurrentProxy
public synchronized void setCurrentProxy(String host, int port)(Code)
Sets the proxy used by this instance. This can be used to override the proxy setting inherited from the default proxy setting. A null or empty string host parameter disables the proxy.

Note that if you set a proxy for the connection using this method, and a request made over this connection is redirected to a different server, then the connection used for new server will not pick this proxy setting, but instead will use the default proxy settings.
See Also:   HTTPConnection.setProxyServer(java.lang.String,int)
Parameters:
  host - the host the proxy runs on
Parameters:
  port - the port the proxy is listening on




setDefaultAllowUserInteraction
public static void setDefaultAllowUserInteraction(boolean allow)(Code)
Sets the default allow-user-action.
Parameters:
  allow - if true allows modules to interact with user.



setDefaultHeaders
public void setDefaultHeaders(NVPair[] headers)(Code)
Sets the default http headers to be sent with each request. The actual headers sent are determined as follows: for each header specified in multiple places a value given as part of the request takes priority over any default values set by this method, which in turn takes priority over any built-in default values. A different way of looking at it is that we start off with a list of all headers specified with the request, then add any default headers set by this method which aren't already in our list, and finally add any built-in headers which aren't yet in the list. There are two exceptions to this rule: "Content-length" and "Host" headers are always ignored; and when posting form-data any default "Content-type" is ignored in favor of the built-in "application/x-www-form-urlencoded" (however it will be overriden by any content-type header specified as part of the request).

Typical headers you might want to set here are "Accept" and its "Accept-*" relatives, "Connection", "From", "User-Agent", etc.
Parameters:
  headers - an array of header-name/value pairs (do not give theseparating ':').




setDefaultTimeout
public static void setDefaultTimeout(int time)(Code)
Sets the default timeout value to be used for each new HTTPConnection. The default is 0.
Parameters:
  time - the timeout in milliseconds.
See Also:   HTTPConnection.setTimeout(int)



setProxyServer
public static void setProxyServer(String host, int port)(Code)
Sets the default proxy server to use. The proxy will only be used for new HTTPConnections created after this call and will not affect currrent instances of HTTPConnection. A null or empty string host parameter disables the proxy.

In an application or using the Appletviewer an alternative to this method is to set the following properties (either in the properties file or on the command line): http.proxyHost and http.proxyPort. Whether http.proxyHost is set or not determines whether a proxy server is used.

If the proxy server requires authorization and you wish to set this authorization information in the code, then you may use any of the AuthorizationInfo.addXXXAuthorization() methods to do so. Specify the same host and port as in this method. If you have not given any authorization info and the proxy server requires authorization then you will be prompted for the necessary info via a popup the first time you do a request.
See Also:   HTTPConnection.setCurrentProxy(java.lang.String,int)
Parameters:
  host - the host on which the proxy server resides.
Parameters:
  port - the port the proxy server is listening on.




setRawMode
public void setRawMode(boolean raw)(Code)
Sets/Resets raw mode. In raw mode all modules are bypassed, meaning the automatic handling of authorization requests, redirections, cookies, etc. is turned off.

The default is false.
See Also:   HTTPConnection.removeModule(java.lang.Class)
Parameters:
  raw - if true removes all modules (except for the retry module)




setSocksServer
public static void setSocksServer(String host)(Code)
Sets the SOCKS server to use. The server will only be used for new HTTPConnections created after this call and will not affect currrent instances of HTTPConnection. A null or empty string host parameter disables SOCKS.

The code will try to determine the SOCKS version to use at connection time. This might fail for a number of reasons, however, in which case you must specify the version explicitly.
See Also:   HTTPConnection.setSocksServer(java.lang.String,int,int)
Parameters:
  host - the host on which the proxy server resides. The portused is the default port 1080.




setSocksServer
public static void setSocksServer(String host, int port)(Code)
Sets the SOCKS server to use. The server will only be used for new HTTPConnections created after this call and will not affect currrent instances of HTTPConnection. A null or empty string host parameter disables SOCKS.

The code will try to determine the SOCKS version to use at connection time. This might fail for a number of reasons, however, in which case you must specify the version explicitly.
See Also:   HTTPConnection.setSocksServer(java.lang.String,int,int)
Parameters:
  host - the host on which the proxy server resides.
Parameters:
  port - the port the proxy server is listening on.




setSocksServer
public static void setSocksServer(String host, int port, int version) throws SocksException(Code)
Sets the SOCKS server to use. The server will only be used for new HTTPConnections created after this call and will not affect currrent instances of HTTPConnection. A null or empty string host parameter disables SOCKS.

In an application or using the Appletviewer an alternative to this method is to set the following properties (either in the properties file or on the command line): HTTPClient.socksHost, HTTPClient.socksPort and HTTPClient.socksVersion. Whether HTTPClient.socksHost is set or not determines whether a SOCKS server is used; if HTTPClient.socksPort is not set it defaults to 1080; if HTTPClient.socksVersion is not set an attempt will be made to automatically determine the version used by the server.

Note: If you have also set a proxy server then a connection will be made to the SOCKS server, which in turn then makes a connection to the proxy server (possibly via other SOCKS servers), which in turn makes the final connection.

If the proxy server is running SOCKS version 5 and requires username/password authorization, and you wish to set this authorization information in the code, then you may use the AuthorizationInfo.addAuthorization() method to do so. Specify the same host and port as in this method, give the scheme "SOCKS5" and the realm "USER/PASS", set the cookie to null and the params to an array containing a single NVPair in turn containing the username and password. Example:

 NVPair[] up = { new NVPair(username, password) };
 AuthorizationInfo.addAuthorization(host, port, "SOCKS5", "USER/PASS",
 null, up);
 
If you have not given any authorization info and the proxy server requires authorization then you will be prompted for the necessary info via a popup the first time you do a request.
Parameters:
  host - the host on which the proxy server resides.
Parameters:
  port - the port the proxy server is listening on.
Parameters:
  version - the SOCKS version the server is running. Currentlythis must be '4' or '5'.
exception:
  SocksException - If version is not '4' or '5'.



setTimeout
public void setTimeout(int time)(Code)
Sets the timeout to be used for creating connections and reading responses. When a timeout expires the operation will throw an InterruptedIOException. The operation may be restarted again afterwards. If the operation is not restarted and it is a read operation (i.e HTTPResponse.xxxx()) then stop() should be invoked.

When creating new sockets the timeout will limit the time spent doing the host name translation and establishing the connection with the server.

The timeout also influences the reading of the response headers. However, it does not specify a how long, for example, getStatusCode() may take, as might be assumed. Instead it specifies how long a read on the socket may take. If the response dribbles in slowly with packets arriving quicker than the timeout then the method will complete normally. I.e. the exception is only thrown if nothing arrives on the socket for the specified time. Furthermore, the timeout only influences the reading of the headers, not the reading of the body.

Read Timeouts are associated with responses, so that you may change this value before each request and it won't affect the reading of responses to previous requests.

Note: The read timeout only works with JDK 1.1 or later. Using this method with JDK 1.0.2 or earlier will only influence the connection creation.
Parameters:
  time - the time in milliseconds. A time of 0 means waitindefinitely.
See Also:   HTTPConnection.stop()




stop
public void stop()(Code)
Aborts all the requests currently in progress on this connection and closes all associated sockets.

Note: there is a small window where a request method such as Get() may have been invoked but the request has not been built and added to the list. Any request in this window will not be aborted.
since:
   V0.2-3




toString
public String toString()(Code)
Generates a string of the form protocol://host.domain:port . the string



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.