# Using HTTP Methods to Set Properties

You can specify the behavior of an Http control in Design View by setting the control's properties in the Property Editor. The following attributes specify class- and method-level configuration attributes for the Http control.

This topic defines the various HTTP methods that you can use to specify properties. Each method is described briefly in Http Control Methods Table 10-1, and detailed in subsequent sections that are referenced to the methods outlined in the table.

You can use the following methods with the Http control:

Purpose of Method | Description | Method
--- | --- | ---
Setting Dynamic Http Control Properties. | This method sets the Http control properties at run time. Dynamic properties always override the static properties set in the Property Editor. |
    void setProperties(HttpControlPropertiesDocument propsDoc)
Setting Connection Time-out. | This method sets the connection time out for an HTTP request. Set this property to define the maximum time you want your Http control to establish a connection. A time-out value of zero (zero is the default value) indicates that the connection time-out has not been used. |
    void setConnectionTimeOut(int timeoutInMilliSeconds)
Setting Connection Retry Count. | This method defines the number of times your Http control will try to establish connection with the target. |
    void setConnectionRetrycount(int retryCount)
Setting Cookie | This method allows you to set cookies for your Http control |
    void setCookies(CookiesDocument cookies)
Configuring Proxy Settings. | This method allows you to specify proxy settings such as String host, initial port, String user name, and String password. |
    void setProxyConfig
    setProxyConfig (String host, int port, String userName, String password)
Configuring Server-side SSL | This property allows you to configure server-side Secure Socket Layer authentication process. |
    void setServerSideSSL(String trustStoreLocation, boolean hostVerificationFlag)
Configuring Client-side SSL | This property allows you to set client-side authentication. |
    void setClientSideSSL(String keyStoreType, String keyStoreLocation, String keyStorePassword, String keyPassword)
Sending an HTTP Get Request | This method allows you to send an HTTP request using the HTTP Get mode and receive the HTTP response code from the server. |
    ResponseDocument sendDataAsHttpGet(ParametersDocument parameters,String charset)
Setting Headers for HTTP Post | This method allows you to set the header properties for the HTTP Post mode. |
    void setHeadersForHttpPost(HeaderDocument headers)
Sending Data as HTTP Post | This method allows you to send body data as HTTP Post and receive the response code. Depending on the body data type that you select while configuring the Http control, the appropriate method is populated in the JCX file. |
    ResponseDocument sendDataAsHttpPost(String bodyData)
    ResponseDocument sendDataAsHttpPost (XmlObject bodyData)
    ResponseDocument sendDataAsHttpPost (byte[] bodyData)
Recieving HTTP Response Headers | This method allows you to get the headers of an HTTP response. |
    HeadersDocument getResponseHeaders()
Recieving Cookies From the Server | This method allows you to receive cookies from an HTTP response. |
    CookiesDocument getCookies()
Recieving HTTP Body Data | Depending on the body data type that you select while configuring the Http control, the appropriate method is populated in the JCX file. |
    String getResponseBodyAsString()
    XmlObject getResponseBodyAsXML()
    byte[] getResponseBodyAsBytes()

### Setting Dynamic Http Control Properties

Method: void setProperties(HttpControlPropertiesDocument propsDoc)

To use dynamic properties, pass an XML variable that conforms to the Http control's dynamic-property schema to the Http control's setProperties() method.

#### Example of an XML Variable to Set Dynamic Properties

    <?xml version="1.0" encoding="UTF-8"?>
    <xyz:HttpControlProperties xmlns:xyz="http://www.bea.com/wli/control/dynamicProperties">
    <xyz:URLName>http://localhost:7001/console</xyz:URLName>
    </xyz:HttpControlProperties>

#### Schema for Http Control Properties

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="http://www.bea.com/wli/control/dynamicProperties" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.bea.com/wli/control/dynamicProperties" elementFormDefault="qualified">
    <xs:element name="HttpControlProperties">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="URLName" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>

### Setting Connection Time-out

Method: setConnectionTimeOut (int timeoutInMilliSeconds)

