Java Doc for HttpURLConnection.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.net.HttpURLConnection
   HTTPClient.HttpURLConnection

HttpURLConnection
public class HttpURLConnection extends java.net.HttpURLConnection implements GlobalConstants(Code)
This class is a wrapper around HTTPConnection providing the interface defined by java.net.URLConnection and java.net.HttpURLConnection.

This class can be used to replace the HttpClient in the JDK with this HTTPClient by defining the property java.protocol.handler.pkgs=HTTPClient.

One difference between Sun's HttpClient and this one is that this one will provide you with a real output stream if possible. This leads to two changes: you should set the request property "Content-Length", if possible, before invoking getOutputStream(); and in many cases getOutputStream() implies connect(). This should be transparent, though, apart from the fact that you can't change any headers or other settings anymore once you've gotten the output stream. So, for large data do:

 HttpURLConnection con = (HttpURLConnection) url.openConnection();
 con.setDoOutput(true);
 con.setRequestProperty("Content-Length", ...);
 OutputStream out = con.getOutputStream();
 out.write(...);
 out.close();
 if (con.getResponseCode() != 200)
 ...
 

The HTTPClient will send the request data using the chunked transfer encoding when no Content-Length is specified and the server is HTTP/1.1 compatible. Because cgi-scripts can't usually handle this, you may experience problems trying to POST data. For this reason, whenever the Content-Type is application/x-www-form-urlencoded getOutputStream() will buffer the data before sending it so as prevent chunking. If you are sending requests with a different Content-Type and are experiencing problems then you may want to try setting the system property HTTPClient.dontChunkRequests to true (this needs to be done either on the command line or somewhere in the code before the first URLConnection.openConnection() is invoked).
version:
   0.3-2 18/06/1999
author:
   Ronald Tschalär
since:
   V0.3




Constructor Summary
public  HttpURLConnection(URL url)
     Construct a connection to the specified url.

Method Summary
public synchronized  voidconnect()
     Connects to the server (if connection not still kept alive) and issues the request.
public  voiddisconnect()
     Closes all the connections to this server.
public static  StringgetDefaultRequestProperty(String name)
     Gets the value for a given default request header.
Parameters:
  name - the name of the header.
public  InputStreamgetErrorStream()
     Returns the error stream if the connection failed but the server sent useful data nonetheless.
public  StringgetHeaderField(String name)
     Get the value part of a header.
public  StringgetHeaderField(int n)
     Gets header value of the n-th header.
public  longgetHeaderFieldDate(String name, long def)
     Get the value part of a header, interprets it as a date and converts it to a long representing the number of milliseconds since 1970.
public  intgetHeaderFieldInt(String name, int def)
     Get the value part of a header and converts it to an int.
public  StringgetHeaderFieldKey(int n)
     Gets header name of the n-th header.
public  InputStreamgetInputStream()
     Gets an input stream from which the data in the response may be read.
public  booleangetInstanceFollowRedirects()
    
public synchronized  OutputStreamgetOutputStream()
     Gets an output stream which can be used send an entity with the request.
public  StringgetRequestMethod()
     Return the request method used.
public  StringgetRequestProperty(String name)
     Gets the value of a given request header.
Parameters:
  name - the name of the header.
public  intgetResponseCode()
     Get the response code.
public  StringgetResponseMessage()
     Get the response message describing the response code.
public  URLgetURL()
     Gets the url for this connection.
public static  voidsetDefaultRequestProperty(String name, String value)
     Sets an arbitrary default request header.
public  voidsetIfModifiedSince(long time)
     Sets the If-Modified-Since header.
public  voidsetInstanceFollowRedirects(boolean set)
     Enables or disables the automatic handling of redirection responses for this instance only.
