com.nexaweb.client.netservice
Interface HttpResponse
- public interface HttpResponse
HttpResponse is an incoming response from an HTTP client.
|
Method Summary |
byte[] |
getContent()
Returns the body of the message. |
java.lang.String |
getHeader(java.lang.String headerName)
Returns the value of the HTTP header with the given name. |
java.lang.String[] |
getHeaderNames()
Returns an array of all the HTTP header names. |
java.io.InputStream |
getInputStream()
Returns an input stream which provides response content
from the internal buffer. |
long |
getLastModified()
Returns the value of the Last-Modified header. |
int |
getResponseCode()
Returns the response code, for example
500 (internal server error) or 200 (ok). |
java.lang.String |
getUri()
Returns the uri indicating the origin of the message. |
getInputStream
public java.io.InputStream getInputStream()
- Returns an input stream which provides response content
from the internal buffer.
- Returns:
- the input stream
getResponseCode
public int getResponseCode()
- Returns the response code, for example
500 (internal server error) or 200 (ok). Other typical
response code can be 404 (file not found), or
503 (service unavailable).
Response code is not always accurate due to
the JVM browser plugin implentations vary.
The basic rules are:
- All successful requests(http or classpath://) return a 200.
There are rare cases where URLConnection doens't return a response code,
neither throw an exception, like Netscape 6.2 + 1.3 SSL.
In this case, it's set to 200. We can't tell if the request
is successful or not.
- When there is a connection problem,
and the URLConnection throws ConnectException
or ProtocolException, it's set to 503. If the url is in classpath:// format,
if the returned bytes is null, it's set to 404.
- If the client JVM is 1.3+, 404, 4xx and 500 response code set on the server
usually can be retrieved. If the response code is not available,
it's set to 503.
- If the client JVM is Netscape 4.x 1.1, the response code is typically not
available when there is an IO exception. It's set to 500.
- If it's MS JVM 1.1 and retrieve a relative url without content, it's set to 500.
- If it's MS JVM 1.1 and retrieve a relative url with a content, for
FileNotFoundException or IOException type exception, it's set to 500;
for ConnectException type exception, it's set to 503.
- With certain 1.4.2 JVMs, URLConnection returns 500 code even server
returns 404. it's set back to 404.
In general, if you wants to rely on resposne code, please keep in mind these guidelines:
- If there is an error, you can NOT rely much on it with MS JVM or Netscape 4.x JVM
- With JDK 1.3+ if the server is setting an error status code, it's usually returned
back to you correctly.
- With JDK 1.3+, if there is a connection problem, URLConnection can't get a response
code successfuly. So it's set to 503, HttpURLConnection.HTTP_UNAVAILABLE.
It's error prone to use string matching from the error messages
to detect a more appropriate response code. So we bascially set it to 503.
- Returns:
- The response code.
getHeader
public java.lang.String getHeader(java.lang.String headerName)
- Returns the value of the HTTP header with the given name.
- Parameters:
headerName - The name of the header.
- Returns:
- The value of the header.
getHeaderNames
public java.lang.String[] getHeaderNames()
- Returns an array of all the HTTP header names.
- Returns:
- An array of header names.
If the HTTP response code is available it will
appear as a header named "status".
getContent
public byte[] getContent()
- Returns the body of the message. If it's a multipart message, the contents
of the preamble (the part of the body before the first part separator)
will be returned.
- Returns:
- byte[] of the body content.
getUri
public java.lang.String getUri()
- Returns the uri indicating the origin of the message.
getLastModified
public long getLastModified()
- Returns the value of the Last-Modified header.
- Returns:
- The last modified date for this response or -1 if not available.
Copyright © 2005 Nexaweb Technologies, Inc. All Rights Reserved.