This method sets the connection time out for an HTTP request. The connection time-out is maximum time that a control is allowed to establish a connection - the connection fails after this time elapses. The parameter time-out is set in milliseconds. A time-out value of zero (zero is the default value) indicates that the connection time-out has not been used.

### Setting Connection Retry Count

Method: setConnectionRetrycount (int retryCount)

This method sets the retry count, that is, the number of times your application will retry for the HTTP request. If this value is not specified, then the application will try to connect only once. If a connection is not established in the first try, the second attempt is likely to succeed. It is recommended that you set this property so that your HTTP requests go through in the second attempt, if not the first one.

### Configuring Server-side SSL

Method: setServerSideSSL (String trustStoreLocation, boolean hostVerificationFlag)

The Http control provides complete support for HTTP over Secure Sockets Layer (SSL) and Transport Layer Security (TLS), by leveraging the Java Secure Socket Extension (JSSE). JSSE is integrated into JDK1.4, which is shipped along with WebLogic Integration Platform.

When you run this method, the configuration for server-side authentication is set. By default, JSSE uses (jdk142_04\jre\lib\security\cacerts) as its Trust Store location, which includes some well-known certificate authorities such as Verisign and CyberTrust. Therefore, you do not need to specify any Trust Store locations for the certificates, which are issued by the certification authority.

Additionally, you can provide a host-name verification flag that ensures that the SSL session's server host-name matches with the host name returned in the server certificates Common Name field of the SubjectDN entry. By default this entry is set to False.

For example, if you specify https://www.verisign.com/ as the URL for authentication, you do not have to specify the Trust Store location, as Verisign is a trusted authority in certificates of JSSE.

To accept self-signed or SSL certificates that are not trusted, you need to import the server certificates into its Trust Store Location. For more information on JSSE, see the Java Secure Socket Extension (JSSE) Reference Guide at the following location:

http://java.sun.com/j2se/1.4.2/docs/guide/security/jsse/JSSERefGuide.html

The following example shows how to create a store, import a server certificate, and to specify the parameters for this method:

1. Run the following Keytool command to create a new Keystore.

keytool -genkey -alias aliasname -keyalg rsa -keystore keystore name

The following is an example of the command, including user-input values:

keytool -genkey -alias teststore -keyalg rsa -keystore c:\teststore.jks

For more information, see Creating a Keystore to Use with JSSE, at the following location:

http://java.sun.com/j2se/1.4.2/docs/guide/security/jsse/JSSERefGuide.html

2. Launch an HTTPS site to copy the certificate. For example, you can launch the WebLogic Server Console of the localhost or any other machine using the https://host:port/console format. When you are prompted for the server certificate, click the View Certificate button, navigate to the Details tab, and then click Copy to File.
3. Import the certificate that you copied to the Keystore that you created in Step 1, using the following command:

keytool -import -alias aliascertname -file certificatename -keystore keystore_name

For example:

keytool -import -alias testcer -file c:\test.cer -keystore c:\teststore.jks

4. In the setServerSideSSL method, specify the Trust Store location as C:\teststore.jks and the URL to which you send a request as https://host:port/console. To verify the host name, set the host-name verification flag as true.

### Configuring Client-side SSL

Method: setClientSideSSL (String keyStoreType, String keyStoreLocation, String keyStorePassword, String keyPassword)

This method sets the configuration for client-side authentication. You should use this method when both server-side and client-side authentication are required. Before configuring this method, you must configure Configuring Server-side SSL.

In this method, both the keyStoreType and keyPassword fields are optional. If you do not specify the keyStoreType, the method uses the default Keystore type (which is specified in the java.security file).

For some Keystores, the Keystore password differs from the key password. In such cases, you must specify both the Keystore password and key password.

If you want both server-side and client-side configuration, the server certificate should be in the Client Trust Store. Similarly, the client certificate should be in the Server Trust Store and the client should specify the Keystore location and passwords appropriately.

### Configuring Proxy Settings

