com.sapportals.portal.ivs.http

Class HttpClient

java.lang.Object
  extended by com.sapportals.portal.ivs.http.HttpClient

public class HttpClient
extends Object

Title: iViewSever for SAP v6.0 Description: Copyright: Copyright (c) 2001 Company: SAP Ra'anana Israel


Field Summary
protected  HttpURLConnection m_httpCon
          The HttpURLConnection which was made by the client.
protected  URL m_url
           
protected  LinkedList reqPropertiesList
           
 
Constructor Summary
HttpClient()
          The construction initialize the post data
 
Method Summary
 void addPostData(String postData)
          Add Post Data
 void appendRequestProperty(String name, String value)
          Append a request property, if the property already exists the value given overrides the old value.
 void disconnect()
          Dissconnect the connection
 String getCookie()
          Get the cookie
 URL getCurrentURL()
          Return the url which the HttpClient object last retreived.
 String getHeaderFieldKey(int pos)
          after the send() method was called , use this method to get the HTTP header name by specifying the header position.
 String getResponseBody()
          after the send() method was called , use this method to get the HTTP response body text that was returned by the HTTP remote server.
 String getResponseHeader(int pos)
          after the send() method was called , use this method to get the HTTP header value by specifying the header position.
 String getResponseHeader(String headerName)
          after the send() method was called , use this method to get the HTTP header value by specifying the header name returned by the remote HTTP server.
 List getResponseHeaders()
          Return all the headers value in a list of String objects
 InputStream getResponseInputStream()
          return the entire server response in an InputStream.
 int getStatusCode()
          after the send() method was called , use this method to get the HTTP status code returned by the remote HTTP server.
 String getStatusMessage()
          after the send() method was called , use this method to get the HTTP status message returned by the remote HTTP server.
 void openConnection(String url)
          Opens a GET of PUT HTTP connection to a remote server according the method which was set before, default is GET.
 void openConnection(String method, String url)
          Opens a HTTP connection to a remote server
 void openConnection(String method, String url, String username, String password, Properties sslProps)
          Opens a HTTP connection to a remote server using basic authintication
 void openConnectionServerCert(String method, String url, Properties sslProps)
          Opens a HTTP connection to a remote server server certificate.
 void putBaseHerf(boolean set)
          Put the base href according the URL
 int send()
          Send the request to the remote server.
 void setCookie(String cookie)
          Set the cookie
 void setFollowRedirects(boolean set)
          Set Follow Redirects
 void setMethod(String method)
          Set method
 void setPassword(String password)
          Set the password to use in the next request for basic authintication.
 void setProxyServer(String proxyServer, int port)
          Set the proxy server and port to use if there is one.
 void setRequestProperties(Attribute[] reqProperties)
          Sets the request properties.
 void setRequestProperties(Attributes reqProperties)
          Deprecated. Please use setRequestProperties (Attribute[] reqProperties) for maintaining parameters order in the URL.
 void setRequestProperty(String headerName, String headerValue)
          Set the request header of a request, if the header already exists the value given overrides the old value.
 void setUsername(String user)
          Set the username to use in the next request for basic authintication.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_url

protected URL m_url

reqPropertiesList

protected LinkedList reqPropertiesList

m_httpCon

protected HttpURLConnection m_httpCon
The HttpURLConnection which was made by the client.

Constructor Detail

HttpClient

public HttpClient()
The construction initialize the post data

Method Detail

openConnection

public void openConnection(String url)
                    throws NullPointerException,
                           IOException
Opens a GET of PUT HTTP connection to a remote server according the method which was set before, default is GET.

Parameters:
url - the url to use in the HTTP request
Throws:
NullPointerException - if an null argument was sent
IOException - if the OpenConnection method failed.

openConnection

public void openConnection(String method,
                           String url)
                    throws NullPointerException,
                           IOException
Opens a HTTP connection to a remote server

Parameters:
method - the method to use in the url request. (GET,POST,PUT etc)
url - the url to use in the HTTP request
Throws:
NullPointerException - if an null argument was sent
IOException - if the OpenConnection method failed.

openConnection

public void openConnection(String method,
                           String url,
                           String username,
                           String password,
                           Properties sslProps)
                    throws IOException
Opens a HTTP connection to a remote server using basic authintication

Parameters:
method - the method to use in the url request. (GET,POST,PUT etc)
url - the url to use in the HTTP request
username - username to use in the request
password - password to use in the request
Throws:
NullPointerException - if an null argument was sent
IOException - if the OpenConnection method failed.

openConnectionServerCert

public void openConnectionServerCert(String method,
                                     String url,
                                     Properties sslProps)
                              throws IOException
Opens a HTTP connection to a remote server server certificate.

Parameters:
method - the method to use in the url request. (GET,POST,PUT etc)
url - the url to use in the HTTP request
Throws:
NullPointerException - if an null argument was sent
IOException - if the OpenConnection method failed.

disconnect

public void disconnect()
Dissconnect the connection


setRequestProperty

public void setRequestProperty(String headerName,
                               String headerValue)
                        throws HttpClientException
Set the request header of a request, if the header already exists the value given overrides the old value. to use ater the connection is opened

