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 File control.

This topic defines the various Http methods that you can use to specify properties. Each method is described briefly in Table 8-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 defines the exact time in milliseconds, by which server connection should time out. Set this property to define how long you want your Http control to wait for a response.

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 Policies

This method allows you to set cookie policies 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 

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 return Http response code.

ResponseDocument sendDataAsHttpGet(ParametersDocument parameters) 

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 Using Http Post



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.

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> 

Note: Using the Dynamic Properties feature, you can modify only the URL during run time. Other properties can be modified using the Property Editor.

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, the application will 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 WLI 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 (\jdk141_03\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 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.
  2. 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.

  3. 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.
  4. Import the certificate that you copied to the Keystore that you created in Step 1, using the following command:
  5. keytool -import -alias <aliascertname> -file <certificatename> -keystore <keystore name>

    For example:

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

  6. 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 that the Http control supports the Basic Scheme protocol. It does not support NTLM protocol. You need to configure your proxy settings accordingly.

Setting Cookie Policies

Method: Cookies (CookiesDocument cookies)

The Http control allows you to manually set the cookies sent to the server. There are several standards for handling cookies, such as the Netscape Cookie Draft, RFC2109, RFC2965 and a large number of vendor specific implementations. The Http control uses the default cookie policy of the Http client, which is the compatibility policy. To send the cookies to an Http request, you have to pass an XML variable that conforms to the Http control's cookies document schema:

Schema for Setting Cookie Policies

<?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> 

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> 

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.

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> 

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> 

Sending an Http Get request

Method: ResponseDocument sendDataAsHttpGet (ParametersDocument parameters)

Use this method when you want to send an Http request as Http Get and receive a response. Typically, the Get method is used to download a document from a Web server. You can also send Http Get parameters with a URL, by passing the parameters in an XML variable that conforms to the Http control's parameter document schema, as follows:

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> 

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> 

Recieving Http Response Code Using Http Get

The ResponseDocument sendDataAsHttpGet (ParametersDocument parameters) method returns the Http response, that is, the Http response code and corresponding message back in a ResponseDocument.

The Schema of the Response Document for Http Get

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema targetNamespace="Http://www.bea.com/wli/control/HttpResponse" xmlns:xs="Http://www.w3.org/2001/XMLSchema" xmlns="Http://www.bea.com/wli/control/HttpResponse" elementFormDefault="qualified"> 
   <xs:element name="Response"> 
      <xs:complexType> 
         <xs:sequence> 
            <xs:element name="ResponseCode" type="xs:int"/> 
            <xs:element name="ResponseMessage" type="xs:string"/> 
         </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 The Schema of the Response Document 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 inSetting 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 Policies.

Recieving Http Body Data Using Http Post

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

The Http control can return response data in three different data types: String, XmlObject, and byte. Therefore, when you create an Http control using the Post mode, you must select the response body data type that you want. If the response body type that you select in the Creating a New WLI Http Control process is not available or cannot be read, you will receive a null value for body type, and the default body type will be returned.

Note: When the response body data is read as a string value, the Http control uses the character encoding in the Content specified in the Content-Type header. If the character encoding is not -1, then the Http control using the default Http content encoding (ISO-8859-Type header.

This indicates that the server should appropriately set the response headers for the Content-Type. For example:

Content-type="text/xml; charset=ISO-8859-1"

Previous Document Next Document