Method: setProxyConfig (String host, int port, String userName, String password)

This method configures parameters for a proxy server. To send an HTTP request using a proxy server, you must properly configure the host, port, user name, and password.

Note: The Http control supports the Basic Scheme protocol. It does not support NTLM protocol. You need to configure your proxy settings accordingly.

### Setting Cookie

Method: setCookies(CookiesDocument cookies)

The Http control allows you to manually set the cookies sent to the server. To send cookies to the server with an HTTP request, you have to pass a XML variable that conforms to the Http control's cookies document schema.

#### Example: XML Variable Used to Set Cookies

    <?xml version="1.0" encoding="UTF-8"?>
    <Cookies xmlns="http://www.bea.com/wli/control/HttpCookies">
    <Cookie>
    <Name>CookieName1</Name>
    <Value>CookieValue1</Value>
    </Cookie>
    <Cookie>
    <Name>CookieName2</Name>
    <Value>CookieValue2</Value>
    </Cookie>
    </Cookies>

#### Schema for Setting Cookie

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.bea.com/wli/control/HttpCookies" elementFormDefault="qualified" targetNamespace="http://www.bea.com/wli/control/HttpCookies">
    <xs:element name="Cookies">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Cookie" minOccurs="0"
    maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Name" type="xs:string"
    minOccurs="0"/>
    <xs:element name="Value" type="xs:string" minOccurs="0"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>

### Setting Headers for HTTP Post

Method: setHeadersForHttpPost (HeadersDocument headers)

This method sets the request header for an HTTP Post. To set the request header, you have to pass an XML variable that conforms to the Http control's headers document schema. You can overwrite the default header's values by specifying them in the following manner:

User-agent, Content-Type, and so on.