Parameters:
headerName - header name to add to the HTTP request headers
headerValue - header value to use with the header.
Throws:
HttpClientException

appendRequestProperty

public void appendRequestProperty(String name,
                                  String value)
                           throws HttpClientException
Append a request property, if the property already exists the value given overrides the old value. to use before the connection was opened

Parameters:
name - name to add to the HTTP request property.
value - value to use with the property.
Throws:
HttpClientException

setRequestProperties

public void setRequestProperties(Attributes reqProperties)
                          throws HttpClientException
Deprecated. Please use setRequestProperties (Attribute[] reqProperties) for maintaining parameters order in the URL.

Sets the request properties. to use before the connection was opened

Parameters:
reqProperties - Attributes to be add as request properties.
Throws:
HttpClientException

setRequestProperties

public void setRequestProperties(Attribute[] reqProperties)
                          throws HttpClientException
Sets the request properties. to use before the connection was opened

Parameters:
reqProperties - A set of Attribute objects to add as request properties. These Attribute objects are reffered as a pair of String 'key' and a String 'value' pairs.
Throws:
HttpClientException

send

public int send()
         throws IOException,
                HttpClientException
Send the request to the remote server. this method should be used only after openConnection(java.lang.String) method was called. to use ater the connection is opened Returns the status code of the http connection response.

Throws:
IOException
HttpClientException

getStatusCode

public int getStatusCode()
                  throws IOException,
                         HttpClientException
after the send() method was called , use this method to get the HTTP status code returned by the remote HTTP server. to use after the request was sent

Returns:
integer value of the status code
Throws:
IOException
HttpClientException

getStatusMessage

public String getStatusMessage()
                        throws IOException,
                               HttpClientException
after the send() method was called , use this method to get the HTTP status message returned by the remote HTTP server. to use after the request was sent

Returns:
String representation of the status code message
Throws:
IOException
HttpClientException

getResponseHeader

public String getResponseHeader(String headerName)
                         throws IOException,
                                HttpClientException
after the send() method was called , use this method to get the HTTP header value by specifying the header name returned by the remote HTTP server. to use after the request was sent

Parameters:
headerName - header name that we wish to get the value from
Returns:
the value of the specified header.
Throws:
IOException
HttpClientException

getResponseHeader

public String getResponseHeader(int pos)
                         throws IOException,
                                HttpClientException
after the send() method was called , use this method to get the HTTP header value by specifying the header position. to use after the request was sent

Parameters:
pos - header position in the list of headers that were returned by the remote server
Returns:
the value of the specified header by it's position.
Throws:
IOException
HttpClientException

getHeaderFieldKey

public String getHeaderFieldKey(int pos)
                         throws IOException,
                                HttpClientException
after the send() method was called , use this method to get the HTTP header name by specifying the header position. to use after the request was sent

Parameters:
pos - header position in the list of headers that were returned by the remote server
Returns:
the Name of the header according to it's postion.
Throws:
IOException
HttpClientException

getResponseBody

public String getResponseBody()
                       throws IOException
after the send() method was called , use this method to get the HTTP response body text that was returned by the HTTP remote server. to use after the request was sent

Returns:
the body text of the response.
Throws:
IOException

getResponseInputStream

public InputStream getResponseInputStream()
                                   throws IOException,
                                          HttpClientException
return the entire server response in an InputStream. to use after the request was sent

Returns:
InputStream of the Entire response.
Throws:
IOException
HttpClientException

setUsername

public void setUsername(String user)
Set the username to use in the next request for basic authintication.

Parameters:
user - username to set.

setPassword

public void setPassword(String password)
Set the password to use in the next request for basic authintication.

Parameters:
password - username to set.

setProxyServer

public void setProxyServer(String proxyServer,
                           int port)
                    throws NullPointerException,
                           IndexOutOfBoundsException
Set the proxy server and port to use if there is one.

Parameters:
proxyServer - - the name or IP address of the proxy server to use
port - - the port to connect to the proxy server.
Throws:
NullPointerException - thrown if a null reference is sent
IndexOutOfBoundsException

getResponseHeaders

public List getResponseHeaders()
                        throws HttpClientException
Return all the headers value in a list of String objects

Returns:
List of String objects
Throws:
HttpClientException

getCurrentURL

public URL getCurrentURL()
                  throws HttpClientException
Return the url which the HttpClient object last retreived.

Throws:
HttpClientException

getCookie

public String getCookie()
Get the cookie

Returns:
the cookie

setCookie

public void setCookie(String cookie)
Set the cookie

Parameters:
cookie -

setFollowRedirects

public void setFollowRedirects(boolean set)
Set Follow Redirects

Parameters:
set -

putBaseHerf

public void putBaseHerf(boolean set)
Put the base href according the URL

Parameters:
set -

addPostData

public void addPostData(String postData)
Add Post Data

Parameters:
postData -

setMethod

public void setMethod(String method)
Set method

Parameters:
method - GET or POST
Access Rights

This class can be accessed from:


SC DC Public Part ACH
[sap.com] EP-RUNTIME [sap.com] tc/ep/connectivity/services/api api EP-PIN


Copyright 2015 SAP AG Complete Copyright Notice