public  voidsetRequestMethod(String method)
     Sets the request method (e.g.
public  voidsetRequestProperty(String name, String value)
     Sets an arbitrary request header.
public  StringtoString()
     produces a string.
public  booleanusingProxy()
     Shows if request are being made through an http proxy or directly.


Constructor Detail
HttpURLConnection
public HttpURLConnection(URL url) throws ProtocolNotSuppException, IOException(Code)
Construct a connection to the specified url. A cache of HTTPConnections is used to maximize the reuse of these across multiple HttpURLConnections.
The default method is "GET".
Parameters:
  url - the url of the request
exception:
  ProtocolNotSuppException - if the protocol is not supported




Method Detail
connect
public synchronized void connect() throws IOException(Code)
Connects to the server (if connection not still kept alive) and issues the request.



disconnect
public void disconnect()(Code)
Closes all the connections to this server.



getDefaultRequestProperty
public static String getDefaultRequestProperty(String name)(Code)
Gets the value for a given default request header.
Parameters:
  name - the name of the header. the value part of the header, or null if no such header.



getErrorStream
public InputStream getErrorStream()(Code)
Returns the error stream if the connection failed but the server sent useful data nonetheless.

This method will not cause a connection to be initiated. an InputStream, or null if either the connection hasn'tbeen established yet or no error occured
See Also:   java.net.HttpURLConnection.getErrorStream
since:
   V0.3-1




getHeaderField
public String getHeaderField(String name)(Code)
Get the value part of a header. Calls connect() if not connected.
Parameters:
  name - the of the header. the value of the header, or null if no such header was returned.



getHeaderField
public String getHeaderField(int n)(Code)
Gets header value of the n-th header. Calls connect() if not connected. The value of 0-th header is the Status-Line (e.g. "HTTP/1.1 200 Ok").
Parameters:
  n - which header to return. the header value, or null if not that many headers.



getHeaderFieldDate
public long getHeaderFieldDate(String name, long def)(Code)
Get the value part of a header, interprets it as a date and converts it to a long representing the number of milliseconds since 1970. If the header does not exist or if its value could not be converted to a date then the default is returned. Calls connect() if not connected.
Parameters:
  name - the of the header.
Parameters:
  def - the default value to return in case of an error. the value of the header, or def in case of an error.



getHeaderFieldInt
public int getHeaderFieldInt(String name, int def)(Code)
Get the value part of a header and converts it to an int. If the header does not exist or if its value could not be converted to an int then the default is returned. Calls connect() if not connected.
Parameters:
  name - the of the header.
Parameters:
  def - the default value to return in case of an error. the value of the header, or null if no such header was returned.



getHeaderFieldKey
public String getHeaderFieldKey(int n)(Code)
Gets header name of the n-th header. Calls connect() if not connected. The name of the 0-th header is null, even though it the 0-th header has a value.
Parameters:
  n - which header to return. the header name, or null if not that many headers.



getInputStream
public InputStream getInputStream() throws IOException(Code)
Gets an input stream from which the data in the response may be read. Calls connect() if not connected. an InputStream
exception:
  ProtocolException - if input not enabled.
See Also:   java.net.URLConnection.setDoInput(boolean)



getInstanceFollowRedirects
public boolean getInstanceFollowRedirects()(Code)
true if automatic redirection handling for this instance isenabled.



getOutputStream
public synchronized OutputStream getOutputStream() throws IOException(Code)
Gets an output stream which can be used send an entity with the request. Can be called multiple times, in which case always the same stream is returned.

The default request method changes to "POST" when this method is called. Cannot be called after connect().

If no Content-type has been set it defaults to application/x-www-form-urlencoded. Furthermore, if the Content-type is application/x-www-form-urlencoded then all output will be collected in a buffer before sending it to the server; otherwise an HttpOutputStream is used. an OutputStream
exception:
  ProtocolException - if already connect()'ed, if output is notenabled or if the request method does notsupport output.
See Also:   java.net.URLConnection.setDoOutput(boolean)
See Also:   HTTPClient.HttpOutputStream




getRequestMethod
public String getRequestMethod()(Code)
Return the request method used. the http method.



getRequestProperty
public String getRequestProperty(String name)(Code)
Gets the value of a given request header.
Parameters:
  name - the name of the header. the value part of the header, or null if no such header.



getResponseCode
public int getResponseCode() throws IOException(Code)
Get the response code. Calls connect() if not connected. the http response code returned.



getResponseMessage
public String getResponseMessage() throws IOException(Code)
Get the response message describing the response code. Calls connect() if not connected. the http response message returned with the response code.



getURL
public URL getURL()(Code)
Gets the url for this connection. If we're connect()'d and the request was redirected then the url returned is that of the final request. the final url, or null if any exception occured.



setDefaultRequestProperty
public static void setDefaultRequestProperty(String name, String value)(Code)
Sets an arbitrary default request header. All headers set here are automatically sent with each request.
Parameters:
  name - the name of the header.
Parameters:
  value - the value for the header.



setIfModifiedSince
public void setIfModifiedSince(long time)(Code)
Sets the If-Modified-Since header.
Parameters:
  time - the number of milliseconds since 1970.



setInstanceFollowRedirects
public void setInstanceFollowRedirects(boolean set)(Code)
Enables or disables the automatic handling of redirection responses for this instance only. Cannot be called after connect().
Parameters:
  set - enables automatic redirection handling if true.



setRequestMethod
public void setRequestMethod(String method) throws ProtocolException(Code)
Sets the request method (e.g. "PUT" or "HEAD"). Can only be set before connect() is called.
Parameters:
  method - the http method.
exception:
  ProtocolException - if already connected.



setRequestProperty
public void setRequestProperty(String name, String value)(Code)
Sets an arbitrary request header.
Parameters:
  name - the name of the header.
Parameters:
  value - the value for the header.



toString
public String toString()(Code)
produces a string. a string containing the HttpURLConnection



usingProxy
public boolean usingProxy()(Code)
Shows if request are being made through an http proxy or directly. true if an http proxy is being used.



Fields inherited from java.net.HttpURLConnection
final public static int HTTP_ACCEPTED(Code)(Java Doc)
final public static int HTTP_BAD_GATEWAY(Code)(Java Doc)
final public static int HTTP_BAD_METHOD(Code)(Java Doc)
final public static int HTTP_BAD_REQUEST(Code)(Java Doc)
final public static int HTTP_CLIENT_TIMEOUT(Code)(Java Doc)
final public static int HTTP_CONFLICT(Code)(Java Doc)
final public static int HTTP_CREATED(Code)(Java Doc)
final public static int HTTP_ENTITY_TOO_LARGE(Code)(Java Doc)
final public static int HTTP_FORBIDDEN(Code)(Java Doc)
final public static int HTTP_GATEWAY_TIMEOUT(Code)(Java Doc)
final public static int HTTP_GONE(Code)(Java Doc)
final public static int HTTP_INTERNAL_ERROR(Code)(Java Doc)
final public static int HTTP_LENGTH_REQUIRED(Code)(Java Doc)
final public static int HTTP_MOVED_PERM(Code)(Java Doc)
final public static int HTTP_MOVED_TEMP(Code)(Java Doc)
final public static int HTTP_MULT_CHOICE(Code)(Java Doc)
final public static int HTTP_NOT_ACCEPTABLE(Code)(Java Doc)
final public static int HTTP_NOT_AUTHORITATIVE(Code)(Java Doc)
final public static int HTTP_NOT_FOUND(Code)(Java Doc)
final public static int HTTP_NOT_IMPLEMENTED(Code)(Java Doc)
final public static int HTTP_NOT_MODIFIED(Code)(Java Doc)
final public static int HTTP_NO_CONTENT(Code)(Java Doc)
final public static int HTTP_OK(Code)(Java Doc)
final public static int HTTP_PARTIAL(Code)(Java Doc)
final public static int HTTP_PAYMENT_REQUIRED(Code)(Java Doc)
final public static int HTTP_PRECON_FAILED(Code)(Java Doc)
final public static int HTTP_PROXY_AUTH(Code)(Java Doc)
final public static int HTTP_REQ_TOO_LONG(Code)(Java Doc)
final public static int HTTP_RESET(Code)(Java Doc)
final public static int HTTP_SEE_OTHER(Code)(Java Doc)
final public static int HTTP_SERVER_ERROR(Code)(Java Doc)
final public static int HTTP_UNAUTHORIZED(Code)(Java Doc)
final public static int HTTP_UNAVAILABLE(Code)(Java Doc)
final public static int HTTP_UNSUPPORTED_TYPE(Code)(Java Doc)
final public static int HTTP_USE_PROXY(Code)(Java Doc)
final public static int HTTP_VERSION(Code)(Java Doc)
protected int chunkLength(Code)(Java Doc)
protected int fixedContentLength(Code)(Java Doc)
protected boolean instanceFollowRedirects(Code)(Java Doc)
protected String method(Code)(Java Doc)
protected int responseCode(Code)(Java Doc)
protected String responseMessage(Code)(Java Doc)

Methods inherited from java.net.HttpURLConnection
abstract public void disconnect()(Code)(Java Doc)
public InputStream getErrorStream()(Code)(Java Doc)
public static boolean getFollowRedirects()(Code)(Java Doc)
public String getHeaderField(int n)(Code)(Java Doc)
public long getHeaderFieldDate(String name, long Default)(Code)(Java Doc)
public String getHeaderFieldKey(int n)(Code)(Java Doc)
public boolean getInstanceFollowRedirects()(Code)(Java Doc)
public Permission getPermission() throws IOException(Code)(Java Doc)
public String getRequestMethod()(Code)(Java Doc)
public int getResponseCode() throws IOException(Code)(Java Doc)
public String getResponseMessage() throws IOException(Code)(Java Doc)
public void setChunkedStreamingMode(int chunklen)(Code)(Java Doc)
public void setFixedLengthStreamingMode(int contentLength)(Code)(Java Doc)
public static void setFollowRedirects(boolean set)(Code)(Java Doc)
public void setInstanceFollowRedirects(boolean followRedirects)(Code)(Java Doc)
public void setRequestMethod(String method) throws ProtocolException(Code)(Java Doc)
abstract public boolean usingProxy()(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.