#### Example: XML Variable Used to Set the Headers

    <?xml version="1.0" encoding="UTF-8"?>
    <xyz:Headers xmlns:xyz="http://www.bea.com/wli/control/HttpHeaders">
    <xyz:Header>
    <xyz:name>Content-Type</xyz:name>
    <xyz:value>text/*</xyz:value>
    </xyz:Header>
    <xyz:Header>
    <xyz:name>header</xyz:name>
    <xyz:value>h1</xyz:value>
    </xyz:Header>
    </xyz:Headers>

#### Schema for Setting HTTP Post Headers

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.bea.com/wli/control/HttpHeaders" elementFormDefault="qualified" targetNamespace="http://www.bea.com/wli/control/HttpHeaders">
    <xs:element name="Headers">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Header" minOccurs="0" maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="name" type="xs:string" minOccurs="0"/>
    <xs:element name="value" type="xs:string" minOccurs="0"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>

### Sending an HTTP Get Request

Method: ResponseDocument sendDataAsHttpGet(ParametersDocument parameters,String charset)

Use this method when you want to send an HTTP Get request. The Get request is mostly used for accessing static resources such as HTML documents from a Web Server and also can be used to retrieve dynamic information by using additional parameters in the request URL.

With Get requests, the request parameters are transmitted as a query string appended to the request URL. To include multi-byte character parameters in the URL, the Http control encodes the parameters to the characters as defined by the charset field of this method. If you do not specify any character set, then the Http control will send the parameter data URL encoded in "UTF-8". To send the parameters with a URL, you must pass the parameters in an XML variable that conforms to the Http control's parameter document schema.

#### Example: XML Variable Used to Set Parameters in HTTP Get

    <?xml version="1.0" encoding="UTF-8"?>
    <xyz:Parameters xmlns:xyz="http://www.bea.com/wli/control/HttpParameter"> <xyz:Parameter>
    <xyz:Name>Customer Id</xyz:Name>
    <xyz:Value>1000</xyz:Value>
    </xyz:Parameter>
    <xyz:Parameter>
    <xyz:Name>Customer Name</xyz:Name>
    <xyz:Value>Robert</xyz:Value>
    </xyz:Parameter>
    </xyz:Parameters>

#### Schema for Sending Parameters for HTTP Get

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.bea.com/wli/control/HttpParameter" elementFormDefault="qualified" targetNamespace="http://www.bea.com/wli/control/HttpParameter">
    <xs:element name="Parameters">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Parameter" minOccurs="0"
    maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Name" type="xs:string"
    minOccurs="0"/>
    <xs:element name="Value" type="xs:string"
    minOccurs="0"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>

### Sending Data as HTTP Post

Method: ResponseDocument sendDataAsHttpPost (String/XmlObject/byte[ ] bodyData)

Use the HTTP Post method to post data to a server. The Http control allows you to post data of three different data types: String, XmlObject, and byte.

The HTTP Post method returns the HTTP response, that is, the HTTP response code and corresponding message in a ResponseDocument. The schema of the response document is the same as described in Schema for Sending Parameters for HTTP Get.

HTTP Post requests are meant to transmit information that is request-dependent, and are used when you need to send large amounts of information to the server. The Http control allows you to post data of three different data types: String, XmlObject, and Byte stream.

In the HTTP protocol, servers and clients use MIME (Multipurpose Internet Mail Extensions) headers to indicate the type of content present in requests and responses. Http control also uses the MIME header(Content-Type), while transmitting data in body of the requests, to describe the type of data being sent. So while posting String or XmlObject data type, you should set the Content-Type header appropriately by using the Http control's setHeadersForHttpPost() method. The Content-Type header contains a charset attribute that indicates the character set of the message body.

If you do not set any charset attribute, then the Http control uses the default HTTP encoding (ISO-8859-1) to encode the message.

The following examples provide more information on how to send data using the HTTP Post mode:

Example 1 - Request body with String data-type

To post a string message of encoding Shift-JIS, you should set the charset attribute in the Content-Type request header, by calling the Http control's setHeadersForHttpPost method, as follows:

Content-type="text/*; charset=Shift-JIS"

Example 2 - Request body with XmlObject data type

While sending request messages of XML data type, you have to set the charset attribute in Content-Type header appropriately.

If you do not specify the character encoding in the Content-Type header, then the Http control uses the default encoding as specified in rfc3023.

For example, to post an XML document of encoding EUC-JP, you need to set the request type header as follows:

Content-Type="text/xml; charset=EUC-JP"

If you do not specify any charset attribute in the request header, the Http control uses us-ascii as default encoding to encode the message.

Note: To avoid garbling of body data while posting String or Xml data types, you should always specify the charset attribute in the Content-Type header.

The HTTP Post method returns the HTTP response, that is, the HTTP response code and corresponding message in a ResponseDocument. The schema of the response document is the same as described in Schema for Sending Parameters for HTTP Get.

### Recieving HTTP Response Headers

Method: HeadersDocument getResponseHeaders

Use this method to receive the HTTP response headers. The response headers are returned in an XML variable of a pre-defined schema.

The schema for the response headers is same as request headers schema described in Setting Headers for HTTP Post.

### Recieving Cookies From the Server

Method: CookiesDocument getCookies

Use this method to receive the cookies from the server. The cookies are returned in an XML document of a pre-defined schema.

The schema for the response cookies is same as the request cookies schema described in Schema for Setting Cookie.

### Recieving HTTP Body Data

Method: String getResponseBodyAsString / XmlObject getResponseBodyAsXml / byte[ ] getResponseBodyAsBytes

In HTTP, in response to a HTTP request, the server sends the body content that corresponds to the resource specified in the request. If you want to receive the response body data, then you should use this method.

The Http control can return the response data in three different data types: String, XmlObject, and Byte[]. You should set the response data type appropriately, depending upon the response data that you expect from the server. If the response body is not available or cannot be read, the control returns a null value.

Note: While parsing the response body of data type String or XmlObject, the Http control uses the character encoding specified in the Content-Type response header. If character encoding is not specified in the Content-Type header, the Http control uses the default HTTP content encoding ISO-8859-1 for String and US-ASCII encoding for XmlObject.

To avoid garbling of data, you should always set the charset attribute in the Content-Type response header.